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 | |
---|
88 | using CbcCompareBase::newSolution ; |
---|
89 | // This allows method to change behavior as it is called |
---|
90 | // after each solution |
---|
91 | virtual void newSolution(CbcModel * model, |
---|
92 | double objectiveAtContinuous, |
---|
93 | int numberInfeasibilitiesAtContinuous) ; |
---|
94 | // This allows method to change behavior |
---|
95 | // Return true if want tree re-sorted |
---|
96 | virtual bool every1000Nodes(CbcModel * model,int numberNodes); |
---|
97 | |
---|
98 | /* if weight == -1.0 then fewest infeasibilities (before solution) |
---|
99 | if -2.0 then do breadth first just for first 1000 nodes |
---|
100 | if -3.0 then depth first before solution |
---|
101 | */ |
---|
102 | inline double getWeight() const |
---|
103 | { return weight_;} |
---|
104 | inline void setWeight(double weight) |
---|
105 | { weight_ = weight;} |
---|
106 | // Depth above which want to explore first |
---|
107 | inline void setBreadthDepth(int value) |
---|
108 | { breadthDepth_ = value;} |
---|
109 | protected: |
---|
110 | // Weight for each infeasibility |
---|
111 | double weight_; |
---|
112 | // Weight for each infeasibility - computed from solution |
---|
113 | double saveWeight_; |
---|
114 | // Number of solutions |
---|
115 | int numberSolutions_; |
---|
116 | // Tree size (at last check) |
---|
117 | int treeSize_; |
---|
118 | // Depth above which want to explore first |
---|
119 | int breadthDepth_; |
---|
120 | }; |
---|
121 | |
---|
122 | /* This is when rounding is being done |
---|
123 | */ |
---|
124 | class CbcCompareEstimate : public CbcCompareBase { |
---|
125 | public: |
---|
126 | // Default Constructor |
---|
127 | CbcCompareEstimate () ; |
---|
128 | ~CbcCompareEstimate() ; |
---|
129 | // Copy constructor |
---|
130 | CbcCompareEstimate ( const CbcCompareEstimate &rhs); |
---|
131 | |
---|
132 | // Assignment operator |
---|
133 | CbcCompareEstimate & operator=( const CbcCompareEstimate& rhs); |
---|
134 | |
---|
135 | /// Clone |
---|
136 | virtual CbcCompareBase * clone() const; |
---|
137 | /// Create C++ lines to get to current state |
---|
138 | virtual void generateCpp( FILE * fp); |
---|
139 | |
---|
140 | virtual bool test (CbcNode * x, CbcNode * y) ; |
---|
141 | }; |
---|
142 | |
---|
143 | #endif |
---|