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
00021 class CbcModel;
00022 class CbcTree;
00023 class CbcCompareBase {
00024 public:
00025
00026 CbcCompareBase () {test_=NULL;};
00027
00028
00029
00030 virtual void newSolution(CbcModel * model) {};
00031
00032
00033
00034 virtual void newSolution(CbcModel * model,
00035 double objectiveAtContinuous,
00036 int numberInfeasibilitiesAtContinuous) {};
00037
00038
00039
00040
00041 virtual bool every1000Nodes(CbcModel * model,int numberNodes) {return false;};
00042
00046 virtual bool fullScan() const { return false;};
00047
00048 virtual ~CbcCompareBase() {};
00050 virtual void generateCpp( FILE * fp) {};
00051
00052
00053 CbcCompareBase ( const CbcCompareBase & rhs)
00054 {test_=rhs.test_;};
00055
00056
00057 CbcCompareBase & operator=( const CbcCompareBase& rhs)
00058 { if (this!=&rhs) {test_=rhs.test_;}
00059 return *this;
00060 };
00061
00063 virtual CbcCompareBase * clone() const=0;
00064
00066 virtual bool test (CbcNode * x, CbcNode * y) {return true;};
00067
00069 virtual bool alternateTest (CbcNode * x, CbcNode * y) {return test(x,y);};
00070
00071 bool operator() (CbcNode * x, CbcNode * y) {
00072 return test(x,y);
00073 }
00075 inline bool equalityTest (CbcNode * x, CbcNode * y) const
00076 {
00077 assert (x);
00078 CbcNodeInfo * infoX = x->nodeInfo();
00079 assert (infoX);
00080 int nodeNumberX = infoX->nodeNumber();
00081 assert (y);
00082 CbcNodeInfo * infoY = y->nodeInfo();
00083 assert (infoY);
00084 int nodeNumberY = infoY->nodeNumber();
00085 assert (nodeNumberX!=nodeNumberY);
00086 return (nodeNumberX>nodeNumberY);
00087 };
00088 protected:
00089 CbcCompareBase * test_;
00090 };
00091 class CbcCompare {
00092 public:
00093 CbcCompareBase * test_;
00094
00095 CbcCompare () {test_=NULL;};
00096
00097 virtual ~CbcCompare() {};
00098
00099 bool operator() (CbcNode * x, CbcNode * y) {
00100 return test_->test(x,y);
00101 }
00103 inline bool alternateTest (CbcNode * x, CbcNode * y) {return test_->alternateTest(x,y);};
00104
00106 inline CbcCompareBase * comparisonObject() const
00107 { return test_;};
00108 };
00109
00110
00111
00112
00113
00114 class CbcChooseVariable {
00115 public:
00116
00117 CbcChooseVariable () {};
00118
00119 virtual ~CbcChooseVariable() {};
00125 virtual int chosen (const CbcModel * model,int numberToLookAt,
00126 const int * which, const double * downMovement,
00127 const double * upMovement, const double * solution,
00128 int & way, double & value)=0;
00129
00130 };
00131 #endif