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 2% 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;} 00106 // Depth above which want to explore first 00107 inline void setBreadthDepth(int value) 00108 { breadthDepth_ = value;} 00109 protected: 00110 // Weight for each infeasibility 00111 double weight_; 00112 // Weight for each infeasibility - computed from solution 00113 double saveWeight_; 00114 // Number of solutions 00115 int numberSolutions_; 00116 // Tree size (at last check) 00117 int treeSize_; 00118 // Depth above which want to explore first 00119 int breadthDepth_; 00120 }; 00121 00122 /* This is when rounding is being done 00123 */ 00124 class CbcCompareEstimate : public CbcCompareBase { 00125 public: 00126 // Default Constructor 00127 CbcCompareEstimate () ; 00128 ~CbcCompareEstimate() ; 00129 // Copy constructor 00130 CbcCompareEstimate ( const CbcCompareEstimate &rhs); 00131 00132 // Assignment operator 00133 CbcCompareEstimate & operator=( const CbcCompareEstimate& rhs); 00134 00136 virtual CbcCompareBase * clone() const; 00138 virtual void generateCpp( FILE * fp); 00139 00140 virtual bool test (CbcNode * x, CbcNode * y) ; 00141 }; 00142 00143 #endif