source: branches/devel/Cbc/src/CbcCompareBase.hpp @ 592

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

many changes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 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
21class CbcModel;
22class CbcTree;
23class CbcCompareBase {
24public:
25  // Default Constructor
26  CbcCompareBase () {test_=NULL;};
27
28  // This allows any method to change behavior as it is called
29  // after each solution
30  virtual void newSolution(CbcModel * model) {};
31
32  // This Also allows any method to change behavior as it is called
33  // after each solution
34  virtual void newSolution(CbcModel * model,
35                           double objectiveAtContinuous,
36                           int numberInfeasibilitiesAtContinuous) {};
37
38  // This allows any method to change behavior as it is called
39  // after every 1000 nodes.
40  // Return true if want tree re-sorted
41  virtual bool every1000Nodes(CbcModel * model,int numberNodes) {return false;};
42
43  /** Returns true if wants code to do scan with alternate criterion
44      NOTE - this is temporarily disabled
45  */
46  virtual bool fullScan() const { return false;};
47
48  virtual ~CbcCompareBase() {};
49  /// Create C++ lines to get to current state
50  virtual void generateCpp( FILE * fp) {};
51
52  // Copy constructor
53  CbcCompareBase ( const CbcCompareBase & rhs)
54  {test_=rhs.test_;};
55   
56  // Assignment operator
57  CbcCompareBase & operator=( const CbcCompareBase& rhs)
58  {  if (this!=&rhs) {test_=rhs.test_;}
59  return *this;
60  };
61
62  /// Clone
63  virtual CbcCompareBase * clone() const=0;
64
65  /// This is test function
66  virtual bool test (CbcNode * x, CbcNode * y) {return true;};
67
68  /// This is alternate test function
69  virtual bool alternateTest (CbcNode * x, CbcNode * y) {return test(x,y);};
70
71  bool operator() (CbcNode * x, CbcNode * y) {
72    return test(x,y);
73  }
74  /// Further test if everything else equal
75  inline bool equalityTest (CbcNode * x, CbcNode * y) const
76  {
77    assert (x);
78    CbcNodeInfo * infoX = x->nodeInfo();
79    assert (infoX);
80    int nodeNumberX = infoX->nodeNumber();
81    assert (y);
82    CbcNodeInfo * infoY = y->nodeInfo();
83    assert (infoY);
84    int nodeNumberY = infoY->nodeNumber();
85    assert (nodeNumberX!=nodeNumberY);
86    return (nodeNumberX>nodeNumberY);
87  };
88protected:
89  CbcCompareBase * test_;
90};
91class CbcCompare {
92public:
93  CbcCompareBase * test_;
94  // Default Constructor
95  CbcCompare () {test_=NULL;};
96
97  virtual ~CbcCompare() {};
98
99  bool operator() (CbcNode * x, CbcNode * y) {
100    return test_->test(x,y);
101  }
102  /// This is alternate test function
103  inline bool alternateTest (CbcNode * x, CbcNode * y) {return test_->alternateTest(x,y);};
104
105  /// return comparison object
106  inline CbcCompareBase * comparisonObject() const
107  { return test_;};
108};
109//#############################################################################
110/*  These can be alternative strategies for choosing variables
111    Any descendant can be passed in by setVariableChoice
112*/
113
114class CbcChooseVariable {
115public:
116  // Default Constructor
117  CbcChooseVariable () {};
118
119  virtual ~CbcChooseVariable() {};
120  /** If strong branching, then only those passed in (and movement is that length)
121      .  If not strong
122      branching then all passed in and ignore movement.
123      Returns which one chosen (or -1 if none).  way should be +1
124      if branching up, -1 if down */
125  virtual int chosen (const CbcModel * model,int numberToLookAt,
126                      const int * which, const double * downMovement,
127                      const double * upMovement, const double * solution,
128                      int & way, double & value)=0;
129
130};
131#endif
Note: See TracBrowser for help on using the repository browser.