1 | // Copyright (C) 2002, International Business Machines |
---|
2 | // Corporation and others. All Rights Reserved. |
---|
3 | #ifndef CbcCompareActual_H |
---|
4 | #define CbcCompareActual_H |
---|
5 | |
---|
6 | |
---|
7 | //############################################################################# |
---|
8 | /* These are alternative strategies for node traversal. |
---|
9 | They can take data etc for fine tuning |
---|
10 | |
---|
11 | At present the node list is stored as a heap and the "test" |
---|
12 | comparison function returns true if node y is better than node x. |
---|
13 | |
---|
14 | */ |
---|
15 | #include "CbcNode.hpp" |
---|
16 | #include "CbcCompareBase.hpp" |
---|
17 | class CbcModel; |
---|
18 | // This is default before first solution |
---|
19 | class CbcCompareDepth : public CbcCompareBase{ |
---|
20 | public: |
---|
21 | // Default Constructor |
---|
22 | CbcCompareDepth () ; |
---|
23 | |
---|
24 | ~CbcCompareDepth(); |
---|
25 | // Copy constructor |
---|
26 | CbcCompareDepth ( const CbcCompareDepth &rhs); |
---|
27 | |
---|
28 | // Assignment operator |
---|
29 | CbcCompareDepth & operator=( const CbcCompareDepth& rhs); |
---|
30 | |
---|
31 | /// Clone |
---|
32 | virtual CbcCompareBase * clone() const; |
---|
33 | /// Create C++ lines to get to current state |
---|
34 | virtual void generateCpp( FILE * fp); |
---|
35 | |
---|
36 | // This returns true if the depth of node y is greater than depth of node x |
---|
37 | virtual bool test (CbcNode * x, CbcNode * y); |
---|
38 | }; |
---|
39 | class CbcCompareObjective : public CbcCompareBase { |
---|
40 | public: |
---|
41 | // Default Constructor |
---|
42 | CbcCompareObjective (); |
---|
43 | |
---|
44 | virtual ~CbcCompareObjective(); |
---|
45 | // Copy constructor |
---|
46 | CbcCompareObjective ( const CbcCompareObjective &rhs); |
---|
47 | |
---|
48 | // Assignment operator |
---|
49 | CbcCompareObjective & operator=( const CbcCompareObjective& rhs); |
---|
50 | |
---|
51 | /// Clone |
---|
52 | virtual CbcCompareBase * clone() const; |
---|
53 | /// Create C++ lines to get to current state |
---|
54 | virtual void generateCpp( FILE * fp); |
---|
55 | |
---|
56 | /* This returns true if objective value of node y is less than |
---|
57 | objective value of node x */ |
---|
58 | virtual bool test (CbcNode * x, CbcNode * y); |
---|
59 | }; |
---|
60 | /* This is an example of a more complex rule with data |
---|
61 | It is default after first solution |
---|
62 | If weight is 0.0 then it is computed to hit first solution |
---|
63 | less 2% |
---|
64 | */ |
---|
65 | class CbcCompareDefault : public CbcCompareBase { |
---|
66 | public: |
---|
67 | // Default Constructor |
---|
68 | CbcCompareDefault () ; |
---|
69 | // Constructor with weight |
---|
70 | CbcCompareDefault (double weight); |
---|
71 | |
---|
72 | // Copy constructor |
---|
73 | CbcCompareDefault ( const CbcCompareDefault &rhs); |
---|
74 | |
---|
75 | // Assignment operator |
---|
76 | CbcCompareDefault & operator=( const CbcCompareDefault& rhs); |
---|
77 | |
---|
78 | /// Clone |
---|
79 | virtual CbcCompareBase * clone() const; |
---|
80 | /// Create C++ lines to get to current state |
---|
81 | virtual void generateCpp( FILE * fp); |
---|
82 | |
---|
83 | ~CbcCompareDefault() ; |
---|
84 | /* This returns true if weighted value of node y is less than |
---|
85 | weighted value of node x */ |
---|
86 | virtual bool test (CbcNode * x, CbcNode * y) ; |
---|
87 | // This allows method to change behavior as it is called |
---|
88 | // after each solution |
---|
89 | virtual void newSolution(CbcModel * model, |
---|
90 | double objectiveAtContinuous, |
---|
91 | int numberInfeasibilitiesAtContinuous) ; |
---|
92 | // This allows method to change behavior |
---|
93 | // Return true if want tree re-sorted |
---|
94 | virtual bool every1000Nodes(CbcModel * model,int numberNodes); |
---|
95 | |
---|
96 | /* if weight == -1.0 then depth first (before solution) |
---|
97 | if -2.0 then do breadth first just for first 1000 nodes |
---|
98 | */ |
---|
99 | inline double getWeight() const |
---|
100 | { return weight_;}; |
---|
101 | inline void setWeight(double weight) |
---|
102 | { weight_ = weight;}; |
---|
103 | protected: |
---|
104 | // Weight for each infeasibility |
---|
105 | double weight_; |
---|
106 | // Weight for each infeasibility - computed from solution |
---|
107 | double saveWeight_; |
---|
108 | // Number of solutions |
---|
109 | int numberSolutions_; |
---|
110 | // Tree size (at last check) |
---|
111 | int treeSize_; |
---|
112 | }; |
---|
113 | |
---|
114 | /* This is when rounding is being done |
---|
115 | */ |
---|
116 | class CbcCompareEstimate : public CbcCompareBase { |
---|
117 | public: |
---|
118 | // Default Constructor |
---|
119 | CbcCompareEstimate () ; |
---|
120 | ~CbcCompareEstimate() ; |
---|
121 | // Copy constructor |
---|
122 | CbcCompareEstimate ( const CbcCompareEstimate &rhs); |
---|
123 | |
---|
124 | // Assignment operator |
---|
125 | CbcCompareEstimate & operator=( const CbcCompareEstimate& rhs); |
---|
126 | |
---|
127 | /// Clone |
---|
128 | virtual CbcCompareBase * clone() const; |
---|
129 | /// Create C++ lines to get to current state |
---|
130 | virtual void generateCpp( FILE * fp); |
---|
131 | |
---|
132 | virtual bool test (CbcNode * x, CbcNode * y) ; |
---|
133 | }; |
---|
134 | |
---|
135 | #endif |
---|