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 | protected: |
---|
105 | // Weight for each infeasibility |
---|
106 | double weight_; |
---|
107 | // Weight for each infeasibility - computed from solution |
---|
108 | double saveWeight_; |
---|
109 | // Number of solutions |
---|
110 | int numberSolutions_; |
---|
111 | // Tree size (at last check) |
---|
112 | int treeSize_; |
---|
113 | }; |
---|
114 | |
---|
115 | /* This is when rounding is being done |
---|
116 | */ |
---|
117 | class CbcCompareEstimate : public CbcCompareBase { |
---|
118 | public: |
---|
119 | // Default Constructor |
---|
120 | CbcCompareEstimate () ; |
---|
121 | ~CbcCompareEstimate() ; |
---|
122 | // Copy constructor |
---|
123 | CbcCompareEstimate ( const CbcCompareEstimate &rhs); |
---|
124 | |
---|
125 | // Assignment operator |
---|
126 | CbcCompareEstimate & operator=( const CbcCompareEstimate& rhs); |
---|
127 | |
---|
128 | /// Clone |
---|
129 | virtual CbcCompareBase * clone() const; |
---|
130 | /// Create C++ lines to get to current state |
---|
131 | virtual void generateCpp( FILE * fp); |
---|
132 | |
---|
133 | virtual bool test (CbcNode * x, CbcNode * y) ; |
---|
134 | }; |
---|
135 | |
---|
136 | #endif |
---|