1 | /* $Id: CbcHeuristicLocal.hpp 1943 2013-07-21 09:05:45Z tkr $ */ |
---|
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 | #ifndef CbcHeuristicLocal_H |
---|
7 | #define CbcHeuristicLocal_H |
---|
8 | |
---|
9 | #include "CbcHeuristic.hpp" |
---|
10 | /** LocalSearch class |
---|
11 | */ |
---|
12 | |
---|
13 | class CbcHeuristicLocal : public CbcHeuristic { |
---|
14 | public: |
---|
15 | |
---|
16 | // Default Constructor |
---|
17 | CbcHeuristicLocal (); |
---|
18 | |
---|
19 | /* Constructor with model - assumed before cuts |
---|
20 | Initial version does not do Lps |
---|
21 | */ |
---|
22 | CbcHeuristicLocal (CbcModel & model); |
---|
23 | |
---|
24 | // Copy constructor |
---|
25 | CbcHeuristicLocal ( const CbcHeuristicLocal &); |
---|
26 | |
---|
27 | // Destructor |
---|
28 | ~CbcHeuristicLocal (); |
---|
29 | |
---|
30 | /// Clone |
---|
31 | virtual CbcHeuristic * clone() const; |
---|
32 | |
---|
33 | /// Assignment operator |
---|
34 | CbcHeuristicLocal & operator=(const CbcHeuristicLocal& rhs); |
---|
35 | |
---|
36 | /// Create C++ lines to get to current state |
---|
37 | virtual void generateCpp( FILE * fp) ; |
---|
38 | |
---|
39 | /// Resets stuff if model changes |
---|
40 | virtual void resetModel(CbcModel * model); |
---|
41 | |
---|
42 | /// update model (This is needed if cliques update matrix etc) |
---|
43 | virtual void setModel(CbcModel * model); |
---|
44 | |
---|
45 | using CbcHeuristic::solution ; |
---|
46 | /** returns 0 if no solution, 1 if valid solution. |
---|
47 | Sets solution values if good, sets objective value (only if good) |
---|
48 | This is called after cuts have been added - so can not add cuts |
---|
49 | First tries setting a variable to better value. If feasible then |
---|
50 | tries setting others. If not feasible then tries swaps |
---|
51 | |
---|
52 | ******** |
---|
53 | |
---|
54 | This first version does not do LP's and does swaps of two integer |
---|
55 | variables. Later versions could do Lps. |
---|
56 | */ |
---|
57 | virtual int solution(double & objectiveValue, |
---|
58 | double * newSolution); |
---|
59 | /// This version fixes stuff and does IP |
---|
60 | int solutionFix(double & objectiveValue, |
---|
61 | double * newSolution, |
---|
62 | const int * keep); |
---|
63 | |
---|
64 | /// Sets type of search |
---|
65 | inline void setSearchType(int value) { |
---|
66 | swap_ = value; |
---|
67 | } |
---|
68 | /// Used array so we can set |
---|
69 | inline int * used() const { |
---|
70 | return used_; |
---|
71 | } |
---|
72 | |
---|
73 | protected: |
---|
74 | // Data |
---|
75 | |
---|
76 | // Original matrix by column |
---|
77 | CoinPackedMatrix matrix_; |
---|
78 | |
---|
79 | // Number of solutions so we only do after new solution |
---|
80 | int numberSolutions_; |
---|
81 | // Type of search 0=normal, 1=BAB |
---|
82 | int swap_; |
---|
83 | /// Whether a variable has been in a solution (also when) |
---|
84 | int * used_; |
---|
85 | }; |
---|
86 | |
---|
87 | /** Proximity Search class |
---|
88 | */ |
---|
89 | class CbcHeuristicFPump; |
---|
90 | class CbcHeuristicProximity : public CbcHeuristic { |
---|
91 | public: |
---|
92 | |
---|
93 | // Default Constructor |
---|
94 | CbcHeuristicProximity (); |
---|
95 | |
---|
96 | /* Constructor with model - assumed before cuts |
---|
97 | */ |
---|
98 | CbcHeuristicProximity (CbcModel & model); |
---|
99 | |
---|
100 | // Copy constructor |
---|
101 | CbcHeuristicProximity ( const CbcHeuristicProximity &); |
---|
102 | |
---|
103 | // Destructor |
---|
104 | ~CbcHeuristicProximity (); |
---|
105 | |
---|
106 | /// Clone |
---|
107 | virtual CbcHeuristic * clone() const; |
---|
108 | |
---|
109 | /// Assignment operator |
---|
110 | CbcHeuristicProximity & operator=(const CbcHeuristicProximity& rhs); |
---|
111 | |
---|
112 | /// Create C++ lines to get to current state |
---|
113 | virtual void generateCpp( FILE * fp) ; |
---|
114 | |
---|
115 | /// Resets stuff if model changes |
---|
116 | virtual void resetModel(CbcModel * model); |
---|
117 | |
---|
118 | /// update model (This is needed if cliques update matrix etc) |
---|
119 | virtual void setModel(CbcModel * model); |
---|
120 | |
---|
121 | using CbcHeuristic::solution ; |
---|
122 | /** returns 0 if no solution, 1 if valid solution. |
---|
123 | Sets solution values if good, sets objective value (only if good) |
---|
124 | */ |
---|
125 | virtual int solution(double & objectiveValue, |
---|
126 | double * newSolution); |
---|
127 | /// Set extra increment |
---|
128 | inline void setIncrement(double value) |
---|
129 | { increment_ = value;} |
---|
130 | /// Used array so we can set |
---|
131 | inline int * used() const { |
---|
132 | return used_; |
---|
133 | } |
---|
134 | |
---|
135 | protected: |
---|
136 | // Data |
---|
137 | /// Increment to use if no change |
---|
138 | double increment_; |
---|
139 | /// Copy of Feasibility pump |
---|
140 | CbcHeuristicFPump * feasibilityPump_; |
---|
141 | /// Number of solutions so we only do after new solution |
---|
142 | int numberSolutions_; |
---|
143 | /// Whether a variable has been in a solution (also when) |
---|
144 | int * used_; |
---|
145 | }; |
---|
146 | |
---|
147 | |
---|
148 | /** Naive class |
---|
149 | a) Fix all ints as close to zero as possible |
---|
150 | b) Fix all ints with nonzero costs and < large to zero |
---|
151 | c) Put bounds round continuous and UIs and maximize |
---|
152 | */ |
---|
153 | |
---|
154 | class CbcHeuristicNaive : public CbcHeuristic { |
---|
155 | public: |
---|
156 | |
---|
157 | // Default Constructor |
---|
158 | CbcHeuristicNaive (); |
---|
159 | |
---|
160 | /* Constructor with model - assumed before cuts |
---|
161 | Initial version does not do Lps |
---|
162 | */ |
---|
163 | CbcHeuristicNaive (CbcModel & model); |
---|
164 | |
---|
165 | // Copy constructor |
---|
166 | CbcHeuristicNaive ( const CbcHeuristicNaive &); |
---|
167 | |
---|
168 | // Destructor |
---|
169 | ~CbcHeuristicNaive (); |
---|
170 | |
---|
171 | /// Clone |
---|
172 | virtual CbcHeuristic * clone() const; |
---|
173 | |
---|
174 | /// Assignment operator |
---|
175 | CbcHeuristicNaive & operator=(const CbcHeuristicNaive& rhs); |
---|
176 | |
---|
177 | /// Create C++ lines to get to current state |
---|
178 | virtual void generateCpp( FILE * fp) ; |
---|
179 | |
---|
180 | /// Resets stuff if model changes |
---|
181 | virtual void resetModel(CbcModel * model); |
---|
182 | |
---|
183 | /// update model (This is needed if cliques update matrix etc) |
---|
184 | virtual void setModel(CbcModel * model); |
---|
185 | |
---|
186 | using CbcHeuristic::solution ; |
---|
187 | /** returns 0 if no solution, 1 if valid solution. |
---|
188 | Sets solution values if good, sets objective value (only if good) |
---|
189 | */ |
---|
190 | virtual int solution(double & objectiveValue, |
---|
191 | double * newSolution); |
---|
192 | |
---|
193 | /// Sets large cost value |
---|
194 | inline void setLargeValue(double value) { |
---|
195 | large_ = value; |
---|
196 | } |
---|
197 | /// Gets large cost value |
---|
198 | inline double largeValue() const { |
---|
199 | return large_; |
---|
200 | } |
---|
201 | |
---|
202 | protected: |
---|
203 | /// Data |
---|
204 | /// Large value |
---|
205 | double large_; |
---|
206 | }; |
---|
207 | |
---|
208 | /** Crossover Search class |
---|
209 | */ |
---|
210 | |
---|
211 | class CbcHeuristicCrossover : public CbcHeuristic { |
---|
212 | public: |
---|
213 | |
---|
214 | // Default Constructor |
---|
215 | CbcHeuristicCrossover (); |
---|
216 | |
---|
217 | /* Constructor with model - assumed before cuts |
---|
218 | Initial version does not do Lps |
---|
219 | */ |
---|
220 | CbcHeuristicCrossover (CbcModel & model); |
---|
221 | |
---|
222 | // Copy constructor |
---|
223 | CbcHeuristicCrossover ( const CbcHeuristicCrossover &); |
---|
224 | |
---|
225 | // Destructor |
---|
226 | ~CbcHeuristicCrossover (); |
---|
227 | |
---|
228 | /// Clone |
---|
229 | virtual CbcHeuristic * clone() const; |
---|
230 | |
---|
231 | /// Assignment operator |
---|
232 | CbcHeuristicCrossover & operator=(const CbcHeuristicCrossover& rhs); |
---|
233 | |
---|
234 | /// Create C++ lines to get to current state |
---|
235 | virtual void generateCpp( FILE * fp) ; |
---|
236 | |
---|
237 | /// Resets stuff if model changes |
---|
238 | virtual void resetModel(CbcModel * model); |
---|
239 | |
---|
240 | /// update model (This is needed if cliques update matrix etc) |
---|
241 | virtual void setModel(CbcModel * model); |
---|
242 | |
---|
243 | using CbcHeuristic::solution ; |
---|
244 | /** returns 0 if no solution, 1 if valid solution. |
---|
245 | Fix variables if agree in useNumber_ solutions |
---|
246 | when_ 0 off, 1 only at new solutions, 2 also every now and then |
---|
247 | add 10 to make only if agree at lower bound |
---|
248 | */ |
---|
249 | virtual int solution(double & objectiveValue, |
---|
250 | double * newSolution); |
---|
251 | |
---|
252 | /// Sets number of solutions to use |
---|
253 | inline void setNumberSolutions(int value) { |
---|
254 | if (value > 0 && value <= 10) |
---|
255 | useNumber_ = value; |
---|
256 | } |
---|
257 | |
---|
258 | protected: |
---|
259 | // Data |
---|
260 | /// Attempts |
---|
261 | std::vector <double> attempts_; |
---|
262 | /// Random numbers to stop same search happening |
---|
263 | double random_[10]; |
---|
264 | /// Number of solutions so we only do after new solution |
---|
265 | int numberSolutions_; |
---|
266 | /// Number of solutions to use |
---|
267 | int useNumber_; |
---|
268 | }; |
---|
269 | |
---|
270 | #endif |
---|
271 | |
---|