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