1 | /* $Id: CbcHeuristicLocal.hpp 1802 2012-11-21 09:38:56Z 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 | #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 | |
---|
128 | /// Used array so we can set |
---|
129 | inline int * used() const { |
---|
130 | return used_; |
---|
131 | } |
---|
132 | |
---|
133 | protected: |
---|
134 | // Data |
---|
135 | // Copy of Feasibility pump |
---|
136 | CbcHeuristicFPump * feasibilityPump_; |
---|
137 | // Number of solutions so we only do after new solution |
---|
138 | int numberSolutions_; |
---|
139 | /// Whether a variable has been in a solution (also when) |
---|
140 | int * used_; |
---|
141 | }; |
---|
142 | |
---|
143 | |
---|
144 | /** Naive class |
---|
145 | a) Fix all ints as close to zero as possible |
---|
146 | b) Fix all ints with nonzero costs and < large to zero |
---|
147 | c) Put bounds round continuous and UIs and maximize |
---|
148 | */ |
---|
149 | |
---|
150 | class CbcHeuristicNaive : public CbcHeuristic { |
---|
151 | public: |
---|
152 | |
---|
153 | // Default Constructor |
---|
154 | CbcHeuristicNaive (); |
---|
155 | |
---|
156 | /* Constructor with model - assumed before cuts |
---|
157 | Initial version does not do Lps |
---|
158 | */ |
---|
159 | CbcHeuristicNaive (CbcModel & model); |
---|
160 | |
---|
161 | // Copy constructor |
---|
162 | CbcHeuristicNaive ( const CbcHeuristicNaive &); |
---|
163 | |
---|
164 | // Destructor |
---|
165 | ~CbcHeuristicNaive (); |
---|
166 | |
---|
167 | /// Clone |
---|
168 | virtual CbcHeuristic * clone() const; |
---|
169 | |
---|
170 | /// Assignment operator |
---|
171 | CbcHeuristicNaive & operator=(const CbcHeuristicNaive& rhs); |
---|
172 | |
---|
173 | /// Create C++ lines to get to current state |
---|
174 | virtual void generateCpp( FILE * fp) ; |
---|
175 | |
---|
176 | /// Resets stuff if model changes |
---|
177 | virtual void resetModel(CbcModel * model); |
---|
178 | |
---|
179 | /// update model (This is needed if cliques update matrix etc) |
---|
180 | virtual void setModel(CbcModel * model); |
---|
181 | |
---|
182 | using CbcHeuristic::solution ; |
---|
183 | /** returns 0 if no solution, 1 if valid solution. |
---|
184 | Sets solution values if good, sets objective value (only if good) |
---|
185 | */ |
---|
186 | virtual int solution(double & objectiveValue, |
---|
187 | double * newSolution); |
---|
188 | |
---|
189 | /// Sets large cost value |
---|
190 | inline void setLargeValue(double value) { |
---|
191 | large_ = value; |
---|
192 | } |
---|
193 | /// Gets large cost value |
---|
194 | inline double largeValue() const { |
---|
195 | return large_; |
---|
196 | } |
---|
197 | |
---|
198 | protected: |
---|
199 | /// Data |
---|
200 | /// Large value |
---|
201 | double large_; |
---|
202 | }; |
---|
203 | |
---|
204 | /** Crossover Search class |
---|
205 | */ |
---|
206 | |
---|
207 | class CbcHeuristicCrossover : public CbcHeuristic { |
---|
208 | public: |
---|
209 | |
---|
210 | // Default Constructor |
---|
211 | CbcHeuristicCrossover (); |
---|
212 | |
---|
213 | /* Constructor with model - assumed before cuts |
---|
214 | Initial version does not do Lps |
---|
215 | */ |
---|
216 | CbcHeuristicCrossover (CbcModel & model); |
---|
217 | |
---|
218 | // Copy constructor |
---|
219 | CbcHeuristicCrossover ( const CbcHeuristicCrossover &); |
---|
220 | |
---|
221 | // Destructor |
---|
222 | ~CbcHeuristicCrossover (); |
---|
223 | |
---|
224 | /// Clone |
---|
225 | virtual CbcHeuristic * clone() const; |
---|
226 | |
---|
227 | /// Assignment operator |
---|
228 | CbcHeuristicCrossover & operator=(const CbcHeuristicCrossover& rhs); |
---|
229 | |
---|
230 | /// Create C++ lines to get to current state |
---|
231 | virtual void generateCpp( FILE * fp) ; |
---|
232 | |
---|
233 | /// Resets stuff if model changes |
---|
234 | virtual void resetModel(CbcModel * model); |
---|
235 | |
---|
236 | /// update model (This is needed if cliques update matrix etc) |
---|
237 | virtual void setModel(CbcModel * model); |
---|
238 | |
---|
239 | using CbcHeuristic::solution ; |
---|
240 | /** returns 0 if no solution, 1 if valid solution. |
---|
241 | Fix variables if agree in useNumber_ solutions |
---|
242 | when_ 0 off, 1 only at new solutions, 2 also every now and then |
---|
243 | add 10 to make only if agree at lower bound |
---|
244 | */ |
---|
245 | virtual int solution(double & objectiveValue, |
---|
246 | double * newSolution); |
---|
247 | |
---|
248 | /// Sets number of solutions to use |
---|
249 | inline void setNumberSolutions(int value) { |
---|
250 | if (value > 0 && value <= 10) |
---|
251 | useNumber_ = value; |
---|
252 | } |
---|
253 | |
---|
254 | protected: |
---|
255 | // Data |
---|
256 | /// Attempts |
---|
257 | std::vector <double> attempts_; |
---|
258 | /// Random numbers to stop same search happening |
---|
259 | double random_[10]; |
---|
260 | /// Number of solutions so we only do after new solution |
---|
261 | int numberSolutions_; |
---|
262 | /// Number of solutions to use |
---|
263 | int useNumber_; |
---|
264 | }; |
---|
265 | |
---|
266 | #endif |
---|
267 | |
---|