Cbc  2.9.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CbcCompareBase.hpp
Go to the documentation of this file.
1 /* $Id: CbcCompareBase.hpp 1573 2011-01-05 01:12:36Z lou $ */
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 //#############################################################################
11 /* These are alternative strategies for node traversal.
12  They can take data etc for fine tuning
13 
14  At present the node list is stored as a heap and the "test"
15  comparison function returns true if node y is better than node x.
16 
17  This is rather inflexible so if the comparison functions wants
18  it can signal to use alternative criterion on a complete pass
19  throgh tree.
20 
21 */
22 #include "CbcNode.hpp"
23 #include "CbcConfig.h"
24 
25 class CbcModel;
26 class CbcTree;
28 public:
29  // Default Constructor
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  return false;
66  }
67 
71  virtual bool fullScan() const {
72  return false;
73  }
74 
75  virtual ~CbcCompareBase() {}
77  virtual void generateCpp( FILE * ) {}
78 
79  // Copy constructor
80  CbcCompareBase ( const CbcCompareBase & rhs) {
81  test_ = rhs.test_;
82  threaded_ = rhs.threaded_;
83  }
84 
85  // Assignment operator
87  if (this != &rhs) {
88  test_ = rhs.test_;
89  threaded_ = rhs.threaded_;
90  }
91  return *this;
92  }
93 
95  virtual CbcCompareBase * clone() const {
96  abort();
97  return NULL;
98  }
99 
101  virtual bool test (CbcNode * , CbcNode * ) {
102  return true;
103  }
104 
106  virtual bool alternateTest (CbcNode * x, CbcNode * y) {
107  return test(x, y);
108  }
109 
110  bool operator() (CbcNode * x, CbcNode * y) {
111  return test(x, y);
112  }
114  inline bool equalityTest (CbcNode * x, CbcNode * y) const {
115  assert (x);
116  assert (y);
117  if (!threaded_) {
118  CbcNodeInfo * infoX = x->nodeInfo();
119  assert (infoX);
120  int nodeNumberX = infoX->nodeNumber();
121  CbcNodeInfo * infoY = y->nodeInfo();
122  assert (infoY);
123  int nodeNumberY = infoY->nodeNumber();
124  assert (nodeNumberX != nodeNumberY);
125  return (nodeNumberX > nodeNumberY);
126  } else {
127  assert (x->nodeNumber() != y->nodeNumber());
128  return (x->nodeNumber() > y->nodeNumber());
129  }
130  }
132  inline void sayThreaded() {
133  threaded_ = true;
134  }
135 protected:
137  // If not threaded we can use better way to break ties
138  bool threaded_;
139 };
140 
141 #endif
142 
CbcCompareBase & operator=(const CbcCompareBase &rhs)
virtual bool test(CbcNode *, CbcNode *)
This is test function.
virtual bool newSolution(CbcModel *, double, int)
Reconsider behaviour after discovering a new solution.
virtual bool newSolution(CbcModel *)
Reconsider behaviour after discovering a new solution.
bool equalityTest(CbcNode *x, CbcNode *y) const
Further test if everything else equal.
virtual CbcCompareBase * clone() const
Clone.
Using MS heap implementation.
Definition: CbcTree.hpp:53
virtual ~CbcCompareBase()
virtual bool fullScan() const
Returns true if wants code to do scan with alternate criterion NOTE - this is temporarily disabled...
virtual void generateCpp(FILE *)
Create C++ lines to get to current state.
Information required while the node is live.
Definition: CbcNode.hpp:49
virtual bool every1000Nodes(CbcModel *, int)
CbcNodeInfo * nodeInfo() const
Definition: CbcNode.hpp:216
int nodeNumber() const
The node number.
Definition: CbcNode.hpp:286
Information required to recreate the subproblem at this node.
Definition: CbcNodeInfo.hpp:68
bool operator()(CbcNode *x, CbcNode *y)
int nodeNumber() const
The node number.
Simple Branch and bound class.
Definition: CbcModel.hpp:101
void sayThreaded()
Say threaded.
CbcCompareBase * test_
virtual bool alternateTest(CbcNode *x, CbcNode *y)
This is alternate test function.
CbcCompareBase(const CbcCompareBase &rhs)