1 | // Copyright (C) 2005, International Business Machines |
---|
2 | // Corporation and others. All Rights Reserved. |
---|
3 | #ifndef CbcHeuristicGreedy_H |
---|
4 | #define CbcHeuristicGreedy_H |
---|
5 | |
---|
6 | #include "CbcHeuristic.hpp" |
---|
7 | /** Greedy heuristic classes |
---|
8 | */ |
---|
9 | |
---|
10 | class CbcHeuristicGreedyCover : public CbcHeuristic { |
---|
11 | public: |
---|
12 | |
---|
13 | // Default Constructor |
---|
14 | CbcHeuristicGreedyCover (); |
---|
15 | |
---|
16 | /* Constructor with model - assumed before cuts |
---|
17 | Initial version does not do Lps |
---|
18 | */ |
---|
19 | CbcHeuristicGreedyCover (CbcModel & model); |
---|
20 | |
---|
21 | // Copy constructor |
---|
22 | CbcHeuristicGreedyCover ( const CbcHeuristicGreedyCover &); |
---|
23 | |
---|
24 | // Destructor |
---|
25 | ~CbcHeuristicGreedyCover (); |
---|
26 | |
---|
27 | /// Clone |
---|
28 | virtual CbcHeuristic * clone() const; |
---|
29 | /// Create C++ lines to get to current state |
---|
30 | virtual void generateCpp( FILE * fp) ; |
---|
31 | |
---|
32 | /// update model (This is needed if cliques update matrix etc) |
---|
33 | virtual void setModel(CbcModel * model); |
---|
34 | |
---|
35 | /** returns 0 if no solution, 1 if valid solution. |
---|
36 | Sets solution values if good, sets objective value (only if good) |
---|
37 | We leave all variables which are at one at this node of the |
---|
38 | tree to that value and will |
---|
39 | initially set all others to zero. We then sort all variables in order of their cost |
---|
40 | divided by the number of entries in rows which are not yet covered. We randomize that |
---|
41 | value a bit so that ties will be broken in different ways on different runs of the heuristic. |
---|
42 | We then choose the best one and set it to one and repeat the exercise. |
---|
43 | |
---|
44 | */ |
---|
45 | virtual int solution(double & objectiveValue, |
---|
46 | double * newSolution); |
---|
47 | /// Validate model i.e. sets when_ to 0 if necessary (may be NULL) |
---|
48 | virtual void validate() ; |
---|
49 | /// Resets stuff if model changes |
---|
50 | virtual void resetModel(CbcModel * model); |
---|
51 | /* Algorithm |
---|
52 | 0 - use current upper bounds |
---|
53 | 1 - use original upper bounds |
---|
54 | If 10 added perturb ratios more |
---|
55 | if 100 added round up all >=0.5 |
---|
56 | */ |
---|
57 | inline int algorithm() const |
---|
58 | { return algorithm_; }; |
---|
59 | inline void setAlgorithm(int value) |
---|
60 | { algorithm_=value; }; |
---|
61 | // Only do this many times |
---|
62 | inline int numberTimes() const |
---|
63 | { return numberTimes_; }; |
---|
64 | inline void setNumberTimes(int value) |
---|
65 | { numberTimes_=value; }; |
---|
66 | |
---|
67 | protected: |
---|
68 | // Data |
---|
69 | |
---|
70 | // Original matrix by column |
---|
71 | CoinPackedMatrix matrix_; |
---|
72 | // original number of rows |
---|
73 | int originalNumberRows_; |
---|
74 | /* Algorithm |
---|
75 | 0 - use current upper bounds |
---|
76 | 1 - use original upper bounds |
---|
77 | If 10 added perturb ratios more |
---|
78 | */ |
---|
79 | int algorithm_; |
---|
80 | /// Do this many times |
---|
81 | int numberTimes_; |
---|
82 | |
---|
83 | private: |
---|
84 | /// Illegal Assignment operator |
---|
85 | CbcHeuristicGreedyCover & operator=(const CbcHeuristicGreedyCover& rhs); |
---|
86 | }; |
---|
87 | |
---|
88 | |
---|
89 | class CbcHeuristicGreedyEquality : public CbcHeuristic { |
---|
90 | public: |
---|
91 | |
---|
92 | // Default Constructor |
---|
93 | CbcHeuristicGreedyEquality (); |
---|
94 | |
---|
95 | /* Constructor with model - assumed before cuts |
---|
96 | Initial version does not do Lps |
---|
97 | */ |
---|
98 | CbcHeuristicGreedyEquality (CbcModel & model); |
---|
99 | |
---|
100 | // Copy constructor |
---|
101 | CbcHeuristicGreedyEquality ( const CbcHeuristicGreedyEquality &); |
---|
102 | |
---|
103 | // Destructor |
---|
104 | ~CbcHeuristicGreedyEquality (); |
---|
105 | |
---|
106 | /// Clone |
---|
107 | virtual CbcHeuristic * clone() const; |
---|
108 | /// Create C++ lines to get to current state |
---|
109 | virtual void generateCpp( FILE * fp) ; |
---|
110 | |
---|
111 | /// update model (This is needed if cliques update matrix etc) |
---|
112 | virtual void setModel(CbcModel * model); |
---|
113 | |
---|
114 | /** returns 0 if no solution, 1 if valid solution. |
---|
115 | Sets solution values if good, sets objective value (only if good) |
---|
116 | We leave all variables which are at one at this node of the |
---|
117 | tree to that value and will |
---|
118 | initially set all others to zero. We then sort all variables in order of their cost |
---|
119 | divided by the number of entries in rows which are not yet covered. We randomize that |
---|
120 | value a bit so that ties will be broken in different ways on different runs of the heuristic. |
---|
121 | We then choose the best one and set it to one and repeat the exercise. |
---|
122 | |
---|
123 | */ |
---|
124 | virtual int solution(double & objectiveValue, |
---|
125 | double * newSolution); |
---|
126 | /// Validate model i.e. sets when_ to 0 if necessary (may be NULL) |
---|
127 | virtual void validate() ; |
---|
128 | /// Resets stuff if model changes |
---|
129 | virtual void resetModel(CbcModel * model); |
---|
130 | /* Algorithm |
---|
131 | 0 - use current upper bounds |
---|
132 | 1 - use original upper bounds |
---|
133 | If 10 added perturb ratios more |
---|
134 | if 100 added round up all >=0.5 |
---|
135 | */ |
---|
136 | inline int algorithm() const |
---|
137 | { return algorithm_; }; |
---|
138 | inline void setAlgorithm(int value) |
---|
139 | { algorithm_=value; }; |
---|
140 | // Fraction of rhs to cover before branch and cut |
---|
141 | inline void setFraction(double value) |
---|
142 | { fraction_ = value;}; |
---|
143 | inline double fraction() const |
---|
144 | { return fraction_;}; |
---|
145 | // Only do this many times |
---|
146 | inline int numberTimes() const |
---|
147 | { return numberTimes_; }; |
---|
148 | inline void setNumberTimes(int value) |
---|
149 | { numberTimes_=value; }; |
---|
150 | protected: |
---|
151 | // Data |
---|
152 | |
---|
153 | // Original matrix by column |
---|
154 | CoinPackedMatrix matrix_; |
---|
155 | // Fraction of rhs to cover before branch and cut |
---|
156 | double fraction_; |
---|
157 | // original number of rows |
---|
158 | int originalNumberRows_; |
---|
159 | /* Algorithm |
---|
160 | 0 - use current upper bounds |
---|
161 | 1 - use original upper bounds |
---|
162 | If 10 added perturb ratios more |
---|
163 | */ |
---|
164 | int algorithm_; |
---|
165 | /// Do this many times |
---|
166 | int numberTimes_; |
---|
167 | |
---|
168 | private: |
---|
169 | /// Illegal Assignment operator |
---|
170 | CbcHeuristicGreedyEquality & operator=(const CbcHeuristicGreedyEquality& rhs); |
---|
171 | }; |
---|
172 | |
---|
173 | |
---|
174 | #endif |
---|