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 depth first (before solution) 00097 if -2.0 then do breadth first just for first 1000 nodes 00098 */ 00099 inline double getWeight() const 00100 { return weight_;}; 00101 inline void setWeight(double weight) 00102 { weight_ = weight;}; 00103 protected: 00104 // Weight for each infeasibility 00105 double weight_; 00106 // Weight for each infeasibility - computed from solution 00107 double saveWeight_; 00108 // Number of solutions 00109 int numberSolutions_; 00110 // Tree size (at last check) 00111 int treeSize_; 00112 }; 00113 00114 /* This is when rounding is being done 00115 */ 00116 class CbcCompareEstimate : public CbcCompareBase { 00117 public: 00118 // Default Constructor 00119 CbcCompareEstimate () ; 00120 ~CbcCompareEstimate() ; 00121 // Copy constructor 00122 CbcCompareEstimate ( const CbcCompareEstimate &rhs); 00123 00124 // Assignment operator 00125 CbcCompareEstimate & operator=( const CbcCompareEstimate& rhs); 00126 00128 virtual CbcCompareBase * clone() const; 00130 virtual void generateCpp( FILE * fp); 00131 00132 virtual bool test (CbcNode * x, CbcNode * y) ; 00133 }; 00134 00135 #endif