1 | /* $Id: CbcHeuristicFPump.hpp 2280 2016-06-14 14:39:54Z forrest $ */ |
---|
2 | // Copyright (C) 2004, 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 CbcHeuristicFeasibilityPump_H |
---|
7 | #define CbcHeuristicFeasibilityPump_H |
---|
8 | |
---|
9 | #include "CbcHeuristic.hpp" |
---|
10 | #include "OsiClpSolverInterface.hpp" |
---|
11 | |
---|
12 | /** Feasibility Pump class |
---|
13 | */ |
---|
14 | |
---|
15 | class CbcHeuristicFPump : public CbcHeuristic { |
---|
16 | public: |
---|
17 | |
---|
18 | // Default Constructor |
---|
19 | CbcHeuristicFPump (); |
---|
20 | |
---|
21 | // Constructor with model - assumed before cuts |
---|
22 | CbcHeuristicFPump (CbcModel & model, |
---|
23 | double downValue = 0.5, bool roundExpensive = false); |
---|
24 | |
---|
25 | // Copy constructor |
---|
26 | CbcHeuristicFPump ( const CbcHeuristicFPump &); |
---|
27 | |
---|
28 | // Destructor |
---|
29 | ~CbcHeuristicFPump (); |
---|
30 | |
---|
31 | /// Assignment operator |
---|
32 | CbcHeuristicFPump & operator=(const CbcHeuristicFPump& rhs); |
---|
33 | /// Clone |
---|
34 | virtual CbcHeuristic * clone() const; |
---|
35 | /// Create C++ lines to get to current state |
---|
36 | virtual void generateCpp( FILE * fp) ; |
---|
37 | |
---|
38 | /// Resets stuff if model changes |
---|
39 | virtual void resetModel(CbcModel * model); |
---|
40 | |
---|
41 | /// update model (This is needed if cliques update matrix etc) |
---|
42 | virtual void setModel(CbcModel * model); |
---|
43 | |
---|
44 | using CbcHeuristic::solution ; |
---|
45 | /** returns 0 if no solution, 1 if valid solution |
---|
46 | with better objective value than one passed in |
---|
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 | |
---|
50 | It may make sense for user to call this outside Branch and Cut to |
---|
51 | get solution. Or normally is just at root node. |
---|
52 | |
---|
53 | * new meanings for when_ - on first try then set back to 1 |
---|
54 | 11 - at end fix all integers at same bound throughout |
---|
55 | 12 - also fix all integers staying at same internal integral value throughout |
---|
56 | 13 - also fix all continuous variables staying at same bound throughout |
---|
57 | 14 - also fix all continuous variables staying at same internal value throughout |
---|
58 | 15 - as 13 but no internal integers |
---|
59 | And beyond that, it's apparently possible for the range to be between 21 |
---|
60 | and 25, in which case it's reduced on entry to solution() to be between |
---|
61 | 11 and 15 and allSlack is set to true. Then, if we're not processing |
---|
62 | general integers, we'll use an all-slack basis to solve ... what? Don't |
---|
63 | see that yet. |
---|
64 | */ |
---|
65 | virtual int solution(double & objectiveValue, |
---|
66 | double * newSolution); |
---|
67 | /** If general integers then adds variables to turn into binaries round |
---|
68 | solution |
---|
69 | */ |
---|
70 | int solutionGeneral(double & objectiveValue, double * newSolution, |
---|
71 | int maxAround=1,bool fixSatisfied=false); |
---|
72 | /// Set maximum Time (default off) - also sets starttime to current |
---|
73 | void setMaximumTime(double value); |
---|
74 | /// Get maximum Time (default 0.0 == time limit off) |
---|
75 | inline double maximumTime() const { |
---|
76 | return maximumTime_; |
---|
77 | } |
---|
78 | /// Set fake cutoff (default COIN_DBL_MAX == off) |
---|
79 | inline void setFakeCutoff(double value) { |
---|
80 | fakeCutoff_ = value; |
---|
81 | } |
---|
82 | /// Get fake cutoff (default 0.0 == off) |
---|
83 | inline double fakeCutoff() const { |
---|
84 | return fakeCutoff_; |
---|
85 | } |
---|
86 | /// Set absolute increment (default 0.0 == off) |
---|
87 | inline void setAbsoluteIncrement(double value) { |
---|
88 | absoluteIncrement_ = value; |
---|
89 | } |
---|
90 | /// Get absolute increment (default 0.0 == off) |
---|
91 | inline double absoluteIncrement() const { |
---|
92 | return absoluteIncrement_; |
---|
93 | } |
---|
94 | /// Set relative increment (default 0.0 == off) |
---|
95 | inline void setRelativeIncrement(double value) { |
---|
96 | relativeIncrement_ = value; |
---|
97 | } |
---|
98 | /// Get relative increment (default 0.0 == off) |
---|
99 | inline double relativeIncrement() const { |
---|
100 | return relativeIncrement_; |
---|
101 | } |
---|
102 | /// Set default rounding (default 0.5) |
---|
103 | inline void setDefaultRounding(double value) { |
---|
104 | defaultRounding_ = value; |
---|
105 | } |
---|
106 | /// Get default rounding (default 0.5) |
---|
107 | inline double defaultRounding() const { |
---|
108 | return defaultRounding_; |
---|
109 | } |
---|
110 | /// Set initial weight (default 0.0 == off) |
---|
111 | inline void setInitialWeight(double value) { |
---|
112 | initialWeight_ = value; |
---|
113 | } |
---|
114 | /// Get initial weight (default 0.0 == off) |
---|
115 | inline double initialWeight() const { |
---|
116 | return initialWeight_; |
---|
117 | } |
---|
118 | /// Set weight factor (default 0.1) |
---|
119 | inline void setWeightFactor(double value) { |
---|
120 | weightFactor_ = value; |
---|
121 | } |
---|
122 | /// Get weight factor (default 0.1) |
---|
123 | inline double weightFactor() const { |
---|
124 | return weightFactor_; |
---|
125 | } |
---|
126 | /// Set threshold cost for using original cost - even on continuous (default infinity) |
---|
127 | inline void setArtificialCost(double value) { |
---|
128 | artificialCost_ = value; |
---|
129 | } |
---|
130 | /// Get threshold cost for using original cost - even on continuous (default infinity) |
---|
131 | inline double artificialCost() const { |
---|
132 | return artificialCost_; |
---|
133 | } |
---|
134 | /// Get iteration to size ratio |
---|
135 | inline double iterationRatio() const { |
---|
136 | return iterationRatio_; |
---|
137 | } |
---|
138 | /// Set iteration to size ratio |
---|
139 | inline void setIterationRatio(double value) { |
---|
140 | iterationRatio_ = value; |
---|
141 | } |
---|
142 | /// Set maximum passes (default 100) |
---|
143 | inline void setMaximumPasses(int value) { |
---|
144 | maximumPasses_ = value; |
---|
145 | } |
---|
146 | /// Get maximum passes (default 100) |
---|
147 | inline int maximumPasses() const { |
---|
148 | return maximumPasses_; |
---|
149 | } |
---|
150 | /// Set maximum retries (default 1) |
---|
151 | inline void setMaximumRetries(int value) { |
---|
152 | maximumRetries_ = value; |
---|
153 | } |
---|
154 | /// Get maximum retries (default 1) |
---|
155 | inline int maximumRetries() const { |
---|
156 | return maximumRetries_; |
---|
157 | } |
---|
158 | /** Set use of multiple solutions and solves |
---|
159 | 0 - do not reuse solves, do not accumulate integer solutions for local search |
---|
160 | 1 - do not reuse solves, accumulate integer solutions for local search |
---|
161 | 2 - reuse solves, do not accumulate integer solutions for local search |
---|
162 | 3 - reuse solves, accumulate integer solutions for local search |
---|
163 | If we add 4 then use second form of problem (with extra rows and variables for general integers) |
---|
164 | At some point (date?), I added |
---|
165 | |
---|
166 | And then there are a few bit fields: |
---|
167 | 4 - something about general integers |
---|
168 | So my (lh) guess for 4 was at least in the ballpark, but I'll have to |
---|
169 | rethink 8 entirely (and it may well not mean the same thing as it did |
---|
170 | when I added that comment. |
---|
171 | 8 - determines whether we process general integers |
---|
172 | |
---|
173 | And on 090831, John added |
---|
174 | |
---|
175 | If we add 4 then use second form of problem (with extra rows and |
---|
176 | variables for general integers) |
---|
177 | If we add 8 then can run after initial cuts (if no solution) |
---|
178 | */ |
---|
179 | inline void setAccumulate(int value) { |
---|
180 | accumulate_ = value; |
---|
181 | } |
---|
182 | /// Get accumulation option |
---|
183 | inline int accumulate() const { |
---|
184 | return accumulate_; |
---|
185 | } |
---|
186 | /** Set whether to fix variables on known solution |
---|
187 | 0 - do not fix |
---|
188 | 1 - fix integers on reduced costs |
---|
189 | 2 - fix integers on reduced costs but only on entry |
---|
190 | */ |
---|
191 | inline void setFixOnReducedCosts(int value) { |
---|
192 | fixOnReducedCosts_ = value; |
---|
193 | } |
---|
194 | /// Get reduced cost option |
---|
195 | inline int fixOnReducedCosts() const { |
---|
196 | return fixOnReducedCosts_; |
---|
197 | } |
---|
198 | /** Set reduced cost multiplier |
---|
199 | 1.0 as normal |
---|
200 | <1.0 (x) - pretend gap is x* actual gap - just for fixing |
---|
201 | */ |
---|
202 | inline void setReducedCostMultiplier(double value) { |
---|
203 | reducedCostMultiplier_ = value; |
---|
204 | } |
---|
205 | /// Get reduced cost multiplier |
---|
206 | inline double reducedCostMultiplier() const { |
---|
207 | return reducedCostMultiplier_; |
---|
208 | } |
---|
209 | |
---|
210 | protected: |
---|
211 | // Data |
---|
212 | /// Start time |
---|
213 | double startTime_; |
---|
214 | /// Maximum Cpu seconds |
---|
215 | double maximumTime_; |
---|
216 | /** Fake cutoff value. |
---|
217 | If set then better of real cutoff and this used to add a constraint |
---|
218 | */ |
---|
219 | double fakeCutoff_; |
---|
220 | /// If positive carry on after solution expecting gain of at least this |
---|
221 | double absoluteIncrement_; |
---|
222 | /// If positive carry on after solution expecting gain of at least this times objective |
---|
223 | double relativeIncrement_; |
---|
224 | /// Default is round up if > this |
---|
225 | double defaultRounding_; |
---|
226 | /// Initial weight for true objective |
---|
227 | double initialWeight_; |
---|
228 | /// Factor for decreasing weight |
---|
229 | double weightFactor_; |
---|
230 | /// Threshold cost for using original cost - even on continuous |
---|
231 | double artificialCost_; |
---|
232 | /** If iterationRatio >0 use instead of maximumPasses_ |
---|
233 | test is iterations > ratio*(2*nrow+ncol) */ |
---|
234 | double iterationRatio_; |
---|
235 | /** Reduced cost multiplier |
---|
236 | 1.0 as normal |
---|
237 | <1.0 (x) - pretend gap is x* actual gap - just for fixing |
---|
238 | */ |
---|
239 | double reducedCostMultiplier_; |
---|
240 | /// Maximum number of passes |
---|
241 | int maximumPasses_; |
---|
242 | /** Maximum number of retries if we find a solution. |
---|
243 | If negative we clean out used array |
---|
244 | */ |
---|
245 | int maximumRetries_; |
---|
246 | /** Set use of multiple solutions and solves |
---|
247 | 0 - do not reuse solves, do not accumulate integer solutions for local search |
---|
248 | 1 - do not reuse solves, accumulate integer solutions for local search |
---|
249 | 2 - reuse solves, do not accumulate integer solutions for local search |
---|
250 | 3 - reuse solves, accumulate integer solutions for local search |
---|
251 | If we add 4 then use second form of problem (with extra rows and variables for general integers) |
---|
252 | If we do not accumulate solutions then no mini branch and bounds will be done |
---|
253 | reuse - refers to initial solve after adding in new "cut" |
---|
254 | If we add 8 then can run after initial cuts (if no solution) |
---|
255 | 16 - extra rounding |
---|
256 | 32,64,128 - create binaries for general |
---|
257 | */ |
---|
258 | int accumulate_; |
---|
259 | /** Set whether to fix variables on known solution |
---|
260 | 0 - do not fix |
---|
261 | 1 - fix integers on reduced costs |
---|
262 | 2 - fix integers on reduced costs but only on entry |
---|
263 | */ |
---|
264 | int fixOnReducedCosts_; |
---|
265 | /// If true round to expensive |
---|
266 | bool roundExpensive_; |
---|
267 | |
---|
268 | private: |
---|
269 | /** Rounds solution - down if < downValue |
---|
270 | If roundExpensive then always to more expnsive. |
---|
271 | returns 0 if current is solution |
---|
272 | */ |
---|
273 | int rounds(OsiSolverInterface * solver, double * solution, |
---|
274 | /*const double * objective, */ |
---|
275 | int numberIntegers, const int * integerVariable, |
---|
276 | /*char * pumpPrint,*/int passNumber, |
---|
277 | /*bool roundExpensive=false,*/ |
---|
278 | double downValue = 0.5, int *flip = 0); |
---|
279 | /// Does real work |
---|
280 | int solutionInternal(double & objectiveValue, double * newSolution); |
---|
281 | /* note for eagle eyed readers. |
---|
282 | when_ can now be exotic - |
---|
283 | <=10 normal |
---|
284 | */ |
---|
285 | }; |
---|
286 | |
---|
287 | # ifdef COIN_HAS_CLP |
---|
288 | |
---|
289 | class CbcDisasterHandler : public OsiClpDisasterHandler { |
---|
290 | public: |
---|
291 | /**@name Virtual methods that the derived classe should provide. |
---|
292 | */ |
---|
293 | //@{ |
---|
294 | #ifdef JJF_ZERO |
---|
295 | /// Into simplex |
---|
296 | virtual void intoSimplex(); |
---|
297 | /// Checks if disaster |
---|
298 | virtual bool check() const ; |
---|
299 | /// saves information for next attempt |
---|
300 | virtual void saveInfo(); |
---|
301 | #endif |
---|
302 | /// Type of disaster 0 can fix, 1 abort |
---|
303 | virtual int typeOfDisaster(); |
---|
304 | //@} |
---|
305 | |
---|
306 | |
---|
307 | /**@name Constructors, destructor */ |
---|
308 | |
---|
309 | //@{ |
---|
310 | /** Default constructor. */ |
---|
311 | CbcDisasterHandler(CbcModel * model = NULL); |
---|
312 | /** Destructor */ |
---|
313 | virtual ~CbcDisasterHandler(); |
---|
314 | // Copy |
---|
315 | CbcDisasterHandler(const CbcDisasterHandler&); |
---|
316 | // Assignment |
---|
317 | CbcDisasterHandler& operator=(const CbcDisasterHandler&); |
---|
318 | /// Clone |
---|
319 | virtual ClpDisasterHandler * clone() const; |
---|
320 | |
---|
321 | //@} |
---|
322 | |
---|
323 | /**@name Sets/gets */ |
---|
324 | |
---|
325 | //@{ |
---|
326 | /** set model. */ |
---|
327 | void setCbcModel(CbcModel * model); |
---|
328 | /// Get model |
---|
329 | inline CbcModel * cbcModel() const { |
---|
330 | return cbcModel_; |
---|
331 | } |
---|
332 | |
---|
333 | //@} |
---|
334 | |
---|
335 | |
---|
336 | protected: |
---|
337 | /**@name Data members |
---|
338 | The data members are protected to allow access for derived classes. */ |
---|
339 | //@{ |
---|
340 | /// Pointer to model |
---|
341 | CbcModel * cbcModel_; |
---|
342 | |
---|
343 | //@} |
---|
344 | }; |
---|
345 | #endif |
---|
346 | |
---|
347 | #endif |
---|
348 | |
---|