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;threaded_=false;}
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_;threaded_=rhs.threaded_;}
00056
00057
00058 CbcCompareBase & operator=( const CbcCompareBase& rhs)
00059 { if (this!=&rhs) {test_=rhs.test_;threaded_=rhs.threaded_;}
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 if (!threaded_) {
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 assert (x->nodeNumber()!=y->nodeNumber());
00092 return (x->nodeNumber()>y->nodeNumber());
00093 }
00094 }
00096 inline void sayThreaded()
00097 { threaded_ = true;}
00098 protected:
00099 CbcCompareBase * test_;
00100
00101 bool threaded_;
00102 };
00103 class CbcCompare {
00104 public:
00105 CbcCompareBase * test_;
00106
00107 CbcCompare () {test_=NULL;}
00108
00109 virtual ~CbcCompare() {}
00110
00111 bool operator() (CbcNode * x, CbcNode * y) {
00112 return test_->test(x,y);
00113 }
00114 bool compareNodes (CbcNode * x, CbcNode * y) {
00115 return test_->test(x,y);
00116 }
00118 inline bool alternateTest (CbcNode * x, CbcNode * y) {return test_->alternateTest(x,y);}
00119
00121 inline CbcCompareBase * comparisonObject() const
00122 { return test_;}
00123 };
00124
00125
00126
00127
00128
00129 class CbcChooseVariable {
00130 public:
00131
00132 CbcChooseVariable () {}
00133
00134 virtual ~CbcChooseVariable() {}
00140 virtual int chosen (const CbcModel * model,int numberToLookAt,
00141 const int * which, const double * downMovement,
00142 const double * upMovement, const double * solution,
00143 int & way, double & value)=0;
00144
00145 };
00146 #endif