00001 // Copyright (C) 2002, International Business Machines 00002 // Corporation and others. All Rights Reserved. 00003 #ifndef CbcCompareActual_H 00004 #define CbcCompareActual_H 00005 00006 00007 //############################################################################# 00008 /* These are alternative strategies for node traversal. 00009 They can take data etc for fine tuning 00010 00011 At present the node list is stored as a heap and the "test" 00012 comparison function returns true if node y is better than node x. 00013 00014 */ 00015 #include "CbcNode.hpp" 00016 #include "CbcCompareBase.hpp" 00017 class CbcModel; 00018 // This is default before first solution 00019 class CbcCompareDepth : public CbcCompareBase{ 00020 public: 00021 // Default Constructor 00022 CbcCompareDepth () ; 00023 00024 ~CbcCompareDepth(); 00025 // Copy constructor 00026 CbcCompareDepth ( const CbcCompareDepth &rhs); 00027 00028 // Assignment operator 00029 CbcCompareDepth & operator=( const CbcCompareDepth& rhs); 00030 00032 virtual CbcCompareBase * clone() const; 00034 virtual void generateCpp( FILE * fp); 00035 00036 // This returns true if the depth of node y is greater than depth of node x 00037 virtual bool test (CbcNode * x, CbcNode * y); 00038 }; 00039 class CbcCompareObjective : public CbcCompareBase { 00040 public: 00041 // Default Constructor 00042 CbcCompareObjective (); 00043 00044 virtual ~CbcCompareObjective(); 00045 // Copy constructor 00046 CbcCompareObjective ( const CbcCompareObjective &rhs); 00047 00048 // Assignment operator 00049 CbcCompareObjective & operator=( const CbcCompareObjective& rhs); 00050 00052 virtual CbcCompareBase * clone() const; 00054 virtual void generateCpp( FILE * fp); 00055 00056 /* This returns true if objective value of node y is less than 00057 objective value of node x */ 00058 virtual bool test (CbcNode * x, CbcNode * y); 00059 }; 00060 /* This is an example of a more complex rule with data 00061 It is default after first solution 00062 If weight is 0.0 then it is computed to hit first solution 00063 less 5% 00064 */ 00065 class CbcCompareDefault : public CbcCompareBase { 00066 public: 00067 // Default Constructor 00068 CbcCompareDefault () ; 00069 // Constructor with weight 00070 CbcCompareDefault (double weight); 00071 00072 // Copy constructor 00073 CbcCompareDefault ( const CbcCompareDefault &rhs); 00074 00075 // Assignment operator 00076 CbcCompareDefault & operator=( const CbcCompareDefault& rhs); 00077 00079 virtual CbcCompareBase * clone() const; 00081 virtual void generateCpp( FILE * fp); 00082 00083 ~CbcCompareDefault() ; 00084 /* This returns true if weighted value of node y is less than 00085 weighted value of node x */ 00086 virtual bool test (CbcNode * x, CbcNode * y) ; 00087 00088 using CbcCompareBase::newSolution ; 00089 // This allows method to change behavior as it is called 00090 // after each solution 00091 virtual void newSolution(CbcModel * model, 00092 double objectiveAtContinuous, 00093 int numberInfeasibilitiesAtContinuous) ; 00094 // This allows method to change behavior 00095 // Return true if want tree re-sorted 00096 virtual bool every1000Nodes(CbcModel * model,int numberNodes); 00097 00098 /* if weight == -1.0 then fewest infeasibilities (before solution) 00099 if -2.0 then do breadth first just for first 1000 nodes 00100 if -3.0 then depth first before solution 00101 */ 00102 inline double getWeight() const 00103 { return weight_;} 00104 inline void setWeight(double weight) 00105 { weight_ = weight;} 00107 inline double getCutoff() const 00108 { return cutoff_;} 00109 inline void setCutoff(double cutoff) 00110 { cutoff_ = cutoff;} 00112 inline double getBestPossible() const 00113 { return bestPossible_;} 00114 inline void setBestPossible(double bestPossible) 00115 { bestPossible_ = bestPossible;} 00116 // Depth above which want to explore first 00117 inline void setBreadthDepth(int value) 00118 { breadthDepth_ = value;} 00119 protected: 00120 // Weight for each infeasibility 00121 double weight_; 00122 // Weight for each infeasibility - computed from solution 00123 double saveWeight_; 00125 double cutoff_; 00127 double bestPossible_; 00128 // Number of solutions 00129 int numberSolutions_; 00130 // Tree size (at last check) 00131 int treeSize_; 00132 // Depth above which want to explore first 00133 int breadthDepth_; 00134 }; 00135 00136 /* This is when rounding is being done 00137 */ 00138 class CbcCompareEstimate : public CbcCompareBase { 00139 public: 00140 // Default Constructor 00141 CbcCompareEstimate () ; 00142 ~CbcCompareEstimate() ; 00143 // Copy constructor 00144 CbcCompareEstimate ( const CbcCompareEstimate &rhs); 00145 00146 // Assignment operator 00147 CbcCompareEstimate & operator=( const CbcCompareEstimate& rhs); 00148 00150 virtual CbcCompareBase * clone() const; 00152 virtual void generateCpp( FILE * fp); 00153 00154 virtual bool test (CbcNode * x, CbcNode * y) ; 00155 }; 00156 00157 #endif