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