source: trunk/Cbc/src/CbcCompareBase.hpp @ 724

Last change on this file since 724 was 724, checked in by forrest, 13 years ago

try and fix heap problem

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1// Copyright (C) 2002, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#ifndef CbcCompareBase_H
4#define CbcCompareBase_H
5
6
7//#############################################################################
8/*  These are alternative strategies for node traversal. 
9    They can take data etc for fine tuning
10
11    At present the node list is stored as a heap and the "test"
12    comparison function returns true if node y is better than node x.
13
14    This is rather inflexible so if the comparison functions wants
15    it can signal to use alternative criterion on a complete pass
16    throgh tree.
17
18*/
19#include "CbcNode.hpp"
20#include "CbcConfig.h"
21
22class CbcModel;
23class CbcTree;
24class CbcCompareBase {
25public:
26  // Default Constructor
27  CbcCompareBase () {test_=NULL;}
28
29  // This allows any method to change behavior as it is called
30  // after each solution
31  virtual void newSolution(CbcModel * model) {}
32
33  // This Also allows any method to change behavior as it is called
34  // after each solution
35  virtual void newSolution(CbcModel * model,
36                           double objectiveAtContinuous,
37                           int numberInfeasibilitiesAtContinuous) {}
38
39  // This allows any method to change behavior as it is called
40  // after every 1000 nodes.
41  // Return true if want tree re-sorted
42  virtual bool every1000Nodes(CbcModel * model,int numberNodes) {return false;}
43
44  /** Returns true if wants code to do scan with alternate criterion
45      NOTE - this is temporarily disabled
46  */
47  virtual bool fullScan() const { return false;}
48
49  virtual ~CbcCompareBase() {}
50  /// Create C++ lines to get to current state
51  virtual void generateCpp( FILE * fp) {}
52
53  // Copy constructor
54  CbcCompareBase ( const CbcCompareBase & rhs)
55  {test_=rhs.test_;}
56   
57  // Assignment operator
58  CbcCompareBase & operator=( const CbcCompareBase& rhs)
59  {  if (this!=&rhs) {test_=rhs.test_;}
60  return *this;
61  }
62
63  /// Clone
64  virtual CbcCompareBase * clone() const
65  { abort(); return NULL;}
66
67  /// This is test function
68  virtual bool test (CbcNode * x, CbcNode * y) {return true;}
69
70  /// This is alternate test function
71  virtual bool alternateTest (CbcNode * x, CbcNode * y) {return test(x,y);}
72
73  bool operator() (CbcNode * x, CbcNode * y) {
74    return test(x,y);
75  }
76  /// Further test if everything else equal
77  inline bool equalityTest (CbcNode * x, CbcNode * y) const
78  {
79    assert (x);
80    assert (y);
81#ifndef CBC_THREAD
82    CbcNodeInfo * infoX = x->nodeInfo();
83    assert (infoX);
84    int nodeNumberX = infoX->nodeNumber();
85    CbcNodeInfo * infoY = y->nodeInfo();
86    assert (infoY);
87    int nodeNumberY = infoY->nodeNumber();
88    assert (nodeNumberX!=nodeNumberY);
89    return (nodeNumberX>nodeNumberY);
90#else
91    // doesn't work if threaded
92    assert (x!=y);
93    return (x>y);
94#endif
95  }
96protected:
97  CbcCompareBase * test_;
98};
99class CbcCompare {
100public:
101  CbcCompareBase * test_;
102  // Default Constructor
103  CbcCompare () {test_=NULL;}
104
105  virtual ~CbcCompare() {}
106
107  bool operator() (CbcNode * x, CbcNode * y) {
108    return test_->test(x,y);
109  }
110  bool compareNodes (CbcNode * x, CbcNode * y) {
111    return test_->test(x,y);
112  }
113  /// This is alternate test function
114  inline bool alternateTest (CbcNode * x, CbcNode * y) {return test_->alternateTest(x,y);}
115
116  /// return comparison object
117  inline CbcCompareBase * comparisonObject() const
118  { return test_;}
119};
120//#############################################################################
121/*  These can be alternative strategies for choosing variables
122    Any descendant can be passed in by setVariableChoice
123*/
124
125class CbcChooseVariable {
126public:
127  // Default Constructor
128  CbcChooseVariable () {}
129
130  virtual ~CbcChooseVariable() {}
131  /** If strong branching, then only those passed in (and movement is that length)
132      .  If not strong
133      branching then all passed in and ignore movement.
134      Returns which one chosen (or -1 if none).  way should be +1
135      if branching up, -1 if down */
136  virtual int chosen (const CbcModel * model,int numberToLookAt,
137                      const int * which, const double * downMovement,
138                      const double * upMovement, const double * solution,
139                      int & way, double & value)=0;
140
141};
142#endif
Note: See TracBrowser for help on using the repository browser.