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