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