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