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