Cbc trunk
CbcModel.hpp
Go to the documentation of this file.
00001 /* $Id$ */
00002 // Copyright (C) 2002, International Business Machines
00003 // Corporation and others.  All Rights Reserved.
00004 // This code is licensed under the terms of the Eclipse Public License (EPL).
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 "CbcMessage.hpp"
00017 #include "CbcEventHandler.hpp"
00018 #include "ClpDualRowPivot.hpp"
00019 
00020 //class OsiSolverInterface;
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 CbcEventHandler ;
00039 class CglPreProcess;
00040 # ifdef COIN_HAS_CLP
00041 class ClpNodeStuff;
00042 #endif
00043 // #define CBC_CHECK_BASIS 1
00044 
00045 //#############################################################################
00046 
00099 class CbcModel  {
00100 
00101 public:
00102 
00103     enum CbcIntParam {
00105         CbcMaxNumNode = 0,
00107         CbcMaxNumSol,
00117         CbcFathomDiscipline,
00121         CbcPrinting,
00124         CbcNumberBranches,
00126         CbcLastIntParam
00127     };
00128 
00129     enum CbcDblParam {
00132         CbcIntegerTolerance = 0,
00135         CbcInfeasibilityWeight,
00138         CbcCutoffIncrement,
00145         CbcAllowableGap,
00152         CbcAllowableFractionGap,
00155         CbcMaximumSeconds,
00157         CbcCurrentCutoff,
00159         CbcOptimizationDirection,
00161         CbcCurrentObjectiveValue,
00163         CbcCurrentMinimizationObjectiveValue,
00166         CbcStartSeconds,
00174         CbcHeuristicGap,
00182         CbcHeuristicFractionGap,
00184         CbcSmallestChange,
00186         CbcSumChange,
00188         CbcLargestChange,
00190         CbcSmallChange,
00192         CbcLastDblParam
00193     };
00194 
00195     //---------------------------------------------------------------------------
00196 
00197 public:
00199 
00200 
00204     void initialSolve();
00205 
00216     void branchAndBound(int doStatistics = 0);
00217 private:
00218 
00226     bool solveWithCuts(OsiCuts & cuts, int numberTries, CbcNode * node);
00234     int serialCuts(OsiCuts & cuts, CbcNode * node, OsiCuts & slackCuts, int lastNumberCuts);
00242     int parallelCuts(CbcBaseModel * master, OsiCuts & cuts, CbcNode * node, OsiCuts & slackCuts, int lastNumberCuts);
00249     CbcNode ** solveOneNode(int whichSolver, CbcNode * node,
00250                             int & numberNodesOutput, int & status) ;
00252     void resizeWhichGenerator(int numberNow, int numberAfter);
00253 public:
00254 #ifdef CBC_KEEP_DEPRECATED
00255     // See if anyone is using these any more!!
00260     CbcModel *  cleanModel(const double * lower, const double * upper);
00277     int subBranchAndBound(CbcModel * model2,
00278                           CbcModel * presolvedModel,
00279                           int maximumNodes);
00295     int subBranchAndBound(const double * lower, const double * upper,
00296                           int maximumNodes);
00297 
00304     OsiSolverInterface *  strengthenedModel();
00314     CglPreProcess * preProcess( int makeEquality = 0, int numberPasses = 5,
00315                                 int tuning = 5);
00318     void postProcess(CglPreProcess * process);
00319 #endif
00320 
00321     void addUpdateInformation(const CbcObjectUpdateData & data);
00328     int doOneNode(CbcModel * baseModel, CbcNode * & node, CbcNode * & newNode);
00329 
00330 public:
00344     int resolve(CbcNodeInfo * parent, int whereFrom,
00345                 double * saveSolution = NULL,
00346                 double * saveLower = NULL,
00347                 double * saveUpper = NULL);
00349     void makeGlobalCuts(int numberRows, const int * which);
00351     void makeGlobalCut(const OsiRowCut * cut);
00353     void makeGlobalCut(const OsiRowCut & cut);
00355     void makeGlobalCut(const OsiColCut * cut);
00357     void makeGlobalCut(const OsiColCut & cut);
00359 
00362 
00374     CbcModel * findCliques(bool makeEquality, int atLeastThisMany,
00375                            int lessThanThis, int defaultValue = 1000);
00376 
00385     CbcModel * integerPresolve(bool weak = false);
00386 
00391     bool integerPresolveThisModel(OsiSolverInterface * originalSolver, bool weak = false);
00392 
00393 
00395     void originalModel(CbcModel * presolvedModel, bool weak);
00396 
00417     bool tightenVubs(int type, bool allowMultipleBinary = false,
00418                      double useCutoff = 1.0e50);
00419 
00425     bool tightenVubs(int numberVubs, const int * which,
00426                      double useCutoff = 1.0e50);
00430     void analyzeObjective();
00431 
00435     void AddIntegers();
00436 
00440     void saveModel(OsiSolverInterface * saveSolver, double * checkCutoffForRestart, bool * feasible);
00441 
00443 
00449 
00451     inline int numberObjects() const {
00452         return numberObjects_;
00453     }
00455     inline void setNumberObjects(int number) {
00456         numberObjects_ = number;
00457     }
00458 
00460     inline OsiObject ** objects() const {
00461         return object_;
00462     }
00463 
00465     const inline OsiObject * object(int which) const {
00466         return object_[which];
00467     }
00469     inline OsiObject * modifiableObject(int which) const {
00470         return object_[which];
00471     }
00472 
00473     void setOptionalInteger(int index);
00474 
00476     void deleteObjects(bool findIntegers = true);
00477 
00482     void addObjects(int numberObjects, OsiObject ** objects);
00483 
00488     void addObjects(int numberObjects, CbcObject ** objects);
00489 
00491     void synchronizeModel() ;
00492 
00502     void findIntegers(bool startAgain, int type = 0);
00503 
00505 
00506     //---------------------------------------------------------------------------
00507 
00517 
00518     inline bool setIntParam(CbcIntParam key, int value) {
00519         intParam_[key] = value;
00520         return true;
00521     }
00523     inline bool setDblParam(CbcDblParam key, double value) {
00524         dblParam_[key] = value;
00525         return true;
00526     }
00528     inline int getIntParam(CbcIntParam key) const {
00529         return intParam_[key];
00530     }
00532     inline double getDblParam(CbcDblParam key) const {
00533         return dblParam_[key];
00534     }
00540     void setCutoff(double value) ;
00541 
00543     inline double getCutoff() const { //double value ;
00544         //solver_->getDblParam(OsiDualObjectiveLimit,value) ;
00545         //assert( dblParam_[CbcCurrentCutoff]== value * solver_->getObjSense());
00546         return dblParam_[CbcCurrentCutoff];
00547     }
00548 
00550     inline bool setMaximumNodes( int value) {
00551         return setIntParam(CbcMaxNumNode, value);
00552     }
00553 
00555     inline int getMaximumNodes() const {
00556         return getIntParam(CbcMaxNumNode);
00557     }
00558 
00563     inline bool setMaximumSolutions( int value) {
00564         return setIntParam(CbcMaxNumSol, value);
00565     }
00570     inline int getMaximumSolutions() const {
00571         return getIntParam(CbcMaxNumSol);
00572     }
00574     inline bool setPrintingMode( int value) {
00575         return setIntParam(CbcPrinting, value);
00576     }
00577 
00579     inline int getPrintingMode() const {
00580         return getIntParam(CbcPrinting);
00581     }
00582 
00587     inline bool setMaximumSeconds( double value) {
00588         return setDblParam(CbcMaximumSeconds, value);
00589     }
00594     inline double getMaximumSeconds() const {
00595         return getDblParam(CbcMaximumSeconds);
00596     }
00598     double getCurrentSeconds() const ;
00599 
00601     bool maximumSecondsReached() const ;
00602 
00606     inline bool setIntegerTolerance( double value) {
00607         return setDblParam(CbcIntegerTolerance, value);
00608     }
00612     inline double getIntegerTolerance() const {
00613         return getDblParam(CbcIntegerTolerance);
00614     }
00615 
00620     inline bool setInfeasibilityWeight( double value) {
00621         return setDblParam(CbcInfeasibilityWeight, value);
00622     }
00627     inline double getInfeasibilityWeight() const {
00628         return getDblParam(CbcInfeasibilityWeight);
00629     }
00630 
00634     inline bool setAllowableGap( double value) {
00635         return setDblParam(CbcAllowableGap, value);
00636     }
00640     inline double getAllowableGap() const {
00641         return getDblParam(CbcAllowableGap);
00642     }
00643 
00647     inline bool setAllowableFractionGap( double value) {
00648         return setDblParam(CbcAllowableFractionGap, value);
00649     }
00653     inline double getAllowableFractionGap() const {
00654         return getDblParam(CbcAllowableFractionGap);
00655     }
00659     inline bool setAllowablePercentageGap( double value) {
00660         return setDblParam(CbcAllowableFractionGap, value*0.01);
00661     }
00665     inline double getAllowablePercentageGap() const {
00666         return 100.0*getDblParam(CbcAllowableFractionGap);
00667     }
00671     inline bool setHeuristicGap( double value) {
00672         return setDblParam(CbcHeuristicGap, value);
00673     }
00677     inline double getHeuristicGap() const {
00678         return getDblParam(CbcHeuristicGap);
00679     }
00680 
00684     inline bool setHeuristicFractionGap( double value) {
00685         return setDblParam(CbcHeuristicFractionGap, value);
00686     }
00690     inline double getHeuristicFractionGap() const {
00691         return getDblParam(CbcHeuristicFractionGap);
00692     }
00697     inline bool setCutoffIncrement( double value) {
00698         return setDblParam(CbcCutoffIncrement, value);
00699     }
00704     inline double getCutoffIncrement() const {
00705         return getDblParam(CbcCutoffIncrement);
00706     }
00707 
00712     void setHotstartSolution(const double * solution, const int * priorities = NULL) ;
00713 
00715     inline void setMinimumDrop(double value) {
00716         minimumDrop_ = value;
00717     }
00719     inline double getMinimumDrop() const {
00720         return minimumDrop_;
00721     }
00722 
00725     inline void setMaximumCutPassesAtRoot(int value) {
00726         maximumCutPassesAtRoot_ = value;
00727     }
00729     inline int getMaximumCutPassesAtRoot() const {
00730         return maximumCutPassesAtRoot_;
00731     }
00732 
00735     inline void setMaximumCutPasses(int value) {
00736         maximumCutPasses_ = value;
00737     }
00739     inline int getMaximumCutPasses() const {
00740         return maximumCutPasses_;
00741     }
00744     inline int getCurrentPassNumber() const {
00745         return currentPassNumber_;
00746     }
00747 
00753     void setNumberStrong(int number);
00757     inline int numberStrong() const {
00758         return numberStrong_;
00759     }
00762     inline void setPreferredWay(int value) {
00763         preferredWay_ = value;
00764     }
00766     inline int getPreferredWay() const {
00767         return preferredWay_;
00768     }
00770     inline int whenCuts() const {
00771         return whenCuts_;
00772     }
00774     inline void setWhenCuts(int value) {
00775         whenCuts_ = value;
00776     }
00782     bool doCutsNow(int allowForTopOfTree) const;
00783 
00789     void setNumberBeforeTrust(int number);
00792     inline int numberBeforeTrust() const {
00793         return numberBeforeTrust_;
00794     }
00800     void setNumberPenalties(int number);
00803     inline int numberPenalties() const {
00804         return numberPenalties_;
00805     }
00807     inline void setNumberAnalyzeIterations(int number) {
00808         numberAnalyzeIterations_ = number;
00809     }
00810     inline int numberAnalyzeIterations() const {
00811         return numberAnalyzeIterations_;
00812     }
00815     inline double penaltyScaleFactor() const {
00816         return penaltyScaleFactor_;
00817     }
00820     void setPenaltyScaleFactor(double value);
00828     void inline setProblemType(int number) {
00829         problemType_ = number;
00830     }
00831     inline int problemType() const {
00832         return problemType_;
00833     }
00835     inline int currentDepth() const {
00836         return currentDepth_;
00837     }
00838 
00840     void setHowOftenGlobalScan(int number);
00842     inline int howOftenGlobalScan() const {
00843         return howOftenGlobalScan_;
00844     }
00846     inline int * originalColumns() const {
00847         return originalColumns_;
00848     }
00850     void setOriginalColumns(const int * originalColumns) ;
00851 
00859     inline void setPrintFrequency(int number) {
00860         printFrequency_ = number;
00861     }
00863     inline int printFrequency() const {
00864         return printFrequency_;
00865     }
00867 
00868     //---------------------------------------------------------------------------
00870 
00871 
00872     bool isAbandoned() const;
00874     bool isProvenOptimal() const;
00876     bool isProvenInfeasible() const;
00878     bool isContinuousUnbounded() const;
00880     bool isProvenDualInfeasible() const;
00882     bool isNodeLimitReached() const;
00884     bool isSecondsLimitReached() const;
00886     bool isSolutionLimitReached() const;
00888     inline int getIterationCount() const {
00889         return numberIterations_;
00890     }
00892     inline void incrementIterationCount(int value) {
00893         numberIterations_ += value;
00894     }
00896     inline int getNodeCount() const {
00897         return numberNodes_;
00898     }
00900     inline void incrementNodeCount(int value) {
00901         numberNodes_ += value;
00902     }
00912     inline int status() const {
00913         return status_;
00914     }
00915     inline void setProblemStatus(int value) {
00916         status_ = value;
00917     }
00929     inline int secondaryStatus() const {
00930         return secondaryStatus_;
00931     }
00932     inline void setSecondaryStatus(int value) {
00933         secondaryStatus_ = value;
00934     }
00936     bool isInitialSolveAbandoned() const ;
00938     bool isInitialSolveProvenOptimal() const ;
00940     bool isInitialSolveProvenPrimalInfeasible() const ;
00942     bool isInitialSolveProvenDualInfeasible() const ;
00943 
00945 
00946     //---------------------------------------------------------------------------
00959 
00960     inline int numberRowsAtContinuous() const {
00961         return numberRowsAtContinuous_;
00962     }
00963 
00965     inline int getNumCols() const {
00966         return solver_->getNumCols();
00967     }
00968 
00970     inline int getNumRows() const {
00971         return solver_->getNumRows();
00972     }
00973 
00975     inline CoinBigIndex getNumElements() const {
00976         return solver_->getNumElements();
00977     }
00978 
00980     inline int numberIntegers() const {
00981         return numberIntegers_;
00982     }
00983     // Integer variables
00984     inline const int * integerVariable() const {
00985         return integerVariable_;
00986     }
00988     inline char integerType(int i) const {
00989         assert (integerInfo_);
00990         assert (integerInfo_[i] == 0 || integerInfo_[i] == 1);
00991         return integerInfo_[i];
00992     }
00994     inline const char * integerType() const {
00995         return integerInfo_;
00996     }
00997 
00999     inline const double * getColLower() const {
01000         return solver_->getColLower();
01001     }
01002 
01004     inline const double * getColUpper() const {
01005         return solver_->getColUpper();
01006     }
01007 
01017     inline const char * getRowSense() const {
01018         return solver_->getRowSense();
01019     }
01020 
01029     inline const double * getRightHandSide() const {
01030         return solver_->getRightHandSide();
01031     }
01032 
01041     inline const double * getRowRange() const {
01042         return solver_->getRowRange();
01043     }
01044 
01046     inline const double * getRowLower() const {
01047         return solver_->getRowLower();
01048     }
01049 
01051     inline const double * getRowUpper() const {
01052         return solver_->getRowUpper();
01053     }
01054 
01056     inline const double * getObjCoefficients() const {
01057         return solver_->getObjCoefficients();
01058     }
01059 
01061     inline double getObjSense() const {
01062         //assert (dblParam_[CbcOptimizationDirection]== solver_->getObjSense());
01063         return dblParam_[CbcOptimizationDirection];
01064     }
01065 
01067     inline bool isContinuous(int colIndex) const {
01068         return solver_->isContinuous(colIndex);
01069     }
01070 
01072     inline bool isBinary(int colIndex) const {
01073         return solver_->isBinary(colIndex);
01074     }
01075 
01080     inline bool isInteger(int colIndex) const {
01081         return solver_->isInteger(colIndex);
01082     }
01083 
01085     inline bool isIntegerNonBinary(int colIndex) const {
01086         return solver_->isIntegerNonBinary(colIndex);
01087     }
01088 
01090     inline bool isFreeBinary(int colIndex) const {
01091         return solver_->isFreeBinary(colIndex) ;
01092     }
01093 
01095     inline const CoinPackedMatrix * getMatrixByRow() const {
01096         return solver_->getMatrixByRow();
01097     }
01098 
01100     inline const CoinPackedMatrix * getMatrixByCol() const {
01101         return solver_->getMatrixByCol();
01102     }
01103 
01105     inline double getInfinity() const {
01106         return solver_->getInfinity();
01107     }
01109     inline const double * getCbcColLower() const {
01110         return cbcColLower_;
01111     }
01113     inline const double * getCbcColUpper() const {
01114         return cbcColUpper_;
01115     }
01117     inline const double * getCbcRowLower() const {
01118         return cbcRowLower_;
01119     }
01121     inline const double * getCbcRowUpper() const {
01122         return cbcRowUpper_;
01123     }
01125     inline const double * getCbcColSolution() const {
01126         return cbcColSolution_;
01127     }
01129     inline const double * getCbcRowPrice() const {
01130         return cbcRowPrice_;
01131     }
01133     inline const double * getCbcReducedCost() const {
01134         return cbcReducedCost_;
01135     }
01137     inline const double * getCbcRowActivity() const {
01138         return cbcRowActivity_;
01139     }
01141 
01142 
01145 
01146     inline double * continuousSolution() const {
01147         return continuousSolution_;
01148     }
01153     inline int * usedInSolution() const {
01154         return usedInSolution_;
01155     }
01157     void incrementUsed(const double * solution);
01159     void setBestSolution(CBC_Message how,
01160                          double & objectiveValue, const double *solution,
01161                          int fixVariables = 0);
01163     void setBestObjectiveValue( double objectiveValue);
01165     CbcEventHandler::CbcAction dealWithEventHandler(CbcEventHandler::CbcEvent event,
01166             double objValue,
01167             const double * solution);
01168 
01175     double checkSolution(double cutoff, double * solution,
01176                          int fixVariables, double originalObjValue);
01183     bool feasibleSolution(int & numberIntegerInfeasibilities,
01184                           int & numberObjectInfeasibilities) const;
01185 
01191     inline double * currentSolution() const {
01192         return currentSolution_;
01193     }
01197     inline const double * testSolution() const {
01198         return testSolution_;
01199     }
01200     inline void setTestSolution(const double * solution) {
01201         testSolution_ = solution;
01202     }
01204     void reserveCurrentSolution(const double * solution = NULL);
01205 
01207     inline const double * getColSolution() const {
01208         return solver_->getColSolution();
01209     }
01210 
01212     inline const double * getRowPrice() const {
01213         return solver_->getRowPrice();
01214     }
01215 
01217     inline const double * getReducedCost() const {
01218         return solver_->getReducedCost();
01219     }
01220 
01222     inline const double * getRowActivity() const {
01223         return solver_->getRowActivity();
01224     }
01225 
01227     inline double getCurrentObjValue() const {
01228         return dblParam_[CbcCurrentObjectiveValue];
01229     }
01231     inline double getCurrentMinimizationObjValue() const {
01232         return dblParam_[CbcCurrentMinimizationObjectiveValue];
01233     }
01234 
01236     inline double getMinimizationObjValue() const {
01237         return bestObjective_;
01238     }
01240     inline void setMinimizationObjValue(double value) {
01241         bestObjective_ = value;
01242     }
01243 
01245     inline double getObjValue() const {
01246         return bestObjective_ * solver_->getObjSense() ;
01247     }
01253     double getBestPossibleObjValue() const;
01255     inline void setObjValue(double value) {
01256         bestObjective_ = value * solver_->getObjSense() ;
01257     }
01259     inline double getSolverObjValue() const {
01260         return solver_->getObjValue() * solver_->getObjSense() ;
01261     }
01262 
01269     inline double * bestSolution() const {
01270         return bestSolution_;
01271     }
01278     void setBestSolution(const double * solution, int numberColumns,
01279                          double objectiveValue, bool check = false);
01280 
01282     inline int getSolutionCount() const {
01283         return numberSolutions_;
01284     }
01285 
01287     inline void setSolutionCount(int value) {
01288         numberSolutions_ = value;
01289     }
01291     int numberSavedSolutions() const;
01293     inline int maximumSavedSolutions() const {
01294         return maximumSavedSolutions_;
01295     }
01297     void setMaximumSavedSolutions(int value);
01299     const double * savedSolution(int which) const;
01301     double savedSolutionObjective(int which) const;
01302 
01311     inline int phase() const {
01312         return phase_;
01313     }
01314 
01316     inline int getNumberHeuristicSolutions() const {
01317         return numberHeuristicSolutions_;
01318     }
01320     inline void setNumberHeuristicSolutions(int value) {
01321         numberHeuristicSolutions_ = value;
01322     }
01323 
01325     inline void setObjSense(double s) {
01326         dblParam_[CbcOptimizationDirection] = s;
01327         solver_->setObjSense(s);
01328     }
01329 
01331     inline double getContinuousObjective() const {
01332         return originalContinuousObjective_;
01333     }
01334     inline void setContinuousObjective(double value) {
01335         originalContinuousObjective_ = value;
01336     }
01338     inline int getContinuousInfeasibilities() const {
01339         return continuousInfeasibilities_;
01340     }
01341     inline void setContinuousInfeasibilities(int value) {
01342         continuousInfeasibilities_ = value;
01343     }
01345     inline double rootObjectiveAfterCuts() const {
01346         return continuousObjective_;
01347     }
01349     inline double sumChangeObjective() const {
01350         return sumChangeObjective1_;
01351     }
01354     inline int numberGlobalViolations() const {
01355         return numberGlobalViolations_;
01356     }
01357     inline void clearNumberGlobalViolations() {
01358         numberGlobalViolations_ = 0;
01359     }
01361     inline bool resolveAfterTakeOffCuts() const {
01362         return resolveAfterTakeOffCuts_;
01363     }
01364     inline void setResolveAfterTakeOffCuts(bool yesNo) {
01365         resolveAfterTakeOffCuts_ = yesNo;
01366     }
01368     inline int maximumRows() const {
01369         return maximumRows_;
01370     }
01372     inline CoinWarmStartBasis & workingBasis() {
01373         return workingBasis_;
01374     }
01376     inline int getStopNumberIterations() const {
01377         return stopNumberIterations_;
01378     }
01380     inline void setStopNumberIterations(int value) {
01381         stopNumberIterations_ = value;
01382     }
01384 
01387     // Comparison functions (which may be overridden by inheritance)
01388     inline CbcCompareBase * nodeComparison() const {
01389         return nodeCompare_;
01390     }
01391     void setNodeComparison(CbcCompareBase * compare);
01392     void setNodeComparison(CbcCompareBase & compare);
01394 
01397     // Feasibility functions (which may be overridden by inheritance)
01398     inline CbcFeasibilityBase * problemFeasibility() const {
01399         return problemFeasibility_;
01400     }
01401     void setProblemFeasibility(CbcFeasibilityBase * feasibility);
01402     void setProblemFeasibility(CbcFeasibilityBase & feasibility);
01404 
01407 
01408     inline CbcTree * tree() const {
01409         return tree_;
01410     }
01412     void passInTreeHandler(CbcTree & tree);
01416     void passInSubTreeModel(CbcModel & model);
01421     CbcModel * subTreeModel(OsiSolverInterface * solver = NULL) const;
01423     inline int numberStoppedSubTrees() const {
01424         return numberStoppedSubTrees_;
01425     }
01427     inline void incrementSubTreeStopped() {
01428         numberStoppedSubTrees_++;
01429     }
01435     inline int typePresolve() const {
01436         return presolve_;
01437     }
01438     inline void setTypePresolve(int value) {
01439         presolve_ = value;
01440     }
01441 
01443 
01449 
01451     inline CbcBranchDecision * branchingMethod() const {
01452         return branchingMethod_;
01453     }
01455     inline void setBranchingMethod(CbcBranchDecision * method) {
01456         delete branchingMethod_;
01457         branchingMethod_ = method->clone();
01458     }
01463     inline void setBranchingMethod(CbcBranchDecision & method) {
01464         delete branchingMethod_;
01465         branchingMethod_ = method.clone();
01466     }
01468     inline CbcCutModifier * cutModifier() const {
01469         return cutModifier_;
01470     }
01472     void setCutModifier(CbcCutModifier * modifier);
01477     void setCutModifier(CbcCutModifier & modifier);
01479 
01482 
01489     inline int stateOfSearch() const {
01490         return stateOfSearch_;
01491     }
01492     inline void setStateOfSearch(int state) {
01493         stateOfSearch_ = state;
01494     }
01496     inline int searchStrategy() const {
01497         return searchStrategy_;
01498     }
01500     inline void setSearchStrategy(int value) {
01501         searchStrategy_ = value;
01502     }
01503 
01505     inline int numberCutGenerators() const {
01506         return numberCutGenerators_;
01507     }
01509     inline CbcCutGenerator ** cutGenerators() const {
01510         return generator_;
01511     }
01513     inline CbcCutGenerator * cutGenerator(int i) const {
01514         return generator_[i];
01515     }
01517     inline CbcCutGenerator * virginCutGenerator(int i) const {
01518         return virginGenerator_[i];
01519     }
01528     void addCutGenerator(CglCutGenerator * generator,
01529                          int howOften = 1, const char * name = NULL,
01530                          bool normal = true, bool atSolution = false,
01531                          bool infeasible = false, int howOftenInSub = -100,
01532                          int whatDepth = -1, int whatDepthInSub = -1);
01534 
01539 
01541     inline CbcStrategy * strategy() const {
01542         return strategy_;
01543     }
01545     void setStrategy(CbcStrategy & strategy);
01547     inline void setStrategy(CbcStrategy * strategy) {
01548         strategy_ = strategy;
01549     }
01551     inline CbcModel * parentModel() const {
01552         return parentModel_;
01553     }
01555     inline void setParentModel(CbcModel & parentModel) {
01556         parentModel_ = &parentModel;
01557     }
01559 
01560 
01567     void addHeuristic(CbcHeuristic * generator, const char *name = NULL,
01568                       int before = -1);
01570     inline CbcHeuristic * heuristic(int i) const {
01571         return heuristic_[i];
01572     }
01574     inline int numberHeuristics() const {
01575         return numberHeuristics_;
01576     }
01578     inline CbcHeuristic * lastHeuristic() const {
01579         return lastHeuristic_;
01580     }
01582     inline void setLastHeuristic(CbcHeuristic * last) {
01583         lastHeuristic_ = last;
01584     }
01585 
01604     void passInPriorities(const int * priorities, bool ifNotSimpleIntegers);
01605 
01607     inline int priority(int sequence) const {
01608         return object_[sequence]->priority();
01609     }
01610 
01615     void passInEventHandler(const CbcEventHandler *eventHandler) ;
01616 
01618     inline CbcEventHandler* getEventHandler() const {
01619         return (eventHandler_) ;
01620     }
01621 
01623 
01633     void setApplicationData (void * appData);
01634 
01636     void * getApplicationData() const;
01649     void passInSolverCharacteristics(OsiBabSolver * solverCharacteristics);
01651     inline const OsiBabSolver * solverCharacteristics() const {
01652         return solverCharacteristics_;
01653     }
01655 
01656     //---------------------------------------------------------------------------
01657 
01660 
01661     void passInMessageHandler(CoinMessageHandler * handler);
01663     void newLanguage(CoinMessages::Language language);
01664     inline void setLanguage(CoinMessages::Language language) {
01665         newLanguage(language);
01666     }
01668     inline CoinMessageHandler * messageHandler() const {
01669         return handler_;
01670     }
01672     inline CoinMessages & messages() {
01673         return messages_;
01674     }
01676     inline CoinMessages * messagesPointer() {
01677         return &messages_;
01678     }
01680     void setLogLevel(int value);
01682     inline int logLevel() const {
01683         return handler_->logLevel();
01684     }
01690     inline void setDefaultHandler(bool yesNo) {
01691         defaultHandler_ = yesNo;
01692     }
01694     //---------------------------------------------------------------------------
01696 
01697 
01719     inline void setSpecialOptions(int value) {
01720         specialOptions_ = value;
01721     }
01723     inline int specialOptions() const {
01724         return specialOptions_;
01725     }
01727     inline bool normalSolver() const {
01728         return (specialOptions_&16) == 0;
01729     }
01740     inline void setMoreSpecialOptions(int value) {
01741         moreSpecialOptions_ = value;
01742     }
01744     inline int moreSpecialOptions() const {
01745         return moreSpecialOptions_;
01746     }
01748     inline void setUseElapsedTime(bool yesNo) {
01749         if (yesNo)
01750           moreSpecialOptions_ |= 131072;
01751         else
01752           moreSpecialOptions_ &= ~131072;
01753     }
01755     inline bool useElapsedTime() const {
01756         return (moreSpecialOptions_&131072)!=0;
01757     }
01759 #ifdef COIN_HAS_CLP
01760     void goToDantzig(int numberNodes, ClpDualRowPivot *& savePivotMethod);
01761 #endif
01762 
01763     inline bool ownObjects() const {
01764         return ownObjects_;
01765     }
01767     void checkModel();
01769     //---------------------------------------------------------------------------
01770 
01772 
01773 
01774     CbcModel();
01775 
01777     CbcModel(const OsiSolverInterface &);
01778 
01787     void assignSolver(OsiSolverInterface *&solver, bool deleteSolver = true);
01788 
01800     inline void setModelOwnsSolver (bool ourSolver) {
01801         ownership_ = ourSolver ? (ownership_ | 0x80000000) : (ownership_ & (~0x80000000)) ;
01802     }
01803 
01809     inline bool modelOwnsSolver () {
01810         return ((ownership_&0x80000000) != 0) ;
01811     }
01812 
01816     CbcModel(const CbcModel & rhs, bool cloneHandler = false);
01817 
01819     CbcModel & operator=(const CbcModel& rhs);
01820 
01822     ~CbcModel ();
01823 
01825     inline OsiSolverInterface * solver() const {
01826         return solver_;
01827     }
01828 
01830     inline OsiSolverInterface * swapSolver(OsiSolverInterface * solver) {
01831         OsiSolverInterface * returnSolver = solver_;
01832         solver_ = solver;
01833         return returnSolver;
01834     }
01835 
01837     inline OsiSolverInterface * continuousSolver() const {
01838         return continuousSolver_;
01839     }
01840 
01842     inline void createContinuousSolver() {
01843         continuousSolver_ = solver_->clone();
01844     }
01846     inline void clearContinuousSolver() {
01847         delete continuousSolver_;
01848         continuousSolver_ = NULL;
01849     }
01850 
01852     inline OsiSolverInterface * referenceSolver() const {
01853         return referenceSolver_;
01854     }
01855 
01857     void saveReferenceSolver();
01858 
01864     void resetToReferenceSolver();
01865 
01867     void gutsOfDestructor();
01870     void gutsOfDestructor2();
01873     void resetModel();
01879     void gutsOfCopy(const CbcModel & rhs, int mode = 0);
01881     void moveInfo(const CbcModel & rhs);
01883 
01885 
01886 
01887     CbcThread * masterThread() const {
01888         return masterThread_;
01889     }
01891     CbcNodeInfo ** walkback() const {
01892         return walkback_;
01893     }
01895     inline int getNumberThreads() const {
01896         return numberThreads_;
01897     }
01899     inline void setNumberThreads(int value) {
01900         numberThreads_ = value;
01901     }
01903     inline int getThreadMode() const {
01904         return threadMode_;
01905     }
01915     inline void setThreadMode(int value) {
01916         threadMode_ = value;
01917     }
01924     inline int parallelMode() const {
01925         if (!numberThreads_) {
01926             if ((threadMode_&1) == 0)
01927                 return 0;
01928             else
01929                 return -1;
01930             return 0;
01931         } else {
01932             if ((threadMode_&1) == 0)
01933                 return 1;
01934             else
01935                 return -2;
01936         }
01937     }
01940     bool isLocked() const;
01941 #ifdef CBC_THREAD
01942 
01946     void lockThread();
01950     void unlockThread();
01951 #else
01952     inline void lockThread() {}
01953     inline void unlockThread() {}
01954 #endif
01955 
01962     void setInfoInChild(int type, CbcThread * info);
01969     void moveToModel(CbcModel * baseModel, int mode);
01971     int splitModel(int numberModels, CbcModel ** model,
01972                    int numberNodes);
01974     void startSplitModel(int numberIterations);
01976     void mergeModels(int numberModel, CbcModel ** model,
01977                      int numberNodes);
01979 
01981 
01982 
01983     int getNodeCount2() const {
01984         return numberNodes2_;
01985     }
01987     void setPointers(const OsiSolverInterface * solver);
01993     int reducedCostFix() ;
01997     void synchronizeHandlers(int makeDefault);
01999     void saveExtraSolution(const double * solution, double objectiveValue);
02001     void saveBestSolution(const double * solution, double objectiveValue);
02003     void deleteSolutions();
02005     int resolve(OsiSolverInterface * solver);
02006 
02010     int chooseBranch(CbcNode * & newNode, int numberPassesLeft,
02011                      CbcNode * oldNode, OsiCuts & cuts,
02012                      bool & resolved, CoinWarmStartBasis *lastws,
02013                      const double * lowerBefore, const double * upperBefore,
02014                      OsiSolverBranch * & branches);
02015     int chooseBranch(CbcNode * newNode, int numberPassesLeft, bool & resolved);
02016 
02023     CoinWarmStartBasis *getEmptyBasis(int ns = 0, int na = 0) const ;
02024 
02036     int takeOffCuts(OsiCuts &cuts,
02037                     bool allowResolve, OsiCuts * saveCuts,
02038                     int numberNewCuts = 0, const OsiRowCut ** newCuts = NULL) ;
02039 
02053     int addCuts(CbcNode * node, CoinWarmStartBasis *&lastws, bool canFix);
02054 
02071     bool addCuts1(CbcNode * node, CoinWarmStartBasis *&lastws);
02075     void previousBounds (CbcNode * node, CbcNodeInfo * where, int iColumn,
02076                          double & lower, double & upper, int force);
02081     void setObjectiveValue(CbcNode * thisNode, const CbcNode * parentNode) const;
02082 
02086     void convertToDynamic();
02088     void synchronizeNumberBeforeTrust(int type = 0);
02090     void zapIntegerInformation(bool leaveObjects = true);
02092     int cliquePseudoCosts(int doStatistics);
02094     void pseudoShadow(int type);
02101     void fillPseudoCosts(double * downCosts, double * upCosts,
02102                          int * priority = NULL,
02103                          int * numberDown = NULL, int * numberUp = NULL,
02104                          int * numberDownInfeasible = NULL,
02105                          int * numberUpInfeasible = NULL) const;
02111     void doHeuristicsAtRoot(int deleteHeuristicsAfterwards = 0);
02113     void adjustHeuristics();
02115     inline const double * hotstartSolution() const {
02116         return hotstartSolution_;
02117     }
02119     inline const int * hotstartPriorities() const {
02120         return hotstartPriorities_;
02121     }
02122 
02124     inline CbcCountRowCut ** addedCuts() const {
02125         return addedCuts_;
02126     }
02128     inline int currentNumberCuts() const {
02129         return currentNumberCuts_;
02130     }
02132     inline OsiCuts * globalCuts() {
02133         return &globalCuts_;
02134     }
02136     void setNextRowCut(const OsiRowCut & cut);
02138     inline CbcNode * currentNode() const {
02139         return currentNode_;
02140     }
02142     inline CglTreeProbingInfo * probingInfo() const {
02143         return probingInfo_;
02144     }
02146     inline CoinThreadRandom * randomNumberGenerator() {
02147         return &randomNumberGenerator_;
02148     }
02150     inline void setNumberStrongIterations(int number) {
02151         numberStrongIterations_ = number;
02152     }
02154     inline int numberStrongIterations() const {
02155         return numberStrongIterations_;
02156     }
02158     inline int maximumNumberIterations() const {
02159         return maximumNumberIterations_;
02160     }
02162     inline void setMaximumNumberIterations(int value) {
02163         maximumNumberIterations_ = value;
02164     }
02165 # ifdef COIN_HAS_CLP
02166 
02167     inline void setFastNodeDepth(int value) {
02168         fastNodeDepth_ = value;
02169     }
02171     inline int fastNodeDepth() const {
02172         return fastNodeDepth_;
02173     }
02175     inline int continuousPriority() const {
02176         return continuousPriority_;
02177     }
02179     inline void setContinuousPriority(int value) {
02180         continuousPriority_ = value;
02181     }
02182     inline void incrementExtra(int nodes, int iterations) {
02183         numberExtraNodes_ += nodes;
02184         numberExtraIterations_ += iterations;
02185     }
02186 #endif
02187 
02188     inline int numberExtraIterations() const {
02189         return numberExtraIterations_;
02190     }
02192     void incrementStrongInfo(int numberTimes, int numberIterations,
02193                              int numberFixed, bool ifInfeasible);
02195     inline const int * strongInfo() const {
02196         return strongInfo_;
02197     }
02198 
02200     inline int * mutableStrongInfo() {
02201         return strongInfo_;
02202     }
02204     CglStored * storedRowCuts() const {
02205         return storedRowCuts_;
02206     }
02208     void setStoredRowCuts(CglStored * cuts) {
02209         storedRowCuts_ = cuts;
02210     }
02212     inline bool allDynamic () const {
02213         return ((ownership_&0x40000000) != 0) ;
02214     }
02216     void generateCpp( FILE * fp, int options);
02218     OsiBranchingInformation usefulInformation() const;
02225     inline void setBestSolutionBasis(const CoinWarmStartBasis & bestSolutionBasis) {
02226         bestSolutionBasis_ = bestSolutionBasis;
02227     }
02229     void redoWalkBack();
02231 
02232 //---------------------------------------------------------------------------
02233 
02234 private:
02236 
02237 
02239     OsiSolverInterface * solver_;
02240 
02246     unsigned int ownership_ ;
02247 
02249     OsiSolverInterface * continuousSolver_;
02250 
02252     OsiSolverInterface * referenceSolver_;
02253 
02255     CoinMessageHandler * handler_;
02256 
02262     bool defaultHandler_;
02263 
02265     CoinMessages messages_;
02266 
02268     int intParam_[CbcLastIntParam];
02269 
02271     double dblParam_[CbcLastDblParam];
02272 
02281     mutable CoinWarmStart *emptyWarmStart_ ;
02282 
02284     double bestObjective_;
02286     double bestPossibleObjective_;
02288     double sumChangeObjective1_;
02290     double sumChangeObjective2_;
02291 
02293     double * bestSolution_;
02295     double ** savedSolutions_;
02296 
02301     double * currentSolution_;
02305     mutable const double * testSolution_;
02312     CoinWarmStartBasis bestSolutionBasis_ ;
02314     OsiCuts globalCuts_;
02315 
02317     double minimumDrop_;
02319     int numberSolutions_;
02321     int numberSavedSolutions_;
02323     int maximumSavedSolutions_;
02330     int stateOfSearch_;
02332     int whenCuts_;
02334     double * hotstartSolution_;
02336     int * hotstartPriorities_;
02338     int numberHeuristicSolutions_;
02340     int numberNodes_;
02344     int numberNodes2_;
02346     int numberIterations_;
02348     int numberSolves_;
02350     int status_;
02361     int secondaryStatus_;
02363     int numberIntegers_;
02365     int numberRowsAtContinuous_;
02367     int maximumNumberCuts_;
02376     int phase_;
02377 
02379     int currentNumberCuts_;
02380 
02385     int maximumDepth_;
02391     CbcNodeInfo ** walkback_;
02392     CbcNodeInfo ** lastNodeInfo_;
02393     const OsiRowCut ** lastCut_;
02394     int lastDepth_;
02395     int lastNumberCuts2_;
02396     int maximumCuts_;
02397     int * lastNumberCuts_;
02398 
02406     CbcCountRowCut ** addedCuts_;
02407 
02411     OsiRowCut * nextRowCut_;
02412 
02414     CbcNode * currentNode_;
02415 
02417     int * integerVariable_;
02419     char * integerInfo_;
02421     double * continuousSolution_;
02423     int * usedInSolution_;
02447     int specialOptions_;
02458     int moreSpecialOptions_;
02460     CbcCompareBase * nodeCompare_;
02462     CbcFeasibilityBase * problemFeasibility_;
02464     CbcTree * tree_;
02466     CbcModel * subTreeModel_;
02468     int numberStoppedSubTrees_;
02470     CbcBranchDecision * branchingMethod_;
02472     CbcCutModifier * cutModifier_;
02474     CbcStrategy * strategy_;
02476     CbcModel * parentModel_;
02482 
02483     const double * cbcColLower_;
02485     const double * cbcColUpper_;
02487     const double * cbcRowLower_;
02489     const double * cbcRowUpper_;
02491     const double * cbcColSolution_;
02493     const double * cbcRowPrice_;
02495     const double * cbcReducedCost_;
02497     const double * cbcRowActivity_;
02499     void * appData_;
02501     int presolve_;
02505     int numberStrong_;
02511     int numberBeforeTrust_;
02515     int numberPenalties_;
02517     int stopNumberIterations_;
02520     double penaltyScaleFactor_;
02522     int numberAnalyzeIterations_;
02524     double * analyzeResults_;
02526     int numberInfeasibleNodes_;
02533     int problemType_;
02535     int printFrequency_;
02537     int numberCutGenerators_;
02538     // Cut generators
02539     CbcCutGenerator ** generator_;
02540     // Cut generators before any changes
02541     CbcCutGenerator ** virginGenerator_;
02543     int numberHeuristics_;
02545     CbcHeuristic ** heuristic_;
02547     CbcHeuristic * lastHeuristic_;
02548 # ifdef COIN_HAS_CLP
02549 
02550     int fastNodeDepth_;
02551 #endif
02552 
02553 # ifdef CBC_ONLY_CLP
02554     ClpEventHandler *eventHandler_ ;
02555 # else
02556     CbcEventHandler *eventHandler_ ;
02557 # endif
02558 
02560     int numberObjects_;
02561 
02572     OsiObject ** object_;
02574     bool ownObjects_;
02575 
02577     int * originalColumns_;
02579     int howOftenGlobalScan_;
02582     int numberGlobalViolations_;
02584     int numberExtraIterations_;
02586     int numberExtraNodes_;
02590     double continuousObjective_;
02593     double originalContinuousObjective_;
02595     int continuousInfeasibilities_;
02597     int maximumCutPassesAtRoot_;
02599     int maximumCutPasses_;
02601     int preferredWay_;
02603     int currentPassNumber_;
02605     int maximumWhich_;
02607     int maximumRows_;
02609     int currentDepth_;
02611     mutable CoinThreadRandom randomNumberGenerator_;
02613     CoinWarmStartBasis workingBasis_;
02615     int * whichGenerator_;
02617     int maximumStatistics_;
02619     CbcStatistics ** statistics_;
02621     int maximumDepthActual_;
02623     double numberDJFixed_;
02625     CglTreeProbingInfo * probingInfo_;
02627     int numberFixedAtRoot_;
02629     int numberFixedNow_;
02631     bool stoppedOnGap_;
02633     mutable bool eventHappened_;
02635     int numberLongStrong_;
02637     int numberOldActiveCuts_;
02639     int numberNewCuts_;
02641     int searchStrategy_;
02643     int numberStrongIterations_;
02646     int strongInfo_[7];
02653     OsiBabSolver * solverCharacteristics_;
02655     bool resolveAfterTakeOffCuts_;
02657     int maximumNumberIterations_;
02659     int continuousPriority_;
02661     int numberUpdateItems_;
02663     int maximumNumberUpdateItems_;
02665     CbcObjectUpdateData * updateItems_;
02667     CglStored * storedRowCuts_;
02675     int numberThreads_;
02683     int threadMode_;
02685     CbcBaseModel * master_;
02687     CbcThread * masterThread_;
02689 };
02691 void getIntegerInformation(const OsiObject * object, double & originalLower,
02692                            double & originalUpper) ;
02693 // So we can call from other programs
02694 // Real main program
02695 class OsiClpSolverInterface;
02696 int CbcMain (int argc, const char *argv[], OsiClpSolverInterface & solver, CbcModel ** babSolver);
02697 int CbcMain (int argc, const char *argv[], CbcModel & babSolver);
02698 // four ways of calling
02699 int callCbc(const char * input2, OsiClpSolverInterface& solver1);
02700 int callCbc(const char * input2);
02701 int callCbc(const std::string input2, OsiClpSolverInterface& solver1);
02702 int callCbc(const std::string input2) ;
02703 // When we want to load up CbcModel with options first
02704 void CbcMain0 (CbcModel & babSolver);
02705 int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver);
02706 // two ways of calling
02707 int callCbc(const char * input2, CbcModel & babSolver);
02708 int callCbc(const std::string input2, CbcModel & babSolver);
02709 // And when CbcMain0 already called to initialize
02710 int callCbc1(const char * input2, CbcModel & babSolver);
02711 int callCbc1(const std::string input2, CbcModel & babSolver);
02712 // And when CbcMain0 already called to initialize (with call back) (see CbcMain1 for whereFrom)
02713 int callCbc1(const char * input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02714 int callCbc1(const std::string input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02715 int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02716 // For uniform setting of cut and heuristic options
02717 void setCutAndHeuristicOptions(CbcModel & model);
02718 #endif
02719 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines