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