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