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

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

for more repeatable runs and OsiPseudoCost?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 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;threaded_=false;}
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_;threaded_=rhs.threaded_;}
56   
57  // Assignment operator
58  CbcCompareBase & operator=( const CbcCompareBase& rhs)
59  {  if (this!=&rhs) {test_=rhs.test_;threaded_=rhs.threaded_;}
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    if (!threaded_) {
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    }
95  }
96  /// Say threaded
97  inline void sayThreaded()
98  { threaded_ = true;}
99protected:
100  CbcCompareBase * test_;
101  // If not threaded we can use better way to break ties
102  bool threaded_;
103};
104class CbcCompare {
105public:
106  CbcCompareBase * test_;
107  // Default Constructor
108  CbcCompare () {test_=NULL;}
109
110  virtual ~CbcCompare() {}
111
112  bool operator() (CbcNode * x, CbcNode * y) {
113    return test_->test(x,y);
114  }
115  bool compareNodes (CbcNode * x, CbcNode * y) {
116    return test_->test(x,y);
117  }
118  /// This is alternate test function
119  inline bool alternateTest (CbcNode * x, CbcNode * y) {return test_->alternateTest(x,y);}
120
121  /// return comparison object
122  inline CbcCompareBase * comparisonObject() const
123  { return test_;}
124};
125//#############################################################################
126/*  These can be alternative strategies for choosing variables
127    Any descendant can be passed in by setVariableChoice
128*/
129
130class CbcChooseVariable {
131public:
132  // Default Constructor
133  CbcChooseVariable () {}
134
135  virtual ~CbcChooseVariable() {}
136  /** If strong branching, then only those passed in (and movement is that length)
137      .  If not strong
138      branching then all passed in and ignore movement.
139      Returns which one chosen (or -1 if none).  way should be +1
140      if branching up, -1 if down */
141  virtual int chosen (const CbcModel * model,int numberToLookAt,
142                      const int * which, const double * downMovement,
143                      const double * upMovement, const double * solution,
144                      int & way, double & value)=0;
145
146};
147#endif
Note: See TracBrowser for help on using the repository browser.