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