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 CbcFeasibilityBase;
00037 class CbcStatistics;
00038 class CbcFullNodeInfo;
00039 class CbcEventHandler ;
00040 class CglPreProcess;
00041 class OsiClpSolverInterface;
00042 class ClpNodeStuff;
00043
00044
00045
00046
00047
00100 class CbcModel {
00101
00102 public:
00103
00104 enum CbcIntParam {
00106 CbcMaxNumNode = 0,
00108 CbcMaxNumSol,
00118 CbcFathomDiscipline,
00122 CbcPrinting,
00125 CbcNumberBranches,
00127 CbcLastIntParam
00128 };
00129
00130 enum CbcDblParam {
00133 CbcIntegerTolerance = 0,
00136 CbcInfeasibilityWeight,
00139 CbcCutoffIncrement,
00146 CbcAllowableGap,
00153 CbcAllowableFractionGap,
00156 CbcMaximumSeconds,
00158 CbcCurrentCutoff,
00160 CbcOptimizationDirection,
00162 CbcCurrentObjectiveValue,
00164 CbcCurrentMinimizationObjectiveValue,
00167 CbcStartSeconds,
00175 CbcHeuristicGap,
00183 CbcHeuristicFractionGap,
00185 CbcSmallestChange,
00187 CbcSumChange,
00189 CbcLargestChange,
00191 CbcSmallChange,
00193 CbcLastDblParam
00194 };
00195
00196
00197
00198 public:
00200
00201
00205 void initialSolve();
00206
00217 void branchAndBound(int doStatistics = 0);
00218 private:
00219
00227 bool solveWithCuts(OsiCuts & cuts, int numberTries, CbcNode * node);
00235 int serialCuts(OsiCuts & cuts, CbcNode * node, OsiCuts & slackCuts, int lastNumberCuts);
00243 int parallelCuts(CbcBaseModel * master, OsiCuts & cuts, CbcNode * node, OsiCuts & slackCuts, int lastNumberCuts);
00250 CbcNode ** solveOneNode(int whichSolver, CbcNode * node,
00251 int & numberNodesOutput, int & status) ;
00253 void resizeWhichGenerator(int numberNow, int numberAfter);
00254 public:
00255 #ifdef CBC_KEEP_DEPRECATED
00256
00261 CbcModel * cleanModel(const double * lower, const double * upper);
00278 int subBranchAndBound(CbcModel * model2,
00279 CbcModel * presolvedModel,
00280 int maximumNodes);
00296 int subBranchAndBound(const double * lower, const double * upper,
00297 int maximumNodes);
00298
00305 OsiSolverInterface * strengthenedModel();
00315 CglPreProcess * preProcess( int makeEquality = 0, int numberPasses = 5,
00316 int tuning = 5);
00319 void postProcess(CglPreProcess * process);
00320 #endif
00322 void addUpdateInformation(const CbcObjectUpdateData & data);
00323
00329 int doOneNode(CbcModel * baseModel, CbcNode * & node, CbcNode * & newNode);
00330
00331 public:
00345 int resolve(CbcNodeInfo * parent, int whereFrom,
00346 double * saveSolution = NULL,
00347 double * saveLower = NULL,
00348 double * saveUpper = NULL);
00350 void makeGlobalCuts(int numberRows, const int * which);
00352 void makeGlobalCut(const OsiRowCut * cut);
00354 void makeGlobalCut(const OsiRowCut & cut);
00356 void makeGlobalCut(const OsiColCut * cut);
00358 void makeGlobalCut(const OsiColCut & cut);
00360 void makePartialCut(const OsiRowCut * cut, const OsiSolverInterface * solver=NULL);
00362 void makeGlobalCuts();
00364 inline const int * whichGenerator() const
00365 { return whichGenerator_;}
00367
00370
00382 CbcModel * findCliques(bool makeEquality, int atLeastThisMany,
00383 int lessThanThis, int defaultValue = 1000);
00384
00393 CbcModel * integerPresolve(bool weak = false);
00394
00399 bool integerPresolveThisModel(OsiSolverInterface * originalSolver, bool weak = false);
00400
00401
00403 void originalModel(CbcModel * presolvedModel, bool weak);
00404
00425 bool tightenVubs(int type, bool allowMultipleBinary = false,
00426 double useCutoff = 1.0e50);
00427
00433 bool tightenVubs(int numberVubs, const int * which,
00434 double useCutoff = 1.0e50);
00438 void analyzeObjective();
00439
00443 void AddIntegers();
00447 void saveModel(OsiSolverInterface * saveSolver, double * checkCutoffForRestart, bool * feasible);
00451 void flipModel();
00452
00454
00460
00462 inline int numberObjects() const {
00463 return numberObjects_;
00464 }
00466 inline void setNumberObjects(int number) {
00467 numberObjects_ = number;
00468 }
00469
00471 inline OsiObject ** objects() const {
00472 return object_;
00473 }
00474
00476 const inline OsiObject * object(int which) const {
00477 return object_[which];
00478 }
00480 inline OsiObject * modifiableObject(int which) const {
00481 return object_[which];
00482 }
00483
00484 void setOptionalInteger(int index);
00485
00487 void deleteObjects(bool findIntegers = true);
00488
00493 void addObjects(int numberObjects, OsiObject ** objects);
00494
00499 void addObjects(int numberObjects, CbcObject ** objects);
00500
00502 void synchronizeModel() ;
00503
00513 void findIntegers(bool startAgain, int type = 0);
00514
00516
00517
00518
00528
00529 inline bool setIntParam(CbcIntParam key, int value) {
00530 intParam_[key] = value;
00531 return true;
00532 }
00534 inline bool setDblParam(CbcDblParam key, double value) {
00535 dblParam_[key] = value;
00536 return true;
00537 }
00539 inline int getIntParam(CbcIntParam key) const {
00540 return intParam_[key];
00541 }
00543 inline double getDblParam(CbcDblParam key) const {
00544 return dblParam_[key];
00545 }
00551 void setCutoff(double value) ;
00552
00554 inline double getCutoff() const {
00555
00556
00557 return dblParam_[CbcCurrentCutoff];
00558 }
00559
00561 inline bool setMaximumNodes( int value) {
00562 return setIntParam(CbcMaxNumNode, value);
00563 }
00564
00566 inline int getMaximumNodes() const {
00567 return getIntParam(CbcMaxNumNode);
00568 }
00569
00574 inline bool setMaximumSolutions( int value) {
00575 return setIntParam(CbcMaxNumSol, value);
00576 }
00581 inline int getMaximumSolutions() const {
00582 return getIntParam(CbcMaxNumSol);
00583 }
00585 inline bool setPrintingMode( int value) {
00586 return setIntParam(CbcPrinting, value);
00587 }
00588
00590 inline int getPrintingMode() const {
00591 return getIntParam(CbcPrinting);
00592 }
00593
00598 inline bool setMaximumSeconds( double value) {
00599 return setDblParam(CbcMaximumSeconds, value);
00600 }
00605 inline double getMaximumSeconds() const {
00606 return getDblParam(CbcMaximumSeconds);
00607 }
00609 double getCurrentSeconds() const ;
00610
00612 bool maximumSecondsReached() const ;
00613
00617 inline bool setIntegerTolerance( double value) {
00618 return setDblParam(CbcIntegerTolerance, value);
00619 }
00623 inline double getIntegerTolerance() const {
00624 return getDblParam(CbcIntegerTolerance);
00625 }
00626
00631 inline bool setInfeasibilityWeight( double value) {
00632 return setDblParam(CbcInfeasibilityWeight, value);
00633 }
00638 inline double getInfeasibilityWeight() const {
00639 return getDblParam(CbcInfeasibilityWeight);
00640 }
00641
00645 inline bool setAllowableGap( double value) {
00646 return setDblParam(CbcAllowableGap, value);
00647 }
00651 inline double getAllowableGap() const {
00652 return getDblParam(CbcAllowableGap);
00653 }
00654
00658 inline bool setAllowableFractionGap( double value) {
00659 return setDblParam(CbcAllowableFractionGap, value);
00660 }
00664 inline double getAllowableFractionGap() const {
00665 return getDblParam(CbcAllowableFractionGap);
00666 }
00670 inline bool setAllowablePercentageGap( double value) {
00671 return setDblParam(CbcAllowableFractionGap, value*0.01);
00672 }
00676 inline double getAllowablePercentageGap() const {
00677 return 100.0*getDblParam(CbcAllowableFractionGap);
00678 }
00682 inline bool setHeuristicGap( double value) {
00683 return setDblParam(CbcHeuristicGap, value);
00684 }
00688 inline double getHeuristicGap() const {
00689 return getDblParam(CbcHeuristicGap);
00690 }
00691
00695 inline bool setHeuristicFractionGap( double value) {
00696 return setDblParam(CbcHeuristicFractionGap, value);
00697 }
00701 inline double getHeuristicFractionGap() const {
00702 return getDblParam(CbcHeuristicFractionGap);
00703 }
00708 inline bool setCutoffIncrement( double value) {
00709 return setDblParam(CbcCutoffIncrement, value);
00710 }
00715 inline double getCutoffIncrement() const {
00716 return getDblParam(CbcCutoffIncrement);
00717 }
00719 bool canStopOnGap() const;
00720
00725 void setHotstartSolution(const double * solution, const int * priorities = NULL) ;
00726
00728 inline void setMinimumDrop(double value) {
00729 minimumDrop_ = value;
00730 }
00732 inline double getMinimumDrop() const {
00733 return minimumDrop_;
00734 }
00735
00738 inline void setMaximumCutPassesAtRoot(int value) {
00739 maximumCutPassesAtRoot_ = value;
00740 }
00742 inline int getMaximumCutPassesAtRoot() const {
00743 return maximumCutPassesAtRoot_;
00744 }
00745
00748 inline void setMaximumCutPasses(int value) {
00749 maximumCutPasses_ = value;
00750 }
00752 inline int getMaximumCutPasses() const {
00753 return maximumCutPasses_;
00754 }
00757 inline int getCurrentPassNumber() const {
00758 return currentPassNumber_;
00759 }
00760
00766 void setNumberStrong(int number);
00770 inline int numberStrong() const {
00771 return numberStrong_;
00772 }
00775 inline void setPreferredWay(int value) {
00776 preferredWay_ = value;
00777 }
00779 inline int getPreferredWay() const {
00780 return preferredWay_;
00781 }
00783 inline int whenCuts() const {
00784 return whenCuts_;
00785 }
00787 inline void setWhenCuts(int value) {
00788 whenCuts_ = value;
00789 }
00795 bool doCutsNow(int allowForTopOfTree) const;
00796
00802 void setNumberBeforeTrust(int number);
00805 inline int numberBeforeTrust() const {
00806 return numberBeforeTrust_;
00807 }
00813 void setNumberPenalties(int number);
00816 inline int numberPenalties() const {
00817 return numberPenalties_;
00818 }
00820 inline const CbcFullNodeInfo * topOfTree() const
00821 { return topOfTree_;}
00823 inline void setNumberAnalyzeIterations(int number) {
00824 numberAnalyzeIterations_ = number;
00825 }
00826 inline int numberAnalyzeIterations() const {
00827 return numberAnalyzeIterations_;
00828 }
00831 inline double penaltyScaleFactor() const {
00832 return penaltyScaleFactor_;
00833 }
00836 void setPenaltyScaleFactor(double value);
00844 void inline setProblemType(int number) {
00845 problemType_ = number;
00846 }
00847 inline int problemType() const {
00848 return problemType_;
00849 }
00851 inline int currentDepth() const {
00852 return currentDepth_;
00853 }
00854
00856 void setHowOftenGlobalScan(int number);
00858 inline int howOftenGlobalScan() const {
00859 return howOftenGlobalScan_;
00860 }
00862 inline int * originalColumns() const {
00863 return originalColumns_;
00864 }
00866 void setOriginalColumns(const int * originalColumns,
00867 int numberGood=COIN_INT_MAX) ;
00869 OsiRowCut * conflictCut(const OsiSolverInterface * solver, bool & localCuts);
00870
00878 inline void setPrintFrequency(int number) {
00879 printFrequency_ = number;
00880 }
00882 inline int printFrequency() const {
00883 return printFrequency_;
00884 }
00886
00887
00889
00890
00891 bool isAbandoned() const;
00893 bool isProvenOptimal() const;
00895 bool isProvenInfeasible() const;
00897 bool isContinuousUnbounded() const;
00899 bool isProvenDualInfeasible() const;
00901 bool isNodeLimitReached() const;
00903 bool isSecondsLimitReached() const;
00905 bool isSolutionLimitReached() const;
00907 inline int getIterationCount() const {
00908 return numberIterations_;
00909 }
00911 inline void incrementIterationCount(int value) {
00912 numberIterations_ += value;
00913 }
00915 inline int getNodeCount() const {
00916 return numberNodes_;
00917 }
00919 inline void incrementNodeCount(int value) {
00920 numberNodes_ += value;
00921 }
00923 inline int getExtraNodeCount() const {
00924 return numberExtraNodes_;
00925 }
00935 inline int status() const {
00936 return status_;
00937 }
00938 inline void setProblemStatus(int value) {
00939 status_ = value;
00940 }
00953 inline int secondaryStatus() const {
00954 return secondaryStatus_;
00955 }
00956 inline void setSecondaryStatus(int value) {
00957 secondaryStatus_ = value;
00958 }
00960 bool isInitialSolveAbandoned() const ;
00962 bool isInitialSolveProvenOptimal() const ;
00964 bool isInitialSolveProvenPrimalInfeasible() const ;
00966 bool isInitialSolveProvenDualInfeasible() const ;
00967
00969
00970
00983
00984 inline int numberRowsAtContinuous() const {
00985 return numberRowsAtContinuous_;
00986 }
00987
00989 inline int getNumCols() const {
00990 return solver_->getNumCols();
00991 }
00992
00994 inline int getNumRows() const {
00995 return solver_->getNumRows();
00996 }
00997
00999 inline CoinBigIndex getNumElements() const {
01000 return solver_->getNumElements();
01001 }
01002
01004 inline int numberIntegers() const {
01005 return numberIntegers_;
01006 }
01007
01008 inline const int * integerVariable() const {
01009 return integerVariable_;
01010 }
01012 inline char integerType(int i) const {
01013 assert (integerInfo_);
01014 assert (integerInfo_[i] == 0 || integerInfo_[i] == 1);
01015 return integerInfo_[i];
01016 }
01018 inline const char * integerType() const {
01019 return integerInfo_;
01020 }
01021
01023 inline const double * getColLower() const {
01024 return solver_->getColLower();
01025 }
01026
01028 inline const double * getColUpper() const {
01029 return solver_->getColUpper();
01030 }
01031
01041 inline const char * getRowSense() const {
01042 return solver_->getRowSense();
01043 }
01044
01053 inline const double * getRightHandSide() const {
01054 return solver_->getRightHandSide();
01055 }
01056
01065 inline const double * getRowRange() const {
01066 return solver_->getRowRange();
01067 }
01068
01070 inline const double * getRowLower() const {
01071 return solver_->getRowLower();
01072 }
01073
01075 inline const double * getRowUpper() const {
01076 return solver_->getRowUpper();
01077 }
01078
01080 inline const double * getObjCoefficients() const {
01081 return solver_->getObjCoefficients();
01082 }
01083
01085 inline double getObjSense() const {
01086
01087 return dblParam_[CbcOptimizationDirection];
01088 }
01089
01091 inline bool isContinuous(int colIndex) const {
01092 return solver_->isContinuous(colIndex);
01093 }
01094
01096 inline bool isBinary(int colIndex) const {
01097 return solver_->isBinary(colIndex);
01098 }
01099
01104 inline bool isInteger(int colIndex) const {
01105 return solver_->isInteger(colIndex);
01106 }
01107
01109 inline bool isIntegerNonBinary(int colIndex) const {
01110 return solver_->isIntegerNonBinary(colIndex);
01111 }
01112
01114 inline bool isFreeBinary(int colIndex) const {
01115 return solver_->isFreeBinary(colIndex) ;
01116 }
01117
01119 inline const CoinPackedMatrix * getMatrixByRow() const {
01120 return solver_->getMatrixByRow();
01121 }
01122
01124 inline const CoinPackedMatrix * getMatrixByCol() const {
01125 return solver_->getMatrixByCol();
01126 }
01127
01129 inline double getInfinity() const {
01130 return solver_->getInfinity();
01131 }
01133 inline const double * getCbcColLower() const {
01134 return cbcColLower_;
01135 }
01137 inline const double * getCbcColUpper() const {
01138 return cbcColUpper_;
01139 }
01141 inline const double * getCbcRowLower() const {
01142 return cbcRowLower_;
01143 }
01145 inline const double * getCbcRowUpper() const {
01146 return cbcRowUpper_;
01147 }
01149 inline const double * getCbcColSolution() const {
01150 return cbcColSolution_;
01151 }
01153 inline const double * getCbcRowPrice() const {
01154 return cbcRowPrice_;
01155 }
01157 inline const double * getCbcReducedCost() const {
01158 return cbcReducedCost_;
01159 }
01161 inline const double * getCbcRowActivity() const {
01162 return cbcRowActivity_;
01163 }
01165
01166
01169
01170 inline double * continuousSolution() const {
01171 return continuousSolution_;
01172 }
01177 inline int * usedInSolution() const {
01178 return usedInSolution_;
01179 }
01181 void incrementUsed(const double * solution);
01183 void setBestSolution(CBC_Message how,
01184 double & objectiveValue, const double *solution,
01185 int fixVariables = 0);
01187 void setBestObjectiveValue( double objectiveValue);
01189 CbcEventHandler::CbcAction dealWithEventHandler(CbcEventHandler::CbcEvent event,
01190 double objValue,
01191 const double * solution);
01192
01200 virtual double checkSolution(double cutoff, double * solution,
01201 int fixVariables, double originalObjValue);
01208 bool feasibleSolution(int & numberIntegerInfeasibilities,
01209 int & numberObjectInfeasibilities) const;
01210
01216 inline double * currentSolution() const {
01217 return currentSolution_;
01218 }
01222 inline const double * testSolution() const {
01223 return testSolution_;
01224 }
01225 inline void setTestSolution(const double * solution) {
01226 testSolution_ = solution;
01227 }
01229 void reserveCurrentSolution(const double * solution = NULL);
01230
01232 inline const double * getColSolution() const {
01233 return solver_->getColSolution();
01234 }
01235
01237 inline const double * getRowPrice() const {
01238 return solver_->getRowPrice();
01239 }
01240
01242 inline const double * getReducedCost() const {
01243 return solver_->getReducedCost();
01244 }
01245
01247 inline const double * getRowActivity() const {
01248 return solver_->getRowActivity();
01249 }
01250
01252 inline double getCurrentObjValue() const {
01253 return dblParam_[CbcCurrentObjectiveValue];
01254 }
01256 inline double getCurrentMinimizationObjValue() const {
01257 return dblParam_[CbcCurrentMinimizationObjectiveValue];
01258 }
01259
01261 inline double getMinimizationObjValue() const {
01262 return bestObjective_;
01263 }
01265 inline void setMinimizationObjValue(double value) {
01266 bestObjective_ = value;
01267 }
01268
01270 inline double getObjValue() const {
01271 return bestObjective_ * solver_->getObjSense() ;
01272 }
01278 double getBestPossibleObjValue() const;
01280 inline void setObjValue(double value) {
01281 bestObjective_ = value * solver_->getObjSense() ;
01282 }
01284 inline double getSolverObjValue() const {
01285 return solver_->getObjValue() * solver_->getObjSense() ;
01286 }
01287
01294 inline double * bestSolution() const {
01295 return bestSolution_;
01296 }
01303 void setBestSolution(const double * solution, int numberColumns,
01304 double objectiveValue, bool check = false);
01305
01307 inline int getSolutionCount() const {
01308 return numberSolutions_;
01309 }
01310
01312 inline void setSolutionCount(int value) {
01313 numberSolutions_ = value;
01314 }
01316 int numberSavedSolutions() const;
01318 inline int maximumSavedSolutions() const {
01319 return maximumSavedSolutions_;
01320 }
01322 void setMaximumSavedSolutions(int value);
01324 const double * savedSolution(int which) const;
01326 double savedSolutionObjective(int which) const;
01328 void deleteSavedSolution(int which);
01329
01338 inline int phase() const {
01339 return phase_;
01340 }
01341
01343 inline int getNumberHeuristicSolutions() const {
01344 return numberHeuristicSolutions_;
01345 }
01347 inline void setNumberHeuristicSolutions(int value) {
01348 numberHeuristicSolutions_ = value;
01349 }
01350
01352 inline void setObjSense(double s) {
01353 dblParam_[CbcOptimizationDirection] = s;
01354 solver_->setObjSense(s);
01355 }
01356
01358 inline double getContinuousObjective() const {
01359 return originalContinuousObjective_;
01360 }
01361 inline void setContinuousObjective(double value) {
01362 originalContinuousObjective_ = value;
01363 }
01365 inline int getContinuousInfeasibilities() const {
01366 return continuousInfeasibilities_;
01367 }
01368 inline void setContinuousInfeasibilities(int value) {
01369 continuousInfeasibilities_ = value;
01370 }
01372 inline double rootObjectiveAfterCuts() const {
01373 return continuousObjective_;
01374 }
01376 inline double sumChangeObjective() const {
01377 return sumChangeObjective1_;
01378 }
01381 inline int numberGlobalViolations() const {
01382 return numberGlobalViolations_;
01383 }
01384 inline void clearNumberGlobalViolations() {
01385 numberGlobalViolations_ = 0;
01386 }
01388 inline bool resolveAfterTakeOffCuts() const {
01389 return resolveAfterTakeOffCuts_;
01390 }
01391 inline void setResolveAfterTakeOffCuts(bool yesNo) {
01392 resolveAfterTakeOffCuts_ = yesNo;
01393 }
01395 inline int maximumRows() const {
01396 return maximumRows_;
01397 }
01399 inline CoinWarmStartBasis & workingBasis() {
01400 return workingBasis_;
01401 }
01403 inline int getStopNumberIterations() const {
01404 return stopNumberIterations_;
01405 }
01407 inline void setStopNumberIterations(int value) {
01408 stopNumberIterations_ = value;
01409 }
01411 inline CbcModel * heuristicModel() const
01412 { return heuristicModel_;}
01414 inline void setHeuristicModel(CbcModel * model)
01415 { heuristicModel_ = model;}
01417
01420
01421 inline CbcCompareBase * nodeComparison() const {
01422 return nodeCompare_;
01423 }
01424 void setNodeComparison(CbcCompareBase * compare);
01425 void setNodeComparison(CbcCompareBase & compare);
01427
01430
01431 inline CbcFeasibilityBase * problemFeasibility() const {
01432 return problemFeasibility_;
01433 }
01434 void setProblemFeasibility(CbcFeasibilityBase * feasibility);
01435 void setProblemFeasibility(CbcFeasibilityBase & feasibility);
01437
01440
01441 inline CbcTree * tree() const {
01442 return tree_;
01443 }
01445 void passInTreeHandler(CbcTree & tree);
01449 void passInSubTreeModel(CbcModel & model);
01454 CbcModel * subTreeModel(OsiSolverInterface * solver = NULL) const;
01456 inline int numberStoppedSubTrees() const {
01457 return numberStoppedSubTrees_;
01458 }
01460 inline void incrementSubTreeStopped() {
01461 numberStoppedSubTrees_++;
01462 }
01468 inline int typePresolve() const {
01469 return presolve_;
01470 }
01471 inline void setTypePresolve(int value) {
01472 presolve_ = value;
01473 }
01474
01476
01482
01484 inline CbcBranchDecision * branchingMethod() const {
01485 return branchingMethod_;
01486 }
01488 inline void setBranchingMethod(CbcBranchDecision * method) {
01489 delete branchingMethod_;
01490 branchingMethod_ = method->clone();
01491 }
01496 inline void setBranchingMethod(CbcBranchDecision & method) {
01497 delete branchingMethod_;
01498 branchingMethod_ = method.clone();
01499 }
01501 inline CbcCutModifier * cutModifier() const {
01502 return cutModifier_;
01503 }
01505 void setCutModifier(CbcCutModifier * modifier);
01510 void setCutModifier(CbcCutModifier & modifier);
01512
01515
01522 inline int stateOfSearch() const {
01523 return stateOfSearch_;
01524 }
01525 inline void setStateOfSearch(int state) {
01526 stateOfSearch_ = state;
01527 }
01529 inline int searchStrategy() const {
01530 return searchStrategy_;
01531 }
01533 inline void setSearchStrategy(int value) {
01534 searchStrategy_ = value;
01535 }
01537 inline int strongStrategy() const {
01538 return strongStrategy_;
01539 }
01541 inline void setStrongStrategy(int value) {
01542 strongStrategy_ = value;
01543 }
01544
01546 inline int numberCutGenerators() const {
01547 return numberCutGenerators_;
01548 }
01550 inline CbcCutGenerator ** cutGenerators() const {
01551 return generator_;
01552 }
01554 inline CbcCutGenerator * cutGenerator(int i) const {
01555 return generator_[i];
01556 }
01558 inline CbcCutGenerator * virginCutGenerator(int i) const {
01559 return virginGenerator_[i];
01560 }
01569 void addCutGenerator(CglCutGenerator * generator,
01570 int howOften = 1, const char * name = NULL,
01571 bool normal = true, bool atSolution = false,
01572 bool infeasible = false, int howOftenInSub = -100,
01573 int whatDepth = -1, int whatDepthInSub = -1);
01575
01580
01582 inline CbcStrategy * strategy() const {
01583 return strategy_;
01584 }
01586 void setStrategy(CbcStrategy & strategy);
01588 inline void setStrategy(CbcStrategy * strategy) {
01589 strategy_ = strategy;
01590 }
01592 inline CbcModel * parentModel() const {
01593 return parentModel_;
01594 }
01596 inline void setParentModel(CbcModel & parentModel) {
01597 parentModel_ = &parentModel;
01598 }
01600
01601
01608 void addHeuristic(CbcHeuristic * generator, const char *name = NULL,
01609 int before = -1);
01611 inline CbcHeuristic * heuristic(int i) const {
01612 return heuristic_[i];
01613 }
01615 inline int numberHeuristics() const {
01616 return numberHeuristics_;
01617 }
01619 inline void setNumberHeuristics(int value) {
01620 numberHeuristics_ = value;
01621 }
01623 inline CbcHeuristic * lastHeuristic() const {
01624 return lastHeuristic_;
01625 }
01627 inline void setLastHeuristic(CbcHeuristic * last) {
01628 lastHeuristic_ = last;
01629 }
01630
01649 void passInPriorities(const int * priorities, bool ifNotSimpleIntegers);
01650
01652 inline int priority(int sequence) const {
01653 return object_[sequence]->priority();
01654 }
01655
01660 void passInEventHandler(const CbcEventHandler *eventHandler) ;
01661
01663 inline CbcEventHandler* getEventHandler() const {
01664 return (eventHandler_) ;
01665 }
01666
01668
01678 void setApplicationData (void * appData);
01679
01681 void * getApplicationData() const;
01694 void passInSolverCharacteristics(OsiBabSolver * solverCharacteristics);
01696 inline const OsiBabSolver * solverCharacteristics() const {
01697 return solverCharacteristics_;
01698 }
01700
01701
01702
01705
01706 void passInMessageHandler(CoinMessageHandler * handler);
01708 void newLanguage(CoinMessages::Language language);
01709 inline void setLanguage(CoinMessages::Language language) {
01710 newLanguage(language);
01711 }
01713 inline CoinMessageHandler * messageHandler() const {
01714 return handler_;
01715 }
01717 inline CoinMessages & messages() {
01718 return messages_;
01719 }
01721 inline CoinMessages * messagesPointer() {
01722 return &messages_;
01723 }
01725 void setLogLevel(int value);
01727 inline int logLevel() const {
01728 return handler_->logLevel();
01729 }
01735 inline void setDefaultHandler(bool yesNo) {
01736 defaultHandler_ = yesNo;
01737 }
01739 inline bool defaultHandler() const {
01740 return defaultHandler_;
01741 }
01743
01745
01746
01773 inline void setSpecialOptions(int value) {
01774 specialOptions_ = value;
01775 }
01777 inline int specialOptions() const {
01778 return specialOptions_;
01779 }
01781 inline void setRandomSeed(int value) {
01782 randomSeed_ = value;
01783 }
01785 inline int getRandomSeed() const {
01786 return randomSeed_;
01787 }
01789 inline void setMultipleRootTries(int value) {
01790 multipleRootTries_ = value;
01791 }
01793 inline int getMultipleRootTries() const {
01794 return multipleRootTries_;
01795 }
01797 inline void sayEventHappened()
01798 { eventHappened_=true;}
01800 inline bool normalSolver() const {
01801 return (specialOptions_&16) == 0;
01802 }
01807 inline bool waitingForMiniBranchAndBound() const {
01808 return (specialOptions_&1048576) != 0;
01809 }
01832 inline void setMoreSpecialOptions(int value) {
01833 moreSpecialOptions_ = value;
01834 }
01836 inline int moreSpecialOptions() const {
01837 return moreSpecialOptions_;
01838 }
01840 inline void setCutoffAsConstraint(bool yesNo) {
01841 cutoffRowNumber_ = (yesNo) ? -2 : -1;
01842 }
01844 inline void setUseElapsedTime(bool yesNo) {
01845 if (yesNo)
01846 moreSpecialOptions_ |= 131072;
01847 else
01848 moreSpecialOptions_ &= ~131072;
01849 }
01851 inline bool useElapsedTime() const {
01852 return (moreSpecialOptions_&131072)!=0;
01853 }
01855 inline void * temporaryPointer() const
01856 { return temporaryPointer_;}
01858 inline void setTemporaryPointer(void * pointer)
01859 { temporaryPointer_=pointer;}
01861 void goToDantzig(int numberNodes, ClpDualRowPivot *& savePivotMethod);
01863 inline bool ownObjects() const {
01864 return ownObjects_;
01865 }
01867 void checkModel();
01869
01870
01872
01873
01874 CbcModel();
01875
01877 CbcModel(const OsiSolverInterface &);
01878
01887 void assignSolver(OsiSolverInterface *&solver, bool deleteSolver = true);
01888
01900 inline void setModelOwnsSolver (bool ourSolver) {
01901 ownership_ = ourSolver ? (ownership_ | 0x80000000) : (ownership_ & (~0x80000000)) ;
01902 }
01903
01909 inline bool modelOwnsSolver () {
01910 return ((ownership_&0x80000000) != 0) ;
01911 }
01912
01916 CbcModel(const CbcModel & rhs, bool cloneHandler = false);
01917
01919 virtual CbcModel *clone (bool cloneHandler);
01920
01922 CbcModel & operator=(const CbcModel& rhs);
01923
01925 virtual ~CbcModel ();
01926
01928 inline OsiSolverInterface * solver() const {
01929 return solver_;
01930 }
01931
01933 inline OsiSolverInterface * swapSolver(OsiSolverInterface * solver) {
01934 OsiSolverInterface * returnSolver = solver_;
01935 solver_ = solver;
01936 return returnSolver;
01937 }
01938
01940 inline OsiSolverInterface * continuousSolver() const {
01941 return continuousSolver_;
01942 }
01943
01945 inline void createContinuousSolver() {
01946 continuousSolver_ = solver_->clone();
01947 }
01949 inline void clearContinuousSolver() {
01950 delete continuousSolver_;
01951 continuousSolver_ = NULL;
01952 }
01953
01955 inline OsiSolverInterface * referenceSolver() const {
01956 return referenceSolver_;
01957 }
01958
01960 void saveReferenceSolver();
01961
01967 void resetToReferenceSolver();
01968
01970 void gutsOfDestructor();
01973 void gutsOfDestructor2();
01976 void resetModel();
01982 void gutsOfCopy(const CbcModel & rhs, int mode = 0);
01984 void moveInfo(const CbcModel & rhs);
01986
01988
01989
01990 static bool haveMultiThreadSupport();
01992 CbcThread * masterThread() const {
01993 return masterThread_;
01994 }
01996 CbcNodeInfo ** walkback() const {
01997 return walkback_;
01998 }
02000 inline int getNumberThreads() const {
02001 return numberThreads_;
02002 }
02004 inline void setNumberThreads(int value) {
02005 numberThreads_ = value;
02006 }
02008 inline int getThreadMode() const {
02009 return threadMode_;
02010 }
02020 inline void setThreadMode(int value) {
02021 threadMode_ = value;
02022 }
02029 inline int parallelMode() const {
02030 if (!numberThreads_) {
02031 if ((threadMode_&1) == 0)
02032 return 0;
02033 else
02034 return -1;
02035 return 0;
02036 } else {
02037 if ((threadMode_&1) == 0)
02038 return 1;
02039 else
02040 return -2;
02041 }
02042 }
02044 inline CbcBaseModel * master() const
02045 { return master_;}
02048 bool isLocked() const;
02049 #ifdef CBC_THREAD
02050
02054 void lockThread();
02058 void unlockThread();
02059 #else
02060 inline void lockThread() {}
02061 inline void unlockThread() {}
02062 #endif
02063
02070 void setInfoInChild(int type, CbcThread * info);
02077 void moveToModel(CbcModel * baseModel, int mode);
02079 int splitModel(int numberModels, CbcModel ** model,
02080 int numberNodes);
02082 void startSplitModel(int numberIterations);
02084 void mergeModels(int numberModel, CbcModel ** model,
02085 int numberNodes);
02087
02089
02090
02091 int getNodeCount2() const {
02092 return numberNodes2_;
02093 }
02095 void setPointers(const OsiSolverInterface * solver);
02101 int reducedCostFix() ;
02105 void synchronizeHandlers(int makeDefault);
02107 void saveExtraSolution(const double * solution, double objectiveValue);
02109 void saveBestSolution(const double * solution, double objectiveValue);
02111 void deleteSolutions();
02113 int resolve(OsiSolverInterface * solver);
02114 #ifdef CLP_RESOLVE
02116 int resolveClp(OsiClpSolverInterface * solver, int type);
02117 #endif
02118
02122 int chooseBranch(CbcNode * & newNode, int numberPassesLeft,
02123 CbcNode * oldNode, OsiCuts & cuts,
02124 bool & resolved, CoinWarmStartBasis *lastws,
02125 const double * lowerBefore, const double * upperBefore,
02126 OsiSolverBranch * & branches);
02127 int chooseBranch(CbcNode * newNode, int numberPassesLeft, bool & resolved);
02128
02135 CoinWarmStartBasis *getEmptyBasis(int ns = 0, int na = 0) const ;
02136
02148 int takeOffCuts(OsiCuts &cuts,
02149 bool allowResolve, OsiCuts * saveCuts,
02150 int numberNewCuts = 0, const OsiRowCut ** newCuts = NULL) ;
02151
02165 int addCuts(CbcNode * node, CoinWarmStartBasis *&lastws, bool canFix);
02166
02183 bool addCuts1(CbcNode * node, CoinWarmStartBasis *&lastws);
02187 void previousBounds (CbcNode * node, CbcNodeInfo * where, int iColumn,
02188 double & lower, double & upper, int force);
02193 void setObjectiveValue(CbcNode * thisNode, const CbcNode * parentNode) const;
02194
02198 void convertToDynamic();
02200 void synchronizeNumberBeforeTrust(int type = 0);
02202 void zapIntegerInformation(bool leaveObjects = true);
02204 int cliquePseudoCosts(int doStatistics);
02206 void pseudoShadow(int type);
02213 void fillPseudoCosts(double * downCosts, double * upCosts,
02214 int * priority = NULL,
02215 int * numberDown = NULL, int * numberUp = NULL,
02216 int * numberDownInfeasible = NULL,
02217 int * numberUpInfeasible = NULL) const;
02223 void doHeuristicsAtRoot(int deleteHeuristicsAfterwards = 0);
02225 void adjustHeuristics();
02227 inline const double * hotstartSolution() const {
02228 return hotstartSolution_;
02229 }
02231 inline const int * hotstartPriorities() const {
02232 return hotstartPriorities_;
02233 }
02234
02236 inline CbcCountRowCut ** addedCuts() const {
02237 return addedCuts_;
02238 }
02240 inline int currentNumberCuts() const {
02241 return currentNumberCuts_;
02242 }
02244 inline CbcRowCuts * globalCuts() {
02245 return &globalCuts_;
02246 }
02248 void setNextRowCut(const OsiRowCut & cut);
02250 inline CbcNode * currentNode() const {
02251 return currentNode_;
02252 }
02254 inline CglTreeProbingInfo * probingInfo() const {
02255 return probingInfo_;
02256 }
02258 inline CoinThreadRandom * randomNumberGenerator() {
02259 return &randomNumberGenerator_;
02260 }
02262 inline void setNumberStrongIterations(int number) {
02263 numberStrongIterations_ = number;
02264 }
02266 inline int numberStrongIterations() const {
02267 return numberStrongIterations_;
02268 }
02270 inline int maximumNumberIterations() const {
02271 return maximumNumberIterations_;
02272 }
02274 inline void setMaximumNumberIterations(int value) {
02275 maximumNumberIterations_ = value;
02276 }
02278 inline void setFastNodeDepth(int value) {
02279 fastNodeDepth_ = value;
02280 }
02282 inline int fastNodeDepth() const {
02283 return fastNodeDepth_;
02284 }
02286 inline int continuousPriority() const {
02287 return continuousPriority_;
02288 }
02290 inline void setContinuousPriority(int value) {
02291 continuousPriority_ = value;
02292 }
02293 inline void incrementExtra(int nodes, int iterations) {
02294 numberExtraNodes_ += nodes;
02295 numberExtraIterations_ += iterations;
02296 }
02298 inline int numberExtraIterations() const {
02299 return numberExtraIterations_;
02300 }
02302 void incrementStrongInfo(int numberTimes, int numberIterations,
02303 int numberFixed, bool ifInfeasible);
02305 inline const int * strongInfo() const {
02306 return strongInfo_;
02307 }
02308
02310 inline int * mutableStrongInfo() {
02311 return strongInfo_;
02312 }
02314 CglStored * storedRowCuts() const {
02315 return storedRowCuts_;
02316 }
02318 void setStoredRowCuts(CglStored * cuts) {
02319 storedRowCuts_ = cuts;
02320 }
02322 inline bool allDynamic () const {
02323 return ((ownership_&0x40000000) != 0) ;
02324 }
02326 void generateCpp( FILE * fp, int options);
02328 OsiBranchingInformation usefulInformation() const;
02335 inline void setBestSolutionBasis(const CoinWarmStartBasis & bestSolutionBasis) {
02336 bestSolutionBasis_ = bestSolutionBasis;
02337 }
02339 void redoWalkBack();
02341
02342
02343
02344 private:
02346
02347
02349 OsiSolverInterface * solver_;
02350
02356 unsigned int ownership_ ;
02357
02359 OsiSolverInterface * continuousSolver_;
02360
02362 OsiSolverInterface * referenceSolver_;
02363
02365 CoinMessageHandler * handler_;
02366
02372 bool defaultHandler_;
02373
02375 CoinMessages messages_;
02376
02378 int intParam_[CbcLastIntParam];
02379
02381 double dblParam_[CbcLastDblParam];
02382
02391 mutable CoinWarmStart *emptyWarmStart_ ;
02392
02394 double bestObjective_;
02396 double bestPossibleObjective_;
02398 double sumChangeObjective1_;
02400 double sumChangeObjective2_;
02401
02403 double * bestSolution_;
02405 double ** savedSolutions_;
02406
02411 double * currentSolution_;
02415 mutable const double * testSolution_;
02422 CoinWarmStartBasis bestSolutionBasis_ ;
02424 CbcRowCuts globalCuts_;
02426 CbcRowCuts * globalConflictCuts_;
02427
02429 double minimumDrop_;
02431 int numberSolutions_;
02433 int numberSavedSolutions_;
02435 int maximumSavedSolutions_;
02442 int stateOfSearch_;
02444 int whenCuts_;
02446 double * hotstartSolution_;
02448 int * hotstartPriorities_;
02450 int numberHeuristicSolutions_;
02452 int numberNodes_;
02456 int numberNodes2_;
02458 int numberIterations_;
02460 int numberSolves_;
02462 int status_;
02473 int secondaryStatus_;
02475 int numberIntegers_;
02477 int numberRowsAtContinuous_;
02483 int cutoffRowNumber_;
02485 int maximumNumberCuts_;
02494 int phase_;
02495
02497 int currentNumberCuts_;
02498
02503 int maximumDepth_;
02509 CbcNodeInfo ** walkback_;
02510 CbcNodeInfo ** lastNodeInfo_;
02511 const OsiRowCut ** lastCut_;
02512 int lastDepth_;
02513 int lastNumberCuts2_;
02514 int maximumCuts_;
02515 int * lastNumberCuts_;
02516
02524 CbcCountRowCut ** addedCuts_;
02525
02529 OsiRowCut * nextRowCut_;
02530
02532 CbcNode * currentNode_;
02533
02535 int * integerVariable_;
02537 char * integerInfo_;
02539 double * continuousSolution_;
02541 int * usedInSolution_;
02565 int specialOptions_;
02580 int moreSpecialOptions_;
02582 CbcCompareBase * nodeCompare_;
02584 CbcFeasibilityBase * problemFeasibility_;
02586 CbcTree * tree_;
02588 CbcFullNodeInfo * topOfTree_;
02590 CbcModel * subTreeModel_;
02592 CbcModel * heuristicModel_;
02594 int numberStoppedSubTrees_;
02596 CbcBranchDecision * branchingMethod_;
02598 CbcCutModifier * cutModifier_;
02600 CbcStrategy * strategy_;
02602 CbcModel * parentModel_;
02608
02609 const double * cbcColLower_;
02611 const double * cbcColUpper_;
02613 const double * cbcRowLower_;
02615 const double * cbcRowUpper_;
02617 const double * cbcColSolution_;
02619 const double * cbcRowPrice_;
02621 const double * cbcReducedCost_;
02623 const double * cbcRowActivity_;
02625 void * appData_;
02627 int presolve_;
02631 int numberStrong_;
02637 int numberBeforeTrust_;
02641 int numberPenalties_;
02643 int stopNumberIterations_;
02646 double penaltyScaleFactor_;
02648 int numberAnalyzeIterations_;
02650 double * analyzeResults_;
02652 void * temporaryPointer_;
02654 int numberInfeasibleNodes_;
02661 int problemType_;
02663 int printFrequency_;
02665 int numberCutGenerators_;
02666
02667 CbcCutGenerator ** generator_;
02668
02669 CbcCutGenerator ** virginGenerator_;
02671 int numberHeuristics_;
02673 CbcHeuristic ** heuristic_;
02675 CbcHeuristic * lastHeuristic_;
02677 int fastNodeDepth_;
02679 # ifdef CBC_ONLY_CLP
02680 ClpEventHandler *eventHandler_ ;
02681 # else
02682 CbcEventHandler *eventHandler_ ;
02683 # endif
02684
02686 int numberObjects_;
02687
02698 OsiObject ** object_;
02700 bool ownObjects_;
02701
02703 int * originalColumns_;
02705 int howOftenGlobalScan_;
02708 int numberGlobalViolations_;
02710 int numberExtraIterations_;
02712 int numberExtraNodes_;
02716 double continuousObjective_;
02719 double originalContinuousObjective_;
02721 int continuousInfeasibilities_;
02723 int maximumCutPassesAtRoot_;
02725 int maximumCutPasses_;
02727 int preferredWay_;
02729 int currentPassNumber_;
02731 int maximumWhich_;
02733 int maximumRows_;
02735 int randomSeed_;
02737 int multipleRootTries_;
02739 int currentDepth_;
02741 mutable CoinThreadRandom randomNumberGenerator_;
02743 CoinWarmStartBasis workingBasis_;
02745 int * whichGenerator_;
02747 int maximumStatistics_;
02749 CbcStatistics ** statistics_;
02751 int maximumDepthActual_;
02753 double numberDJFixed_;
02755 CglTreeProbingInfo * probingInfo_;
02757 int numberFixedAtRoot_;
02759 int numberFixedNow_;
02761 bool stoppedOnGap_;
02763 mutable bool eventHappened_;
02765 int numberLongStrong_;
02767 int numberOldActiveCuts_;
02769 int numberNewCuts_;
02771 int searchStrategy_;
02783 int strongStrategy_;
02785 int numberStrongIterations_;
02788 int strongInfo_[7];
02795 OsiBabSolver * solverCharacteristics_;
02797 bool resolveAfterTakeOffCuts_;
02799 int maximumNumberIterations_;
02801 int continuousPriority_;
02803 int numberUpdateItems_;
02805 int maximumNumberUpdateItems_;
02807 CbcObjectUpdateData * updateItems_;
02809 CglStored * storedRowCuts_;
02817 int numberThreads_;
02825 int threadMode_;
02827 CbcBaseModel * master_;
02829 CbcThread * masterThread_;
02831 };
02833 void getIntegerInformation(const OsiObject * object, double & originalLower,
02834 double & originalUpper) ;
02835
02836
02837 class OsiClpSolverInterface;
02838 int CbcMain (int argc, const char *argv[], OsiClpSolverInterface & solver, CbcModel ** babSolver);
02839 int CbcMain (int argc, const char *argv[], CbcModel & babSolver);
02840
02841 int callCbc(const char * input2, OsiClpSolverInterface& solver1);
02842 int callCbc(const char * input2);
02843 int callCbc(const std::string input2, OsiClpSolverInterface& solver1);
02844 int callCbc(const std::string input2) ;
02845
02846 void CbcMain0 (CbcModel & babSolver);
02847 int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver);
02848
02849 int callCbc(const char * input2, CbcModel & babSolver);
02850 int callCbc(const std::string input2, CbcModel & babSolver);
02851
02852 int callCbc1(const char * input2, CbcModel & babSolver);
02853 int callCbc1(const std::string input2, CbcModel & babSolver);
02854
02855 int callCbc1(const char * input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02856 int callCbc1(const std::string input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02857 int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02858
02859 void setCutAndHeuristicOptions(CbcModel & model);
02860 #endif
02861