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 }
01833 inline void setMoreSpecialOptions(int value) {
01834 moreSpecialOptions_ = value;
01835 }
01837 inline int moreSpecialOptions() const {
01838 return moreSpecialOptions_;
01839 }
01841 inline void setCutoffAsConstraint(bool yesNo) {
01842 cutoffRowNumber_ = (yesNo) ? -2 : -1;
01843 }
01845 inline void setUseElapsedTime(bool yesNo) {
01846 if (yesNo)
01847 moreSpecialOptions_ |= 131072;
01848 else
01849 moreSpecialOptions_ &= ~131072;
01850 }
01852 inline bool useElapsedTime() const {
01853 return (moreSpecialOptions_&131072)!=0;
01854 }
01856 inline void * temporaryPointer() const
01857 { return temporaryPointer_;}
01859 inline void setTemporaryPointer(void * pointer)
01860 { temporaryPointer_=pointer;}
01862 void goToDantzig(int numberNodes, ClpDualRowPivot *& savePivotMethod);
01864 inline bool ownObjects() const {
01865 return ownObjects_;
01866 }
01868 void checkModel();
01870
01871
01873
01874
01875 CbcModel();
01876
01878 CbcModel(const OsiSolverInterface &);
01879
01888 void assignSolver(OsiSolverInterface *&solver, bool deleteSolver = true);
01889
01901 inline void setModelOwnsSolver (bool ourSolver) {
01902 ownership_ = ourSolver ? (ownership_ | 0x80000000) : (ownership_ & (~0x80000000)) ;
01903 }
01904
01910 inline bool modelOwnsSolver () {
01911 return ((ownership_&0x80000000) != 0) ;
01912 }
01913
01917 CbcModel(const CbcModel & rhs, bool cloneHandler = false);
01918
01920 virtual CbcModel *clone (bool cloneHandler);
01921
01923 CbcModel & operator=(const CbcModel& rhs);
01924
01926 virtual ~CbcModel ();
01927
01929 inline OsiSolverInterface * solver() const {
01930 return solver_;
01931 }
01932
01934 inline OsiSolverInterface * swapSolver(OsiSolverInterface * solver) {
01935 OsiSolverInterface * returnSolver = solver_;
01936 solver_ = solver;
01937 return returnSolver;
01938 }
01939
01941 inline OsiSolverInterface * continuousSolver() const {
01942 return continuousSolver_;
01943 }
01944
01946 inline void createContinuousSolver() {
01947 continuousSolver_ = solver_->clone();
01948 }
01950 inline void clearContinuousSolver() {
01951 delete continuousSolver_;
01952 continuousSolver_ = NULL;
01953 }
01954
01956 inline OsiSolverInterface * referenceSolver() const {
01957 return referenceSolver_;
01958 }
01959
01961 void saveReferenceSolver();
01962
01968 void resetToReferenceSolver();
01969
01971 void gutsOfDestructor();
01974 void gutsOfDestructor2();
01977 void resetModel();
01983 void gutsOfCopy(const CbcModel & rhs, int mode = 0);
01985 void moveInfo(const CbcModel & rhs);
01987
01989
01990
01991 static bool haveMultiThreadSupport();
01993 CbcThread * masterThread() const {
01994 return masterThread_;
01995 }
01997 CbcNodeInfo ** walkback() const {
01998 return walkback_;
01999 }
02001 inline int getNumberThreads() const {
02002 return numberThreads_;
02003 }
02005 inline void setNumberThreads(int value) {
02006 numberThreads_ = value;
02007 }
02009 inline int getThreadMode() const {
02010 return threadMode_;
02011 }
02021 inline void setThreadMode(int value) {
02022 threadMode_ = value;
02023 }
02030 inline int parallelMode() const {
02031 if (!numberThreads_) {
02032 if ((threadMode_&1) == 0)
02033 return 0;
02034 else
02035 return -1;
02036 return 0;
02037 } else {
02038 if ((threadMode_&1) == 0)
02039 return 1;
02040 else
02041 return -2;
02042 }
02043 }
02045 inline CbcBaseModel * master() const
02046 { return master_;}
02049 bool isLocked() const;
02050 #ifdef CBC_THREAD
02051
02055 void lockThread();
02059 void unlockThread();
02060 #else
02061 inline void lockThread() {}
02062 inline void unlockThread() {}
02063 #endif
02064
02071 void setInfoInChild(int type, CbcThread * info);
02078 void moveToModel(CbcModel * baseModel, int mode);
02080 int splitModel(int numberModels, CbcModel ** model,
02081 int numberNodes);
02083 void startSplitModel(int numberIterations);
02085 void mergeModels(int numberModel, CbcModel ** model,
02086 int numberNodes);
02088
02090
02091
02092 int getNodeCount2() const {
02093 return numberNodes2_;
02094 }
02096 void setPointers(const OsiSolverInterface * solver);
02102 int reducedCostFix() ;
02106 void synchronizeHandlers(int makeDefault);
02108 void saveExtraSolution(const double * solution, double objectiveValue);
02110 void saveBestSolution(const double * solution, double objectiveValue);
02112 void deleteSolutions();
02114 int resolve(OsiSolverInterface * solver);
02115 #ifdef CLP_RESOLVE
02117 int resolveClp(OsiClpSolverInterface * solver, int type);
02118 #endif
02119
02123 int chooseBranch(CbcNode * & newNode, int numberPassesLeft,
02124 CbcNode * oldNode, OsiCuts & cuts,
02125 bool & resolved, CoinWarmStartBasis *lastws,
02126 const double * lowerBefore, const double * upperBefore,
02127 OsiSolverBranch * & branches);
02128 int chooseBranch(CbcNode * newNode, int numberPassesLeft, bool & resolved);
02129
02136 CoinWarmStartBasis *getEmptyBasis(int ns = 0, int na = 0) const ;
02137
02149 int takeOffCuts(OsiCuts &cuts,
02150 bool allowResolve, OsiCuts * saveCuts,
02151 int numberNewCuts = 0, const OsiRowCut ** newCuts = NULL) ;
02152
02166 int addCuts(CbcNode * node, CoinWarmStartBasis *&lastws, bool canFix);
02167
02184 bool addCuts1(CbcNode * node, CoinWarmStartBasis *&lastws);
02188 void previousBounds (CbcNode * node, CbcNodeInfo * where, int iColumn,
02189 double & lower, double & upper, int force);
02194 void setObjectiveValue(CbcNode * thisNode, const CbcNode * parentNode) const;
02195
02199 void convertToDynamic();
02201 void synchronizeNumberBeforeTrust(int type = 0);
02203 void zapIntegerInformation(bool leaveObjects = true);
02205 int cliquePseudoCosts(int doStatistics);
02207 void pseudoShadow(int type);
02214 void fillPseudoCosts(double * downCosts, double * upCosts,
02215 int * priority = NULL,
02216 int * numberDown = NULL, int * numberUp = NULL,
02217 int * numberDownInfeasible = NULL,
02218 int * numberUpInfeasible = NULL) const;
02224 void doHeuristicsAtRoot(int deleteHeuristicsAfterwards = 0);
02226 void adjustHeuristics();
02228 inline const double * hotstartSolution() const {
02229 return hotstartSolution_;
02230 }
02232 inline const int * hotstartPriorities() const {
02233 return hotstartPriorities_;
02234 }
02235
02237 inline CbcCountRowCut ** addedCuts() const {
02238 return addedCuts_;
02239 }
02241 inline int currentNumberCuts() const {
02242 return currentNumberCuts_;
02243 }
02245 inline CbcRowCuts * globalCuts() {
02246 return &globalCuts_;
02247 }
02249 void setNextRowCut(const OsiRowCut & cut);
02251 inline CbcNode * currentNode() const {
02252 return currentNode_;
02253 }
02255 inline CglTreeProbingInfo * probingInfo() const {
02256 return probingInfo_;
02257 }
02259 inline CoinThreadRandom * randomNumberGenerator() {
02260 return &randomNumberGenerator_;
02261 }
02263 inline void setNumberStrongIterations(int number) {
02264 numberStrongIterations_ = number;
02265 }
02267 inline int numberStrongIterations() const {
02268 return numberStrongIterations_;
02269 }
02271 inline int maximumNumberIterations() const {
02272 return maximumNumberIterations_;
02273 }
02275 inline void setMaximumNumberIterations(int value) {
02276 maximumNumberIterations_ = value;
02277 }
02279 inline void setFastNodeDepth(int value) {
02280 fastNodeDepth_ = value;
02281 }
02283 inline int fastNodeDepth() const {
02284 return fastNodeDepth_;
02285 }
02287 inline int continuousPriority() const {
02288 return continuousPriority_;
02289 }
02291 inline void setContinuousPriority(int value) {
02292 continuousPriority_ = value;
02293 }
02294 inline void incrementExtra(int nodes, int iterations) {
02295 numberExtraNodes_ += nodes;
02296 numberExtraIterations_ += iterations;
02297 }
02299 inline int numberExtraIterations() const {
02300 return numberExtraIterations_;
02301 }
02303 void incrementStrongInfo(int numberTimes, int numberIterations,
02304 int numberFixed, bool ifInfeasible);
02306 inline const int * strongInfo() const {
02307 return strongInfo_;
02308 }
02309
02311 inline int * mutableStrongInfo() {
02312 return strongInfo_;
02313 }
02315 CglStored * storedRowCuts() const {
02316 return storedRowCuts_;
02317 }
02319 void setStoredRowCuts(CglStored * cuts) {
02320 storedRowCuts_ = cuts;
02321 }
02323 inline bool allDynamic () const {
02324 return ((ownership_&0x40000000) != 0) ;
02325 }
02327 void generateCpp( FILE * fp, int options);
02329 OsiBranchingInformation usefulInformation() const;
02336 inline void setBestSolutionBasis(const CoinWarmStartBasis & bestSolutionBasis) {
02337 bestSolutionBasis_ = bestSolutionBasis;
02338 }
02340 void redoWalkBack();
02342
02343
02344
02345 private:
02347
02348
02350 OsiSolverInterface * solver_;
02351
02357 unsigned int ownership_ ;
02358
02360 OsiSolverInterface * continuousSolver_;
02361
02363 OsiSolverInterface * referenceSolver_;
02364
02366 CoinMessageHandler * handler_;
02367
02373 bool defaultHandler_;
02374
02376 CoinMessages messages_;
02377
02379 int intParam_[CbcLastIntParam];
02380
02382 double dblParam_[CbcLastDblParam];
02383
02392 mutable CoinWarmStart *emptyWarmStart_ ;
02393
02395 double bestObjective_;
02397 double bestPossibleObjective_;
02399 double sumChangeObjective1_;
02401 double sumChangeObjective2_;
02402
02404 double * bestSolution_;
02406 double ** savedSolutions_;
02407
02412 double * currentSolution_;
02416 mutable const double * testSolution_;
02423 CoinWarmStartBasis bestSolutionBasis_ ;
02425 CbcRowCuts globalCuts_;
02427 CbcRowCuts * globalConflictCuts_;
02428
02430 double minimumDrop_;
02432 int numberSolutions_;
02434 int numberSavedSolutions_;
02436 int maximumSavedSolutions_;
02443 int stateOfSearch_;
02445 int whenCuts_;
02447 double * hotstartSolution_;
02449 int * hotstartPriorities_;
02451 int numberHeuristicSolutions_;
02453 int numberNodes_;
02457 int numberNodes2_;
02459 int numberIterations_;
02461 int numberSolves_;
02463 int status_;
02474 int secondaryStatus_;
02476 int numberIntegers_;
02478 int numberRowsAtContinuous_;
02484 int cutoffRowNumber_;
02486 int maximumNumberCuts_;
02495 int phase_;
02496
02498 int currentNumberCuts_;
02499
02504 int maximumDepth_;
02510 CbcNodeInfo ** walkback_;
02511 CbcNodeInfo ** lastNodeInfo_;
02512 const OsiRowCut ** lastCut_;
02513 int lastDepth_;
02514 int lastNumberCuts2_;
02515 int maximumCuts_;
02516 int * lastNumberCuts_;
02517
02525 CbcCountRowCut ** addedCuts_;
02526
02530 OsiRowCut * nextRowCut_;
02531
02533 CbcNode * currentNode_;
02534
02536 int * integerVariable_;
02538 char * integerInfo_;
02540 double * continuousSolution_;
02542 int * usedInSolution_;
02566 int specialOptions_;
02581 int moreSpecialOptions_;
02583 CbcCompareBase * nodeCompare_;
02585 CbcFeasibilityBase * problemFeasibility_;
02587 CbcTree * tree_;
02589 CbcFullNodeInfo * topOfTree_;
02591 CbcModel * subTreeModel_;
02593 CbcModel * heuristicModel_;
02595 int numberStoppedSubTrees_;
02597 CbcBranchDecision * branchingMethod_;
02599 CbcCutModifier * cutModifier_;
02601 CbcStrategy * strategy_;
02603 CbcModel * parentModel_;
02609
02610 const double * cbcColLower_;
02612 const double * cbcColUpper_;
02614 const double * cbcRowLower_;
02616 const double * cbcRowUpper_;
02618 const double * cbcColSolution_;
02620 const double * cbcRowPrice_;
02622 const double * cbcReducedCost_;
02624 const double * cbcRowActivity_;
02626 void * appData_;
02628 int presolve_;
02632 int numberStrong_;
02638 int numberBeforeTrust_;
02642 int numberPenalties_;
02644 int stopNumberIterations_;
02647 double penaltyScaleFactor_;
02649 int numberAnalyzeIterations_;
02651 double * analyzeResults_;
02653 void * temporaryPointer_;
02655 int numberInfeasibleNodes_;
02662 int problemType_;
02664 int printFrequency_;
02666 int numberCutGenerators_;
02667
02668 CbcCutGenerator ** generator_;
02669
02670 CbcCutGenerator ** virginGenerator_;
02672 int numberHeuristics_;
02674 CbcHeuristic ** heuristic_;
02676 CbcHeuristic * lastHeuristic_;
02678 int fastNodeDepth_;
02680 # ifdef CBC_ONLY_CLP
02681 ClpEventHandler *eventHandler_ ;
02682 # else
02683 CbcEventHandler *eventHandler_ ;
02684 # endif
02685
02687 int numberObjects_;
02688
02699 OsiObject ** object_;
02701 bool ownObjects_;
02702
02704 int * originalColumns_;
02706 int howOftenGlobalScan_;
02709 int numberGlobalViolations_;
02711 int numberExtraIterations_;
02713 int numberExtraNodes_;
02717 double continuousObjective_;
02720 double originalContinuousObjective_;
02722 int continuousInfeasibilities_;
02724 int maximumCutPassesAtRoot_;
02726 int maximumCutPasses_;
02728 int preferredWay_;
02730 int currentPassNumber_;
02732 int maximumWhich_;
02734 int maximumRows_;
02736 int randomSeed_;
02738 int multipleRootTries_;
02740 int currentDepth_;
02742 mutable CoinThreadRandom randomNumberGenerator_;
02744 CoinWarmStartBasis workingBasis_;
02746 int * whichGenerator_;
02748 int maximumStatistics_;
02750 CbcStatistics ** statistics_;
02752 int maximumDepthActual_;
02754 double numberDJFixed_;
02756 CglTreeProbingInfo * probingInfo_;
02758 int numberFixedAtRoot_;
02760 int numberFixedNow_;
02762 bool stoppedOnGap_;
02764 mutable bool eventHappened_;
02766 int numberLongStrong_;
02768 int numberOldActiveCuts_;
02770 int numberNewCuts_;
02772 int searchStrategy_;
02784 int strongStrategy_;
02786 int numberStrongIterations_;
02789 int strongInfo_[7];
02796 OsiBabSolver * solverCharacteristics_;
02798 bool resolveAfterTakeOffCuts_;
02800 int maximumNumberIterations_;
02802 int continuousPriority_;
02804 int numberUpdateItems_;
02806 int maximumNumberUpdateItems_;
02808 CbcObjectUpdateData * updateItems_;
02810 CglStored * storedRowCuts_;
02818 int numberThreads_;
02826 int threadMode_;
02828 CbcBaseModel * master_;
02830 CbcThread * masterThread_;
02832 };
02834 void getIntegerInformation(const OsiObject * object, double & originalLower,
02835 double & originalUpper) ;
02836
02837
02838 class OsiClpSolverInterface;
02839 int CbcMain (int argc, const char *argv[], OsiClpSolverInterface & solver, CbcModel ** babSolver);
02840 int CbcMain (int argc, const char *argv[], CbcModel & babSolver);
02841
02842 int callCbc(const char * input2, OsiClpSolverInterface& solver1);
02843 int callCbc(const char * input2);
02844 int callCbc(const std::string input2, OsiClpSolverInterface& solver1);
02845 int callCbc(const std::string input2) ;
02846
02847 void CbcMain0 (CbcModel & babSolver);
02848 int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver);
02849
02850 int callCbc(const char * input2, CbcModel & babSolver);
02851 int callCbc(const std::string input2, CbcModel & babSolver);
02852
02853 int callCbc1(const char * input2, CbcModel & babSolver);
02854 int callCbc1(const std::string input2, CbcModel & babSolver);
02855
02856 int callCbc1(const char * input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02857 int callCbc1(const std::string input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02858 int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02859
02860 void setCutAndHeuristicOptions(CbcModel & model);
02861 #endif
02862