Cbc  2.10.5
 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 2465 2019-01-03 19:26:52Z unxusr $ */
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 
24 class CbcModel;
25 class CbcTree;
27 public:
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 
146 protected:
148  // If not threaded we can use better way to break ties
149  bool threaded_;
150 };
151 
152 #endif
153 
154 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
155 */
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:52
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:215
int nodeNumber() const
The node number.
Definition: CbcNode.hpp:300
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:100
void sayThreaded()
Say threaded.
CbcCompareBase * test_
virtual bool alternateTest(CbcNode *x, CbcNode *y)
This is alternate test function.
CbcCompareBase(const CbcCompareBase &rhs)