00001
00002
00003
00004
00005
00006 #ifndef CbcModel_H
00007 #define CbcModel_H
00008 #include <string>
00009 #include <vector>
00010 #include "CoinMessageHandler.hpp"
00011 #include "OsiSolverInterface.hpp"
00012 #include "OsiBranchingObject.hpp"
00013 #include "OsiCuts.hpp"
00014 #include "CoinWarmStartBasis.hpp"
00015 #include "CbcCompareBase.hpp"
00016 #include "CbcCountRowCut.hpp"
00017 #include "CbcMessage.hpp"
00018 #include "CbcEventHandler.hpp"
00019 #include "ClpDualRowPivot.hpp"
00020
00021
00022 class CbcCutGenerator;
00023 class CbcBaseModel;
00024 class OsiRowCut;
00025 class OsiBabSolver;
00026 class OsiRowCutDebugger;
00027 class CglCutGenerator;
00028 class CglStored;
00029 class CbcCutModifier;
00030 class CglTreeProbingInfo;
00031 class CbcHeuristic;
00032 class OsiObject;
00033 class CbcThread;
00034 class CbcTree;
00035 class CbcStrategy;
00036 class CbcSymmetry;
00037 class CbcFeasibilityBase;
00038 class CbcStatistics;
00039 class CbcFullNodeInfo;
00040 class CbcEventHandler ;
00041 class CglPreProcess;
00042 class OsiClpSolverInterface;
00043 class ClpNodeStuff;
00044
00045
00046
00047
00048
00101 class CbcModel {
00102
00103 public:
00104
00105 enum CbcIntParam {
00107 CbcMaxNumNode = 0,
00109 CbcMaxNumSol,
00119 CbcFathomDiscipline,
00123 CbcPrinting,
00126 CbcNumberBranches,
00128 CbcLastIntParam
00129 };
00130
00131 enum CbcDblParam {
00134 CbcIntegerTolerance = 0,
00137 CbcInfeasibilityWeight,
00140 CbcCutoffIncrement,
00147 CbcAllowableGap,
00154 CbcAllowableFractionGap,
00157 CbcMaximumSeconds,
00159 CbcCurrentCutoff,
00161 CbcOptimizationDirection,
00163 CbcCurrentObjectiveValue,
00165 CbcCurrentMinimizationObjectiveValue,
00168 CbcStartSeconds,
00176 CbcHeuristicGap,
00184 CbcHeuristicFractionGap,
00186 CbcSmallestChange,
00188 CbcSumChange,
00190 CbcLargestChange,
00192 CbcSmallChange,
00194 CbcLastDblParam
00195 };
00196
00197
00198
00199 public:
00201
00202
00206 void initialSolve();
00207
00218 void branchAndBound(int doStatistics = 0);
00219 private:
00220
00228 bool solveWithCuts(OsiCuts & cuts, int numberTries, CbcNode * node);
00236 int serialCuts(OsiCuts & cuts, CbcNode * node, OsiCuts & slackCuts, int lastNumberCuts);
00244 int parallelCuts(CbcBaseModel * master, OsiCuts & cuts, CbcNode * node, OsiCuts & slackCuts, int lastNumberCuts);
00251 CbcNode ** solveOneNode(int whichSolver, CbcNode * node,
00252 int & numberNodesOutput, int & status) ;
00254 void resizeWhichGenerator(int numberNow, int numberAfter);
00255 public:
00256 #ifdef CBC_KEEP_DEPRECATED
00257
00262 CbcModel * cleanModel(const double * lower, const double * upper);
00279 int subBranchAndBound(CbcModel * model2,
00280 CbcModel * presolvedModel,
00281 int maximumNodes);
00297 int subBranchAndBound(const double * lower, const double * upper,
00298 int maximumNodes);
00299
00306 OsiSolverInterface * strengthenedModel();
00316 CglPreProcess * preProcess( int makeEquality = 0, int numberPasses = 5,
00317 int tuning = 5);
00320 void postProcess(CglPreProcess * process);
00321 #endif
00323 void addUpdateInformation(const CbcObjectUpdateData & data);
00324
00330 int doOneNode(CbcModel * baseModel, CbcNode * & node, CbcNode * & newNode);
00331
00332 public:
00346 int resolve(CbcNodeInfo * parent, int whereFrom,
00347 double * saveSolution = NULL,
00348 double * saveLower = NULL,
00349 double * saveUpper = NULL);
00351 void makeGlobalCuts(int numberRows, const int * which);
00353 int makeGlobalCut(const OsiRowCut * cut);
00355 int makeGlobalCut(const OsiRowCut & cut);
00357 void makeGlobalCut(const OsiColCut * cut);
00359 void makeGlobalCut(const OsiColCut & cut);
00361 void makePartialCut(const OsiRowCut * cut, const OsiSolverInterface * solver=NULL);
00363 void makeGlobalCuts();
00365 inline const int * whichGenerator() const
00366 { return whichGenerator_;}
00368
00371
00383 CbcModel * findCliques(bool makeEquality, int atLeastThisMany,
00384 int lessThanThis, int defaultValue = 1000);
00385
00394 CbcModel * integerPresolve(bool weak = false);
00395
00400 bool integerPresolveThisModel(OsiSolverInterface * originalSolver, bool weak = false);
00401
00402
00404 void originalModel(CbcModel * presolvedModel, bool weak);
00405
00426 bool tightenVubs(int type, bool allowMultipleBinary = false,
00427 double useCutoff = 1.0e50);
00428
00434 bool tightenVubs(int numberVubs, const int * which,
00435 double useCutoff = 1.0e50);
00439 void analyzeObjective();
00440
00444 void AddIntegers();
00448 void saveModel(OsiSolverInterface * saveSolver, double * checkCutoffForRestart, bool * feasible);
00452 void flipModel();
00453
00455
00461
00463 inline int numberObjects() const {
00464 return numberObjects_;
00465 }
00467 inline void setNumberObjects(int number) {
00468 numberObjects_ = number;
00469 }
00470
00472 inline OsiObject ** objects() const {
00473 return object_;
00474 }
00475
00477 const inline OsiObject * object(int which) const {
00478 return object_[which];
00479 }
00481 inline OsiObject * modifiableObject(int which) const {
00482 return object_[which];
00483 }
00484
00485 void setOptionalInteger(int index);
00486
00488 void deleteObjects(bool findIntegers = true);
00489
00494 void addObjects(int numberObjects, OsiObject ** objects);
00495
00500 void addObjects(int numberObjects, CbcObject ** objects);
00501
00503 void synchronizeModel() ;
00504
00514 void findIntegers(bool startAgain, int type = 0);
00515
00516 #ifdef SWITCH_VARIABLES
00518 int findSwitching();
00520 int fixAssociated(OsiSolverInterface * solver,int cleanBasis);
00522 int checkAssociated(const OsiSolverInterface * solver,
00523 const double * solution, int printLevel);
00524 #endif
00525
00526
00527
00528
00538
00539 inline bool setIntParam(CbcIntParam key, int value) {
00540 intParam_[key] = value;
00541 return true;
00542 }
00544 inline bool setDblParam(CbcDblParam key, double value) {
00545 dblParam_[key] = value;
00546 return true;
00547 }
00549 inline int getIntParam(CbcIntParam key) const {
00550 return intParam_[key];
00551 }
00553 inline double getDblParam(CbcDblParam key) const {
00554 return dblParam_[key];
00555 }
00561 void setCutoff(double value) ;
00562
00564 inline double getCutoff() const {
00565
00566
00567 return dblParam_[CbcCurrentCutoff];
00568 }
00569
00571 inline bool setMaximumNodes( int value) {
00572 return setIntParam(CbcMaxNumNode, value);
00573 }
00574
00576 inline int getMaximumNodes() const {
00577 return getIntParam(CbcMaxNumNode);
00578 }
00579
00584 inline bool setMaximumSolutions( int value) {
00585 return setIntParam(CbcMaxNumSol, value);
00586 }
00591 inline int getMaximumSolutions() const {
00592 return getIntParam(CbcMaxNumSol);
00593 }
00595 inline bool setPrintingMode( int value) {
00596 return setIntParam(CbcPrinting, value);
00597 }
00598
00600 inline int getPrintingMode() const {
00601 return getIntParam(CbcPrinting);
00602 }
00603
00608 inline bool setMaximumSeconds( double value) {
00609 return setDblParam(CbcMaximumSeconds, value);
00610 }
00615 inline double getMaximumSeconds() const {
00616 return getDblParam(CbcMaximumSeconds);
00617 }
00619 double getCurrentSeconds() const ;
00620
00622 bool maximumSecondsReached() const ;
00623
00627 inline bool setIntegerTolerance( double value) {
00628 return setDblParam(CbcIntegerTolerance, value);
00629 }
00633 inline double getIntegerTolerance() const {
00634 return getDblParam(CbcIntegerTolerance);
00635 }
00636
00641 inline bool setInfeasibilityWeight( double value) {
00642 return setDblParam(CbcInfeasibilityWeight, value);
00643 }
00648 inline double getInfeasibilityWeight() const {
00649 return getDblParam(CbcInfeasibilityWeight);
00650 }
00651
00655 inline bool setAllowableGap( double value) {
00656 return setDblParam(CbcAllowableGap, value);
00657 }
00661 inline double getAllowableGap() const {
00662 return getDblParam(CbcAllowableGap);
00663 }
00664
00668 inline bool setAllowableFractionGap( double value) {
00669 return setDblParam(CbcAllowableFractionGap, value);
00670 }
00674 inline double getAllowableFractionGap() const {
00675 return getDblParam(CbcAllowableFractionGap);
00676 }
00680 inline bool setAllowablePercentageGap( double value) {
00681 return setDblParam(CbcAllowableFractionGap, value*0.01);
00682 }
00686 inline double getAllowablePercentageGap() const {
00687 return 100.0*getDblParam(CbcAllowableFractionGap);
00688 }
00692 inline bool setHeuristicGap( double value) {
00693 return setDblParam(CbcHeuristicGap, value);
00694 }
00698 inline double getHeuristicGap() const {
00699 return getDblParam(CbcHeuristicGap);
00700 }
00701
00705 inline bool setHeuristicFractionGap( double value) {
00706 return setDblParam(CbcHeuristicFractionGap, value);
00707 }
00711 inline double getHeuristicFractionGap() const {
00712 return getDblParam(CbcHeuristicFractionGap);
00713 }
00718 inline bool setCutoffIncrement( double value) {
00719 return setDblParam(CbcCutoffIncrement, value);
00720 }
00725 inline double getCutoffIncrement() const {
00726 return getDblParam(CbcCutoffIncrement);
00727 }
00729 bool canStopOnGap() const;
00730
00735 void setHotstartSolution(const double * solution, const int * priorities = NULL) ;
00736
00738 inline void setMinimumDrop(double value) {
00739 minimumDrop_ = value;
00740 }
00742 inline double getMinimumDrop() const {
00743 return minimumDrop_;
00744 }
00745
00748 inline void setMaximumCutPassesAtRoot(int value) {
00749 maximumCutPassesAtRoot_ = value;
00750 }
00752 inline int getMaximumCutPassesAtRoot() const {
00753 return maximumCutPassesAtRoot_;
00754 }
00755
00758 inline void setMaximumCutPasses(int value) {
00759 maximumCutPasses_ = value;
00760 }
00762 inline int getMaximumCutPasses() const {
00763 return maximumCutPasses_;
00764 }
00767 inline int getCurrentPassNumber() const {
00768 return currentPassNumber_;
00769 }
00772 inline void setCurrentPassNumber(int value) {
00773 currentPassNumber_ = value;
00774 }
00775
00781 void setNumberStrong(int number);
00785 inline int numberStrong() const {
00786 return numberStrong_;
00787 }
00790 inline void setPreferredWay(int value) {
00791 preferredWay_ = value;
00792 }
00794 inline int getPreferredWay() const {
00795 return preferredWay_;
00796 }
00798 inline int whenCuts() const {
00799 return whenCuts_;
00800 }
00802 inline void setWhenCuts(int value) {
00803 whenCuts_ = value;
00804 }
00810 bool doCutsNow(int allowForTopOfTree) const;
00811
00817 void setNumberBeforeTrust(int number);
00820 inline int numberBeforeTrust() const {
00821 return numberBeforeTrust_;
00822 }
00828 void setNumberPenalties(int number);
00831 inline int numberPenalties() const {
00832 return numberPenalties_;
00833 }
00835 inline const CbcFullNodeInfo * topOfTree() const
00836 { return topOfTree_;}
00838 inline void setNumberAnalyzeIterations(int number) {
00839 numberAnalyzeIterations_ = number;
00840 }
00841 inline int numberAnalyzeIterations() const {
00842 return numberAnalyzeIterations_;
00843 }
00846 inline double penaltyScaleFactor() const {
00847 return penaltyScaleFactor_;
00848 }
00851 void setPenaltyScaleFactor(double value);
00859 void inline setProblemType(int number) {
00860 problemType_ = number;
00861 }
00862 inline int problemType() const {
00863 return problemType_;
00864 }
00866 inline int currentDepth() const {
00867 return currentDepth_;
00868 }
00869
00871 void setHowOftenGlobalScan(int number);
00873 inline int howOftenGlobalScan() const {
00874 return howOftenGlobalScan_;
00875 }
00877 inline int * originalColumns() const {
00878 return originalColumns_;
00879 }
00881 void setOriginalColumns(const int * originalColumns,
00882 int numberGood=COIN_INT_MAX) ;
00884 OsiRowCut * conflictCut(const OsiSolverInterface * solver, bool & localCuts);
00885
00893 inline void setPrintFrequency(int number) {
00894 printFrequency_ = number;
00895 }
00897 inline int printFrequency() const {
00898 return printFrequency_;
00899 }
00901
00902
00904
00905
00906 bool isAbandoned() const;
00908 bool isProvenOptimal() const;
00910 bool isProvenInfeasible() const;
00912 bool isContinuousUnbounded() const;
00914 bool isProvenDualInfeasible() const;
00916 bool isNodeLimitReached() const;
00918 bool isSecondsLimitReached() const;
00920 bool isSolutionLimitReached() const;
00922 inline int getIterationCount() const {
00923 return numberIterations_;
00924 }
00926 inline void incrementIterationCount(int value) {
00927 numberIterations_ += value;
00928 }
00930 inline int getNodeCount() const {
00931 return numberNodes_;
00932 }
00934 inline void incrementNodeCount(int value) {
00935 numberNodes_ += value;
00936 }
00938 inline int getExtraNodeCount() const {
00939 return numberExtraNodes_;
00940 }
00942 inline int getFathomCount() const {
00943 return numberFathoms_;
00944 }
00954 inline int status() const {
00955 return status_;
00956 }
00957 inline void setProblemStatus(int value) {
00958 status_ = value;
00959 }
00972 inline int secondaryStatus() const {
00973 return secondaryStatus_;
00974 }
00975 inline void setSecondaryStatus(int value) {
00976 secondaryStatus_ = value;
00977 }
00979 bool isInitialSolveAbandoned() const ;
00981 bool isInitialSolveProvenOptimal() const ;
00983 bool isInitialSolveProvenPrimalInfeasible() const ;
00985 bool isInitialSolveProvenDualInfeasible() const ;
00986
00988
00989
01002
01003 inline int numberRowsAtContinuous() const {
01004 return numberRowsAtContinuous_;
01005 }
01006
01008 inline int getNumCols() const {
01009 return solver_->getNumCols();
01010 }
01011
01013 inline int getNumRows() const {
01014 return solver_->getNumRows();
01015 }
01016
01018 inline CoinBigIndex getNumElements() const {
01019 return solver_->getNumElements();
01020 }
01021
01023 inline int numberIntegers() const {
01024 return numberIntegers_;
01025 }
01026
01027 inline const int * integerVariable() const {
01028 return integerVariable_;
01029 }
01031 inline char integerType(int i) const {
01032 assert (integerInfo_);
01033 assert (integerInfo_[i] == 0 || integerInfo_[i] == 1);
01034 return integerInfo_[i];
01035 }
01037 inline const char * integerType() const {
01038 return integerInfo_;
01039 }
01040
01042 inline const double * getColLower() const {
01043 return solver_->getColLower();
01044 }
01045
01047 inline const double * getColUpper() const {
01048 return solver_->getColUpper();
01049 }
01050
01060 inline const char * getRowSense() const {
01061 return solver_->getRowSense();
01062 }
01063
01072 inline const double * getRightHandSide() const {
01073 return solver_->getRightHandSide();
01074 }
01075
01084 inline const double * getRowRange() const {
01085 return solver_->getRowRange();
01086 }
01087
01089 inline const double * getRowLower() const {
01090 return solver_->getRowLower();
01091 }
01092
01094 inline const double * getRowUpper() const {
01095 return solver_->getRowUpper();
01096 }
01097
01099 inline const double * getObjCoefficients() const {
01100 return solver_->getObjCoefficients();
01101 }
01102
01104 inline double getObjSense() const {
01105
01106 return dblParam_[CbcOptimizationDirection];
01107 }
01108
01110 inline bool isContinuous(int colIndex) const {
01111 return solver_->isContinuous(colIndex);
01112 }
01113
01115 inline bool isBinary(int colIndex) const {
01116 return solver_->isBinary(colIndex);
01117 }
01118
01123 inline bool isInteger(int colIndex) const {
01124 return solver_->isInteger(colIndex);
01125 }
01126
01128 inline bool isIntegerNonBinary(int colIndex) const {
01129 return solver_->isIntegerNonBinary(colIndex);
01130 }
01131
01133 inline bool isFreeBinary(int colIndex) const {
01134 return solver_->isFreeBinary(colIndex) ;
01135 }
01136
01138 inline const CoinPackedMatrix * getMatrixByRow() const {
01139 return solver_->getMatrixByRow();
01140 }
01141
01143 inline const CoinPackedMatrix * getMatrixByCol() const {
01144 return solver_->getMatrixByCol();
01145 }
01146
01148 inline double getInfinity() const {
01149 return solver_->getInfinity();
01150 }
01152 inline const double * getCbcColLower() const {
01153 return cbcColLower_;
01154 }
01156 inline const double * getCbcColUpper() const {
01157 return cbcColUpper_;
01158 }
01160 inline const double * getCbcRowLower() const {
01161 return cbcRowLower_;
01162 }
01164 inline const double * getCbcRowUpper() const {
01165 return cbcRowUpper_;
01166 }
01168 inline const double * getCbcColSolution() const {
01169 return cbcColSolution_;
01170 }
01172 inline const double * getCbcRowPrice() const {
01173 return cbcRowPrice_;
01174 }
01176 inline const double * getCbcReducedCost() const {
01177 return cbcReducedCost_;
01178 }
01180 inline const double * getCbcRowActivity() const {
01181 return cbcRowActivity_;
01182 }
01184
01185
01188
01189 inline double * continuousSolution() const {
01190 return continuousSolution_;
01191 }
01196 inline int * usedInSolution() const {
01197 return usedInSolution_;
01198 }
01200 void incrementUsed(const double * solution);
01202 void setBestSolution(CBC_Message how,
01203 double & objectiveValue, const double *solution,
01204 int fixVariables = 0);
01206 void setBestObjectiveValue( double objectiveValue);
01208 CbcEventHandler::CbcAction dealWithEventHandler(CbcEventHandler::CbcEvent event,
01209 double objValue,
01210 const double * solution);
01211
01219 virtual double checkSolution(double cutoff, double * solution,
01220 int fixVariables, double originalObjValue);
01227 bool feasibleSolution(int & numberIntegerInfeasibilities,
01228 int & numberObjectInfeasibilities) const;
01229
01235 inline double * currentSolution() const {
01236 return currentSolution_;
01237 }
01241 inline const double * testSolution() const {
01242 return testSolution_;
01243 }
01244 inline void setTestSolution(const double * solution) {
01245 testSolution_ = solution;
01246 }
01248 void reserveCurrentSolution(const double * solution = NULL);
01249
01251 inline const double * getColSolution() const {
01252 return solver_->getColSolution();
01253 }
01254
01256 inline const double * getRowPrice() const {
01257 return solver_->getRowPrice();
01258 }
01259
01261 inline const double * getReducedCost() const {
01262 return solver_->getReducedCost();
01263 }
01264
01266 inline const double * getRowActivity() const {
01267 return solver_->getRowActivity();
01268 }
01269
01271 inline double getCurrentObjValue() const {
01272 return dblParam_[CbcCurrentObjectiveValue];
01273 }
01275 inline double getCurrentMinimizationObjValue() const {
01276 return dblParam_[CbcCurrentMinimizationObjectiveValue];
01277 }
01278
01280 inline double getMinimizationObjValue() const {
01281 return bestObjective_;
01282 }
01284 inline void setMinimizationObjValue(double value) {
01285 bestObjective_ = value;
01286 }
01287
01289 inline double getObjValue() const {
01290 return bestObjective_ * solver_->getObjSense() ;
01291 }
01297 double getBestPossibleObjValue() const;
01299 inline void setObjValue(double value) {
01300 bestObjective_ = value * solver_->getObjSense() ;
01301 }
01303 inline double getSolverObjValue() const {
01304 return solver_->getObjValue() * solver_->getObjSense() ;
01305 }
01306
01313 inline double * bestSolution() const {
01314 return bestSolution_;
01315 }
01322 void setBestSolution(const double * solution, int numberColumns,
01323 double objectiveValue, bool check = false);
01324
01326 inline int getSolutionCount() const {
01327 return numberSolutions_;
01328 }
01329
01331 inline void setSolutionCount(int value) {
01332 numberSolutions_ = value;
01333 }
01335 int numberSavedSolutions() const;
01337 inline int maximumSavedSolutions() const {
01338 return maximumSavedSolutions_;
01339 }
01341 void setMaximumSavedSolutions(int value);
01343 const double * savedSolution(int which) const;
01345 double savedSolutionObjective(int which) const;
01347 void deleteSavedSolution(int which);
01348
01357 inline int phase() const {
01358 return phase_;
01359 }
01360
01362 inline int getNumberHeuristicSolutions() const {
01363 return numberHeuristicSolutions_;
01364 }
01366 inline void setNumberHeuristicSolutions(int value) {
01367 numberHeuristicSolutions_ = value;
01368 }
01369
01371 inline void setObjSense(double s) {
01372 dblParam_[CbcOptimizationDirection] = s;
01373 solver_->setObjSense(s);
01374 }
01375
01377 inline double getContinuousObjective() const {
01378 return originalContinuousObjective_;
01379 }
01380 inline void setContinuousObjective(double value) {
01381 originalContinuousObjective_ = value;
01382 }
01384 inline int getContinuousInfeasibilities() const {
01385 return continuousInfeasibilities_;
01386 }
01387 inline void setContinuousInfeasibilities(int value) {
01388 continuousInfeasibilities_ = value;
01389 }
01391 inline double rootObjectiveAfterCuts() const {
01392 return continuousObjective_;
01393 }
01395 inline double sumChangeObjective() const {
01396 return sumChangeObjective1_;
01397 }
01400 inline int numberGlobalViolations() const {
01401 return numberGlobalViolations_;
01402 }
01403 inline void clearNumberGlobalViolations() {
01404 numberGlobalViolations_ = 0;
01405 }
01407 inline bool resolveAfterTakeOffCuts() const {
01408 return resolveAfterTakeOffCuts_;
01409 }
01410 inline void setResolveAfterTakeOffCuts(bool yesNo) {
01411 resolveAfterTakeOffCuts_ = yesNo;
01412 }
01414 inline int maximumRows() const {
01415 return maximumRows_;
01416 }
01418 inline CoinWarmStartBasis & workingBasis() {
01419 return workingBasis_;
01420 }
01422 inline int getStopNumberIterations() const {
01423 return stopNumberIterations_;
01424 }
01426 inline void setStopNumberIterations(int value) {
01427 stopNumberIterations_ = value;
01428 }
01430 inline CbcModel * heuristicModel() const
01431 { return heuristicModel_;}
01433 inline void setHeuristicModel(CbcModel * model)
01434 { heuristicModel_ = model;}
01436
01439
01440 inline CbcCompareBase * nodeComparison() const {
01441 return nodeCompare_;
01442 }
01443 void setNodeComparison(CbcCompareBase * compare);
01444 void setNodeComparison(CbcCompareBase & compare);
01446
01449
01450 inline CbcFeasibilityBase * problemFeasibility() const {
01451 return problemFeasibility_;
01452 }
01453 void setProblemFeasibility(CbcFeasibilityBase * feasibility);
01454 void setProblemFeasibility(CbcFeasibilityBase & feasibility);
01456
01459
01460 inline CbcTree * tree() const {
01461 return tree_;
01462 }
01464 void passInTreeHandler(CbcTree & tree);
01468 void passInSubTreeModel(CbcModel & model);
01473 CbcModel * subTreeModel(OsiSolverInterface * solver = NULL) const;
01475 inline int numberStoppedSubTrees() const {
01476 return numberStoppedSubTrees_;
01477 }
01479 inline void incrementSubTreeStopped() {
01480 numberStoppedSubTrees_++;
01481 }
01487 inline int typePresolve() const {
01488 return presolve_;
01489 }
01490 inline void setTypePresolve(int value) {
01491 presolve_ = value;
01492 }
01493
01495
01501
01503 inline CbcBranchDecision * branchingMethod() const {
01504 return branchingMethod_;
01505 }
01507 inline void setBranchingMethod(CbcBranchDecision * method) {
01508 delete branchingMethod_;
01509 branchingMethod_ = method->clone();
01510 }
01515 inline void setBranchingMethod(CbcBranchDecision & method) {
01516 delete branchingMethod_;
01517 branchingMethod_ = method.clone();
01518 }
01520 inline CbcCutModifier * cutModifier() const {
01521 return cutModifier_;
01522 }
01524 void setCutModifier(CbcCutModifier * modifier);
01529 void setCutModifier(CbcCutModifier & modifier);
01531
01534
01541 inline int stateOfSearch() const {
01542 return stateOfSearch_;
01543 }
01544 inline void setStateOfSearch(int state) {
01545 stateOfSearch_ = state;
01546 }
01548 inline int searchStrategy() const {
01549 return searchStrategy_;
01550 }
01552 inline void setSearchStrategy(int value) {
01553 searchStrategy_ = value;
01554 }
01556 inline int strongStrategy() const {
01557 return strongStrategy_;
01558 }
01560 inline void setStrongStrategy(int value) {
01561 strongStrategy_ = value;
01562 }
01563
01565 inline int numberCutGenerators() const {
01566 return numberCutGenerators_;
01567 }
01569 inline CbcCutGenerator ** cutGenerators() const {
01570 return generator_;
01571 }
01573 inline CbcCutGenerator * cutGenerator(int i) const {
01574 return generator_[i];
01575 }
01577 inline CbcCutGenerator * virginCutGenerator(int i) const {
01578 return virginGenerator_[i];
01579 }
01588 void addCutGenerator(CglCutGenerator * generator,
01589 int howOften = 1, const char * name = NULL,
01590 bool normal = true, bool atSolution = false,
01591 bool infeasible = false, int howOftenInSub = -100,
01592 int whatDepth = -1, int whatDepthInSub = -1);
01594
01599
01601 inline CbcStrategy * strategy() const {
01602 return strategy_;
01603 }
01605 void setStrategy(CbcStrategy & strategy);
01607 inline void setStrategy(CbcStrategy * strategy) {
01608 strategy_ = strategy;
01609 }
01611 inline CbcModel * parentModel() const {
01612 return parentModel_;
01613 }
01615 inline void setParentModel(CbcModel & parentModel) {
01616 parentModel_ = &parentModel;
01617 }
01619
01620
01627 void addHeuristic(CbcHeuristic * generator, const char *name = NULL,
01628 int before = -1);
01630 inline CbcHeuristic * heuristic(int i) const {
01631 return heuristic_[i];
01632 }
01634 inline int numberHeuristics() const {
01635 return numberHeuristics_;
01636 }
01638 inline void setNumberHeuristics(int value) {
01639 numberHeuristics_ = value;
01640 }
01642 inline CbcHeuristic * lastHeuristic() const {
01643 return lastHeuristic_;
01644 }
01646 inline void setLastHeuristic(CbcHeuristic * last) {
01647 lastHeuristic_ = last;
01648 }
01649
01668 void passInPriorities(const int * priorities, bool ifNotSimpleIntegers);
01669
01671 inline int priority(int sequence) const {
01672 return object_[sequence]->priority();
01673 }
01674
01679 void passInEventHandler(const CbcEventHandler *eventHandler) ;
01680
01682 inline CbcEventHandler* getEventHandler() const {
01683 return (eventHandler_) ;
01684 }
01685
01687
01697 void setApplicationData (void * appData);
01698
01700 void * getApplicationData() const;
01713 void passInSolverCharacteristics(OsiBabSolver * solverCharacteristics);
01715 inline const OsiBabSolver * solverCharacteristics() const {
01716 return solverCharacteristics_;
01717 }
01719
01720
01721
01724
01725 void passInMessageHandler(CoinMessageHandler * handler);
01727 void newLanguage(CoinMessages::Language language);
01728 inline void setLanguage(CoinMessages::Language language) {
01729 newLanguage(language);
01730 }
01732 inline CoinMessageHandler * messageHandler() const {
01733 return handler_;
01734 }
01736 inline CoinMessages & messages() {
01737 return messages_;
01738 }
01740 inline CoinMessages * messagesPointer() {
01741 return &messages_;
01742 }
01744 void setLogLevel(int value);
01746 inline int logLevel() const {
01747 return handler_->logLevel();
01748 }
01754 inline void setDefaultHandler(bool yesNo) {
01755 defaultHandler_ = yesNo;
01756 }
01758 inline bool defaultHandler() const {
01759 return defaultHandler_;
01760 }
01762
01764
01765
01793 inline void setSpecialOptions(int value) {
01794 specialOptions_ = value;
01795 }
01797 inline int specialOptions() const {
01798 return specialOptions_;
01799 }
01801 inline void setRandomSeed(int value) {
01802 randomSeed_ = value;
01803 }
01805 inline int getRandomSeed() const {
01806 return randomSeed_;
01807 }
01809 inline void setMultipleRootTries(int value) {
01810 multipleRootTries_ = value;
01811 }
01813 inline int getMultipleRootTries() const {
01814 return multipleRootTries_;
01815 }
01817 inline void sayEventHappened()
01818 { eventHappened_=true;}
01820 inline bool normalSolver() const {
01821 return (specialOptions_&16) == 0;
01822 }
01827 inline bool waitingForMiniBranchAndBound() const {
01828 return (specialOptions_&1048576) != 0;
01829 }
01853 inline void setMoreSpecialOptions(int value) {
01854 moreSpecialOptions_ = value;
01855 }
01857 inline int moreSpecialOptions() const {
01858 return moreSpecialOptions_;
01859 }
01874 inline void setMoreSpecialOptions2(int value) {
01875 moreSpecialOptions2_ = value;
01876 }
01878 inline int moreSpecialOptions2() const {
01879 return moreSpecialOptions2_;
01880 }
01882 inline void setCutoffAsConstraint(bool yesNo) {
01883 cutoffRowNumber_ = (yesNo) ? -2 : -1;
01884 }
01886 inline void setUseElapsedTime(bool yesNo) {
01887 if (yesNo)
01888 moreSpecialOptions_ |= 131072;
01889 else
01890 moreSpecialOptions_ &= ~131072;
01891 }
01893 inline bool useElapsedTime() const {
01894 return (moreSpecialOptions_&131072)!=0;
01895 }
01897 inline void * temporaryPointer() const
01898 { return temporaryPointer_;}
01900 inline void setTemporaryPointer(void * pointer)
01901 { temporaryPointer_=pointer;}
01903 void goToDantzig(int numberNodes, ClpDualRowPivot *& savePivotMethod);
01905 inline bool ownObjects() const {
01906 return ownObjects_;
01907 }
01909 void checkModel();
01911
01912
01914
01915
01916 CbcModel();
01917
01919 CbcModel(const OsiSolverInterface &);
01920
01929 void assignSolver(OsiSolverInterface *&solver, bool deleteSolver = true);
01930
01942 inline void setModelOwnsSolver (bool ourSolver) {
01943 ownership_ = ourSolver ? (ownership_ | 0x80000000) : (ownership_ & (~0x80000000)) ;
01944 }
01945
01951 inline bool modelOwnsSolver () {
01952 return ((ownership_&0x80000000) != 0) ;
01953 }
01954
01958 CbcModel(const CbcModel & rhs, bool cloneHandler = false);
01959
01961 virtual CbcModel *clone (bool cloneHandler);
01962
01964 CbcModel & operator=(const CbcModel& rhs);
01965
01967 virtual ~CbcModel ();
01968
01970 inline OsiSolverInterface * solver() const {
01971 return solver_;
01972 }
01973
01975 inline OsiSolverInterface * swapSolver(OsiSolverInterface * solver) {
01976 OsiSolverInterface * returnSolver = solver_;
01977 solver_ = solver;
01978 return returnSolver;
01979 }
01980
01982 inline OsiSolverInterface * continuousSolver() const {
01983 return continuousSolver_;
01984 }
01985
01987 inline void createContinuousSolver() {
01988 continuousSolver_ = solver_->clone();
01989 }
01991 inline void clearContinuousSolver() {
01992 delete continuousSolver_;
01993 continuousSolver_ = NULL;
01994 }
01995
01997 inline OsiSolverInterface * referenceSolver() const {
01998 return referenceSolver_;
01999 }
02000
02002 void saveReferenceSolver();
02003
02009 void resetToReferenceSolver();
02010
02012 void gutsOfDestructor();
02015 void gutsOfDestructor2();
02018 void resetModel();
02024 void gutsOfCopy(const CbcModel & rhs, int mode = 0);
02026 void moveInfo(const CbcModel & rhs);
02028
02030
02031
02032 static bool haveMultiThreadSupport();
02034 CbcThread * masterThread() const {
02035 return masterThread_;
02036 }
02038 CbcNodeInfo ** walkback() const {
02039 return walkback_;
02040 }
02042 inline int getNumberThreads() const {
02043 return numberThreads_;
02044 }
02046 inline void setNumberThreads(int value) {
02047 numberThreads_ = value;
02048 }
02050 inline int getThreadMode() const {
02051 return threadMode_;
02052 }
02062 inline void setThreadMode(int value) {
02063 threadMode_ = value;
02064 }
02071 inline int parallelMode() const {
02072 if (!numberThreads_) {
02073 if ((threadMode_&1) == 0)
02074 return 0;
02075 else
02076 return -1;
02077 return 0;
02078 } else {
02079 if ((threadMode_&1) == 0)
02080 return 1;
02081 else
02082 return -2;
02083 }
02084 }
02086 inline CbcBaseModel * master() const
02087 { return master_;}
02090 bool isLocked() const;
02091 #ifdef CBC_THREAD
02092
02096 void lockThread();
02100 void unlockThread();
02101 #else
02102 inline void lockThread() {}
02103 inline void unlockThread() {}
02104 #endif
02105
02112 void setInfoInChild(int type, CbcThread * info);
02119 void moveToModel(CbcModel * baseModel, int mode);
02121 int splitModel(int numberModels, CbcModel ** model,
02122 int numberNodes);
02124 void startSplitModel(int numberIterations);
02126 void mergeModels(int numberModel, CbcModel ** model,
02127 int numberNodes);
02129
02131
02132
02133 int getNodeCount2() const {
02134 return numberNodes2_;
02135 }
02137 void setPointers(const OsiSolverInterface * solver);
02143 int reducedCostFix() ;
02147 void synchronizeHandlers(int makeDefault);
02149 void saveExtraSolution(const double * solution, double objectiveValue);
02151 void saveBestSolution(const double * solution, double objectiveValue);
02153 void deleteSolutions();
02155 int resolve(OsiSolverInterface * solver);
02156 #ifdef CLP_RESOLVE
02158 int resolveClp(OsiClpSolverInterface * solver, int type);
02159 #endif
02160
02164 int chooseBranch(CbcNode * & newNode, int numberPassesLeft,
02165 CbcNode * oldNode, OsiCuts & cuts,
02166 bool & resolved, CoinWarmStartBasis *lastws,
02167 const double * lowerBefore, const double * upperBefore,
02168 OsiSolverBranch * & branches);
02169 int chooseBranch(CbcNode * newNode, int numberPassesLeft, bool & resolved);
02170
02177 CoinWarmStartBasis *getEmptyBasis(int ns = 0, int na = 0) const ;
02178
02190 int takeOffCuts(OsiCuts &cuts,
02191 bool allowResolve, OsiCuts * saveCuts,
02192 int numberNewCuts = 0, const OsiRowCut ** newCuts = NULL) ;
02193
02206 int addCuts(CbcNode * node, CoinWarmStartBasis *&lastws);
02207
02224 bool addCuts1(CbcNode * node, CoinWarmStartBasis *&lastws);
02228 void previousBounds (CbcNode * node, CbcNodeInfo * where, int iColumn,
02229 double & lower, double & upper, int force);
02234 void setObjectiveValue(CbcNode * thisNode, const CbcNode * parentNode) const;
02235
02239 void convertToDynamic();
02241 void synchronizeNumberBeforeTrust(int type = 0);
02243 void zapIntegerInformation(bool leaveObjects = true);
02245 int cliquePseudoCosts(int doStatistics);
02247 void pseudoShadow(int type);
02254 void fillPseudoCosts(double * downCosts, double * upCosts,
02255 int * priority = NULL,
02256 int * numberDown = NULL, int * numberUp = NULL,
02257 int * numberDownInfeasible = NULL,
02258 int * numberUpInfeasible = NULL) const;
02264 void doHeuristicsAtRoot(int deleteHeuristicsAfterwards = 0);
02266 void adjustHeuristics();
02268 inline const double * hotstartSolution() const {
02269 return hotstartSolution_;
02270 }
02272 inline const int * hotstartPriorities() const {
02273 return hotstartPriorities_;
02274 }
02275
02277 inline CbcCountRowCut ** addedCuts() const {
02278 return addedCuts_;
02279 }
02281 inline int currentNumberCuts() const {
02282 return currentNumberCuts_;
02283 }
02285 inline CbcRowCuts * globalCuts() {
02286 return &globalCuts_;
02287 }
02289 inline void zapGlobalCuts() {
02290 globalCuts_ = CbcRowCuts();
02291 }
02293 void setNextRowCut(const OsiRowCut & cut);
02295 inline CbcNode * currentNode() const {
02296 return currentNode_;
02297 }
02299 inline CglTreeProbingInfo * probingInfo() const {
02300 return probingInfo_;
02301 }
02303 inline CoinThreadRandom * randomNumberGenerator() {
02304 return &randomNumberGenerator_;
02305 }
02307 inline void setNumberStrongIterations(int number) {
02308 numberStrongIterations_ = number;
02309 }
02311 inline int numberStrongIterations() const {
02312 return numberStrongIterations_;
02313 }
02315 inline int maximumNumberIterations() const {
02316 return maximumNumberIterations_;
02317 }
02319 inline void setMaximumNumberIterations(int value) {
02320 maximumNumberIterations_ = value;
02321 }
02322 #ifdef COIN_HAS_NTY
02324 inline CbcSymmetry * symmetryInfo() const
02325 { return symmetryInfo_;}
02326 #endif
02328 inline void setFastNodeDepth(int value) {
02329 fastNodeDepth_ = value;
02330 }
02332 inline int fastNodeDepth() const {
02333 return fastNodeDepth_;
02334 }
02336 inline int continuousPriority() const {
02337 return continuousPriority_;
02338 }
02340 inline void setContinuousPriority(int value) {
02341 continuousPriority_ = value;
02342 }
02343 inline void incrementExtra(int nodes, int iterations, int fathoms=1) {
02344 numberExtraNodes_ += nodes;
02345 numberExtraIterations_ += iterations;
02346 numberFathoms_ += fathoms;
02347 }
02349 inline void zeroExtra() {
02350 numberExtraNodes_ = 0;
02351 numberExtraIterations_ = 0;
02352 numberFathoms_ = 0;
02353 }
02355 inline int numberExtraIterations() const {
02356 return numberExtraIterations_;
02357 }
02359 void incrementStrongInfo(int numberTimes, int numberIterations,
02360 int numberFixed, bool ifInfeasible);
02362 inline const int * strongInfo() const {
02363 return strongInfo_;
02364 }
02365
02367 inline int * mutableStrongInfo() {
02368 return strongInfo_;
02369 }
02371 CglStored * storedRowCuts() const {
02372 return storedRowCuts_;
02373 }
02375 void setStoredRowCuts(CglStored * cuts) {
02376 storedRowCuts_ = cuts;
02377 }
02379 inline bool allDynamic () const {
02380 return ((ownership_&0x40000000) != 0) ;
02381 }
02383 void generateCpp( FILE * fp, int options);
02385 OsiBranchingInformation usefulInformation() const;
02392 inline void setBestSolutionBasis(const CoinWarmStartBasis & bestSolutionBasis) {
02393 bestSolutionBasis_ = bestSolutionBasis;
02394 }
02396 void redoWalkBack();
02398
02399 void setMIPStart( const std::vector< std::pair< std::string, double > > &mips ) {
02400 this->mipStart_ = mips;
02401 }
02402
02403 const std::vector< std::pair< std::string, double > > &getMIPStart() {
02404 return this->mipStart_;
02405 }
02406
02407
02408
02409
02410 private:
02412
02413
02415 OsiSolverInterface * solver_;
02416
02422 unsigned int ownership_ ;
02423
02425 OsiSolverInterface * continuousSolver_;
02426
02428 OsiSolverInterface * referenceSolver_;
02429
02431 CoinMessageHandler * handler_;
02432
02438 bool defaultHandler_;
02439
02441 CoinMessages messages_;
02442
02444 int intParam_[CbcLastIntParam];
02445
02447 double dblParam_[CbcLastDblParam];
02448
02457 mutable CoinWarmStart *emptyWarmStart_ ;
02458
02460 double bestObjective_;
02462 double bestPossibleObjective_;
02464 double sumChangeObjective1_;
02466 double sumChangeObjective2_;
02467
02469 double * bestSolution_;
02471 double ** savedSolutions_;
02472
02477 double * currentSolution_;
02481 mutable const double * testSolution_;
02485 std::vector< std::pair< std::string, double > > mipStart_;
02492 CoinWarmStartBasis bestSolutionBasis_ ;
02494 CbcRowCuts globalCuts_;
02496 CbcRowCuts * globalConflictCuts_;
02497
02499 double minimumDrop_;
02501 int numberSolutions_;
02503 int numberSavedSolutions_;
02505 int maximumSavedSolutions_;
02512 int stateOfSearch_;
02514 int whenCuts_;
02516 double * hotstartSolution_;
02518 int * hotstartPriorities_;
02520 int numberHeuristicSolutions_;
02522 int numberNodes_;
02526 int numberNodes2_;
02528 int numberIterations_;
02530 int numberSolves_;
02532 int status_;
02543 int secondaryStatus_;
02545 int numberIntegers_;
02547 int numberRowsAtContinuous_;
02553 int cutoffRowNumber_;
02555 int maximumNumberCuts_;
02564 int phase_;
02565
02567 int currentNumberCuts_;
02568
02573 int maximumDepth_;
02579 CbcNodeInfo ** walkback_;
02580 CbcNodeInfo ** lastNodeInfo_;
02581 const OsiRowCut ** lastCut_;
02582 int lastDepth_;
02583 int lastNumberCuts2_;
02584 int maximumCuts_;
02585 int * lastNumberCuts_;
02586
02594 CbcCountRowCut ** addedCuts_;
02595
02599 OsiRowCut * nextRowCut_;
02600
02602 CbcNode * currentNode_;
02603
02605 int * integerVariable_;
02607 char * integerInfo_;
02609 double * continuousSolution_;
02611 int * usedInSolution_;
02639 int specialOptions_;
02654 int moreSpecialOptions_;
02668 int moreSpecialOptions2_;
02670 CbcCompareBase * nodeCompare_;
02672 CbcFeasibilityBase * problemFeasibility_;
02674 CbcTree * tree_;
02676 CbcFullNodeInfo * topOfTree_;
02678 CbcModel * subTreeModel_;
02680 CbcModel * heuristicModel_;
02682 int numberStoppedSubTrees_;
02684 CbcBranchDecision * branchingMethod_;
02686 CbcCutModifier * cutModifier_;
02688 CbcStrategy * strategy_;
02690 CbcModel * parentModel_;
02696
02697 const double * cbcColLower_;
02699 const double * cbcColUpper_;
02701 const double * cbcRowLower_;
02703 const double * cbcRowUpper_;
02705 const double * cbcColSolution_;
02707 const double * cbcRowPrice_;
02709 const double * cbcReducedCost_;
02711 const double * cbcRowActivity_;
02713 void * appData_;
02715 int presolve_;
02719 int numberStrong_;
02725 int numberBeforeTrust_;
02729 int numberPenalties_;
02731 int stopNumberIterations_;
02734 double penaltyScaleFactor_;
02736 int numberAnalyzeIterations_;
02738 double * analyzeResults_;
02740 void * temporaryPointer_;
02742 int numberInfeasibleNodes_;
02749 int problemType_;
02751 int printFrequency_;
02753 int numberCutGenerators_;
02754
02755 CbcCutGenerator ** generator_;
02756
02757 CbcCutGenerator ** virginGenerator_;
02759 int numberHeuristics_;
02761 CbcHeuristic ** heuristic_;
02763 CbcHeuristic * lastHeuristic_;
02765 int fastNodeDepth_;
02767 # ifdef CBC_ONLY_CLP
02768 ClpEventHandler *eventHandler_ ;
02769 # else
02770 CbcEventHandler *eventHandler_ ;
02771 # endif
02772 #ifdef COIN_HAS_NTY
02774 CbcSymmetry * symmetryInfo_;
02775 #endif
02777 int numberObjects_;
02778
02789 OsiObject ** object_;
02791 bool ownObjects_;
02792
02794 int * originalColumns_;
02796 int howOftenGlobalScan_;
02799 int numberGlobalViolations_;
02801 int numberExtraIterations_;
02803 int numberExtraNodes_;
02805 int numberFathoms_;
02809 double continuousObjective_;
02812 double originalContinuousObjective_;
02814 int continuousInfeasibilities_;
02816 int maximumCutPassesAtRoot_;
02818 int maximumCutPasses_;
02820 int preferredWay_;
02822 int currentPassNumber_;
02824 int maximumWhich_;
02826 int maximumRows_;
02828 int randomSeed_;
02830 int multipleRootTries_;
02832 int currentDepth_;
02834 mutable CoinThreadRandom randomNumberGenerator_;
02836 CoinWarmStartBasis workingBasis_;
02838 int * whichGenerator_;
02840 int maximumStatistics_;
02842 CbcStatistics ** statistics_;
02844 int maximumDepthActual_;
02846 double numberDJFixed_;
02848 CglTreeProbingInfo * probingInfo_;
02850 int numberFixedAtRoot_;
02852 int numberFixedNow_;
02854 bool stoppedOnGap_;
02856 mutable bool eventHappened_;
02858 int numberLongStrong_;
02860 int numberOldActiveCuts_;
02862 int numberNewCuts_;
02864 int searchStrategy_;
02876 int strongStrategy_;
02878 int numberStrongIterations_;
02881 int strongInfo_[7];
02888 OsiBabSolver * solverCharacteristics_;
02890 bool resolveAfterTakeOffCuts_;
02892 int maximumNumberIterations_;
02894 int continuousPriority_;
02896 int numberUpdateItems_;
02898 int maximumNumberUpdateItems_;
02900 CbcObjectUpdateData * updateItems_;
02902 CglStored * storedRowCuts_;
02910 int numberThreads_;
02918 int threadMode_;
02920 int numberGlobalCutsIn_;
02922 CbcBaseModel * master_;
02924 CbcThread * masterThread_;
02926 };
02928 void getIntegerInformation(const OsiObject * object, double & originalLower,
02929 double & originalUpper) ;
02930
02931
02932 class OsiClpSolverInterface;
02933 int CbcMain (int argc, const char *argv[], OsiClpSolverInterface & solver, CbcModel ** babSolver);
02934 int CbcMain (int argc, const char *argv[], CbcModel & babSolver);
02935
02936 int callCbc(const char * input2, OsiClpSolverInterface& solver1);
02937 int callCbc(const char * input2);
02938 int callCbc(const std::string input2, OsiClpSolverInterface& solver1);
02939 int callCbc(const std::string input2) ;
02940
02941 void CbcMain0 (CbcModel & babSolver);
02942 int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver);
02943
02944 int callCbc(const char * input2, CbcModel & babSolver);
02945 int callCbc(const std::string input2, CbcModel & babSolver);
02946
02947 int callCbc1(const char * input2, CbcModel & babSolver);
02948 int callCbc1(const std::string input2, CbcModel & babSolver);
02949
02950 int callCbc1(const char * input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02951 int callCbc1(const std::string input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02952 int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02953
02954 void setCutAndHeuristicOptions(CbcModel & model);
02955 #endif
02956