Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
build
buildd
coinor-cbc-2.5.0
Cbc
src
CbcCompareBase.hpp
Go to the documentation of this file.
1
/* $Id: CbcCompareBase.hpp 1400 2009-12-11 14:14:06Z lou $ */
2
// Copyright (C) 2002, International Business Machines
3
// Corporation and others. All Rights Reserved.
4
#ifndef CbcCompareBase_H
5
#define CbcCompareBase_H
6
7
8
//#############################################################################
9
/* These are alternative strategies for node traversal.
10
They can take data etc for fine tuning
11
12
At present the node list is stored as a heap and the "test"
13
comparison function returns true if node y is better than node x.
14
15
This is rather inflexible so if the comparison functions wants
16
it can signal to use alternative criterion on a complete pass
17
throgh tree.
18
19
*/
20
#include "
CbcNode.hpp
"
21
#include "
CbcConfig.h
"
22
23
class
CbcModel
;
24
class
CbcTree
;
25
class
CbcCompareBase
{
26
public
:
27
// Default Constructor
28
CbcCompareBase
() {
29
test_
= NULL;
30
threaded_
=
false
;
31
}
32
33
// This allows any method to change behavior as it is called
34
// after each solution
35
virtual
void
newSolution
(
CbcModel
* ) {}
36
37
// This Also allows any method to change behavior as it is called
38
// after each solution
39
virtual
void
newSolution
(
CbcModel
* ,
40
double
,
41
int
) {}
42
43
// This allows any method to change behavior as it is called
44
// after every 1000 nodes.
45
// Return true if want tree re-sorted
46
virtual
bool
every1000Nodes
(
CbcModel
* ,
int
) {
47
return
false
;
48
}
49
53
virtual
bool
fullScan
()
const
{
54
return
false
;
55
}
56
57
virtual
~CbcCompareBase
() {}
59
virtual
void
generateCpp
( FILE * ) {}
60
61
// Copy constructor
62
CbcCompareBase
(
const
CbcCompareBase
& rhs) {
63
test_
= rhs.
test_
;
64
threaded_
= rhs.
threaded_
;
65
}
66
67
// Assignment operator
68
CbcCompareBase
&
operator=
(
const
CbcCompareBase
& rhs) {
69
if
(
this
!= &rhs) {
70
test_
= rhs.
test_
;
71
threaded_
= rhs.
threaded_
;
72
}
73
return
*
this
;
74
}
75
77
virtual
CbcCompareBase
*
clone
()
const
{
78
abort();
79
return
NULL;
80
}
81
83
virtual
bool
test
(
CbcNode
* ,
CbcNode
* ) {
84
return
true
;
85
}
86
88
virtual
bool
alternateTest
(
CbcNode
* x,
CbcNode
* y) {
89
return
test
(x, y);
90
}
91
92
bool
operator()
(
CbcNode
* x,
CbcNode
* y) {
93
return
test
(x, y);
94
}
96
inline
bool
equalityTest
(
CbcNode
* x,
CbcNode
* y)
const
{
97
assert (x);
98
assert (y);
99
if
(!
threaded_
) {
100
CbcNodeInfo
* infoX = x->
nodeInfo
();
101
assert (infoX);
102
int
nodeNumberX = infoX->
nodeNumber
();
103
CbcNodeInfo
* infoY = y->
nodeInfo
();
104
assert (infoY);
105
int
nodeNumberY = infoY->
nodeNumber
();
106
assert (nodeNumberX != nodeNumberY);
107
return
(nodeNumberX > nodeNumberY);
108
}
else
{
109
assert (x->
nodeNumber
() != y->
nodeNumber
());
110
return
(x->
nodeNumber
() > y->
nodeNumber
());
111
}
112
}
114
inline
void
sayThreaded
() {
115
threaded_
=
true
;
116
}
117
protected
:
118
CbcCompareBase
*
test_
;
119
// If not threaded we can use better way to break ties
120
bool
threaded_
;
121
};
122
123
#endif
124
Generated on Fri Jun 29 2012 06:31:52 by
1.8.1.1