Cbc 2.10.11
Loading...
Searching...
No Matches
CbcCompareBase.hpp
Go to the documentation of this file.
1/* $Id$ */
2// Copyright (C) 2002, International Business Machines
3// Corporation and others. All Rights Reserved.
4// This code is licensed under the terms of the Eclipse Public License (EPL).
5
6#ifndef CbcCompareBase_H
7#define CbcCompareBase_H
8
9//#############################################################################
10/* These are alternative strategies for node traversal.
11 They can take data etc for fine tuning
12
13 At present the node list is stored as a heap and the "test"
14 comparison function returns true if node y is better than node x.
15
16 This is rather inflexible so if the comparison functions wants
17 it can signal to use alternative criterion on a complete pass
18 throgh tree.
19
20*/
21#include "CbcNode.hpp"
22#include "CbcConfig.h"
23
24class CbcModel;
25class CbcTree;
27public:
28 // Default Constructor
30 {
31 test_ = NULL;
32 threaded_ = false;
33 }
34
45 virtual bool newSolution(CbcModel *) { return (false); }
46
57 virtual bool newSolution(CbcModel *,
58 double,
59 int) { return (false); }
60
61 // This allows any method to change behavior as it is called
62 // after every 1000 nodes.
63 // Return true if want tree re-sorted
64 virtual bool every1000Nodes(CbcModel *, int)
65 {
66 return false;
67 }
68
72 virtual bool fullScan() const
73 {
74 return false;
75 }
76
77 virtual ~CbcCompareBase() {}
79 virtual void generateCpp(FILE *) {}
80
81 // Copy constructor
83 {
84 test_ = rhs.test_;
85 threaded_ = rhs.threaded_;
86 }
87
88 // Assignment operator
90 {
91 if (this != &rhs) {
92 test_ = rhs.test_;
93 threaded_ = rhs.threaded_;
94 }
95 return *this;
96 }
97
99 virtual CbcCompareBase *clone() const
100 {
101 abort();
102 return NULL;
103 }
104
106 virtual bool test(CbcNode *, CbcNode *)
107 {
108 return true;
109 }
110
112 virtual bool alternateTest(CbcNode *x, CbcNode *y)
113 {
114 return test(x, y);
115 }
116
118 {
119 return test(x, y);
120 }
122 inline bool equalityTest(CbcNode *x, CbcNode *y) const
123 {
124 assert(x);
125 assert(y);
126 if (!threaded_) {
127 CbcNodeInfo *infoX = x->nodeInfo();
128 assert(infoX);
129 int nodeNumberX = infoX->nodeNumber();
130 CbcNodeInfo *infoY = y->nodeInfo();
131 assert(infoY);
132 int nodeNumberY = infoY->nodeNumber();
133 assert(nodeNumberX != nodeNumberY);
134 return (nodeNumberX > nodeNumberY);
135 } else {
136 assert(x->nodeNumber() != y->nodeNumber());
137 return (x->nodeNumber() > y->nodeNumber());
138 }
139 }
141 inline void sayThreaded()
142 {
143 threaded_ = true;
144 }
145
146protected:
148 // If not threaded we can use better way to break ties
150};
151
152#endif
153
154/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
155*/
virtual bool alternateTest(CbcNode *x, CbcNode *y)
This is alternate test function.
virtual bool test(CbcNode *, CbcNode *)
This is test function.
CbcCompareBase & operator=(const CbcCompareBase &rhs)
virtual CbcCompareBase * clone() const
Clone.
bool operator()(CbcNode *x, CbcNode *y)
virtual ~CbcCompareBase()
bool equalityTest(CbcNode *x, CbcNode *y) const
Further test if everything else equal.
CbcCompareBase * test_
virtual void generateCpp(FILE *)
Create C++ lines to get to current state.
virtual bool fullScan() const
Returns true if wants code to do scan with alternate criterion NOTE - this is temporarily disabled.
virtual bool newSolution(CbcModel *)
Reconsider behaviour after discovering a new solution.
CbcCompareBase(const CbcCompareBase &rhs)
virtual bool every1000Nodes(CbcModel *, int)
void sayThreaded()
Say threaded.
virtual bool newSolution(CbcModel *, double, int)
Reconsider behaviour after discovering a new solution.
Simple Branch and bound class.
Definition CbcModel.hpp:100
Information required to recreate the subproblem at this node.
int nodeNumber() const
The node number.
Information required while the node is live.
Definition CbcNode.hpp:49
CbcNodeInfo * nodeInfo() const
Definition CbcNode.hpp:215
int nodeNumber() const
The node number.
Definition CbcNode.hpp:300
Using MS heap implementation.
Definition CbcTree.hpp:52