1 | /* $Id: CbcModel.hpp 1971 2013-10-19 15:55:33Z stefan $ */ |
---|
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 CbcModel_H |
---|
7 | #define CbcModel_H |
---|
8 | #include <string> |
---|
9 | #include <vector> |
---|
10 | #include "CoinMessageHandler.hpp" |
---|
11 | #include "OsiSolverInterface.hpp" |
---|
12 | #include "OsiBranchingObject.hpp" |
---|
13 | #include "OsiCuts.hpp" |
---|
14 | #include "CoinWarmStartBasis.hpp" |
---|
15 | #include "CbcCompareBase.hpp" |
---|
16 | #include "CbcCountRowCut.hpp" |
---|
17 | #include "CbcMessage.hpp" |
---|
18 | #include "CbcEventHandler.hpp" |
---|
19 | #include "ClpDualRowPivot.hpp" |
---|
20 | |
---|
21 | |
---|
22 | class CbcCutGenerator; |
---|
23 | class CbcBaseModel; |
---|
24 | class OsiRowCut; |
---|
25 | class OsiBabSolver; |
---|
26 | class OsiRowCutDebugger; |
---|
27 | class CglCutGenerator; |
---|
28 | class CglStored; |
---|
29 | class CbcCutModifier; |
---|
30 | class CglTreeProbingInfo; |
---|
31 | class CbcHeuristic; |
---|
32 | class OsiObject; |
---|
33 | class CbcThread; |
---|
34 | class CbcTree; |
---|
35 | class CbcStrategy; |
---|
36 | class CbcFeasibilityBase; |
---|
37 | class CbcStatistics; |
---|
38 | class CbcFullNodeInfo; |
---|
39 | class CbcEventHandler ; |
---|
40 | class CglPreProcess; |
---|
41 | class OsiClpSolverInterface; |
---|
42 | class ClpNodeStuff; |
---|
43 | |
---|
44 | // #define CBC_CHECK_BASIS 1 |
---|
45 | |
---|
46 | //############################################################################# |
---|
47 | |
---|
48 | /** Simple Branch and bound class |
---|
49 | |
---|
50 | The initialSolve() method solves the initial LP relaxation of the MIP |
---|
51 | problem. The branchAndBound() method can then be called to finish using |
---|
52 | a branch and cut algorithm. |
---|
53 | |
---|
54 | <h3>Search Tree Traversal</h3> |
---|
55 | |
---|
56 | Subproblems (aka nodes) requiring additional evaluation are stored using |
---|
57 | the CbcNode and CbcNodeInfo objects. Ancestry linkage is maintained in the |
---|
58 | CbcNodeInfo object. Evaluation of a subproblem within branchAndBound() |
---|
59 | proceeds as follows: |
---|
60 | <ul> |
---|
61 | <li> The node representing the most promising parent subproblem is popped |
---|
62 | from the heap which holds the set of subproblems requiring further |
---|
63 | evaluation. |
---|
64 | <li> Using branching instructions stored in the node, and information in |
---|
65 | its ancestors, the model and solver are adjusted to create the |
---|
66 | active subproblem. |
---|
67 | <li> If the parent subproblem will require further evaluation |
---|
68 | (<i>i.e.</i>, there are branches remaining) its node is pushed back |
---|
69 | on the heap. Otherwise, the node is deleted. This may trigger |
---|
70 | recursive deletion of ancestors. |
---|
71 | <li> The newly created subproblem is evaluated. |
---|
72 | <li> If the subproblem requires further evaluation, a node is created. |
---|
73 | All information needed to recreate the subproblem (branching |
---|
74 | information, row and column cuts) is placed in the node and the node |
---|
75 | is added to the set of subproblems awaiting further evaluation. |
---|
76 | </ul> |
---|
77 | Note that there is never a node representing the active subproblem; the model |
---|
78 | and solver represent the active subproblem. |
---|
79 | |
---|
80 | <h3>Row (Constraint) Cut Handling</h3> |
---|
81 | |
---|
82 | For a typical subproblem, the sequence of events is as follows: |
---|
83 | <ul> |
---|
84 | <li> The subproblem is rebuilt for further evaluation: One result of a |
---|
85 | call to addCuts() is a traversal of ancestors, leaving a list of all |
---|
86 | cuts used in the ancestors in #addedCuts_. This list is then scanned |
---|
87 | to construct a basis that includes only tight cuts. Entries for |
---|
88 | loose cuts are set to NULL. |
---|
89 | <li> The subproblem is evaluated: One result of a call to solveWithCuts() |
---|
90 | is the return of a set of newly generated cuts for the subproblem. |
---|
91 | #addedCuts_ is also kept up-to-date as old cuts become loose. |
---|
92 | <li> The subproblem is stored for further processing: A call to |
---|
93 | CbcNodeInfo::addCuts() adds the newly generated cuts to the |
---|
94 | CbcNodeInfo object associated with this node. |
---|
95 | </ul> |
---|
96 | See CbcCountRowCut for details of the bookkeeping associated with cut |
---|
97 | management. |
---|
98 | */ |
---|
99 | |
---|
100 | class CbcModel { |
---|
101 | |
---|
102 | public: |
---|
103 | |
---|
104 | enum CbcIntParam { |
---|
105 | /** The maximum number of nodes before terminating */ |
---|
106 | CbcMaxNumNode = 0, |
---|
107 | /** The maximum number of solutions before terminating */ |
---|
108 | CbcMaxNumSol, |
---|
109 | /** Fathoming discipline |
---|
110 | |
---|
111 | Controls objective function comparisons for purposes of fathoming by bound |
---|
112 | or determining monotonic variables. |
---|
113 | |
---|
114 | If 1, action is taken only when the current objective is strictly worse |
---|
115 | than the target. Implementation is handled by adding a small tolerance to |
---|
116 | the target. |
---|
117 | */ |
---|
118 | CbcFathomDiscipline, |
---|
119 | /** Adjusts printout |
---|
120 | 1 does different node message with number unsatisfied on last branch |
---|
121 | */ |
---|
122 | CbcPrinting, |
---|
123 | /** Number of branches (may be more than number of nodes as may |
---|
124 | include strong branching) */ |
---|
125 | CbcNumberBranches, |
---|
126 | /** Just a marker, so that a static sized array can store parameters. */ |
---|
127 | CbcLastIntParam |
---|
128 | }; |
---|
129 | |
---|
130 | enum CbcDblParam { |
---|
131 | /** The maximum amount the value of an integer variable can vary from |
---|
132 | integer and still be considered feasible. */ |
---|
133 | CbcIntegerTolerance = 0, |
---|
134 | /** The objective is assumed to worsen by this amount for each |
---|
135 | integer infeasibility. */ |
---|
136 | CbcInfeasibilityWeight, |
---|
137 | /** The amount by which to tighten the objective function cutoff when |
---|
138 | a new solution is discovered. */ |
---|
139 | CbcCutoffIncrement, |
---|
140 | /** Stop when the gap between the objective value of the best known solution |
---|
141 | and the best bound on the objective of any solution is less than this. |
---|
142 | |
---|
143 | This is an absolute value. Conversion from a percentage is left to the |
---|
144 | client. |
---|
145 | */ |
---|
146 | CbcAllowableGap, |
---|
147 | /** Stop when the gap between the objective value of the best known solution |
---|
148 | and the best bound on the objective of any solution is less than this |
---|
149 | fraction of of the absolute value of best known solution. |
---|
150 | |
---|
151 | Code stops if either this test or CbcAllowableGap test succeeds |
---|
152 | */ |
---|
153 | CbcAllowableFractionGap, |
---|
154 | /** \brief The maximum number of seconds before terminating. |
---|
155 | A double should be adequate! */ |
---|
156 | CbcMaximumSeconds, |
---|
157 | /// Cutoff - stored for speed |
---|
158 | CbcCurrentCutoff, |
---|
159 | /// Optimization direction - stored for speed |
---|
160 | CbcOptimizationDirection, |
---|
161 | /// Current objective value |
---|
162 | CbcCurrentObjectiveValue, |
---|
163 | /// Current minimization objective value |
---|
164 | CbcCurrentMinimizationObjectiveValue, |
---|
165 | /** \brief The time at start of model. |
---|
166 | So that other pieces of code can access */ |
---|
167 | CbcStartSeconds, |
---|
168 | /** Stop doing heuristics when the gap between the objective value of the |
---|
169 | best known solution and the best bound on the objective of any solution |
---|
170 | is less than this. |
---|
171 | |
---|
172 | This is an absolute value. Conversion from a percentage is left to the |
---|
173 | client. |
---|
174 | */ |
---|
175 | CbcHeuristicGap, |
---|
176 | /** Stop doing heuristics when the gap between the objective value of the |
---|
177 | best known solution and the best bound on the objective of any solution |
---|
178 | is less than this fraction of of the absolute value of best known |
---|
179 | solution. |
---|
180 | |
---|
181 | Code stops if either this test or CbcAllowableGap test succeeds |
---|
182 | */ |
---|
183 | CbcHeuristicFractionGap, |
---|
184 | /// Smallest non-zero change on a branch |
---|
185 | CbcSmallestChange, |
---|
186 | /// Sum of non-zero changes on a branch |
---|
187 | CbcSumChange, |
---|
188 | /// Largest non-zero change on a branch |
---|
189 | CbcLargestChange, |
---|
190 | /// Small non-zero change on a branch to be used as guess |
---|
191 | CbcSmallChange, |
---|
192 | /** Just a marker, so that a static sized array can store parameters. */ |
---|
193 | CbcLastDblParam |
---|
194 | }; |
---|
195 | |
---|
196 | //--------------------------------------------------------------------------- |
---|
197 | |
---|
198 | public: |
---|
199 | ///@name Solve methods |
---|
200 | //@{ |
---|
201 | /** \brief Solve the initial LP relaxation |
---|
202 | |
---|
203 | Invoke the solver's %initialSolve() method. |
---|
204 | */ |
---|
205 | void initialSolve(); |
---|
206 | |
---|
207 | /** \brief Invoke the branch \& cut algorithm |
---|
208 | |
---|
209 | The method assumes that initialSolve() has been called to solve the |
---|
210 | LP relaxation. It processes the root node, then proceeds to explore the |
---|
211 | branch & cut search tree. The search ends when the tree is exhausted or |
---|
212 | one of several execution limits is reached. |
---|
213 | If doStatistics is 1 summary statistics are printed |
---|
214 | if 2 then also the path to best solution (if found by branching) |
---|
215 | if 3 then also one line per node |
---|
216 | */ |
---|
217 | void branchAndBound(int doStatistics = 0); |
---|
218 | private: |
---|
219 | |
---|
220 | /** \brief Evaluate a subproblem using cutting planes and heuristics |
---|
221 | |
---|
222 | The method invokes a main loop which generates cuts, applies heuristics, |
---|
223 | and reoptimises using the solver's native %resolve() method. |
---|
224 | It returns true if the subproblem remains feasible at the end of the |
---|
225 | evaluation. |
---|
226 | */ |
---|
227 | bool solveWithCuts(OsiCuts & cuts, int numberTries, CbcNode * node); |
---|
228 | /** Generate one round of cuts - serial mode |
---|
229 | returns - |
---|
230 | 0 - normal |
---|
231 | 1 - must keep going |
---|
232 | 2 - set numberTries to zero |
---|
233 | -1 - infeasible |
---|
234 | */ |
---|
235 | int serialCuts(OsiCuts & cuts, CbcNode * node, OsiCuts & slackCuts, int lastNumberCuts); |
---|
236 | /** Generate one round of cuts - parallel mode |
---|
237 | returns - |
---|
238 | 0 - normal |
---|
239 | 1 - must keep going |
---|
240 | 2 - set numberTries to zero |
---|
241 | -1 - infeasible |
---|
242 | */ |
---|
243 | int parallelCuts(CbcBaseModel * master, OsiCuts & cuts, CbcNode * node, OsiCuts & slackCuts, int lastNumberCuts); |
---|
244 | /** Input one node output N nodes to put on tree and optional solution update |
---|
245 | This should be able to operate in parallel so is given a solver and is const(ish) |
---|
246 | However we will need to keep an array of solver_ and bases and more |
---|
247 | status is 0 for normal, 1 if solution |
---|
248 | Calling code should always push nodes back on tree |
---|
249 | */ |
---|
250 | CbcNode ** solveOneNode(int whichSolver, CbcNode * node, |
---|
251 | int & numberNodesOutput, int & status) ; |
---|
252 | /// Update size of whichGenerator |
---|
253 | void resizeWhichGenerator(int numberNow, int numberAfter); |
---|
254 | public: |
---|
255 | #ifdef CBC_KEEP_DEPRECATED |
---|
256 | // See if anyone is using these any more!! |
---|
257 | /** \brief create a clean model from partially fixed problem |
---|
258 | |
---|
259 | The method creates a new model with given bounds and with no tree. |
---|
260 | */ |
---|
261 | CbcModel * cleanModel(const double * lower, const double * upper); |
---|
262 | /** \brief Invoke the branch \& cut algorithm on partially fixed problem |
---|
263 | |
---|
264 | The method presolves the given model and does branch and cut. The search |
---|
265 | ends when the tree is exhausted or maximum nodes is reached. |
---|
266 | |
---|
267 | If better solution found then it is saved. |
---|
268 | |
---|
269 | Returns 0 if search completed and solution, 1 if not completed and solution, |
---|
270 | 2 if completed and no solution, 3 if not completed and no solution. |
---|
271 | |
---|
272 | Normally okay to do cleanModel immediately followed by subBranchandBound |
---|
273 | (== other form of subBranchAndBound) |
---|
274 | but may need to get at model for advanced features. |
---|
275 | |
---|
276 | Deletes model2 |
---|
277 | */ |
---|
278 | int subBranchAndBound(CbcModel * model2, |
---|
279 | CbcModel * presolvedModel, |
---|
280 | int maximumNodes); |
---|
281 | /** \brief Invoke the branch \& cut algorithm on partially fixed problem |
---|
282 | |
---|
283 | The method creates a new model with given bounds, presolves it |
---|
284 | then proceeds to explore the branch & cut search tree. The search |
---|
285 | ends when the tree is exhausted or maximum nodes is reached. |
---|
286 | |
---|
287 | If better solution found then it is saved. |
---|
288 | |
---|
289 | Returns 0 if search completed and solution, 1 if not completed and solution, |
---|
290 | 2 if completed and no solution, 3 if not completed and no solution. |
---|
291 | |
---|
292 | This is just subModel immediately followed by other version of |
---|
293 | subBranchandBound. |
---|
294 | |
---|
295 | */ |
---|
296 | int subBranchAndBound(const double * lower, const double * upper, |
---|
297 | int maximumNodes); |
---|
298 | |
---|
299 | /** \brief Process root node and return a strengthened model |
---|
300 | |
---|
301 | The method assumes that initialSolve() has been called to solve the |
---|
302 | LP relaxation. It processes the root node and then returns a pointer |
---|
303 | to the strengthened model (or NULL if infeasible) |
---|
304 | */ |
---|
305 | OsiSolverInterface * strengthenedModel(); |
---|
306 | /** preProcess problem - replacing solver |
---|
307 | If makeEquality true then <= cliques converted to ==. |
---|
308 | Presolve will be done numberPasses times. |
---|
309 | |
---|
310 | Returns NULL if infeasible |
---|
311 | |
---|
312 | If makeEquality is 1 add slacks to get cliques, |
---|
313 | if 2 add slacks to get sos (but only if looks plausible) and keep sos info |
---|
314 | */ |
---|
315 | CglPreProcess * preProcess( int makeEquality = 0, int numberPasses = 5, |
---|
316 | int tuning = 5); |
---|
317 | /** Does postprocessing - original solver back. |
---|
318 | User has to delete process */ |
---|
319 | void postProcess(CglPreProcess * process); |
---|
320 | #endif |
---|
321 | /// Adds an update information object |
---|
322 | void addUpdateInformation(const CbcObjectUpdateData & data); |
---|
323 | /** Do one node - broken out for clarity? |
---|
324 | also for parallel (when baseModel!=this) |
---|
325 | Returns 1 if solution found |
---|
326 | node NULL on return if no branches left |
---|
327 | newNode NULL if no new node created |
---|
328 | */ |
---|
329 | int doOneNode(CbcModel * baseModel, CbcNode * & node, CbcNode * & newNode); |
---|
330 | |
---|
331 | public: |
---|
332 | /** \brief Reoptimise an LP relaxation |
---|
333 | |
---|
334 | Invoke the solver's %resolve() method. |
---|
335 | whereFrom - |
---|
336 | 0 - initial continuous |
---|
337 | 1 - resolve on branch (before new cuts) |
---|
338 | 2 - after new cuts |
---|
339 | 3 - obsolete code or something modified problem in unexpected way |
---|
340 | 10 - after strong branching has fixed variables at root |
---|
341 | 11 - after strong branching has fixed variables in tree |
---|
342 | |
---|
343 | returns 1 feasible, 0 infeasible, -1 feasible but skip cuts |
---|
344 | */ |
---|
345 | int resolve(CbcNodeInfo * parent, int whereFrom, |
---|
346 | double * saveSolution = NULL, |
---|
347 | double * saveLower = NULL, |
---|
348 | double * saveUpper = NULL); |
---|
349 | /// Make given rows (L or G) into global cuts and remove from lp |
---|
350 | void makeGlobalCuts(int numberRows, const int * which); |
---|
351 | /// Make given cut into a global cut |
---|
352 | void makeGlobalCut(const OsiRowCut * cut); |
---|
353 | /// Make given cut into a global cut |
---|
354 | void makeGlobalCut(const OsiRowCut & cut); |
---|
355 | /// Make given column cut into a global cut |
---|
356 | void makeGlobalCut(const OsiColCut * cut); |
---|
357 | /// Make given column cut into a global cut |
---|
358 | void makeGlobalCut(const OsiColCut & cut); |
---|
359 | /// Make partial cut into a global cut and save |
---|
360 | void makePartialCut(const OsiRowCut * cut, const OsiSolverInterface * solver=NULL); |
---|
361 | /// Make partial cuts into global cuts |
---|
362 | void makeGlobalCuts(); |
---|
363 | /// Which cut generator generated this cut |
---|
364 | inline const int * whichGenerator() const |
---|
365 | { return whichGenerator_;} |
---|
366 | //@} |
---|
367 | |
---|
368 | /** \name Presolve methods */ |
---|
369 | //@{ |
---|
370 | |
---|
371 | /** Identify cliques and construct corresponding objects. |
---|
372 | |
---|
373 | Find cliques with size in the range |
---|
374 | [\p atLeastThisMany, \p lessThanThis] and construct corresponding |
---|
375 | CbcClique objects. |
---|
376 | If \p makeEquality is true then a new model may be returned if |
---|
377 | modifications had to be made, otherwise \c this is returned. |
---|
378 | If the problem is infeasible #numberObjects_ is set to -1. |
---|
379 | A client must use deleteObjects() before a second call to findCliques(). |
---|
380 | If priorities exist, clique priority is set to the default. |
---|
381 | */ |
---|
382 | CbcModel * findCliques(bool makeEquality, int atLeastThisMany, |
---|
383 | int lessThanThis, int defaultValue = 1000); |
---|
384 | |
---|
385 | /** Do integer presolve, creating a new (presolved) model. |
---|
386 | |
---|
387 | Returns the new model, or NULL if feasibility is lost. |
---|
388 | If weak is true then just does a normal presolve |
---|
389 | |
---|
390 | \todo It remains to work out the cleanest way of getting a solution to |
---|
391 | the original problem at the end. So this is very preliminary. |
---|
392 | */ |
---|
393 | CbcModel * integerPresolve(bool weak = false); |
---|
394 | |
---|
395 | /** Do integer presolve, modifying the current model. |
---|
396 | |
---|
397 | Returns true if the model remains feasible after presolve. |
---|
398 | */ |
---|
399 | bool integerPresolveThisModel(OsiSolverInterface * originalSolver, bool weak = false); |
---|
400 | |
---|
401 | |
---|
402 | /// Put back information into the original model after integer presolve. |
---|
403 | void originalModel(CbcModel * presolvedModel, bool weak); |
---|
404 | |
---|
405 | /** \brief For variables involved in VUB constraints, see if we can tighten |
---|
406 | bounds by solving lp's |
---|
407 | |
---|
408 | Returns false if feasibility is lost. |
---|
409 | If CglProbing is available, it will be tried as well to see if it can |
---|
410 | tighten bounds. |
---|
411 | This routine is just a front end for tightenVubs(int,const int*,double). |
---|
412 | |
---|
413 | If <tt>type = -1</tt> all variables are processed (could be very slow). |
---|
414 | If <tt>type = 0</tt> only variables involved in VUBs are processed. |
---|
415 | If <tt>type = n > 0</tt>, only the n most expensive VUB variables |
---|
416 | are processed, where it is assumed that x is at its maximum so delta |
---|
417 | would have to go to 1 (if x not at bound). |
---|
418 | |
---|
419 | If \p allowMultipleBinary is true, then a VUB constraint is a row with |
---|
420 | one continuous variable and any number of binary variables. |
---|
421 | |
---|
422 | If <tt>useCutoff < 1.0e30</tt>, the original objective is installed as a |
---|
423 | constraint with \p useCutoff as a bound. |
---|
424 | */ |
---|
425 | bool tightenVubs(int type, bool allowMultipleBinary = false, |
---|
426 | double useCutoff = 1.0e50); |
---|
427 | |
---|
428 | /** \brief For variables involved in VUB constraints, see if we can tighten |
---|
429 | bounds by solving lp's |
---|
430 | |
---|
431 | This version is just handed a list of variables to be processed. |
---|
432 | */ |
---|
433 | bool tightenVubs(int numberVubs, const int * which, |
---|
434 | double useCutoff = 1.0e50); |
---|
435 | /** |
---|
436 | Analyze problem to find a minimum change in the objective function. |
---|
437 | */ |
---|
438 | void analyzeObjective(); |
---|
439 | |
---|
440 | /** |
---|
441 | Add additional integers. |
---|
442 | */ |
---|
443 | void AddIntegers(); |
---|
444 | /** |
---|
445 | Save copy of the model. |
---|
446 | */ |
---|
447 | void saveModel(OsiSolverInterface * saveSolver, double * checkCutoffForRestart, bool * feasible); |
---|
448 | /** |
---|
449 | Flip direction of optimization on all models |
---|
450 | */ |
---|
451 | void flipModel(); |
---|
452 | |
---|
453 | //@} |
---|
454 | |
---|
455 | /** \name Object manipulation routines |
---|
456 | |
---|
457 | See OsiObject for an explanation of `object' in the context of CbcModel. |
---|
458 | */ |
---|
459 | //@{ |
---|
460 | |
---|
461 | /// Get the number of objects |
---|
462 | inline int numberObjects() const { |
---|
463 | return numberObjects_; |
---|
464 | } |
---|
465 | /// Set the number of objects |
---|
466 | inline void setNumberObjects(int number) { |
---|
467 | numberObjects_ = number; |
---|
468 | } |
---|
469 | |
---|
470 | /// Get the array of objects |
---|
471 | inline OsiObject ** objects() const { |
---|
472 | return object_; |
---|
473 | } |
---|
474 | |
---|
475 | /// Get the specified object |
---|
476 | const inline OsiObject * object(int which) const { |
---|
477 | return object_[which]; |
---|
478 | } |
---|
479 | /// Get the specified object |
---|
480 | inline OsiObject * modifiableObject(int which) const { |
---|
481 | return object_[which]; |
---|
482 | } |
---|
483 | |
---|
484 | void setOptionalInteger(int index); |
---|
485 | |
---|
486 | /// Delete all object information (and just back to integers if true) |
---|
487 | void deleteObjects(bool findIntegers = true); |
---|
488 | |
---|
489 | /** Add in object information. |
---|
490 | |
---|
491 | Objects are cloned; the owner can delete the originals. |
---|
492 | */ |
---|
493 | void addObjects(int numberObjects, OsiObject ** objects); |
---|
494 | |
---|
495 | /** Add in object information. |
---|
496 | |
---|
497 | Objects are cloned; the owner can delete the originals. |
---|
498 | */ |
---|
499 | void addObjects(int numberObjects, CbcObject ** objects); |
---|
500 | |
---|
501 | /// Ensure attached objects point to this model. |
---|
502 | void synchronizeModel() ; |
---|
503 | |
---|
504 | /** \brief Identify integer variables and create corresponding objects. |
---|
505 | |
---|
506 | Record integer variables and create an CbcSimpleInteger object for each |
---|
507 | one. |
---|
508 | If \p startAgain is true, a new scan is forced, overwriting any existing |
---|
509 | integer variable information. |
---|
510 | If type > 0 then 1==PseudoCost, 2 new ones low priority |
---|
511 | */ |
---|
512 | |
---|
513 | void findIntegers(bool startAgain, int type = 0); |
---|
514 | |
---|
515 | #ifdef SWITCH_VARIABLES |
---|
516 | /// Convert Dynamic to Switching |
---|
517 | int findSwitching(); |
---|
518 | /// Fix associated variables |
---|
519 | int fixAssociated(OsiSolverInterface * solver,int cleanBasis); |
---|
520 | /// Debug associated variables |
---|
521 | int checkAssociated(const OsiSolverInterface * solver, |
---|
522 | const double * solution, int printLevel); |
---|
523 | #endif |
---|
524 | //@} |
---|
525 | |
---|
526 | //--------------------------------------------------------------------------- |
---|
527 | |
---|
528 | /**@name Parameter set/get methods |
---|
529 | |
---|
530 | The set methods return true if the parameter was set to the given value, |
---|
531 | false if the value of the parameter is out of range. |
---|
532 | |
---|
533 | The get methods return the value of the parameter. |
---|
534 | |
---|
535 | */ |
---|
536 | //@{ |
---|
537 | /// Set an integer parameter |
---|
538 | inline bool setIntParam(CbcIntParam key, int value) { |
---|
539 | intParam_[key] = value; |
---|
540 | return true; |
---|
541 | } |
---|
542 | /// Set a double parameter |
---|
543 | inline bool setDblParam(CbcDblParam key, double value) { |
---|
544 | dblParam_[key] = value; |
---|
545 | return true; |
---|
546 | } |
---|
547 | /// Get an integer parameter |
---|
548 | inline int getIntParam(CbcIntParam key) const { |
---|
549 | return intParam_[key]; |
---|
550 | } |
---|
551 | /// Get a double parameter |
---|
552 | inline double getDblParam(CbcDblParam key) const { |
---|
553 | return dblParam_[key]; |
---|
554 | } |
---|
555 | /*! \brief Set cutoff bound on the objective function. |
---|
556 | |
---|
557 | When using strict comparison, the bound is adjusted by a tolerance to |
---|
558 | avoid accidentally cutting off the optimal solution. |
---|
559 | */ |
---|
560 | void setCutoff(double value) ; |
---|
561 | |
---|
562 | /// Get the cutoff bound on the objective function - always as minimize |
---|
563 | inline double getCutoff() const { //double value ; |
---|
564 | //solver_->getDblParam(OsiDualObjectiveLimit,value) ; |
---|
565 | //assert( dblParam_[CbcCurrentCutoff]== value * solver_->getObjSense()); |
---|
566 | return dblParam_[CbcCurrentCutoff]; |
---|
567 | } |
---|
568 | |
---|
569 | /// Set the \link CbcModel::CbcMaxNumNode maximum node limit \endlink |
---|
570 | inline bool setMaximumNodes( int value) { |
---|
571 | return setIntParam(CbcMaxNumNode, value); |
---|
572 | } |
---|
573 | |
---|
574 | /// Get the \link CbcModel::CbcMaxNumNode maximum node limit \endlink |
---|
575 | inline int getMaximumNodes() const { |
---|
576 | return getIntParam(CbcMaxNumNode); |
---|
577 | } |
---|
578 | |
---|
579 | /** Set the |
---|
580 | \link CbcModel::CbcMaxNumSol maximum number of solutions \endlink |
---|
581 | desired. |
---|
582 | */ |
---|
583 | inline bool setMaximumSolutions( int value) { |
---|
584 | return setIntParam(CbcMaxNumSol, value); |
---|
585 | } |
---|
586 | /** Get the |
---|
587 | \link CbcModel::CbcMaxNumSol maximum number of solutions \endlink |
---|
588 | desired. |
---|
589 | */ |
---|
590 | inline int getMaximumSolutions() const { |
---|
591 | return getIntParam(CbcMaxNumSol); |
---|
592 | } |
---|
593 | /// Set the printing mode |
---|
594 | inline bool setPrintingMode( int value) { |
---|
595 | return setIntParam(CbcPrinting, value); |
---|
596 | } |
---|
597 | |
---|
598 | /// Get the printing mode |
---|
599 | inline int getPrintingMode() const { |
---|
600 | return getIntParam(CbcPrinting); |
---|
601 | } |
---|
602 | |
---|
603 | /** Set the |
---|
604 | \link CbcModel::CbcMaximumSeconds maximum number of seconds \endlink |
---|
605 | desired. |
---|
606 | */ |
---|
607 | inline bool setMaximumSeconds( double value) { |
---|
608 | return setDblParam(CbcMaximumSeconds, value); |
---|
609 | } |
---|
610 | /** Get the |
---|
611 | \link CbcModel::CbcMaximumSeconds maximum number of seconds \endlink |
---|
612 | desired. |
---|
613 | */ |
---|
614 | inline double getMaximumSeconds() const { |
---|
615 | return getDblParam(CbcMaximumSeconds); |
---|
616 | } |
---|
617 | /// Current time since start of branchAndbound |
---|
618 | double getCurrentSeconds() const ; |
---|
619 | |
---|
620 | /// Return true if maximum time reached |
---|
621 | bool maximumSecondsReached() const ; |
---|
622 | |
---|
623 | /** Set the |
---|
624 | \link CbcModel::CbcIntegerTolerance integrality tolerance \endlink |
---|
625 | */ |
---|
626 | inline bool setIntegerTolerance( double value) { |
---|
627 | return setDblParam(CbcIntegerTolerance, value); |
---|
628 | } |
---|
629 | /** Get the |
---|
630 | \link CbcModel::CbcIntegerTolerance integrality tolerance \endlink |
---|
631 | */ |
---|
632 | inline double getIntegerTolerance() const { |
---|
633 | return getDblParam(CbcIntegerTolerance); |
---|
634 | } |
---|
635 | |
---|
636 | /** Set the |
---|
637 | \link CbcModel::CbcInfeasibilityWeight |
---|
638 | weight per integer infeasibility \endlink |
---|
639 | */ |
---|
640 | inline bool setInfeasibilityWeight( double value) { |
---|
641 | return setDblParam(CbcInfeasibilityWeight, value); |
---|
642 | } |
---|
643 | /** Get the |
---|
644 | \link CbcModel::CbcInfeasibilityWeight |
---|
645 | weight per integer infeasibility \endlink |
---|
646 | */ |
---|
647 | inline double getInfeasibilityWeight() const { |
---|
648 | return getDblParam(CbcInfeasibilityWeight); |
---|
649 | } |
---|
650 | |
---|
651 | /** Set the \link CbcModel::CbcAllowableGap allowable gap \endlink |
---|
652 | between the best known solution and the best possible solution. |
---|
653 | */ |
---|
654 | inline bool setAllowableGap( double value) { |
---|
655 | return setDblParam(CbcAllowableGap, value); |
---|
656 | } |
---|
657 | /** Get the \link CbcModel::CbcAllowableGap allowable gap \endlink |
---|
658 | between the best known solution and the best possible solution. |
---|
659 | */ |
---|
660 | inline double getAllowableGap() const { |
---|
661 | return getDblParam(CbcAllowableGap); |
---|
662 | } |
---|
663 | |
---|
664 | /** Set the \link CbcModel::CbcAllowableFractionGap fraction allowable gap \endlink |
---|
665 | between the best known solution and the best possible solution. |
---|
666 | */ |
---|
667 | inline bool setAllowableFractionGap( double value) { |
---|
668 | return setDblParam(CbcAllowableFractionGap, value); |
---|
669 | } |
---|
670 | /** Get the \link CbcModel::CbcAllowableFractionGap fraction allowable gap \endlink |
---|
671 | between the best known solution and the best possible solution. |
---|
672 | */ |
---|
673 | inline double getAllowableFractionGap() const { |
---|
674 | return getDblParam(CbcAllowableFractionGap); |
---|
675 | } |
---|
676 | /** Set the \link CbcModel::CbcAllowableFractionGap percentage allowable gap \endlink |
---|
677 | between the best known solution and the best possible solution. |
---|
678 | */ |
---|
679 | inline bool setAllowablePercentageGap( double value) { |
---|
680 | return setDblParam(CbcAllowableFractionGap, value*0.01); |
---|
681 | } |
---|
682 | /** Get the \link CbcModel::CbcAllowableFractionGap percentage allowable gap \endlink |
---|
683 | between the best known solution and the best possible solution. |
---|
684 | */ |
---|
685 | inline double getAllowablePercentageGap() const { |
---|
686 | return 100.0*getDblParam(CbcAllowableFractionGap); |
---|
687 | } |
---|
688 | /** Set the \link CbcModel::CbcHeuristicGap heuristic gap \endlink |
---|
689 | between the best known solution and the best possible solution. |
---|
690 | */ |
---|
691 | inline bool setHeuristicGap( double value) { |
---|
692 | return setDblParam(CbcHeuristicGap, value); |
---|
693 | } |
---|
694 | /** Get the \link CbcModel::CbcHeuristicGap heuristic gap \endlink |
---|
695 | between the best known solution and the best possible solution. |
---|
696 | */ |
---|
697 | inline double getHeuristicGap() const { |
---|
698 | return getDblParam(CbcHeuristicGap); |
---|
699 | } |
---|
700 | |
---|
701 | /** Set the \link CbcModel::CbcHeuristicFractionGap fraction heuristic gap \endlink |
---|
702 | between the best known solution and the best possible solution. |
---|
703 | */ |
---|
704 | inline bool setHeuristicFractionGap( double value) { |
---|
705 | return setDblParam(CbcHeuristicFractionGap, value); |
---|
706 | } |
---|
707 | /** Get the \link CbcModel::CbcHeuristicFractionGap fraction heuristic gap \endlink |
---|
708 | between the best known solution and the best possible solution. |
---|
709 | */ |
---|
710 | inline double getHeuristicFractionGap() const { |
---|
711 | return getDblParam(CbcHeuristicFractionGap); |
---|
712 | } |
---|
713 | /** Set the |
---|
714 | \link CbcModel::CbcCutoffIncrement \endlink |
---|
715 | desired. |
---|
716 | */ |
---|
717 | inline bool setCutoffIncrement( double value) { |
---|
718 | return setDblParam(CbcCutoffIncrement, value); |
---|
719 | } |
---|
720 | /** Get the |
---|
721 | \link CbcModel::CbcCutoffIncrement \endlink |
---|
722 | desired. |
---|
723 | */ |
---|
724 | inline double getCutoffIncrement() const { |
---|
725 | return getDblParam(CbcCutoffIncrement); |
---|
726 | } |
---|
727 | /// See if can stop on gap |
---|
728 | bool canStopOnGap() const; |
---|
729 | |
---|
730 | /** Pass in target solution and optional priorities. |
---|
731 | If priorities then >0 means only branch if incorrect |
---|
732 | while <0 means branch even if correct. +1 or -1 are |
---|
733 | highest priority */ |
---|
734 | void setHotstartSolution(const double * solution, const int * priorities = NULL) ; |
---|
735 | |
---|
736 | /// Set the minimum drop to continue cuts |
---|
737 | inline void setMinimumDrop(double value) { |
---|
738 | minimumDrop_ = value; |
---|
739 | } |
---|
740 | /// Get the minimum drop to continue cuts |
---|
741 | inline double getMinimumDrop() const { |
---|
742 | return minimumDrop_; |
---|
743 | } |
---|
744 | |
---|
745 | /** Set the maximum number of cut passes at root node (default 20) |
---|
746 | Minimum drop can also be used for fine tuning */ |
---|
747 | inline void setMaximumCutPassesAtRoot(int value) { |
---|
748 | maximumCutPassesAtRoot_ = value; |
---|
749 | } |
---|
750 | /** Get the maximum number of cut passes at root node */ |
---|
751 | inline int getMaximumCutPassesAtRoot() const { |
---|
752 | return maximumCutPassesAtRoot_; |
---|
753 | } |
---|
754 | |
---|
755 | /** Set the maximum number of cut passes at other nodes (default 10) |
---|
756 | Minimum drop can also be used for fine tuning */ |
---|
757 | inline void setMaximumCutPasses(int value) { |
---|
758 | maximumCutPasses_ = value; |
---|
759 | } |
---|
760 | /** Get the maximum number of cut passes at other nodes (default 10) */ |
---|
761 | inline int getMaximumCutPasses() const { |
---|
762 | return maximumCutPasses_; |
---|
763 | } |
---|
764 | /** Get current cut pass number in this round of cuts. |
---|
765 | (1 is first pass) */ |
---|
766 | inline int getCurrentPassNumber() const { |
---|
767 | return currentPassNumber_; |
---|
768 | } |
---|
769 | /** Set current cut pass number in this round of cuts. |
---|
770 | (1 is first pass) */ |
---|
771 | inline void setCurrentPassNumber(int value) { |
---|
772 | currentPassNumber_ = value; |
---|
773 | } |
---|
774 | |
---|
775 | /** Set the maximum number of candidates to be evaluated for strong |
---|
776 | branching. |
---|
777 | |
---|
778 | A value of 0 disables strong branching. |
---|
779 | */ |
---|
780 | void setNumberStrong(int number); |
---|
781 | /** Get the maximum number of candidates to be evaluated for strong |
---|
782 | branching. |
---|
783 | */ |
---|
784 | inline int numberStrong() const { |
---|
785 | return numberStrong_; |
---|
786 | } |
---|
787 | /** Set global preferred way to branch |
---|
788 | -1 down, +1 up, 0 no preference */ |
---|
789 | inline void setPreferredWay(int value) { |
---|
790 | preferredWay_ = value; |
---|
791 | } |
---|
792 | /** Get the preferred way to branch (default 0) */ |
---|
793 | inline int getPreferredWay() const { |
---|
794 | return preferredWay_; |
---|
795 | } |
---|
796 | /// Get at which depths to do cuts |
---|
797 | inline int whenCuts() const { |
---|
798 | return whenCuts_; |
---|
799 | } |
---|
800 | /// Set at which depths to do cuts |
---|
801 | inline void setWhenCuts(int value) { |
---|
802 | whenCuts_ = value; |
---|
803 | } |
---|
804 | /** Return true if we want to do cuts |
---|
805 | If allowForTopOfTree zero then just does on multiples of depth |
---|
806 | if 1 then allows for doing at top of tree |
---|
807 | if 2 then says if cuts allowed anywhere apart from root |
---|
808 | */ |
---|
809 | bool doCutsNow(int allowForTopOfTree) const; |
---|
810 | |
---|
811 | /** Set the number of branches before pseudo costs believed |
---|
812 | in dynamic strong branching. |
---|
813 | |
---|
814 | A value of 0 disables dynamic strong branching. |
---|
815 | */ |
---|
816 | void setNumberBeforeTrust(int number); |
---|
817 | /** get the number of branches before pseudo costs believed |
---|
818 | in dynamic strong branching. */ |
---|
819 | inline int numberBeforeTrust() const { |
---|
820 | return numberBeforeTrust_; |
---|
821 | } |
---|
822 | /** Set the number of variables for which to compute penalties |
---|
823 | in dynamic strong branching. |
---|
824 | |
---|
825 | A value of 0 disables penalties. |
---|
826 | */ |
---|
827 | void setNumberPenalties(int number); |
---|
828 | /** get the number of variables for which to compute penalties |
---|
829 | in dynamic strong branching. */ |
---|
830 | inline int numberPenalties() const { |
---|
831 | return numberPenalties_; |
---|
832 | } |
---|
833 | /// Pointer to top of tree |
---|
834 | inline const CbcFullNodeInfo * topOfTree() const |
---|
835 | { return topOfTree_;} |
---|
836 | /// Number of analyze iterations to do |
---|
837 | inline void setNumberAnalyzeIterations(int number) { |
---|
838 | numberAnalyzeIterations_ = number; |
---|
839 | } |
---|
840 | inline int numberAnalyzeIterations() const { |
---|
841 | return numberAnalyzeIterations_; |
---|
842 | } |
---|
843 | /** Get scale factor to make penalties match strong. |
---|
844 | Should/will be computed */ |
---|
845 | inline double penaltyScaleFactor() const { |
---|
846 | return penaltyScaleFactor_; |
---|
847 | } |
---|
848 | /** Set scale factor to make penalties match strong. |
---|
849 | Should/will be computed */ |
---|
850 | void setPenaltyScaleFactor(double value); |
---|
851 | /** Problem type as set by user or found by analysis. This will be extended |
---|
852 | 0 - not known |
---|
853 | 1 - Set partitioning <= |
---|
854 | 2 - Set partitioning == |
---|
855 | 3 - Set covering |
---|
856 | 4 - all +- 1 or all +1 and odd |
---|
857 | */ |
---|
858 | void inline setProblemType(int number) { |
---|
859 | problemType_ = number; |
---|
860 | } |
---|
861 | inline int problemType() const { |
---|
862 | return problemType_; |
---|
863 | } |
---|
864 | /// Current depth |
---|
865 | inline int currentDepth() const { |
---|
866 | return currentDepth_; |
---|
867 | } |
---|
868 | |
---|
869 | /// Set how often to scan global cuts |
---|
870 | void setHowOftenGlobalScan(int number); |
---|
871 | /// Get how often to scan global cuts |
---|
872 | inline int howOftenGlobalScan() const { |
---|
873 | return howOftenGlobalScan_; |
---|
874 | } |
---|
875 | /// Original columns as created by integerPresolve or preprocessing |
---|
876 | inline int * originalColumns() const { |
---|
877 | return originalColumns_; |
---|
878 | } |
---|
879 | /// Set original columns as created by preprocessing |
---|
880 | void setOriginalColumns(const int * originalColumns, |
---|
881 | int numberGood=COIN_INT_MAX) ; |
---|
882 | /// Create conflict cut (well - most of) |
---|
883 | OsiRowCut * conflictCut(const OsiSolverInterface * solver, bool & localCuts); |
---|
884 | |
---|
885 | /** Set the print frequency. |
---|
886 | |
---|
887 | Controls the number of nodes evaluated between status prints. |
---|
888 | If <tt>number <=0</tt> the print frequency is set to 100 nodes for large |
---|
889 | problems, 1000 for small problems. |
---|
890 | Print frequency has very slight overhead if small. |
---|
891 | */ |
---|
892 | inline void setPrintFrequency(int number) { |
---|
893 | printFrequency_ = number; |
---|
894 | } |
---|
895 | /// Get the print frequency |
---|
896 | inline int printFrequency() const { |
---|
897 | return printFrequency_; |
---|
898 | } |
---|
899 | //@} |
---|
900 | |
---|
901 | //--------------------------------------------------------------------------- |
---|
902 | ///@name Methods returning info on how the solution process terminated |
---|
903 | //@{ |
---|
904 | /// Are there a numerical difficulties? |
---|
905 | bool isAbandoned() const; |
---|
906 | /// Is optimality proven? |
---|
907 | bool isProvenOptimal() const; |
---|
908 | /// Is infeasiblity proven (or none better than cutoff)? |
---|
909 | bool isProvenInfeasible() const; |
---|
910 | /// Was continuous solution unbounded |
---|
911 | bool isContinuousUnbounded() const; |
---|
912 | /// Was continuous solution unbounded |
---|
913 | bool isProvenDualInfeasible() const; |
---|
914 | /// Node limit reached? |
---|
915 | bool isNodeLimitReached() const; |
---|
916 | /// Time limit reached? |
---|
917 | bool isSecondsLimitReached() const; |
---|
918 | /// Solution limit reached? |
---|
919 | bool isSolutionLimitReached() const; |
---|
920 | /// Get how many iterations it took to solve the problem. |
---|
921 | inline int getIterationCount() const { |
---|
922 | return numberIterations_; |
---|
923 | } |
---|
924 | /// Increment how many iterations it took to solve the problem. |
---|
925 | inline void incrementIterationCount(int value) { |
---|
926 | numberIterations_ += value; |
---|
927 | } |
---|
928 | /// Get how many Nodes it took to solve the problem (including those in complete fathoming B&B inside CLP). |
---|
929 | inline int getNodeCount() const { |
---|
930 | return numberNodes_; |
---|
931 | } |
---|
932 | /// Increment how many nodes it took to solve the problem. |
---|
933 | inline void incrementNodeCount(int value) { |
---|
934 | numberNodes_ += value; |
---|
935 | } |
---|
936 | /// Get how many Nodes were enumerated in complete fathoming B&B inside CLP |
---|
937 | inline int getExtraNodeCount() const { |
---|
938 | return numberExtraNodes_; |
---|
939 | } |
---|
940 | /** Final status of problem |
---|
941 | Some of these can be found out by is...... functions |
---|
942 | -1 before branchAndBound |
---|
943 | 0 finished - check isProvenOptimal or isProvenInfeasible to see if solution found |
---|
944 | (or check value of best solution) |
---|
945 | 1 stopped - on maxnodes, maxsols, maxtime |
---|
946 | 2 difficulties so run was abandoned |
---|
947 | (5 event user programmed event occurred) |
---|
948 | */ |
---|
949 | inline int status() const { |
---|
950 | return status_; |
---|
951 | } |
---|
952 | inline void setProblemStatus(int value) { |
---|
953 | status_ = value; |
---|
954 | } |
---|
955 | /** Secondary status of problem |
---|
956 | -1 unset (status_ will also be -1) |
---|
957 | 0 search completed with solution |
---|
958 | 1 linear relaxation not feasible (or worse than cutoff) |
---|
959 | 2 stopped on gap |
---|
960 | 3 stopped on nodes |
---|
961 | 4 stopped on time |
---|
962 | 5 stopped on user event |
---|
963 | 6 stopped on solutions |
---|
964 | 7 linear relaxation unbounded |
---|
965 | 8 stopped on iteration limit |
---|
966 | */ |
---|
967 | inline int secondaryStatus() const { |
---|
968 | return secondaryStatus_; |
---|
969 | } |
---|
970 | inline void setSecondaryStatus(int value) { |
---|
971 | secondaryStatus_ = value; |
---|
972 | } |
---|
973 | /// Are there numerical difficulties (for initialSolve) ? |
---|
974 | bool isInitialSolveAbandoned() const ; |
---|
975 | /// Is optimality proven (for initialSolve) ? |
---|
976 | bool isInitialSolveProvenOptimal() const ; |
---|
977 | /// Is primal infeasiblity proven (for initialSolve) ? |
---|
978 | bool isInitialSolveProvenPrimalInfeasible() const ; |
---|
979 | /// Is dual infeasiblity proven (for initialSolve) ? |
---|
980 | bool isInitialSolveProvenDualInfeasible() const ; |
---|
981 | |
---|
982 | //@} |
---|
983 | |
---|
984 | //--------------------------------------------------------------------------- |
---|
985 | /**@name Problem information methods |
---|
986 | |
---|
987 | These methods call the solver's query routines to return |
---|
988 | information about the problem referred to by the current object. |
---|
989 | Querying a problem that has no data associated with it result in |
---|
990 | zeros for the number of rows and columns, and NULL pointers from |
---|
991 | the methods that return vectors. |
---|
992 | |
---|
993 | Const pointers returned from any data-query method are valid as |
---|
994 | long as the data is unchanged and the solver is not called. |
---|
995 | */ |
---|
996 | //@{ |
---|
997 | /// Number of rows in continuous (root) problem. |
---|
998 | inline int numberRowsAtContinuous() const { |
---|
999 | return numberRowsAtContinuous_; |
---|
1000 | } |
---|
1001 | |
---|
1002 | /// Get number of columns |
---|
1003 | inline int getNumCols() const { |
---|
1004 | return solver_->getNumCols(); |
---|
1005 | } |
---|
1006 | |
---|
1007 | /// Get number of rows |
---|
1008 | inline int getNumRows() const { |
---|
1009 | return solver_->getNumRows(); |
---|
1010 | } |
---|
1011 | |
---|
1012 | /// Get number of nonzero elements |
---|
1013 | inline CoinBigIndex getNumElements() const { |
---|
1014 | return solver_->getNumElements(); |
---|
1015 | } |
---|
1016 | |
---|
1017 | /// Number of integers in problem |
---|
1018 | inline int numberIntegers() const { |
---|
1019 | return numberIntegers_; |
---|
1020 | } |
---|
1021 | // Integer variables |
---|
1022 | inline const int * integerVariable() const { |
---|
1023 | return integerVariable_; |
---|
1024 | } |
---|
1025 | /// Whether or not integer |
---|
1026 | inline char integerType(int i) const { |
---|
1027 | assert (integerInfo_); |
---|
1028 | assert (integerInfo_[i] == 0 || integerInfo_[i] == 1); |
---|
1029 | return integerInfo_[i]; |
---|
1030 | } |
---|
1031 | /// Whether or not integer |
---|
1032 | inline const char * integerType() const { |
---|
1033 | return integerInfo_; |
---|
1034 | } |
---|
1035 | |
---|
1036 | /// Get pointer to array[getNumCols()] of column lower bounds |
---|
1037 | inline const double * getColLower() const { |
---|
1038 | return solver_->getColLower(); |
---|
1039 | } |
---|
1040 | |
---|
1041 | /// Get pointer to array[getNumCols()] of column upper bounds |
---|
1042 | inline const double * getColUpper() const { |
---|
1043 | return solver_->getColUpper(); |
---|
1044 | } |
---|
1045 | |
---|
1046 | /** Get pointer to array[getNumRows()] of row constraint senses. |
---|
1047 | <ul> |
---|
1048 | <li>'L': <= constraint |
---|
1049 | <li>'E': = constraint |
---|
1050 | <li>'G': >= constraint |
---|
1051 | <li>'R': ranged constraint |
---|
1052 | <li>'N': free constraint |
---|
1053 | </ul> |
---|
1054 | */ |
---|
1055 | inline const char * getRowSense() const { |
---|
1056 | return solver_->getRowSense(); |
---|
1057 | } |
---|
1058 | |
---|
1059 | /** Get pointer to array[getNumRows()] of rows right-hand sides |
---|
1060 | <ul> |
---|
1061 | <li> if rowsense()[i] == 'L' then rhs()[i] == rowupper()[i] |
---|
1062 | <li> if rowsense()[i] == 'G' then rhs()[i] == rowlower()[i] |
---|
1063 | <li> if rowsense()[i] == 'R' then rhs()[i] == rowupper()[i] |
---|
1064 | <li> if rowsense()[i] == 'N' then rhs()[i] == 0.0 |
---|
1065 | </ul> |
---|
1066 | */ |
---|
1067 | inline const double * getRightHandSide() const { |
---|
1068 | return solver_->getRightHandSide(); |
---|
1069 | } |
---|
1070 | |
---|
1071 | /** Get pointer to array[getNumRows()] of row ranges. |
---|
1072 | <ul> |
---|
1073 | <li> if rowsense()[i] == 'R' then |
---|
1074 | rowrange()[i] == rowupper()[i] - rowlower()[i] |
---|
1075 | <li> if rowsense()[i] != 'R' then |
---|
1076 | rowrange()[i] is 0.0 |
---|
1077 | </ul> |
---|
1078 | */ |
---|
1079 | inline const double * getRowRange() const { |
---|
1080 | return solver_->getRowRange(); |
---|
1081 | } |
---|
1082 | |
---|
1083 | /// Get pointer to array[getNumRows()] of row lower bounds |
---|
1084 | inline const double * getRowLower() const { |
---|
1085 | return solver_->getRowLower(); |
---|
1086 | } |
---|
1087 | |
---|
1088 | /// Get pointer to array[getNumRows()] of row upper bounds |
---|
1089 | inline const double * getRowUpper() const { |
---|
1090 | return solver_->getRowUpper(); |
---|
1091 | } |
---|
1092 | |
---|
1093 | /// Get pointer to array[getNumCols()] of objective function coefficients |
---|
1094 | inline const double * getObjCoefficients() const { |
---|
1095 | return solver_->getObjCoefficients(); |
---|
1096 | } |
---|
1097 | |
---|
1098 | /// Get objective function sense (1 for min (default), -1 for max) |
---|
1099 | inline double getObjSense() const { |
---|
1100 | //assert (dblParam_[CbcOptimizationDirection]== solver_->getObjSense()); |
---|
1101 | return dblParam_[CbcOptimizationDirection]; |
---|
1102 | } |
---|
1103 | |
---|
1104 | /// Return true if variable is continuous |
---|
1105 | inline bool isContinuous(int colIndex) const { |
---|
1106 | return solver_->isContinuous(colIndex); |
---|
1107 | } |
---|
1108 | |
---|
1109 | /// Return true if variable is binary |
---|
1110 | inline bool isBinary(int colIndex) const { |
---|
1111 | return solver_->isBinary(colIndex); |
---|
1112 | } |
---|
1113 | |
---|
1114 | /** Return true if column is integer. |
---|
1115 | Note: This function returns true if the the column |
---|
1116 | is binary or a general integer. |
---|
1117 | */ |
---|
1118 | inline bool isInteger(int colIndex) const { |
---|
1119 | return solver_->isInteger(colIndex); |
---|
1120 | } |
---|
1121 | |
---|
1122 | /// Return true if variable is general integer |
---|
1123 | inline bool isIntegerNonBinary(int colIndex) const { |
---|
1124 | return solver_->isIntegerNonBinary(colIndex); |
---|
1125 | } |
---|
1126 | |
---|
1127 | /// Return true if variable is binary and not fixed at either bound |
---|
1128 | inline bool isFreeBinary(int colIndex) const { |
---|
1129 | return solver_->isFreeBinary(colIndex) ; |
---|
1130 | } |
---|
1131 | |
---|
1132 | /// Get pointer to row-wise copy of matrix |
---|
1133 | inline const CoinPackedMatrix * getMatrixByRow() const { |
---|
1134 | return solver_->getMatrixByRow(); |
---|
1135 | } |
---|
1136 | |
---|
1137 | /// Get pointer to column-wise copy of matrix |
---|
1138 | inline const CoinPackedMatrix * getMatrixByCol() const { |
---|
1139 | return solver_->getMatrixByCol(); |
---|
1140 | } |
---|
1141 | |
---|
1142 | /// Get solver's value for infinity |
---|
1143 | inline double getInfinity() const { |
---|
1144 | return solver_->getInfinity(); |
---|
1145 | } |
---|
1146 | /// Get pointer to array[getNumCols()] (for speed) of column lower bounds |
---|
1147 | inline const double * getCbcColLower() const { |
---|
1148 | return cbcColLower_; |
---|
1149 | } |
---|
1150 | /// Get pointer to array[getNumCols()] (for speed) of column upper bounds |
---|
1151 | inline const double * getCbcColUpper() const { |
---|
1152 | return cbcColUpper_; |
---|
1153 | } |
---|
1154 | /// Get pointer to array[getNumRows()] (for speed) of row lower bounds |
---|
1155 | inline const double * getCbcRowLower() const { |
---|
1156 | return cbcRowLower_; |
---|
1157 | } |
---|
1158 | /// Get pointer to array[getNumRows()] (for speed) of row upper bounds |
---|
1159 | inline const double * getCbcRowUpper() const { |
---|
1160 | return cbcRowUpper_; |
---|
1161 | } |
---|
1162 | /// Get pointer to array[getNumCols()] (for speed) of primal solution vector |
---|
1163 | inline const double * getCbcColSolution() const { |
---|
1164 | return cbcColSolution_; |
---|
1165 | } |
---|
1166 | /// Get pointer to array[getNumRows()] (for speed) of dual prices |
---|
1167 | inline const double * getCbcRowPrice() const { |
---|
1168 | return cbcRowPrice_; |
---|
1169 | } |
---|
1170 | /// Get a pointer to array[getNumCols()] (for speed) of reduced costs |
---|
1171 | inline const double * getCbcReducedCost() const { |
---|
1172 | return cbcReducedCost_; |
---|
1173 | } |
---|
1174 | /// Get pointer to array[getNumRows()] (for speed) of row activity levels. |
---|
1175 | inline const double * getCbcRowActivity() const { |
---|
1176 | return cbcRowActivity_; |
---|
1177 | } |
---|
1178 | //@} |
---|
1179 | |
---|
1180 | |
---|
1181 | /**@name Methods related to querying the solution */ |
---|
1182 | //@{ |
---|
1183 | /// Holds solution at continuous (after cuts if branchAndBound called) |
---|
1184 | inline double * continuousSolution() const { |
---|
1185 | return continuousSolution_; |
---|
1186 | } |
---|
1187 | /** Array marked whenever a solution is found if non-zero. |
---|
1188 | Code marks if heuristic returns better so heuristic |
---|
1189 | need only mark if it wants to on solutions which |
---|
1190 | are worse than current */ |
---|
1191 | inline int * usedInSolution() const { |
---|
1192 | return usedInSolution_; |
---|
1193 | } |
---|
1194 | /// Increases usedInSolution for nonzeros |
---|
1195 | void incrementUsed(const double * solution); |
---|
1196 | /// Record a new incumbent solution and update objectiveValue |
---|
1197 | void setBestSolution(CBC_Message how, |
---|
1198 | double & objectiveValue, const double *solution, |
---|
1199 | int fixVariables = 0); |
---|
1200 | /// Just update objectiveValue |
---|
1201 | void setBestObjectiveValue( double objectiveValue); |
---|
1202 | /// Deals with event handler and solution |
---|
1203 | CbcEventHandler::CbcAction dealWithEventHandler(CbcEventHandler::CbcEvent event, |
---|
1204 | double objValue, |
---|
1205 | const double * solution); |
---|
1206 | |
---|
1207 | /** Call this to really test if a valid solution can be feasible |
---|
1208 | Solution is number columns in size. |
---|
1209 | If fixVariables true then bounds of continuous solver updated. |
---|
1210 | Returns objective value (worse than cutoff if not feasible) |
---|
1211 | Previously computed objective value is now passed in (in case user does not do solve) |
---|
1212 | virtual so user can override |
---|
1213 | */ |
---|
1214 | virtual double checkSolution(double cutoff, double * solution, |
---|
1215 | int fixVariables, double originalObjValue); |
---|
1216 | /** Test the current solution for feasiblility. |
---|
1217 | |
---|
1218 | Scan all objects for indications of infeasibility. This is broken down |
---|
1219 | into simple integer infeasibility (\p numberIntegerInfeasibilities) |
---|
1220 | and all other reports of infeasibility (\p numberObjectInfeasibilities). |
---|
1221 | */ |
---|
1222 | bool feasibleSolution(int & numberIntegerInfeasibilities, |
---|
1223 | int & numberObjectInfeasibilities) const; |
---|
1224 | |
---|
1225 | /** Solution to the most recent lp relaxation. |
---|
1226 | |
---|
1227 | The solver's solution to the most recent lp relaxation. |
---|
1228 | */ |
---|
1229 | |
---|
1230 | inline double * currentSolution() const { |
---|
1231 | return currentSolution_; |
---|
1232 | } |
---|
1233 | /** For testing infeasibilities - will point to |
---|
1234 | currentSolution_ or solver-->getColSolution() |
---|
1235 | */ |
---|
1236 | inline const double * testSolution() const { |
---|
1237 | return testSolution_; |
---|
1238 | } |
---|
1239 | inline void setTestSolution(const double * solution) { |
---|
1240 | testSolution_ = solution; |
---|
1241 | } |
---|
1242 | /// Make sure region there and optionally copy solution |
---|
1243 | void reserveCurrentSolution(const double * solution = NULL); |
---|
1244 | |
---|
1245 | /// Get pointer to array[getNumCols()] of primal solution vector |
---|
1246 | inline const double * getColSolution() const { |
---|
1247 | return solver_->getColSolution(); |
---|
1248 | } |
---|
1249 | |
---|
1250 | /// Get pointer to array[getNumRows()] of dual prices |
---|
1251 | inline const double * getRowPrice() const { |
---|
1252 | return solver_->getRowPrice(); |
---|
1253 | } |
---|
1254 | |
---|
1255 | /// Get a pointer to array[getNumCols()] of reduced costs |
---|
1256 | inline const double * getReducedCost() const { |
---|
1257 | return solver_->getReducedCost(); |
---|
1258 | } |
---|
1259 | |
---|
1260 | /// Get pointer to array[getNumRows()] of row activity levels. |
---|
1261 | inline const double * getRowActivity() const { |
---|
1262 | return solver_->getRowActivity(); |
---|
1263 | } |
---|
1264 | |
---|
1265 | /// Get current objective function value |
---|
1266 | inline double getCurrentObjValue() const { |
---|
1267 | return dblParam_[CbcCurrentObjectiveValue]; |
---|
1268 | } |
---|
1269 | /// Get current minimization objective function value |
---|
1270 | inline double getCurrentMinimizationObjValue() const { |
---|
1271 | return dblParam_[CbcCurrentMinimizationObjectiveValue]; |
---|
1272 | } |
---|
1273 | |
---|
1274 | /// Get best objective function value as minimization |
---|
1275 | inline double getMinimizationObjValue() const { |
---|
1276 | return bestObjective_; |
---|
1277 | } |
---|
1278 | /// Set best objective function value as minimization |
---|
1279 | inline void setMinimizationObjValue(double value) { |
---|
1280 | bestObjective_ = value; |
---|
1281 | } |
---|
1282 | |
---|
1283 | /// Get best objective function value |
---|
1284 | inline double getObjValue() const { |
---|
1285 | return bestObjective_ * solver_->getObjSense() ; |
---|
1286 | } |
---|
1287 | /** Get best possible objective function value. |
---|
1288 | This is better of best possible left on tree |
---|
1289 | and best solution found. |
---|
1290 | If called from within branch and cut may be optimistic. |
---|
1291 | */ |
---|
1292 | double getBestPossibleObjValue() const; |
---|
1293 | /// Set best objective function value |
---|
1294 | inline void setObjValue(double value) { |
---|
1295 | bestObjective_ = value * solver_->getObjSense() ; |
---|
1296 | } |
---|
1297 | /// Get solver objective function value (as minimization) |
---|
1298 | inline double getSolverObjValue() const { |
---|
1299 | return solver_->getObjValue() * solver_->getObjSense() ; |
---|
1300 | } |
---|
1301 | |
---|
1302 | /** The best solution to the integer programming problem. |
---|
1303 | |
---|
1304 | The best solution to the integer programming problem found during |
---|
1305 | the search. If no solution is found, the method returns null. |
---|
1306 | */ |
---|
1307 | |
---|
1308 | inline double * bestSolution() const { |
---|
1309 | return bestSolution_; |
---|
1310 | } |
---|
1311 | /** User callable setBestSolution. |
---|
1312 | If check false does not check valid |
---|
1313 | If true then sees if feasible and warns if objective value |
---|
1314 | worse than given (so just set to COIN_DBL_MAX if you don't care). |
---|
1315 | If check true then does not save solution if not feasible |
---|
1316 | */ |
---|
1317 | void setBestSolution(const double * solution, int numberColumns, |
---|
1318 | double objectiveValue, bool check = false); |
---|
1319 | |
---|
1320 | /// Get number of solutions |
---|
1321 | inline int getSolutionCount() const { |
---|
1322 | return numberSolutions_; |
---|
1323 | } |
---|
1324 | |
---|
1325 | /// Set number of solutions (so heuristics will be different) |
---|
1326 | inline void setSolutionCount(int value) { |
---|
1327 | numberSolutions_ = value; |
---|
1328 | } |
---|
1329 | /// Number of saved solutions (including best) |
---|
1330 | int numberSavedSolutions() const; |
---|
1331 | /// Maximum number of extra saved solutions |
---|
1332 | inline int maximumSavedSolutions() const { |
---|
1333 | return maximumSavedSolutions_; |
---|
1334 | } |
---|
1335 | /// Set maximum number of extra saved solutions |
---|
1336 | void setMaximumSavedSolutions(int value); |
---|
1337 | /// Return a saved solution (0==best) - NULL if off end |
---|
1338 | const double * savedSolution(int which) const; |
---|
1339 | /// Return a saved solution objective (0==best) - COIN_DBL_MAX if off end |
---|
1340 | double savedSolutionObjective(int which) const; |
---|
1341 | /// Delete a saved solution and move others up |
---|
1342 | void deleteSavedSolution(int which); |
---|
1343 | |
---|
1344 | /** Current phase (so heuristics etc etc can find out). |
---|
1345 | 0 - initial solve |
---|
1346 | 1 - solve with cuts at root |
---|
1347 | 2 - solve with cuts |
---|
1348 | 3 - other e.g. strong branching |
---|
1349 | 4 - trying to validate a solution |
---|
1350 | 5 - at end of search |
---|
1351 | */ |
---|
1352 | inline int phase() const { |
---|
1353 | return phase_; |
---|
1354 | } |
---|
1355 | |
---|
1356 | /// Get number of heuristic solutions |
---|
1357 | inline int getNumberHeuristicSolutions() const { |
---|
1358 | return numberHeuristicSolutions_; |
---|
1359 | } |
---|
1360 | /// Set number of heuristic solutions |
---|
1361 | inline void setNumberHeuristicSolutions(int value) { |
---|
1362 | numberHeuristicSolutions_ = value; |
---|
1363 | } |
---|
1364 | |
---|
1365 | /// Set objective function sense (1 for min (default), -1 for max,) |
---|
1366 | inline void setObjSense(double s) { |
---|
1367 | dblParam_[CbcOptimizationDirection] = s; |
---|
1368 | solver_->setObjSense(s); |
---|
1369 | } |
---|
1370 | |
---|
1371 | /// Value of objective at continuous |
---|
1372 | inline double getContinuousObjective() const { |
---|
1373 | return originalContinuousObjective_; |
---|
1374 | } |
---|
1375 | inline void setContinuousObjective(double value) { |
---|
1376 | originalContinuousObjective_ = value; |
---|
1377 | } |
---|
1378 | /// Number of infeasibilities at continuous |
---|
1379 | inline int getContinuousInfeasibilities() const { |
---|
1380 | return continuousInfeasibilities_; |
---|
1381 | } |
---|
1382 | inline void setContinuousInfeasibilities(int value) { |
---|
1383 | continuousInfeasibilities_ = value; |
---|
1384 | } |
---|
1385 | /// Value of objective after root node cuts added |
---|
1386 | inline double rootObjectiveAfterCuts() const { |
---|
1387 | return continuousObjective_; |
---|
1388 | } |
---|
1389 | /// Sum of Changes to objective by first solve |
---|
1390 | inline double sumChangeObjective() const { |
---|
1391 | return sumChangeObjective1_; |
---|
1392 | } |
---|
1393 | /** Number of times global cuts violated. When global cut pool then this |
---|
1394 | should be kept for each cut and type of cut */ |
---|
1395 | inline int numberGlobalViolations() const { |
---|
1396 | return numberGlobalViolations_; |
---|
1397 | } |
---|
1398 | inline void clearNumberGlobalViolations() { |
---|
1399 | numberGlobalViolations_ = 0; |
---|
1400 | } |
---|
1401 | /// Whether to force a resolve after takeOffCuts |
---|
1402 | inline bool resolveAfterTakeOffCuts() const { |
---|
1403 | return resolveAfterTakeOffCuts_; |
---|
1404 | } |
---|
1405 | inline void setResolveAfterTakeOffCuts(bool yesNo) { |
---|
1406 | resolveAfterTakeOffCuts_ = yesNo; |
---|
1407 | } |
---|
1408 | /// Maximum number of rows |
---|
1409 | inline int maximumRows() const { |
---|
1410 | return maximumRows_; |
---|
1411 | } |
---|
1412 | /// Work basis for temporary use |
---|
1413 | inline CoinWarmStartBasis & workingBasis() { |
---|
1414 | return workingBasis_; |
---|
1415 | } |
---|
1416 | /// Get number of "iterations" to stop after |
---|
1417 | inline int getStopNumberIterations() const { |
---|
1418 | return stopNumberIterations_; |
---|
1419 | } |
---|
1420 | /// Set number of "iterations" to stop after |
---|
1421 | inline void setStopNumberIterations(int value) { |
---|
1422 | stopNumberIterations_ = value; |
---|
1423 | } |
---|
1424 | /// A pointer to model from CbcHeuristic |
---|
1425 | inline CbcModel * heuristicModel() const |
---|
1426 | { return heuristicModel_;} |
---|
1427 | /// Set a pointer to model from CbcHeuristic |
---|
1428 | inline void setHeuristicModel(CbcModel * model) |
---|
1429 | { heuristicModel_ = model;} |
---|
1430 | //@} |
---|
1431 | |
---|
1432 | /** \name Node selection */ |
---|
1433 | //@{ |
---|
1434 | // Comparison functions (which may be overridden by inheritance) |
---|
1435 | inline CbcCompareBase * nodeComparison() const { |
---|
1436 | return nodeCompare_; |
---|
1437 | } |
---|
1438 | void setNodeComparison(CbcCompareBase * compare); |
---|
1439 | void setNodeComparison(CbcCompareBase & compare); |
---|
1440 | //@} |
---|
1441 | |
---|
1442 | /** \name Problem feasibility checking */ |
---|
1443 | //@{ |
---|
1444 | // Feasibility functions (which may be overridden by inheritance) |
---|
1445 | inline CbcFeasibilityBase * problemFeasibility() const { |
---|
1446 | return problemFeasibility_; |
---|
1447 | } |
---|
1448 | void setProblemFeasibility(CbcFeasibilityBase * feasibility); |
---|
1449 | void setProblemFeasibility(CbcFeasibilityBase & feasibility); |
---|
1450 | //@} |
---|
1451 | |
---|
1452 | /** \name Tree methods and subtree methods */ |
---|
1453 | //@{ |
---|
1454 | /// Tree method e.g. heap (which may be overridden by inheritance) |
---|
1455 | inline CbcTree * tree() const { |
---|
1456 | return tree_; |
---|
1457 | } |
---|
1458 | /// For modifying tree handling (original is cloned) |
---|
1459 | void passInTreeHandler(CbcTree & tree); |
---|
1460 | /** For passing in an CbcModel to do a sub Tree (with derived tree handlers). |
---|
1461 | Passed in model must exist for duration of branch and bound |
---|
1462 | */ |
---|
1463 | void passInSubTreeModel(CbcModel & model); |
---|
1464 | /** For retrieving a copy of subtree model with given OsiSolver. |
---|
1465 | If no subtree model will use self (up to user to reset cutoff etc). |
---|
1466 | If solver NULL uses current |
---|
1467 | */ |
---|
1468 | CbcModel * subTreeModel(OsiSolverInterface * solver = NULL) const; |
---|
1469 | /// Returns number of times any subtree stopped on nodes, time etc |
---|
1470 | inline int numberStoppedSubTrees() const { |
---|
1471 | return numberStoppedSubTrees_; |
---|
1472 | } |
---|
1473 | /// Says a sub tree was stopped |
---|
1474 | inline void incrementSubTreeStopped() { |
---|
1475 | numberStoppedSubTrees_++; |
---|
1476 | } |
---|
1477 | /** Whether to automatically do presolve before branch and bound (subTrees). |
---|
1478 | 0 - no |
---|
1479 | 1 - ordinary presolve |
---|
1480 | 2 - integer presolve (dodgy) |
---|
1481 | */ |
---|
1482 | inline int typePresolve() const { |
---|
1483 | return presolve_; |
---|
1484 | } |
---|
1485 | inline void setTypePresolve(int value) { |
---|
1486 | presolve_ = value; |
---|
1487 | } |
---|
1488 | |
---|
1489 | //@} |
---|
1490 | |
---|
1491 | /** \name Branching Decisions |
---|
1492 | |
---|
1493 | See the CbcBranchDecision class for additional information. |
---|
1494 | */ |
---|
1495 | //@{ |
---|
1496 | |
---|
1497 | /// Get the current branching decision method. |
---|
1498 | inline CbcBranchDecision * branchingMethod() const { |
---|
1499 | return branchingMethod_; |
---|
1500 | } |
---|
1501 | /// Set the branching decision method. |
---|
1502 | inline void setBranchingMethod(CbcBranchDecision * method) { |
---|
1503 | delete branchingMethod_; |
---|
1504 | branchingMethod_ = method->clone(); |
---|
1505 | } |
---|
1506 | /** Set the branching method |
---|
1507 | |
---|
1508 | \overload |
---|
1509 | */ |
---|
1510 | inline void setBranchingMethod(CbcBranchDecision & method) { |
---|
1511 | delete branchingMethod_; |
---|
1512 | branchingMethod_ = method.clone(); |
---|
1513 | } |
---|
1514 | /// Get the current cut modifier method |
---|
1515 | inline CbcCutModifier * cutModifier() const { |
---|
1516 | return cutModifier_; |
---|
1517 | } |
---|
1518 | /// Set the cut modifier method |
---|
1519 | void setCutModifier(CbcCutModifier * modifier); |
---|
1520 | /** Set the cut modifier method |
---|
1521 | |
---|
1522 | \overload |
---|
1523 | */ |
---|
1524 | void setCutModifier(CbcCutModifier & modifier); |
---|
1525 | //@} |
---|
1526 | |
---|
1527 | /** \name Row (constraint) and Column (variable) cut generation */ |
---|
1528 | //@{ |
---|
1529 | |
---|
1530 | /** State of search |
---|
1531 | 0 - no solution |
---|
1532 | 1 - only heuristic solutions |
---|
1533 | 2 - branched to a solution |
---|
1534 | 3 - no solution but many nodes |
---|
1535 | */ |
---|
1536 | inline int stateOfSearch() const { |
---|
1537 | return stateOfSearch_; |
---|
1538 | } |
---|
1539 | inline void setStateOfSearch(int state) { |
---|
1540 | stateOfSearch_ = state; |
---|
1541 | } |
---|
1542 | /// Strategy worked out - mainly at root node for use by CbcNode |
---|
1543 | inline int searchStrategy() const { |
---|
1544 | return searchStrategy_; |
---|
1545 | } |
---|
1546 | /// Set strategy worked out - mainly at root node for use by CbcNode |
---|
1547 | inline void setSearchStrategy(int value) { |
---|
1548 | searchStrategy_ = value; |
---|
1549 | } |
---|
1550 | /// Stong branching strategy |
---|
1551 | inline int strongStrategy() const { |
---|
1552 | return strongStrategy_; |
---|
1553 | } |
---|
1554 | /// Set strong branching strategy |
---|
1555 | inline void setStrongStrategy(int value) { |
---|
1556 | strongStrategy_ = value; |
---|
1557 | } |
---|
1558 | |
---|
1559 | /// Get the number of cut generators |
---|
1560 | inline int numberCutGenerators() const { |
---|
1561 | return numberCutGenerators_; |
---|
1562 | } |
---|
1563 | /// Get the list of cut generators |
---|
1564 | inline CbcCutGenerator ** cutGenerators() const { |
---|
1565 | return generator_; |
---|
1566 | } |
---|
1567 | ///Get the specified cut generator |
---|
1568 | inline CbcCutGenerator * cutGenerator(int i) const { |
---|
1569 | return generator_[i]; |
---|
1570 | } |
---|
1571 | ///Get the specified cut generator before any changes |
---|
1572 | inline CbcCutGenerator * virginCutGenerator(int i) const { |
---|
1573 | return virginGenerator_[i]; |
---|
1574 | } |
---|
1575 | /** Add one generator - up to user to delete generators. |
---|
1576 | howoften affects how generator is used. 0 or 1 means always, |
---|
1577 | >1 means every that number of nodes. Negative values have same |
---|
1578 | meaning as positive but they may be switched off (-> -100) by code if |
---|
1579 | not many cuts generated at continuous. -99 is just done at root. |
---|
1580 | Name is just for printout. |
---|
1581 | If depth >0 overrides how often generator is called (if howOften==-1 or >0). |
---|
1582 | */ |
---|
1583 | void addCutGenerator(CglCutGenerator * generator, |
---|
1584 | int howOften = 1, const char * name = NULL, |
---|
1585 | bool normal = true, bool atSolution = false, |
---|
1586 | bool infeasible = false, int howOftenInSub = -100, |
---|
1587 | int whatDepth = -1, int whatDepthInSub = -1); |
---|
1588 | //@} |
---|
1589 | /** \name Strategy and sub models |
---|
1590 | |
---|
1591 | See the CbcStrategy class for additional information. |
---|
1592 | */ |
---|
1593 | //@{ |
---|
1594 | |
---|
1595 | /// Get the current strategy |
---|
1596 | inline CbcStrategy * strategy() const { |
---|
1597 | return strategy_; |
---|
1598 | } |
---|
1599 | /// Set the strategy. Clones |
---|
1600 | void setStrategy(CbcStrategy & strategy); |
---|
1601 | /// Set the strategy. assigns |
---|
1602 | inline void setStrategy(CbcStrategy * strategy) { |
---|
1603 | strategy_ = strategy; |
---|
1604 | } |
---|
1605 | /// Get the current parent model |
---|
1606 | inline CbcModel * parentModel() const { |
---|
1607 | return parentModel_; |
---|
1608 | } |
---|
1609 | /// Set the parent model |
---|
1610 | inline void setParentModel(CbcModel & parentModel) { |
---|
1611 | parentModel_ = &parentModel; |
---|
1612 | } |
---|
1613 | //@} |
---|
1614 | |
---|
1615 | |
---|
1616 | /** \name Heuristics and priorities */ |
---|
1617 | //@{ |
---|
1618 | /*! \brief Add one heuristic - up to user to delete |
---|
1619 | |
---|
1620 | The name is just used for print messages. |
---|
1621 | */ |
---|
1622 | void addHeuristic(CbcHeuristic * generator, const char *name = NULL, |
---|
1623 | int before = -1); |
---|
1624 | ///Get the specified heuristic |
---|
1625 | inline CbcHeuristic * heuristic(int i) const { |
---|
1626 | return heuristic_[i]; |
---|
1627 | } |
---|
1628 | /// Get the number of heuristics |
---|
1629 | inline int numberHeuristics() const { |
---|
1630 | return numberHeuristics_; |
---|
1631 | } |
---|
1632 | /// Set the number of heuristics |
---|
1633 | inline void setNumberHeuristics(int value) { |
---|
1634 | numberHeuristics_ = value; |
---|
1635 | } |
---|
1636 | /// Pointer to heuristic solver which found last solution (or NULL) |
---|
1637 | inline CbcHeuristic * lastHeuristic() const { |
---|
1638 | return lastHeuristic_; |
---|
1639 | } |
---|
1640 | /// set last heuristic which found a solution |
---|
1641 | inline void setLastHeuristic(CbcHeuristic * last) { |
---|
1642 | lastHeuristic_ = last; |
---|
1643 | } |
---|
1644 | |
---|
1645 | /** Pass in branching priorities. |
---|
1646 | |
---|
1647 | If ifClique then priorities are on cliques otherwise priorities are |
---|
1648 | on integer variables. |
---|
1649 | Other type (if exists set to default) |
---|
1650 | 1 is highest priority. (well actually -INT_MAX is but that's ugly) |
---|
1651 | If hotstart > 0 then branches are created to force |
---|
1652 | the variable to the value given by best solution. This enables a |
---|
1653 | sort of hot start. The node choice should be greatest depth |
---|
1654 | and hotstart should normally be switched off after a solution. |
---|
1655 | |
---|
1656 | If ifNotSimpleIntegers true then appended to normal integers |
---|
1657 | |
---|
1658 | This is now deprecated except for simple usage. If user |
---|
1659 | creates Cbcobjects then set priority in them |
---|
1660 | |
---|
1661 | \internal Added for Kurt Spielberg. |
---|
1662 | */ |
---|
1663 | void passInPriorities(const int * priorities, bool ifNotSimpleIntegers); |
---|
1664 | |
---|
1665 | /// Returns priority level for an object (or 1000 if no priorities exist) |
---|
1666 | inline int priority(int sequence) const { |
---|
1667 | return object_[sequence]->priority(); |
---|
1668 | } |
---|
1669 | |
---|
1670 | /*! \brief Set an event handler |
---|
1671 | |
---|
1672 | A clone of the handler passed as a parameter is stored in CbcModel. |
---|
1673 | */ |
---|
1674 | void passInEventHandler(const CbcEventHandler *eventHandler) ; |
---|
1675 | |
---|
1676 | /*! \brief Retrieve a pointer to the event handler */ |
---|
1677 | inline CbcEventHandler* getEventHandler() const { |
---|
1678 | return (eventHandler_) ; |
---|
1679 | } |
---|
1680 | |
---|
1681 | //@} |
---|
1682 | |
---|
1683 | /**@name Setting/Accessing application data */ |
---|
1684 | //@{ |
---|
1685 | /** Set application data. |
---|
1686 | |
---|
1687 | This is a pointer that the application can store into and |
---|
1688 | retrieve from the solver interface. |
---|
1689 | This field is available for the application to optionally |
---|
1690 | define and use. |
---|
1691 | */ |
---|
1692 | void setApplicationData (void * appData); |
---|
1693 | |
---|
1694 | /// Get application data |
---|
1695 | void * getApplicationData() const; |
---|
1696 | /** |
---|
1697 | For advanced applications you may wish to modify the behavior of Cbc |
---|
1698 | e.g. if the solver is a NLP solver then you may not have an exact |
---|
1699 | optimum solution at each step. Information could be built into |
---|
1700 | OsiSolverInterface but this is an alternative so that that interface |
---|
1701 | does not have to be changed. If something similar is useful to |
---|
1702 | enough solvers then it could be migrated |
---|
1703 | You can also pass in by using solver->setAuxiliaryInfo. |
---|
1704 | You should do that if solver is odd - if solver is normal simplex |
---|
1705 | then use this. |
---|
1706 | NOTE - characteristics are not cloned |
---|
1707 | */ |
---|
1708 | void passInSolverCharacteristics(OsiBabSolver * solverCharacteristics); |
---|
1709 | /// Get solver characteristics |
---|
1710 | inline const OsiBabSolver * solverCharacteristics() const { |
---|
1711 | return solverCharacteristics_; |
---|
1712 | } |
---|
1713 | //@} |
---|
1714 | |
---|
1715 | //--------------------------------------------------------------------------- |
---|
1716 | |
---|
1717 | /**@name Message handling etc */ |
---|
1718 | //@{ |
---|
1719 | /// Pass in Message handler (not deleted at end) |
---|
1720 | void passInMessageHandler(CoinMessageHandler * handler); |
---|
1721 | /// Set language |
---|
1722 | void newLanguage(CoinMessages::Language language); |
---|
1723 | inline void setLanguage(CoinMessages::Language language) { |
---|
1724 | newLanguage(language); |
---|
1725 | } |
---|
1726 | /// Return handler |
---|
1727 | inline CoinMessageHandler * messageHandler() const { |
---|
1728 | return handler_; |
---|
1729 | } |
---|
1730 | /// Return messages |
---|
1731 | inline CoinMessages & messages() { |
---|
1732 | return messages_; |
---|
1733 | } |
---|
1734 | /// Return pointer to messages |
---|
1735 | inline CoinMessages * messagesPointer() { |
---|
1736 | return &messages_; |
---|
1737 | } |
---|
1738 | /// Set log level |
---|
1739 | void setLogLevel(int value); |
---|
1740 | /// Get log level |
---|
1741 | inline int logLevel() const { |
---|
1742 | return handler_->logLevel(); |
---|
1743 | } |
---|
1744 | /** Set flag to say if handler_ is the default handler. |
---|
1745 | |
---|
1746 | The default handler is deleted when the model is deleted. Other |
---|
1747 | handlers (supplied by the client) will not be deleted. |
---|
1748 | */ |
---|
1749 | inline void setDefaultHandler(bool yesNo) { |
---|
1750 | defaultHandler_ = yesNo; |
---|
1751 | } |
---|
1752 | /// Check default handler |
---|
1753 | inline bool defaultHandler() const { |
---|
1754 | return defaultHandler_; |
---|
1755 | } |
---|
1756 | //@} |
---|
1757 | //--------------------------------------------------------------------------- |
---|
1758 | ///@name Specialized |
---|
1759 | //@{ |
---|
1760 | |
---|
1761 | /** |
---|
1762 | Set special options |
---|
1763 | 0 bit (1) - check if cuts valid (if on debugger list) |
---|
1764 | 1 bit (2) - use current basis to check integer solution (rather than all slack) |
---|
1765 | 2 bit (4) - don't check integer solution (by solving LP) |
---|
1766 | 3 bit (8) - fast analyze |
---|
1767 | 4 bit (16) - non-linear model - so no well defined CoinPackedMatrix |
---|
1768 | 5 bit (32) - keep names |
---|
1769 | 6 bit (64) - try for dominated columns |
---|
1770 | 7 bit (128) - SOS type 1 but all declared integer |
---|
1771 | 8 bit (256) - Set to say solution just found, unset by doing cuts |
---|
1772 | 9 bit (512) - Try reduced model after 100 nodes |
---|
1773 | 10 bit (1024) - Switch on some heuristics even if seems unlikely |
---|
1774 | 11 bit (2048) - Mark as in small branch and bound |
---|
1775 | 12 bit (4096) - Funny cuts so do slow way (in some places) |
---|
1776 | 13 bit (8192) - Funny cuts so do slow way (in other places) |
---|
1777 | 14 bit (16384) - Use Cplex! for fathoming |
---|
1778 | 15 bit (32768) - Try reduced model after 0 nodes |
---|
1779 | 16 bit (65536) - Original model had integer bounds |
---|
1780 | 17 bit (131072) - Perturbation switched off |
---|
1781 | 18 bit (262144) - donor CbcModel |
---|
1782 | 19 bit (524288) - recipient CbcModel |
---|
1783 | 20 bit (1048576) - waiting for sub model to return |
---|
1784 | 22 bit (4194304) - do not initialize random seed in solver (user has) |
---|
1785 | 23 bit (8388608) - leave solver_ with cuts |
---|
1786 | 24 bit (16777216) - just get feasible if no cutoff |
---|
1787 | */ |
---|
1788 | inline void setSpecialOptions(int value) { |
---|
1789 | specialOptions_ = value; |
---|
1790 | } |
---|
1791 | /// Get special options |
---|
1792 | inline int specialOptions() const { |
---|
1793 | return specialOptions_; |
---|
1794 | } |
---|
1795 | /// Set random seed |
---|
1796 | inline void setRandomSeed(int value) { |
---|
1797 | randomSeed_ = value; |
---|
1798 | } |
---|
1799 | /// Get random seed |
---|
1800 | inline int getRandomSeed() const { |
---|
1801 | return randomSeed_; |
---|
1802 | } |
---|
1803 | /// Set multiple root tries |
---|
1804 | inline void setMultipleRootTries(int value) { |
---|
1805 | multipleRootTries_ = value; |
---|
1806 | } |
---|
1807 | /// Get multiple root tries |
---|
1808 | inline int getMultipleRootTries() const { |
---|
1809 | return multipleRootTries_; |
---|
1810 | } |
---|
1811 | /// Tell model to stop on event |
---|
1812 | inline void sayEventHappened() |
---|
1813 | { eventHappened_=true;} |
---|
1814 | /// Says if normal solver i.e. has well defined CoinPackedMatrix |
---|
1815 | inline bool normalSolver() const { |
---|
1816 | return (specialOptions_&16) == 0; |
---|
1817 | } |
---|
1818 | /** Says if model is sitting there waiting for mini branch and bound to finish |
---|
1819 | This is because an event handler may only have access to parent model in |
---|
1820 | mini branch and bound |
---|
1821 | */ |
---|
1822 | inline bool waitingForMiniBranchAndBound() const { |
---|
1823 | return (specialOptions_&1048576) != 0; |
---|
1824 | } |
---|
1825 | /** Set more special options |
---|
1826 | at present bottom 6 bits used for shadow price mode |
---|
1827 | 1024 for experimental hotstart |
---|
1828 | 2048,4096 breaking out of cuts |
---|
1829 | 8192 slowly increase minimum drop |
---|
1830 | 16384 gomory |
---|
1831 | 32768 more heuristics in sub trees |
---|
1832 | 65536 no cuts in preprocessing |
---|
1833 | 131072 Time limits elapsed |
---|
1834 | 18 bit (262144) - Perturb fathom nodes |
---|
1835 | 19 bit (524288) - No limit on fathom nodes |
---|
1836 | 20 bit (1048576) - Reduce sum of infeasibilities before cuts |
---|
1837 | 21 bit (2097152) - Reduce sum of infeasibilities after cuts |
---|
1838 | 22 bit (4194304) - Conflict analysis |
---|
1839 | 23 bit (8388608) - Conflict analysis - temporary bit |
---|
1840 | 24 bit (16777216) - Add cutoff as LP constraint (out) |
---|
1841 | 25 bit (33554432) - diving/reordering |
---|
1842 | 26 bit (67108864) - load global cuts from file |
---|
1843 | 27 bit (134217728) - append binding global cuts to file |
---|
1844 | 28 bit (268435456) - idiot branching |
---|
1845 | 29 bit (536870912) - don't make fake objective |
---|
1846 | */ |
---|
1847 | inline void setMoreSpecialOptions(int value) { |
---|
1848 | moreSpecialOptions_ = value; |
---|
1849 | } |
---|
1850 | /// Get more special options |
---|
1851 | inline int moreSpecialOptions() const { |
---|
1852 | return moreSpecialOptions_; |
---|
1853 | } |
---|
1854 | /** Set more more special options |
---|
1855 | 0 bit (1) - find switching variables |
---|
1856 | 1 bit (2) - using fake objective until solution |
---|
1857 | 2 bit (4) - switching variables exist |
---|
1858 | 3 bit (8) - skip most of setBestSolution checks |
---|
1859 | 4 bit (16) - very lightweight preprocessing in smallB&B |
---|
1860 | 5 bit (32) - event handler needs to be cloned when parallel |
---|
1861 | */ |
---|
1862 | inline void setMoreSpecialOptions2(int value) { |
---|
1863 | moreSpecialOptions2_ = value; |
---|
1864 | } |
---|
1865 | /// Get more special options2 |
---|
1866 | inline int moreSpecialOptions2() const { |
---|
1867 | return moreSpecialOptions2_; |
---|
1868 | } |
---|
1869 | /// Set cutoff as constraint |
---|
1870 | inline void setCutoffAsConstraint(bool yesNo) { |
---|
1871 | cutoffRowNumber_ = (yesNo) ? -2 : -1; |
---|
1872 | } |
---|
1873 | /// Set time method |
---|
1874 | inline void setUseElapsedTime(bool yesNo) { |
---|
1875 | if (yesNo) |
---|
1876 | moreSpecialOptions_ |= 131072; |
---|
1877 | else |
---|
1878 | moreSpecialOptions_ &= ~131072; |
---|
1879 | } |
---|
1880 | /// Get time method |
---|
1881 | inline bool useElapsedTime() const { |
---|
1882 | return (moreSpecialOptions_&131072)!=0; |
---|
1883 | } |
---|
1884 | /// Get useful temporary pointer |
---|
1885 | inline void * temporaryPointer() const |
---|
1886 | { return temporaryPointer_;} |
---|
1887 | /// Set useful temporary pointer |
---|
1888 | inline void setTemporaryPointer(void * pointer) |
---|
1889 | { temporaryPointer_=pointer;} |
---|
1890 | /// Go to dantzig pivot selection if easy problem (clp only) |
---|
1891 | void goToDantzig(int numberNodes, ClpDualRowPivot *& savePivotMethod); |
---|
1892 | /// Now we may not own objects - just point to solver's objects |
---|
1893 | inline bool ownObjects() const { |
---|
1894 | return ownObjects_; |
---|
1895 | } |
---|
1896 | /// Check original model before it gets messed up |
---|
1897 | void checkModel(); |
---|
1898 | //@} |
---|
1899 | //--------------------------------------------------------------------------- |
---|
1900 | |
---|
1901 | ///@name Constructors and destructors etc |
---|
1902 | //@{ |
---|
1903 | /// Default Constructor |
---|
1904 | CbcModel(); |
---|
1905 | |
---|
1906 | /// Constructor from solver |
---|
1907 | CbcModel(const OsiSolverInterface &); |
---|
1908 | |
---|
1909 | /** Assign a solver to the model (model assumes ownership) |
---|
1910 | |
---|
1911 | On return, \p solver will be NULL. |
---|
1912 | If deleteSolver then current solver deleted (if model owned) |
---|
1913 | |
---|
1914 | \note Parameter settings in the outgoing solver are not inherited by |
---|
1915 | the incoming solver. |
---|
1916 | */ |
---|
1917 | void assignSolver(OsiSolverInterface *&solver, bool deleteSolver = true); |
---|
1918 | |
---|
1919 | /** \brief Set ownership of solver |
---|
1920 | |
---|
1921 | A parameter of false tells CbcModel it does not own the solver and |
---|
1922 | should not delete it. Once you claim ownership of the solver, you're |
---|
1923 | responsible for eventually deleting it. Note that CbcModel clones |
---|
1924 | solvers with abandon. Unless you have a deep understanding of the |
---|
1925 | workings of CbcModel, the only time you want to claim ownership is when |
---|
1926 | you're about to delete the CbcModel object but want the solver to |
---|
1927 | continue to exist (as, for example, when branchAndBound has finished |
---|
1928 | and you want to hang on to the answer). |
---|
1929 | */ |
---|
1930 | inline void setModelOwnsSolver (bool ourSolver) { |
---|
1931 | ownership_ = ourSolver ? (ownership_ | 0x80000000) : (ownership_ & (~0x80000000)) ; |
---|
1932 | } |
---|
1933 | |
---|
1934 | /*! \brief Get ownership of solver |
---|
1935 | |
---|
1936 | A return value of true means that CbcModel owns the solver and will |
---|
1937 | take responsibility for deleting it when that becomes necessary. |
---|
1938 | */ |
---|
1939 | inline bool modelOwnsSolver () { |
---|
1940 | return ((ownership_&0x80000000) != 0) ; |
---|
1941 | } |
---|
1942 | |
---|
1943 | /** Copy constructor . |
---|
1944 | If cloneHandler is true then message handler is cloned |
---|
1945 | */ |
---|
1946 | CbcModel(const CbcModel & rhs, bool cloneHandler = false); |
---|
1947 | |
---|
1948 | /** Clone */ |
---|
1949 | virtual CbcModel *clone (bool cloneHandler); |
---|
1950 | |
---|
1951 | /// Assignment operator |
---|
1952 | CbcModel & operator=(const CbcModel& rhs); |
---|
1953 | |
---|
1954 | /// Destructor |
---|
1955 | virtual ~CbcModel (); |
---|
1956 | |
---|
1957 | /// Returns solver - has current state |
---|
1958 | inline OsiSolverInterface * solver() const { |
---|
1959 | return solver_; |
---|
1960 | } |
---|
1961 | |
---|
1962 | /// Returns current solver - sets new one |
---|
1963 | inline OsiSolverInterface * swapSolver(OsiSolverInterface * solver) { |
---|
1964 | OsiSolverInterface * returnSolver = solver_; |
---|
1965 | solver_ = solver; |
---|
1966 | return returnSolver; |
---|
1967 | } |
---|
1968 | |
---|
1969 | /// Returns solver with continuous state |
---|
1970 | inline OsiSolverInterface * continuousSolver() const { |
---|
1971 | return continuousSolver_; |
---|
1972 | } |
---|
1973 | |
---|
1974 | /// Create solver with continuous state |
---|
1975 | inline void createContinuousSolver() { |
---|
1976 | continuousSolver_ = solver_->clone(); |
---|
1977 | } |
---|
1978 | /// Clear solver with continuous state |
---|
1979 | inline void clearContinuousSolver() { |
---|
1980 | delete continuousSolver_; |
---|
1981 | continuousSolver_ = NULL; |
---|
1982 | } |
---|
1983 | |
---|
1984 | /// A copy of the solver, taken at constructor or by saveReferenceSolver |
---|
1985 | inline OsiSolverInterface * referenceSolver() const { |
---|
1986 | return referenceSolver_; |
---|
1987 | } |
---|
1988 | |
---|
1989 | /// Save a copy of the current solver so can be reset to |
---|
1990 | void saveReferenceSolver(); |
---|
1991 | |
---|
1992 | /** Uses a copy of reference solver to be current solver. |
---|
1993 | Because of possible mismatches all exotic integer information is loat |
---|
1994 | (apart from normal information in OsiSolverInterface) |
---|
1995 | so SOS etc and priorities will have to be redone |
---|
1996 | */ |
---|
1997 | void resetToReferenceSolver(); |
---|
1998 | |
---|
1999 | /// Clears out as much as possible (except solver) |
---|
2000 | void gutsOfDestructor(); |
---|
2001 | /** Clears out enough to reset CbcModel as if no branch and bound done |
---|
2002 | */ |
---|
2003 | void gutsOfDestructor2(); |
---|
2004 | /** Clears out enough to reset CbcModel cutoff etc |
---|
2005 | */ |
---|
2006 | void resetModel(); |
---|
2007 | /** Most of copy constructor |
---|
2008 | mode - 0 copy but don't delete before |
---|
2009 | 1 copy and delete before |
---|
2010 | 2 copy and delete before (but use virgin generators) |
---|
2011 | */ |
---|
2012 | void gutsOfCopy(const CbcModel & rhs, int mode = 0); |
---|
2013 | /// Move status, nodes etc etc across |
---|
2014 | void moveInfo(const CbcModel & rhs); |
---|
2015 | //@} |
---|
2016 | |
---|
2017 | ///@name Multithreading |
---|
2018 | //@{ |
---|
2019 | /// Indicates whether Cbc library has been compiled with multithreading support |
---|
2020 | static bool haveMultiThreadSupport(); |
---|
2021 | /// Get pointer to masterthread |
---|
2022 | CbcThread * masterThread() const { |
---|
2023 | return masterThread_; |
---|
2024 | } |
---|
2025 | /// Get pointer to walkback |
---|
2026 | CbcNodeInfo ** walkback() const { |
---|
2027 | return walkback_; |
---|
2028 | } |
---|
2029 | /// Get number of threads |
---|
2030 | inline int getNumberThreads() const { |
---|
2031 | return numberThreads_; |
---|
2032 | } |
---|
2033 | /// Set number of threads |
---|
2034 | inline void setNumberThreads(int value) { |
---|
2035 | numberThreads_ = value; |
---|
2036 | } |
---|
2037 | /// Get thread mode |
---|
2038 | inline int getThreadMode() const { |
---|
2039 | return threadMode_; |
---|
2040 | } |
---|
2041 | /** Set thread mode |
---|
2042 | always use numberThreads for branching |
---|
2043 | 1 set then deterministic |
---|
2044 | 2 set then use numberThreads for root cuts |
---|
2045 | 4 set then use numberThreads in root mini branch and bound |
---|
2046 | 8 set and numberThreads - do heuristics numberThreads at a time |
---|
2047 | 8 set and numberThreads==0 do all heuristics at once |
---|
2048 | default is 0 |
---|
2049 | */ |
---|
2050 | inline void setThreadMode(int value) { |
---|
2051 | threadMode_ = value; |
---|
2052 | } |
---|
2053 | /** Return |
---|
2054 | -2 if deterministic threaded and main thread |
---|
2055 | -1 if deterministic threaded and serial thread |
---|
2056 | 0 if serial |
---|
2057 | 1 if opportunistic threaded |
---|
2058 | */ |
---|
2059 | inline int parallelMode() const { |
---|
2060 | if (!numberThreads_) { |
---|
2061 | if ((threadMode_&1) == 0) |
---|
2062 | return 0; |
---|
2063 | else |
---|
2064 | return -1; |
---|
2065 | return 0; |
---|
2066 | } else { |
---|
2067 | if ((threadMode_&1) == 0) |
---|
2068 | return 1; |
---|
2069 | else |
---|
2070 | return -2; |
---|
2071 | } |
---|
2072 | } |
---|
2073 | /// From here to end of section - code in CbcThread.cpp until class changed |
---|
2074 | /// Returns true if locked |
---|
2075 | bool isLocked() const; |
---|
2076 | #ifdef CBC_THREAD |
---|
2077 | /** |
---|
2078 | Locks a thread if parallel so that stuff like cut pool |
---|
2079 | can be updated and/or used. |
---|
2080 | */ |
---|
2081 | void lockThread(); |
---|
2082 | /** |
---|
2083 | Unlocks a thread if parallel to say cut pool stuff not needed |
---|
2084 | */ |
---|
2085 | void unlockThread(); |
---|
2086 | #else |
---|
2087 | inline void lockThread() {} |
---|
2088 | inline void unlockThread() {} |
---|
2089 | #endif |
---|
2090 | /** Set information in a child |
---|
2091 | -3 pass pointer to child thread info |
---|
2092 | -2 just stop |
---|
2093 | -1 delete simple child stuff |
---|
2094 | 0 delete opportunistic child stuff |
---|
2095 | 1 delete deterministic child stuff |
---|
2096 | */ |
---|
2097 | void setInfoInChild(int type, CbcThread * info); |
---|
2098 | /** Move/copy information from one model to another |
---|
2099 | -1 - initialization |
---|
2100 | 0 - from base model |
---|
2101 | 1 - to base model (and reset) |
---|
2102 | 2 - add in final statistics etc (and reset so can do clean destruction) |
---|
2103 | */ |
---|
2104 | void moveToModel(CbcModel * baseModel, int mode); |
---|
2105 | /// Split up nodes |
---|
2106 | int splitModel(int numberModels, CbcModel ** model, |
---|
2107 | int numberNodes); |
---|
2108 | /// Start threads |
---|
2109 | void startSplitModel(int numberIterations); |
---|
2110 | /// Merge models |
---|
2111 | void mergeModels(int numberModel, CbcModel ** model, |
---|
2112 | int numberNodes); |
---|
2113 | //@} |
---|
2114 | |
---|
2115 | ///@name semi-private i.e. users should not use |
---|
2116 | //@{ |
---|
2117 | /// Get how many Nodes it took to solve the problem. |
---|
2118 | int getNodeCount2() const { |
---|
2119 | return numberNodes2_; |
---|
2120 | } |
---|
2121 | /// Set pointers for speed |
---|
2122 | void setPointers(const OsiSolverInterface * solver); |
---|
2123 | /** Perform reduced cost fixing |
---|
2124 | |
---|
2125 | Fixes integer variables at their current value based on reduced cost |
---|
2126 | penalties. Returns number fixed |
---|
2127 | */ |
---|
2128 | int reducedCostFix() ; |
---|
2129 | /** Makes all handlers same. If makeDefault 1 then makes top level |
---|
2130 | default and rest point to that. If 2 then each is copy |
---|
2131 | */ |
---|
2132 | void synchronizeHandlers(int makeDefault); |
---|
2133 | /// Save a solution to saved list |
---|
2134 | void saveExtraSolution(const double * solution, double objectiveValue); |
---|
2135 | /// Save a solution to best and move current to saved |
---|
2136 | void saveBestSolution(const double * solution, double objectiveValue); |
---|
2137 | /// Delete best and saved solutions |
---|
2138 | void deleteSolutions(); |
---|
2139 | /// Encapsulates solver resolve |
---|
2140 | int resolve(OsiSolverInterface * solver); |
---|
2141 | #ifdef CLP_RESOLVE |
---|
2142 | /// Special purpose resolve |
---|
2143 | int resolveClp(OsiClpSolverInterface * solver, int type); |
---|
2144 | #endif |
---|
2145 | |
---|
2146 | /** Encapsulates choosing a variable - |
---|
2147 | anyAction -2, infeasible (-1 round again), 0 done |
---|
2148 | */ |
---|
2149 | int chooseBranch(CbcNode * & newNode, int numberPassesLeft, |
---|
2150 | CbcNode * oldNode, OsiCuts & cuts, |
---|
2151 | bool & resolved, CoinWarmStartBasis *lastws, |
---|
2152 | const double * lowerBefore, const double * upperBefore, |
---|
2153 | OsiSolverBranch * & branches); |
---|
2154 | int chooseBranch(CbcNode * newNode, int numberPassesLeft, bool & resolved); |
---|
2155 | |
---|
2156 | /** Return an empty basis object of the specified size |
---|
2157 | |
---|
2158 | A useful utility when constructing a basis for a subproblem from scratch. |
---|
2159 | The object returned will be of the requested capacity and appropriate for |
---|
2160 | the solver attached to the model. |
---|
2161 | */ |
---|
2162 | CoinWarmStartBasis *getEmptyBasis(int ns = 0, int na = 0) const ; |
---|
2163 | |
---|
2164 | /** Remove inactive cuts from the model |
---|
2165 | |
---|
2166 | An OsiSolverInterface is expected to maintain a valid basis, but not a |
---|
2167 | valid solution, when loose cuts are deleted. Restoring a valid solution |
---|
2168 | requires calling the solver to reoptimise. If it's certain the solution |
---|
2169 | will not be required, set allowResolve to false to suppress |
---|
2170 | reoptimisation. |
---|
2171 | If saveCuts then slack cuts will be saved |
---|
2172 | On input current cuts are cuts and newCuts |
---|
2173 | on exit current cuts will be correct. Returns number dropped |
---|
2174 | */ |
---|
2175 | int takeOffCuts(OsiCuts &cuts, |
---|
2176 | bool allowResolve, OsiCuts * saveCuts, |
---|
2177 | int numberNewCuts = 0, const OsiRowCut ** newCuts = NULL) ; |
---|
2178 | |
---|
2179 | /** Determine and install the active cuts that need to be added for |
---|
2180 | the current subproblem |
---|
2181 | |
---|
2182 | The whole truth is a bit more complicated. The first action is a call to |
---|
2183 | addCuts1(). addCuts() then sorts through the list, installs the tight |
---|
2184 | cuts in the model, and does bookkeeping (adjusts reference counts). |
---|
2185 | The basis returned from addCuts1() is adjusted accordingly. |
---|
2186 | |
---|
2187 | If it turns out that the node should really be fathomed by bound, |
---|
2188 | addCuts() simply treats all the cuts as loose as it does the bookkeeping. |
---|
2189 | |
---|
2190 | canFix true if extra information being passed |
---|
2191 | */ |
---|
2192 | int addCuts(CbcNode * node, CoinWarmStartBasis *&lastws, bool canFix); |
---|
2193 | |
---|
2194 | /** Traverse the tree from node to root and prep the model |
---|
2195 | |
---|
2196 | addCuts1() begins the job of prepping the model to match the current |
---|
2197 | subproblem. The model is stripped of all cuts, and the search tree is |
---|
2198 | traversed from node to root to determine the changes required. Appropriate |
---|
2199 | bounds changes are installed, a list of cuts is collected but not |
---|
2200 | installed, and an appropriate basis (minus the cuts, but big enough to |
---|
2201 | accommodate them) is constructed. |
---|
2202 | |
---|
2203 | Returns true if new problem similar to old |
---|
2204 | |
---|
2205 | \todo addCuts1() is called in contexts where it's known in advance that |
---|
2206 | all that's desired is to determine a list of cuts and do the |
---|
2207 | bookkeeping (adjust the reference counts). The work of installing |
---|
2208 | bounds and building a basis goes to waste. |
---|
2209 | */ |
---|
2210 | bool addCuts1(CbcNode * node, CoinWarmStartBasis *&lastws); |
---|
2211 | /** Returns bounds just before where - initially original bounds. |
---|
2212 | Also sets downstream nodes (lower if force 1, upper if 2) |
---|
2213 | */ |
---|
2214 | void previousBounds (CbcNode * node, CbcNodeInfo * where, int iColumn, |
---|
2215 | double & lower, double & upper, int force); |
---|
2216 | /** Set objective value in a node. This is separated out so that |
---|
2217 | odd solvers can use. It may look at extra information in |
---|
2218 | solverCharacteriscs_ and will also use bound from parent node |
---|
2219 | */ |
---|
2220 | void setObjectiveValue(CbcNode * thisNode, const CbcNode * parentNode) const; |
---|
2221 | |
---|
2222 | /** If numberBeforeTrust >0 then we are going to use CbcBranchDynamic. |
---|
2223 | Scan and convert CbcSimpleInteger objects |
---|
2224 | */ |
---|
2225 | void convertToDynamic(); |
---|
2226 | /// Set numberBeforeTrust in all objects |
---|
2227 | void synchronizeNumberBeforeTrust(int type = 0); |
---|
2228 | /// Zap integer information in problem (may leave object info) |
---|
2229 | void zapIntegerInformation(bool leaveObjects = true); |
---|
2230 | /// Use cliques for pseudocost information - return nonzero if infeasible |
---|
2231 | int cliquePseudoCosts(int doStatistics); |
---|
2232 | /// Fill in useful estimates |
---|
2233 | void pseudoShadow(int type); |
---|
2234 | /** Return pseudo costs |
---|
2235 | If not all integers or not pseudo costs - returns all zero |
---|
2236 | Length of arrays are numberIntegers() and entries |
---|
2237 | correspond to integerVariable()[i] |
---|
2238 | User must allocate arrays before call |
---|
2239 | */ |
---|
2240 | void fillPseudoCosts(double * downCosts, double * upCosts, |
---|
2241 | int * priority = NULL, |
---|
2242 | int * numberDown = NULL, int * numberUp = NULL, |
---|
2243 | int * numberDownInfeasible = NULL, |
---|
2244 | int * numberUpInfeasible = NULL) const; |
---|
2245 | /** Do heuristics at root. |
---|
2246 | 0 - don't delete |
---|
2247 | 1 - delete |
---|
2248 | 2 - just delete - don't even use |
---|
2249 | */ |
---|
2250 | void doHeuristicsAtRoot(int deleteHeuristicsAfterwards = 0); |
---|
2251 | /// Adjust heuristics based on model |
---|
2252 | void adjustHeuristics(); |
---|
2253 | /// Get the hotstart solution |
---|
2254 | inline const double * hotstartSolution() const { |
---|
2255 | return hotstartSolution_; |
---|
2256 | } |
---|
2257 | /// Get the hotstart priorities |
---|
2258 | inline const int * hotstartPriorities() const { |
---|
2259 | return hotstartPriorities_; |
---|
2260 | } |
---|
2261 | |
---|
2262 | /// Return the list of cuts initially collected for this subproblem |
---|
2263 | inline CbcCountRowCut ** addedCuts() const { |
---|
2264 | return addedCuts_; |
---|
2265 | } |
---|
2266 | /// Number of entries in the list returned by #addedCuts() |
---|
2267 | inline int currentNumberCuts() const { |
---|
2268 | return currentNumberCuts_; |
---|
2269 | } |
---|
2270 | /// Global cuts |
---|
2271 | inline CbcRowCuts * globalCuts() { |
---|
2272 | return &globalCuts_; |
---|
2273 | } |
---|
2274 | /// Copy and set a pointer to a row cut which will be added instead of normal branching. |
---|
2275 | void setNextRowCut(const OsiRowCut & cut); |
---|
2276 | /// Get a pointer to current node (be careful) |
---|
2277 | inline CbcNode * currentNode() const { |
---|
2278 | return currentNode_; |
---|
2279 | } |
---|
2280 | /// Get a pointer to probing info |
---|
2281 | inline CglTreeProbingInfo * probingInfo() const { |
---|
2282 | return probingInfo_; |
---|
2283 | } |
---|
2284 | /// Thread specific random number generator |
---|
2285 | inline CoinThreadRandom * randomNumberGenerator() { |
---|
2286 | return &randomNumberGenerator_; |
---|
2287 | } |
---|
2288 | /// Set the number of iterations done in strong branching. |
---|
2289 | inline void setNumberStrongIterations(int number) { |
---|
2290 | numberStrongIterations_ = number; |
---|
2291 | } |
---|
2292 | /// Get the number of iterations done in strong branching. |
---|
2293 | inline int numberStrongIterations() const { |
---|
2294 | return numberStrongIterations_; |
---|
2295 | } |
---|
2296 | /// Get maximum number of iterations (designed to be used in heuristics) |
---|
2297 | inline int maximumNumberIterations() const { |
---|
2298 | return maximumNumberIterations_; |
---|
2299 | } |
---|
2300 | /// Set maximum number of iterations (designed to be used in heuristics) |
---|
2301 | inline void setMaximumNumberIterations(int value) { |
---|
2302 | maximumNumberIterations_ = value; |
---|
2303 | } |
---|
2304 | /// Set depth for fast nodes |
---|
2305 | inline void setFastNodeDepth(int value) { |
---|
2306 | fastNodeDepth_ = value; |
---|
2307 | } |
---|
2308 | /// Get depth for fast nodes |
---|
2309 | inline int fastNodeDepth() const { |
---|
2310 | return fastNodeDepth_; |
---|
2311 | } |
---|
2312 | /// Get anything with priority >= this can be treated as continuous |
---|
2313 | inline int continuousPriority() const { |
---|
2314 | return continuousPriority_; |
---|
2315 | } |
---|
2316 | /// Set anything with priority >= this can be treated as continuous |
---|
2317 | inline void setContinuousPriority(int value) { |
---|
2318 | continuousPriority_ = value; |
---|
2319 | } |
---|
2320 | inline void incrementExtra(int nodes, int iterations) { |
---|
2321 | numberExtraNodes_ += nodes; |
---|
2322 | numberExtraIterations_ += iterations; |
---|
2323 | } |
---|
2324 | /// Number of extra iterations |
---|
2325 | inline int numberExtraIterations() const { |
---|
2326 | return numberExtraIterations_; |
---|
2327 | } |
---|
2328 | /// Increment strong info |
---|
2329 | void incrementStrongInfo(int numberTimes, int numberIterations, |
---|
2330 | int numberFixed, bool ifInfeasible); |
---|
2331 | /// Return strong info |
---|
2332 | inline const int * strongInfo() const { |
---|
2333 | return strongInfo_; |
---|
2334 | } |
---|
2335 | |
---|
2336 | /// Return mutable strong info |
---|
2337 | inline int * mutableStrongInfo() { |
---|
2338 | return strongInfo_; |
---|
2339 | } |
---|
2340 | /// Get stored row cuts for donor/recipient CbcModel |
---|
2341 | CglStored * storedRowCuts() const { |
---|
2342 | return storedRowCuts_; |
---|
2343 | } |
---|
2344 | /// Set stored row cuts for donor/recipient CbcModel |
---|
2345 | void setStoredRowCuts(CglStored * cuts) { |
---|
2346 | storedRowCuts_ = cuts; |
---|
2347 | } |
---|
2348 | /// Says whether all dynamic integers |
---|
2349 | inline bool allDynamic () const { |
---|
2350 | return ((ownership_&0x40000000) != 0) ; |
---|
2351 | } |
---|
2352 | /// Create C++ lines to get to current state |
---|
2353 | void generateCpp( FILE * fp, int options); |
---|
2354 | /// Generate an OsiBranchingInformation object |
---|
2355 | OsiBranchingInformation usefulInformation() const; |
---|
2356 | /** Warm start object produced by heuristic or strong branching |
---|
2357 | |
---|
2358 | If get a valid integer solution outside branch and bound then it can take |
---|
2359 | a reasonable time to solve LP which produces clean solution. If this object has |
---|
2360 | any size then it will be used in solve. |
---|
2361 | */ |
---|
2362 | inline void setBestSolutionBasis(const CoinWarmStartBasis & bestSolutionBasis) { |
---|
2363 | bestSolutionBasis_ = bestSolutionBasis; |
---|
2364 | } |
---|
2365 | /// Redo walkback arrays |
---|
2366 | void redoWalkBack(); |
---|
2367 | //@} |
---|
2368 | |
---|
2369 | void setMIPStart( const std::vector< std::pair< std::string, double > > &mips ) { |
---|
2370 | this->mipStart_ = mips; |
---|
2371 | } |
---|
2372 | |
---|
2373 | const std::vector< std::pair< std::string, double > > &getMIPStart() { |
---|
2374 | return this->mipStart_; |
---|
2375 | } |
---|
2376 | |
---|
2377 | |
---|
2378 | //--------------------------------------------------------------------------- |
---|
2379 | |
---|
2380 | private: |
---|
2381 | ///@name Private member data |
---|
2382 | //@{ |
---|
2383 | |
---|
2384 | /// The solver associated with this model. |
---|
2385 | OsiSolverInterface * solver_; |
---|
2386 | |
---|
2387 | /** Ownership of objects and other stuff |
---|
2388 | |
---|
2389 | 0x80000000 model owns solver |
---|
2390 | 0x40000000 all variables CbcDynamicPseudoCost |
---|
2391 | */ |
---|
2392 | unsigned int ownership_ ; |
---|
2393 | |
---|
2394 | /// A copy of the solver, taken at the continuous (root) node. |
---|
2395 | OsiSolverInterface * continuousSolver_; |
---|
2396 | |
---|
2397 | /// A copy of the solver, taken at constructor or by saveReferenceSolver |
---|
2398 | OsiSolverInterface * referenceSolver_; |
---|
2399 | |
---|
2400 | /// Message handler |
---|
2401 | CoinMessageHandler * handler_; |
---|
2402 | |
---|
2403 | /** Flag to say if handler_ is the default handler. |
---|
2404 | |
---|
2405 | The default handler is deleted when the model is deleted. Other |
---|
2406 | handlers (supplied by the client) will not be deleted. |
---|
2407 | */ |
---|
2408 | bool defaultHandler_; |
---|
2409 | |
---|
2410 | /// Cbc messages |
---|
2411 | CoinMessages messages_; |
---|
2412 | |
---|
2413 | /// Array for integer parameters |
---|
2414 | int intParam_[CbcLastIntParam]; |
---|
2415 | |
---|
2416 | /// Array for double parameters |
---|
2417 | double dblParam_[CbcLastDblParam]; |
---|
2418 | |
---|
2419 | /** Pointer to an empty warm start object |
---|
2420 | |
---|
2421 | It turns out to be useful to have this available as a base from |
---|
2422 | which to build custom warm start objects. This is typed as CoinWarmStart |
---|
2423 | rather than CoinWarmStartBasis to allow for the possibility that a |
---|
2424 | client might want to apply a solver that doesn't use a basis-based warm |
---|
2425 | start. See getEmptyBasis for an example of how this field can be used. |
---|
2426 | */ |
---|
2427 | mutable CoinWarmStart *emptyWarmStart_ ; |
---|
2428 | |
---|
2429 | /// Best objective |
---|
2430 | double bestObjective_; |
---|
2431 | /// Best possible objective |
---|
2432 | double bestPossibleObjective_; |
---|
2433 | /// Sum of Changes to objective by first solve |
---|
2434 | double sumChangeObjective1_; |
---|
2435 | /// Sum of Changes to objective by subsequent solves |
---|
2436 | double sumChangeObjective2_; |
---|
2437 | |
---|
2438 | /// Array holding the incumbent (best) solution. |
---|
2439 | double * bestSolution_; |
---|
2440 | /// Arrays holding other solutions. |
---|
2441 | double ** savedSolutions_; |
---|
2442 | |
---|
2443 | /** Array holding the current solution. |
---|
2444 | |
---|
2445 | This array is used more as a temporary. |
---|
2446 | */ |
---|
2447 | double * currentSolution_; |
---|
2448 | /** For testing infeasibilities - will point to |
---|
2449 | currentSolution_ or solver-->getColSolution() |
---|
2450 | */ |
---|
2451 | mutable const double * testSolution_; |
---|
2452 | /** MIPstart values |
---|
2453 | values for integer variables which will be converted to a complete integer initial feasible solution |
---|
2454 | */ |
---|
2455 | std::vector< std::pair< std::string, double > > mipStart_; |
---|
2456 | /** Warm start object produced by heuristic or strong branching |
---|
2457 | |
---|
2458 | If get a valid integer solution outside branch and bound then it can take |
---|
2459 | a reasonable time to solve LP which produces clean solution. If this object has |
---|
2460 | any size then it will be used in solve. |
---|
2461 | */ |
---|
2462 | CoinWarmStartBasis bestSolutionBasis_ ; |
---|
2463 | /// Global cuts |
---|
2464 | CbcRowCuts globalCuts_; |
---|
2465 | /// Global conflict cuts |
---|
2466 | CbcRowCuts * globalConflictCuts_; |
---|
2467 | |
---|
2468 | /// Minimum degradation in objective value to continue cut generation |
---|
2469 | double minimumDrop_; |
---|
2470 | /// Number of solutions |
---|
2471 | int numberSolutions_; |
---|
2472 | /// Number of saved solutions |
---|
2473 | int numberSavedSolutions_; |
---|
2474 | /// Maximum number of saved solutions |
---|
2475 | int maximumSavedSolutions_; |
---|
2476 | /** State of search |
---|
2477 | 0 - no solution |
---|
2478 | 1 - only heuristic solutions |
---|
2479 | 2 - branched to a solution |
---|
2480 | 3 - no solution but many nodes |
---|
2481 | */ |
---|
2482 | int stateOfSearch_; |
---|
2483 | /// At which depths to do cuts |
---|
2484 | int whenCuts_; |
---|
2485 | /// Hotstart solution |
---|
2486 | double * hotstartSolution_; |
---|
2487 | /// Hotstart priorities |
---|
2488 | int * hotstartPriorities_; |
---|
2489 | /// Number of heuristic solutions |
---|
2490 | int numberHeuristicSolutions_; |
---|
2491 | /// Cumulative number of nodes |
---|
2492 | int numberNodes_; |
---|
2493 | /** Cumulative number of nodes for statistics. |
---|
2494 | Must fix to match up |
---|
2495 | */ |
---|
2496 | int numberNodes2_; |
---|
2497 | /// Cumulative number of iterations |
---|
2498 | int numberIterations_; |
---|
2499 | /// Cumulative number of solves |
---|
2500 | int numberSolves_; |
---|
2501 | /// Status of problem - 0 finished, 1 stopped, 2 difficulties |
---|
2502 | int status_; |
---|
2503 | /** Secondary status of problem |
---|
2504 | -1 unset (status_ will also be -1) |
---|
2505 | 0 search completed with solution |
---|
2506 | 1 linear relaxation not feasible (or worse than cutoff) |
---|
2507 | 2 stopped on gap |
---|
2508 | 3 stopped on nodes |
---|
2509 | 4 stopped on time |
---|
2510 | 5 stopped on user event |
---|
2511 | 6 stopped on solutions |
---|
2512 | */ |
---|
2513 | int secondaryStatus_; |
---|
2514 | /// Number of integers in problem |
---|
2515 | int numberIntegers_; |
---|
2516 | /// Number of rows at continuous |
---|
2517 | int numberRowsAtContinuous_; |
---|
2518 | /** |
---|
2519 | -1 - cutoff as constraint not activated |
---|
2520 | -2 - waiting to activate |
---|
2521 | >=0 - activated |
---|
2522 | */ |
---|
2523 | int cutoffRowNumber_; |
---|
2524 | /// Maximum number of cuts |
---|
2525 | int maximumNumberCuts_; |
---|
2526 | /** Current phase (so heuristics etc etc can find out). |
---|
2527 | 0 - initial solve |
---|
2528 | 1 - solve with cuts at root |
---|
2529 | 2 - solve with cuts |
---|
2530 | 3 - other e.g. strong branching |
---|
2531 | 4 - trying to validate a solution |
---|
2532 | 5 - at end of search |
---|
2533 | */ |
---|
2534 | int phase_; |
---|
2535 | |
---|
2536 | /// Number of entries in #addedCuts_ |
---|
2537 | int currentNumberCuts_; |
---|
2538 | |
---|
2539 | /** Current limit on search tree depth |
---|
2540 | |
---|
2541 | The allocated size of #walkback_. Increased as needed. |
---|
2542 | */ |
---|
2543 | int maximumDepth_; |
---|
2544 | /** Array used to assemble the path between a node and the search tree root |
---|
2545 | |
---|
2546 | The array is resized when necessary. #maximumDepth_ is the current |
---|
2547 | allocated size. |
---|
2548 | */ |
---|
2549 | CbcNodeInfo ** walkback_; |
---|
2550 | CbcNodeInfo ** lastNodeInfo_; |
---|
2551 | const OsiRowCut ** lastCut_; |
---|
2552 | int lastDepth_; |
---|
2553 | int lastNumberCuts2_; |
---|
2554 | int maximumCuts_; |
---|
2555 | int * lastNumberCuts_; |
---|
2556 | |
---|
2557 | /** The list of cuts initially collected for this subproblem |
---|
2558 | |
---|
2559 | When the subproblem at this node is rebuilt, a set of cuts is collected |
---|
2560 | for inclusion in the constraint system. If any of these cuts are |
---|
2561 | subsequently removed because they have become loose, the corresponding |
---|
2562 | entry is set to NULL. |
---|
2563 | */ |
---|
2564 | CbcCountRowCut ** addedCuts_; |
---|
2565 | |
---|
2566 | /** A pointer to a row cut which will be added instead of normal branching. |
---|
2567 | After use it should be set to NULL. |
---|
2568 | */ |
---|
2569 | OsiRowCut * nextRowCut_; |
---|
2570 | |
---|
2571 | /// Current node so can be used elsewhere |
---|
2572 | CbcNode * currentNode_; |
---|
2573 | |
---|
2574 | /// Indices of integer variables |
---|
2575 | int * integerVariable_; |
---|
2576 | /// Whether of not integer |
---|
2577 | char * integerInfo_; |
---|
2578 | /// Holds solution at continuous (after cuts) |
---|
2579 | double * continuousSolution_; |
---|
2580 | /// Array marked whenever a solution is found if non-zero |
---|
2581 | int * usedInSolution_; |
---|
2582 | /** |
---|
2583 | Special options |
---|
2584 | 0 bit (1) - check if cuts valid (if on debugger list) |
---|
2585 | 1 bit (2) - use current basis to check integer solution (rather than all slack) |
---|
2586 | 2 bit (4) - don't check integer solution (by solving LP) |
---|
2587 | 3 bit (8) - fast analyze |
---|
2588 | 4 bit (16) - non-linear model - so no well defined CoinPackedMatrix |
---|
2589 | 5 bit (32) - keep names |
---|
2590 | 6 bit (64) - try for dominated columns |
---|
2591 | 7 bit (128) - SOS type 1 but all declared integer |
---|
2592 | 8 bit (256) - Set to say solution just found, unset by doing cuts |
---|
2593 | 9 bit (512) - Try reduced model after 100 nodes |
---|
2594 | 10 bit (1024) - Switch on some heuristics even if seems unlikely |
---|
2595 | 11 bit (2048) - Mark as in small branch and bound |
---|
2596 | 12 bit (4096) - Funny cuts so do slow way (in some places) |
---|
2597 | 13 bit (8192) - Funny cuts so do slow way (in other places) |
---|
2598 | 14 bit (16384) - Use Cplex! for fathoming |
---|
2599 | 15 bit (32768) - Try reduced model after 0 nodes |
---|
2600 | 16 bit (65536) - Original model had integer bounds |
---|
2601 | 17 bit (131072) - Perturbation switched off |
---|
2602 | 18 bit (262144) - donor CbcModel |
---|
2603 | 19 bit (524288) - recipient CbcModel |
---|
2604 | 20 bit (1048576) - waiting for sub model to return |
---|
2605 | 22 bit (4194304) - do not initialize random seed in solver (user has) |
---|
2606 | 23 bit (8388608) - leave solver_ with cuts |
---|
2607 | 24 bit (16777216) - just get feasible if no cutoff |
---|
2608 | */ |
---|
2609 | int specialOptions_; |
---|
2610 | /** More special options |
---|
2611 | at present bottom 6 bits used for shadow price mode |
---|
2612 | 1024 for experimental hotstart |
---|
2613 | 2048,4096 breaking out of cuts |
---|
2614 | 8192 slowly increase minimum drop |
---|
2615 | 16384 gomory |
---|
2616 | 32768 more heuristics in sub trees |
---|
2617 | 65536 no cuts in preprocessing |
---|
2618 | 131072 Time limits elapsed |
---|
2619 | 18 bit (262144) - Perturb fathom nodes |
---|
2620 | 19 bit (524288) - No limit on fathom nodes |
---|
2621 | 20 bit (1048576) - Reduce sum of infeasibilities before cuts |
---|
2622 | 21 bit (2097152) - Reduce sum of infeasibilities after cuts |
---|
2623 | */ |
---|
2624 | int moreSpecialOptions_; |
---|
2625 | /** More more special options |
---|
2626 | 0 bit (1) - find switching variables |
---|
2627 | 1 bit (2) - using fake objective until solution |
---|
2628 | 2 bit (4) - switching variables exist |
---|
2629 | 3 bit (8) - skip most of setBestSolution checks |
---|
2630 | 4 bit (16) - very lightweight preprocessing in smallB&B |
---|
2631 | 5 bit (32) - event handler needs to be cloned when parallel |
---|
2632 | */ |
---|
2633 | int moreSpecialOptions2_; |
---|
2634 | /// User node comparison function |
---|
2635 | CbcCompareBase * nodeCompare_; |
---|
2636 | /// User feasibility function (see CbcFeasibleBase.hpp) |
---|
2637 | CbcFeasibilityBase * problemFeasibility_; |
---|
2638 | /// Tree |
---|
2639 | CbcTree * tree_; |
---|
2640 | /// Pointer to top of tree |
---|
2641 | CbcFullNodeInfo * topOfTree_; |
---|
2642 | /// A pointer to model to be used for subtrees |
---|
2643 | CbcModel * subTreeModel_; |
---|
2644 | /// A pointer to model from CbcHeuristic |
---|
2645 | CbcModel * heuristicModel_; |
---|
2646 | /// Number of times any subtree stopped on nodes, time etc |
---|
2647 | int numberStoppedSubTrees_; |
---|
2648 | /// Variable selection function |
---|
2649 | CbcBranchDecision * branchingMethod_; |
---|
2650 | /// Cut modifier function |
---|
2651 | CbcCutModifier * cutModifier_; |
---|
2652 | /// Strategy |
---|
2653 | CbcStrategy * strategy_; |
---|
2654 | /// Parent model |
---|
2655 | CbcModel * parentModel_; |
---|
2656 | /** Whether to automatically do presolve before branch and bound. |
---|
2657 | 0 - no |
---|
2658 | 1 - ordinary presolve |
---|
2659 | 2 - integer presolve (dodgy) |
---|
2660 | */ |
---|
2661 | /// Pointer to array[getNumCols()] (for speed) of column lower bounds |
---|
2662 | const double * cbcColLower_; |
---|
2663 | /// Pointer to array[getNumCols()] (for speed) of column upper bounds |
---|
2664 | const double * cbcColUpper_; |
---|
2665 | /// Pointer to array[getNumRows()] (for speed) of row lower bounds |
---|
2666 | const double * cbcRowLower_; |
---|
2667 | /// Pointer to array[getNumRows()] (for speed) of row upper bounds |
---|
2668 | const double * cbcRowUpper_; |
---|
2669 | /// Pointer to array[getNumCols()] (for speed) of primal solution vector |
---|
2670 | const double * cbcColSolution_; |
---|
2671 | /// Pointer to array[getNumRows()] (for speed) of dual prices |
---|
2672 | const double * cbcRowPrice_; |
---|
2673 | /// Get a pointer to array[getNumCols()] (for speed) of reduced costs |
---|
2674 | const double * cbcReducedCost_; |
---|
2675 | /// Pointer to array[getNumRows()] (for speed) of row activity levels. |
---|
2676 | const double * cbcRowActivity_; |
---|
2677 | /// Pointer to user-defined data structure |
---|
2678 | void * appData_; |
---|
2679 | /// Presolve for CbcTreeLocal |
---|
2680 | int presolve_; |
---|
2681 | /** Maximum number of candidates to consider for strong branching. |
---|
2682 | To disable strong branching, set this to 0. |
---|
2683 | */ |
---|
2684 | int numberStrong_; |
---|
2685 | /** \brief The number of branches before pseudo costs believed |
---|
2686 | in dynamic strong branching. |
---|
2687 | |
---|
2688 | A value of 0 is off. |
---|
2689 | */ |
---|
2690 | int numberBeforeTrust_; |
---|
2691 | /** \brief The number of variables for which to compute penalties |
---|
2692 | in dynamic strong branching. |
---|
2693 | */ |
---|
2694 | int numberPenalties_; |
---|
2695 | /// For threads - stop after this many "iterations" |
---|
2696 | int stopNumberIterations_; |
---|
2697 | /** Scale factor to make penalties match strong. |
---|
2698 | Should/will be computed */ |
---|
2699 | double penaltyScaleFactor_; |
---|
2700 | /// Number of analyze iterations to do |
---|
2701 | int numberAnalyzeIterations_; |
---|
2702 | /// Arrays with analysis results |
---|
2703 | double * analyzeResults_; |
---|
2704 | /// Useful temporary pointer |
---|
2705 | void * temporaryPointer_; |
---|
2706 | /// Number of nodes infeasible by normal branching (before cuts) |
---|
2707 | int numberInfeasibleNodes_; |
---|
2708 | /** Problem type as set by user or found by analysis. This will be extended |
---|
2709 | 0 - not known |
---|
2710 | 1 - Set partitioning <= |
---|
2711 | 2 - Set partitioning == |
---|
2712 | 3 - Set covering |
---|
2713 | */ |
---|
2714 | int problemType_; |
---|
2715 | /// Print frequency |
---|
2716 | int printFrequency_; |
---|
2717 | /// Number of cut generators |
---|
2718 | int numberCutGenerators_; |
---|
2719 | // Cut generators |
---|
2720 | CbcCutGenerator ** generator_; |
---|
2721 | // Cut generators before any changes |
---|
2722 | CbcCutGenerator ** virginGenerator_; |
---|
2723 | /// Number of heuristics |
---|
2724 | int numberHeuristics_; |
---|
2725 | /// Heuristic solvers |
---|
2726 | CbcHeuristic ** heuristic_; |
---|
2727 | /// Pointer to heuristic solver which found last solution (or NULL) |
---|
2728 | CbcHeuristic * lastHeuristic_; |
---|
2729 | /// Depth for fast nodes |
---|
2730 | int fastNodeDepth_; |
---|
2731 | /*! Pointer to the event handler */ |
---|
2732 | # ifdef CBC_ONLY_CLP |
---|
2733 | ClpEventHandler *eventHandler_ ; |
---|
2734 | # else |
---|
2735 | CbcEventHandler *eventHandler_ ; |
---|
2736 | # endif |
---|
2737 | |
---|
2738 | /// Total number of objects |
---|
2739 | int numberObjects_; |
---|
2740 | |
---|
2741 | /** \brief Integer and Clique and ... information |
---|
2742 | |
---|
2743 | \note The code assumes that the first objects on the list will be |
---|
2744 | SimpleInteger objects for each integer variable, followed by |
---|
2745 | Clique objects. Portions of the code that understand Clique objects |
---|
2746 | will fail if they do not immediately follow the SimpleIntegers. |
---|
2747 | Large chunks of the code will fail if the first objects are not |
---|
2748 | SimpleInteger. As of 2003.08, SimpleIntegers and Cliques are the only |
---|
2749 | objects. |
---|
2750 | */ |
---|
2751 | OsiObject ** object_; |
---|
2752 | /// Now we may not own objects - just point to solver's objects |
---|
2753 | bool ownObjects_; |
---|
2754 | |
---|
2755 | /// Original columns as created by integerPresolve or preprocessing |
---|
2756 | int * originalColumns_; |
---|
2757 | /// How often to scan global cuts |
---|
2758 | int howOftenGlobalScan_; |
---|
2759 | /** Number of times global cuts violated. When global cut pool then this |
---|
2760 | should be kept for each cut and type of cut */ |
---|
2761 | int numberGlobalViolations_; |
---|
2762 | /// Number of extra iterations in fast lp |
---|
2763 | int numberExtraIterations_; |
---|
2764 | /// Number of extra nodes in fast lp |
---|
2765 | int numberExtraNodes_; |
---|
2766 | /** Value of objective at continuous |
---|
2767 | (Well actually after initial round of cuts) |
---|
2768 | */ |
---|
2769 | double continuousObjective_; |
---|
2770 | /** Value of objective before root node cuts added |
---|
2771 | */ |
---|
2772 | double originalContinuousObjective_; |
---|
2773 | /// Number of infeasibilities at continuous |
---|
2774 | int continuousInfeasibilities_; |
---|
2775 | /// Maximum number of cut passes at root |
---|
2776 | int maximumCutPassesAtRoot_; |
---|
2777 | /// Maximum number of cut passes |
---|
2778 | int maximumCutPasses_; |
---|
2779 | /// Preferred way of branching |
---|
2780 | int preferredWay_; |
---|
2781 | /// Current cut pass number |
---|
2782 | int currentPassNumber_; |
---|
2783 | /// Maximum number of cuts (for whichGenerator_) |
---|
2784 | int maximumWhich_; |
---|
2785 | /// Maximum number of rows |
---|
2786 | int maximumRows_; |
---|
2787 | /// Random seed |
---|
2788 | int randomSeed_; |
---|
2789 | /// Multiple root tries |
---|
2790 | int multipleRootTries_; |
---|
2791 | /// Current depth |
---|
2792 | int currentDepth_; |
---|
2793 | /// Thread specific random number generator |
---|
2794 | mutable CoinThreadRandom randomNumberGenerator_; |
---|
2795 | /// Work basis for temporary use |
---|
2796 | CoinWarmStartBasis workingBasis_; |
---|
2797 | /// Which cut generator generated this cut |
---|
2798 | int * whichGenerator_; |
---|
2799 | /// Maximum number of statistics |
---|
2800 | int maximumStatistics_; |
---|
2801 | /// statistics |
---|
2802 | CbcStatistics ** statistics_; |
---|
2803 | /// Maximum depth reached |
---|
2804 | int maximumDepthActual_; |
---|
2805 | /// Number of reduced cost fixings |
---|
2806 | double numberDJFixed_; |
---|
2807 | /// Probing info |
---|
2808 | CglTreeProbingInfo * probingInfo_; |
---|
2809 | /// Number of fixed by analyze at root |
---|
2810 | int numberFixedAtRoot_; |
---|
2811 | /// Number fixed by analyze so far |
---|
2812 | int numberFixedNow_; |
---|
2813 | /// Whether stopping on gap |
---|
2814 | bool stoppedOnGap_; |
---|
2815 | /// Whether event happened |
---|
2816 | mutable bool eventHappened_; |
---|
2817 | /// Number of long strong goes |
---|
2818 | int numberLongStrong_; |
---|
2819 | /// Number of old active cuts |
---|
2820 | int numberOldActiveCuts_; |
---|
2821 | /// Number of new cuts |
---|
2822 | int numberNewCuts_; |
---|
2823 | /// Strategy worked out - mainly at root node |
---|
2824 | int searchStrategy_; |
---|
2825 | /** Strategy for strong branching |
---|
2826 | 0 - normal |
---|
2827 | when to do all fractional |
---|
2828 | 1 - root node |
---|
2829 | 2 - depth less than modifier |
---|
2830 | 4 - if objective == best possible |
---|
2831 | 6 - as 2+4 |
---|
2832 | when to do all including satisfied |
---|
2833 | 10 - root node etc. |
---|
2834 | If >=100 then do when depth <= strategy/100 (otherwise 5) |
---|
2835 | */ |
---|
2836 | int strongStrategy_; |
---|
2837 | /// Number of iterations in strong branching |
---|
2838 | int numberStrongIterations_; |
---|
2839 | /** 0 - number times strong branching done, 1 - number fixed, 2 - number infeasible |
---|
2840 | Second group of three is a snapshot at node [6] */ |
---|
2841 | int strongInfo_[7]; |
---|
2842 | /** |
---|
2843 | For advanced applications you may wish to modify the behavior of Cbc |
---|
2844 | e.g. if the solver is a NLP solver then you may not have an exact |
---|
2845 | optimum solution at each step. This gives characteristics - just for one BAB. |
---|
2846 | For actually saving/restoring a solution you need the actual solver one. |
---|
2847 | */ |
---|
2848 | OsiBabSolver * solverCharacteristics_; |
---|
2849 | /// Whether to force a resolve after takeOffCuts |
---|
2850 | bool resolveAfterTakeOffCuts_; |
---|
2851 | /// Maximum number of iterations (designed to be used in heuristics) |
---|
2852 | int maximumNumberIterations_; |
---|
2853 | /// Anything with priority >= this can be treated as continuous |
---|
2854 | int continuousPriority_; |
---|
2855 | /// Number of outstanding update information items |
---|
2856 | int numberUpdateItems_; |
---|
2857 | /// Maximum number of outstanding update information items |
---|
2858 | int maximumNumberUpdateItems_; |
---|
2859 | /// Update items |
---|
2860 | CbcObjectUpdateData * updateItems_; |
---|
2861 | /// Stored row cuts for donor/recipient CbcModel |
---|
2862 | CglStored * storedRowCuts_; |
---|
2863 | /** |
---|
2864 | Parallel |
---|
2865 | 0 - off |
---|
2866 | 1 - testing |
---|
2867 | 2-99 threads |
---|
2868 | other special meanings |
---|
2869 | */ |
---|
2870 | int numberThreads_; |
---|
2871 | /** thread mode |
---|
2872 | always use numberThreads for branching |
---|
2873 | 1 set then deterministic |
---|
2874 | 2 set then use numberThreads for root cuts |
---|
2875 | 4 set then use numberThreads in root mini branch and bound |
---|
2876 | default is 0 |
---|
2877 | */ |
---|
2878 | int threadMode_; |
---|
2879 | /// Thread stuff for master |
---|
2880 | CbcBaseModel * master_; |
---|
2881 | /// Pointer to masterthread |
---|
2882 | CbcThread * masterThread_; |
---|
2883 | //@} |
---|
2884 | }; |
---|
2885 | /// So we can use osiObject or CbcObject during transition |
---|
2886 | void getIntegerInformation(const OsiObject * object, double & originalLower, |
---|
2887 | double & originalUpper) ; |
---|
2888 | // So we can call from other programs |
---|
2889 | // Real main program |
---|
2890 | class OsiClpSolverInterface; |
---|
2891 | int CbcMain (int argc, const char *argv[], OsiClpSolverInterface & solver, CbcModel ** babSolver); |
---|
2892 | int CbcMain (int argc, const char *argv[], CbcModel & babSolver); |
---|
2893 | // four ways of calling |
---|
2894 | int callCbc(const char * input2, OsiClpSolverInterface& solver1); |
---|
2895 | int callCbc(const char * input2); |
---|
2896 | int callCbc(const std::string input2, OsiClpSolverInterface& solver1); |
---|
2897 | int callCbc(const std::string input2) ; |
---|
2898 | // When we want to load up CbcModel with options first |
---|
2899 | void CbcMain0 (CbcModel & babSolver); |
---|
2900 | int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver); |
---|
2901 | // two ways of calling |
---|
2902 | int callCbc(const char * input2, CbcModel & babSolver); |
---|
2903 | int callCbc(const std::string input2, CbcModel & babSolver); |
---|
2904 | // And when CbcMain0 already called to initialize |
---|
2905 | int callCbc1(const char * input2, CbcModel & babSolver); |
---|
2906 | int callCbc1(const std::string input2, CbcModel & babSolver); |
---|
2907 | // And when CbcMain0 already called to initialize (with call back) (see CbcMain1 for whereFrom) |
---|
2908 | int callCbc1(const char * input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom)); |
---|
2909 | int callCbc1(const std::string input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom)); |
---|
2910 | int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom)); |
---|
2911 | // For uniform setting of cut and heuristic options |
---|
2912 | void setCutAndHeuristicOptions(CbcModel & model); |
---|
2913 | #endif |
---|
2914 | |
---|