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 // This allows method to change behavior as it is called 00088 // after each solution 00089 virtual void newSolution(CbcModel * model, 00090 double objectiveAtContinuous, 00091 int numberInfeasibilitiesAtContinuous) ; 00092 // This allows method to change behavior 00093 // Return true if want tree re-sorted 00094 virtual bool every1000Nodes(CbcModel * model,int numberNodes); 00095 00096 /* if weight == -1.0 then fewest infeasibilities (before solution) 00097 if -2.0 then do breadth first just for first 1000 nodes 00098 if -3.0 then depth first before solution 00099 */ 00100 inline double getWeight() const 00101 { return weight_;}; 00102 inline void setWeight(double weight) 00103 { weight_ = weight;}; 00104 protected: 00105 // Weight for each infeasibility 00106 double weight_; 00107 // Weight for each infeasibility - computed from solution 00108 double saveWeight_; 00109 // Number of solutions 00110 int numberSolutions_; 00111 // Tree size (at last check) 00112 int treeSize_; 00113 }; 00114 00115 /* This is when rounding is being done 00116 */ 00117 class CbcCompareEstimate : public CbcCompareBase { 00118 public: 00119 // Default Constructor 00120 CbcCompareEstimate () ; 00121 ~CbcCompareEstimate() ; 00122 // Copy constructor 00123 CbcCompareEstimate ( const CbcCompareEstimate &rhs); 00124 00125 // Assignment operator 00126 CbcCompareEstimate & operator=( const CbcCompareEstimate& rhs); 00127 00129 virtual CbcCompareBase * clone() const; 00131 virtual void generateCpp( FILE * fp); 00132 00133 virtual bool test (CbcNode * x, CbcNode * y) ; 00134 }; 00135 00136 #endif