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