00001
00002
00003 #ifndef CbcCompareBase_H
00004 #define CbcCompareBase_H
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "CbcNode.hpp"
00020 #include "CbcConfig.h"
00021
00022 class CbcModel;
00023 class CbcTree;
00024 class CbcCompareBase {
00025 public:
00026
00027 CbcCompareBase () {test_=NULL;}
00028
00029
00030
00031 virtual void newSolution(CbcModel * model) {}
00032
00033
00034
00035 virtual void newSolution(CbcModel * model,
00036 double objectiveAtContinuous,
00037 int numberInfeasibilitiesAtContinuous) {}
00038
00039
00040
00041
00042 virtual bool every1000Nodes(CbcModel * model,int numberNodes) {return false;}
00043
00047 virtual bool fullScan() const { return false;}
00048
00049 virtual ~CbcCompareBase() {}
00051 virtual void generateCpp( FILE * fp) {}
00052
00053
00054 CbcCompareBase ( const CbcCompareBase & rhs)
00055 {test_=rhs.test_;}
00056
00057
00058 CbcCompareBase & operator=( const CbcCompareBase& rhs)
00059 { if (this!=&rhs) {test_=rhs.test_;}
00060 return *this;
00061 }
00062
00064 virtual CbcCompareBase * clone() const
00065 { abort(); return NULL;}
00066
00068 virtual bool test (CbcNode * x, CbcNode * y) {return true;}
00069
00071 virtual bool alternateTest (CbcNode * x, CbcNode * y) {return test(x,y);}
00072
00073 bool operator() (CbcNode * x, CbcNode * y) {
00074 return test(x,y);
00075 }
00077 inline bool equalityTest (CbcNode * x, CbcNode * y) const
00078 {
00079 assert (x);
00080 assert (y);
00081 #ifndef CBC_THREAD
00082 CbcNodeInfo * infoX = x->nodeInfo();
00083 assert (infoX);
00084 int nodeNumberX = infoX->nodeNumber();
00085 CbcNodeInfo * infoY = y->nodeInfo();
00086 assert (infoY);
00087 int nodeNumberY = infoY->nodeNumber();
00088 assert (nodeNumberX!=nodeNumberY);
00089 return (nodeNumberX>nodeNumberY);
00090 #else
00091
00092 assert (x!=y);
00093 return (x>y);
00094 #endif
00095 }
00096 protected:
00097 CbcCompareBase * test_;
00098 };
00099 class CbcCompare {
00100 public:
00101 CbcCompareBase * test_;
00102
00103 CbcCompare () {test_=NULL;}
00104
00105 virtual ~CbcCompare() {}
00106
00107 bool operator() (CbcNode * x, CbcNode * y) {
00108 return test_->test(x,y);
00109 }
00110 bool compareNodes (CbcNode * x, CbcNode * y) {
00111 return test_->test(x,y);
00112 }
00114 inline bool alternateTest (CbcNode * x, CbcNode * y) {return test_->alternateTest(x,y);}
00115
00117 inline CbcCompareBase * comparisonObject() const
00118 { return test_;}
00119 };
00120
00121
00122
00123
00124
00125 class CbcChooseVariable {
00126 public:
00127
00128 CbcChooseVariable () {}
00129
00130 virtual ~CbcChooseVariable() {}
00136 virtual int chosen (const CbcModel * model,int numberToLookAt,
00137 const int * which, const double * downMovement,
00138 const double * upMovement, const double * solution,
00139 int & way, double & value)=0;
00140
00141 };
00142 #endif