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

Last change on this file since 648 was 642, checked in by forrest, 12 years ago

update branches/devel for threads

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 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=0;
65
66  /// This is test function
67  virtual bool test (CbcNode * x, CbcNode * y) {return true;};
68
69  /// This is alternate test function
70  virtual bool alternateTest (CbcNode * x, CbcNode * y) {return test(x,y);};
71
72  bool operator() (CbcNode * x, CbcNode * y) {
73    return test(x,y);
74  }
75  /// Further test if everything else equal
76  inline bool equalityTest (CbcNode * x, CbcNode * y) const
77  {
78    assert (x);
79    assert (y);
80#ifndef CBC_THREAD
81    CbcNodeInfo * infoX = x->nodeInfo();
82    assert (infoX);
83    int nodeNumberX = infoX->nodeNumber();
84    CbcNodeInfo * infoY = y->nodeInfo();
85    assert (infoY);
86    int nodeNumberY = infoY->nodeNumber();
87    assert (nodeNumberX!=nodeNumberY);
88    return (nodeNumberX>nodeNumberY);
89#else
90    // doesn't work if threaded
91    assert (x!=y);
92    return (x>y);
93#endif
94  };
95protected:
96  CbcCompareBase * test_;
97};
98class CbcCompare {
99public:
100  CbcCompareBase * test_;
101  // Default Constructor
102  CbcCompare () {test_=NULL;};
103
104  virtual ~CbcCompare() {};
105
106  bool operator() (CbcNode * x, CbcNode * y) {
107    return test_->test(x,y);
108  }
109  /// This is alternate test function
110  inline bool alternateTest (CbcNode * x, CbcNode * y) {return test_->alternateTest(x,y);};
111
112  /// return comparison object
113  inline CbcCompareBase * comparisonObject() const
114  { return test_;};
115};
116//#############################################################################
117/*  These can be alternative strategies for choosing variables
118    Any descendant can be passed in by setVariableChoice
119*/
120
121class CbcChooseVariable {
122public:
123  // Default Constructor
124  CbcChooseVariable () {};
125
126  virtual ~CbcChooseVariable() {};
127  /** If strong branching, then only those passed in (and movement is that length)
128      .  If not strong
129      branching then all passed in and ignore movement.
130      Returns which one chosen (or -1 if none).  way should be +1
131      if branching up, -1 if down */
132  virtual int chosen (const CbcModel * model,int numberToLookAt,
133                      const int * which, const double * downMovement,
134                      const double * upMovement, const double * solution,
135                      int & way, double & value)=0;
136
137};
138#endif
Note: See TracBrowser for help on using the repository browser.