1 | // $Id: CbcCompareDefault.hpp 1899 2013-04-09 18:12:08Z forrest $ |
---|
2 | // Copyright (C) 2002, International Business Machines |
---|
3 | // Corporation and others. All Rights Reserved. |
---|
4 | // This code is licensed under the terms of the Eclipse Public License (EPL). |
---|
5 | |
---|
6 | //Edwin 11/25/09 carved out of CbcCompareActual |
---|
7 | |
---|
8 | #ifndef CbcCompareDefault_H |
---|
9 | #define CbcCompareDefault_H |
---|
10 | |
---|
11 | |
---|
12 | //############################################################################# |
---|
13 | /* These are alternative strategies for node traversal. |
---|
14 | They can take data etc for fine tuning |
---|
15 | |
---|
16 | At present the node list is stored as a heap and the "test" |
---|
17 | comparison function returns true if node y is better than node x. |
---|
18 | |
---|
19 | */ |
---|
20 | #include "CbcNode.hpp" |
---|
21 | #include "CbcCompareBase.hpp" |
---|
22 | #include "CbcCompare.hpp" |
---|
23 | |
---|
24 | class CbcModel; |
---|
25 | |
---|
26 | /* This is an example of a more complex rule with data |
---|
27 | It is default after first solution |
---|
28 | If weight is 0.0 then it is computed to hit first solution |
---|
29 | less 5% |
---|
30 | */ |
---|
31 | class CbcCompareDefault : public CbcCompareBase { |
---|
32 | public: |
---|
33 | /// Default Constructor |
---|
34 | CbcCompareDefault () ; |
---|
35 | /// Constructor with weight |
---|
36 | CbcCompareDefault (double weight); |
---|
37 | |
---|
38 | /// Copy constructor |
---|
39 | CbcCompareDefault ( const CbcCompareDefault &rhs); |
---|
40 | |
---|
41 | /// Assignment operator |
---|
42 | CbcCompareDefault & operator=( const CbcCompareDefault& rhs); |
---|
43 | |
---|
44 | /// Clone |
---|
45 | virtual CbcCompareBase * clone() const; |
---|
46 | /// Create C++ lines to get to current state |
---|
47 | virtual void generateCpp( FILE * fp); |
---|
48 | |
---|
49 | ~CbcCompareDefault() ; |
---|
50 | /* This returns true if weighted value of node y is less than |
---|
51 | weighted value of node x */ |
---|
52 | virtual bool test (CbcNode * x, CbcNode * y) ; |
---|
53 | |
---|
54 | using CbcCompareBase::newSolution ; |
---|
55 | /// This allows method to change behavior as it is called |
---|
56 | /// after each solution |
---|
57 | virtual bool newSolution(CbcModel * model, |
---|
58 | double objectiveAtContinuous, |
---|
59 | int numberInfeasibilitiesAtContinuous) ; |
---|
60 | /// This allows method to change behavior |
---|
61 | /// Return true if want tree re-sorted |
---|
62 | virtual bool every1000Nodes(CbcModel * model, int numberNodes); |
---|
63 | |
---|
64 | /* if weight == -1.0 then fewest infeasibilities (before solution) |
---|
65 | if -2.0 then do breadth first just for first 1000 nodes |
---|
66 | if -3.0 then depth first before solution |
---|
67 | */ |
---|
68 | inline double getWeight() const { |
---|
69 | return weight_; |
---|
70 | } |
---|
71 | inline void setWeight(double weight) { |
---|
72 | weight_ = weight; |
---|
73 | } |
---|
74 | /// Cutoff |
---|
75 | inline double getCutoff() const { |
---|
76 | return cutoff_; |
---|
77 | } |
---|
78 | inline void setCutoff(double cutoff) { |
---|
79 | cutoff_ = cutoff; |
---|
80 | } |
---|
81 | /// Best possible solution |
---|
82 | inline double getBestPossible() const { |
---|
83 | return bestPossible_; |
---|
84 | } |
---|
85 | inline void setBestPossible(double bestPossible) { |
---|
86 | bestPossible_ = bestPossible; |
---|
87 | } |
---|
88 | /// Depth above which want to explore first |
---|
89 | inline void setBreadthDepth(int value) { |
---|
90 | breadthDepth_ = value; |
---|
91 | } |
---|
92 | /// Start dive |
---|
93 | void startDive(CbcModel * model); |
---|
94 | /// Clean up diving (i.e. switch off or prepare) |
---|
95 | void cleanDive(); |
---|
96 | protected: |
---|
97 | /// Weight for each infeasibility |
---|
98 | double weight_; |
---|
99 | /// Weight for each infeasibility - computed from solution |
---|
100 | double saveWeight_; |
---|
101 | /// Cutoff |
---|
102 | double cutoff_; |
---|
103 | /// Best possible solution |
---|
104 | double bestPossible_; |
---|
105 | /// Number of solutions |
---|
106 | int numberSolutions_; |
---|
107 | /// Tree size (at last check) |
---|
108 | int treeSize_; |
---|
109 | /// Depth above which want to explore first |
---|
110 | int breadthDepth_; |
---|
111 | /// Chosen node from estimated (-1 is off) |
---|
112 | int startNodeNumber_; |
---|
113 | /// Node number when dive started |
---|
114 | int afterNodeNumber_; |
---|
115 | /// Indicates doing setup for diving |
---|
116 | bool setupForDiving_ ; |
---|
117 | }; |
---|
118 | |
---|
119 | #endif //CbcCompareDefault_H |
---|
120 | |
---|