CbcModel.hpp

Go to the documentation of this file.
00001 /* $Id: CbcModel.hpp 1779 2012-05-19 12:30:04Z stefan $ */
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 
00021 class CbcCutGenerator;
00022 class CbcBaseModel;
00023 class OsiRowCut;
00024 class OsiBabSolver;
00025 class OsiRowCutDebugger;
00026 class CglCutGenerator;
00027 class CglStored;
00028 class CbcCutModifier;
00029 class CglTreeProbingInfo;
00030 class CbcHeuristic;
00031 class OsiObject;
00032 class CbcThread;
00033 class CbcTree;
00034 class CbcStrategy;
00035 class CbcFeasibilityBase;
00036 class CbcStatistics;
00037 class CbcEventHandler ;
00038 class CglPreProcess;
00039 # ifdef COIN_HAS_CLP
00040 class OsiClpSolverInterface;
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
00321     void addUpdateInformation(const CbcObjectUpdateData & data);
00322 
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     }
00904     inline int getExtraNodeCount() const {
00905        return numberExtraNodes_;
00906     }
00916     inline int status() const {
00917         return status_;
00918     }
00919     inline void setProblemStatus(int value) {
00920         status_ = value;
00921     }
00933     inline int secondaryStatus() const {
00934         return secondaryStatus_;
00935     }
00936     inline void setSecondaryStatus(int value) {
00937         secondaryStatus_ = value;
00938     }
00940     bool isInitialSolveAbandoned() const ;
00942     bool isInitialSolveProvenOptimal() const ;
00944     bool isInitialSolveProvenPrimalInfeasible() const ;
00946     bool isInitialSolveProvenDualInfeasible() const ;
00947 
00949 
00950     //---------------------------------------------------------------------------
00963 
00964     inline int numberRowsAtContinuous() const {
00965         return numberRowsAtContinuous_;
00966     }
00967 
00969     inline int getNumCols() const {
00970         return solver_->getNumCols();
00971     }
00972 
00974     inline int getNumRows() const {
00975         return solver_->getNumRows();
00976     }
00977 
00979     inline CoinBigIndex getNumElements() const {
00980         return solver_->getNumElements();
00981     }
00982 
00984     inline int numberIntegers() const {
00985         return numberIntegers_;
00986     }
00987     // Integer variables
00988     inline const int * integerVariable() const {
00989         return integerVariable_;
00990     }
00992     inline char integerType(int i) const {
00993         assert (integerInfo_);
00994         assert (integerInfo_[i] == 0 || integerInfo_[i] == 1);
00995         return integerInfo_[i];
00996     }
00998     inline const char * integerType() const {
00999         return integerInfo_;
01000     }
01001 
01003     inline const double * getColLower() const {
01004         return solver_->getColLower();
01005     }
01006 
01008     inline const double * getColUpper() const {
01009         return solver_->getColUpper();
01010     }
01011 
01021     inline const char * getRowSense() const {
01022         return solver_->getRowSense();
01023     }
01024 
01033     inline const double * getRightHandSide() const {
01034         return solver_->getRightHandSide();
01035     }
01036 
01045     inline const double * getRowRange() const {
01046         return solver_->getRowRange();
01047     }
01048 
01050     inline const double * getRowLower() const {
01051         return solver_->getRowLower();
01052     }
01053 
01055     inline const double * getRowUpper() const {
01056         return solver_->getRowUpper();
01057     }
01058 
01060     inline const double * getObjCoefficients() const {
01061         return solver_->getObjCoefficients();
01062     }
01063 
01065     inline double getObjSense() const {
01066         //assert (dblParam_[CbcOptimizationDirection]== solver_->getObjSense());
01067         return dblParam_[CbcOptimizationDirection];
01068     }
01069 
01071     inline bool isContinuous(int colIndex) const {
01072         return solver_->isContinuous(colIndex);
01073     }
01074 
01076     inline bool isBinary(int colIndex) const {
01077         return solver_->isBinary(colIndex);
01078     }
01079 
01084     inline bool isInteger(int colIndex) const {
01085         return solver_->isInteger(colIndex);
01086     }
01087 
01089     inline bool isIntegerNonBinary(int colIndex) const {
01090         return solver_->isIntegerNonBinary(colIndex);
01091     }
01092 
01094     inline bool isFreeBinary(int colIndex) const {
01095         return solver_->isFreeBinary(colIndex) ;
01096     }
01097 
01099     inline const CoinPackedMatrix * getMatrixByRow() const {
01100         return solver_->getMatrixByRow();
01101     }
01102 
01104     inline const CoinPackedMatrix * getMatrixByCol() const {
01105         return solver_->getMatrixByCol();
01106     }
01107 
01109     inline double getInfinity() const {
01110         return solver_->getInfinity();
01111     }
01113     inline const double * getCbcColLower() const {
01114         return cbcColLower_;
01115     }
01117     inline const double * getCbcColUpper() const {
01118         return cbcColUpper_;
01119     }
01121     inline const double * getCbcRowLower() const {
01122         return cbcRowLower_;
01123     }
01125     inline const double * getCbcRowUpper() const {
01126         return cbcRowUpper_;
01127     }
01129     inline const double * getCbcColSolution() const {
01130         return cbcColSolution_;
01131     }
01133     inline const double * getCbcRowPrice() const {
01134         return cbcRowPrice_;
01135     }
01137     inline const double * getCbcReducedCost() const {
01138         return cbcReducedCost_;
01139     }
01141     inline const double * getCbcRowActivity() const {
01142         return cbcRowActivity_;
01143     }
01145 
01146 
01149 
01150     inline double * continuousSolution() const {
01151         return continuousSolution_;
01152     }
01157     inline int * usedInSolution() const {
01158         return usedInSolution_;
01159     }
01161     void incrementUsed(const double * solution);
01163     void setBestSolution(CBC_Message how,
01164                          double & objectiveValue, const double *solution,
01165                          int fixVariables = 0);
01167     void setBestObjectiveValue( double objectiveValue);
01169     CbcEventHandler::CbcAction dealWithEventHandler(CbcEventHandler::CbcEvent event,
01170             double objValue,
01171             const double * solution);
01172 
01179     double checkSolution(double cutoff, double * solution,
01180                          int fixVariables, double originalObjValue);
01187     bool feasibleSolution(int & numberIntegerInfeasibilities,
01188                           int & numberObjectInfeasibilities) const;
01189 
01195     inline double * currentSolution() const {
01196         return currentSolution_;
01197     }
01201     inline const double * testSolution() const {
01202         return testSolution_;
01203     }
01204     inline void setTestSolution(const double * solution) {
01205         testSolution_ = solution;
01206     }
01208     void reserveCurrentSolution(const double * solution = NULL);
01209 
01211     inline const double * getColSolution() const {
01212         return solver_->getColSolution();
01213     }
01214 
01216     inline const double * getRowPrice() const {
01217         return solver_->getRowPrice();
01218     }
01219 
01221     inline const double * getReducedCost() const {
01222         return solver_->getReducedCost();
01223     }
01224 
01226     inline const double * getRowActivity() const {
01227         return solver_->getRowActivity();
01228     }
01229 
01231     inline double getCurrentObjValue() const {
01232         return dblParam_[CbcCurrentObjectiveValue];
01233     }
01235     inline double getCurrentMinimizationObjValue() const {
01236         return dblParam_[CbcCurrentMinimizationObjectiveValue];
01237     }
01238 
01240     inline double getMinimizationObjValue() const {
01241         return bestObjective_;
01242     }
01244     inline void setMinimizationObjValue(double value) {
01245         bestObjective_ = value;
01246     }
01247 
01249     inline double getObjValue() const {
01250         return bestObjective_ * solver_->getObjSense() ;
01251     }
01257     double getBestPossibleObjValue() const;
01259     inline void setObjValue(double value) {
01260         bestObjective_ = value * solver_->getObjSense() ;
01261     }
01263     inline double getSolverObjValue() const {
01264         return solver_->getObjValue() * solver_->getObjSense() ;
01265     }
01266 
01273     inline double * bestSolution() const {
01274         return bestSolution_;
01275     }
01282     void setBestSolution(const double * solution, int numberColumns,
01283                          double objectiveValue, bool check = false);
01284 
01286     inline int getSolutionCount() const {
01287         return numberSolutions_;
01288     }
01289 
01291     inline void setSolutionCount(int value) {
01292         numberSolutions_ = value;
01293     }
01295     int numberSavedSolutions() const;
01297     inline int maximumSavedSolutions() const {
01298         return maximumSavedSolutions_;
01299     }
01301     void setMaximumSavedSolutions(int value);
01303     const double * savedSolution(int which) const;
01305     double savedSolutionObjective(int which) const;
01306 
01315     inline int phase() const {
01316         return phase_;
01317     }
01318 
01320     inline int getNumberHeuristicSolutions() const {
01321         return numberHeuristicSolutions_;
01322     }
01324     inline void setNumberHeuristicSolutions(int value) {
01325         numberHeuristicSolutions_ = value;
01326     }
01327 
01329     inline void setObjSense(double s) {
01330         dblParam_[CbcOptimizationDirection] = s;
01331         solver_->setObjSense(s);
01332     }
01333 
01335     inline double getContinuousObjective() const {
01336         return originalContinuousObjective_;
01337     }
01338     inline void setContinuousObjective(double value) {
01339         originalContinuousObjective_ = value;
01340     }
01342     inline int getContinuousInfeasibilities() const {
01343         return continuousInfeasibilities_;
01344     }
01345     inline void setContinuousInfeasibilities(int value) {
01346         continuousInfeasibilities_ = value;
01347     }
01349     inline double rootObjectiveAfterCuts() const {
01350         return continuousObjective_;
01351     }
01353     inline double sumChangeObjective() const {
01354         return sumChangeObjective1_;
01355     }
01358     inline int numberGlobalViolations() const {
01359         return numberGlobalViolations_;
01360     }
01361     inline void clearNumberGlobalViolations() {
01362         numberGlobalViolations_ = 0;
01363     }
01365     inline bool resolveAfterTakeOffCuts() const {
01366         return resolveAfterTakeOffCuts_;
01367     }
01368     inline void setResolveAfterTakeOffCuts(bool yesNo) {
01369         resolveAfterTakeOffCuts_ = yesNo;
01370     }
01372     inline int maximumRows() const {
01373         return maximumRows_;
01374     }
01376     inline CoinWarmStartBasis & workingBasis() {
01377         return workingBasis_;
01378     }
01380     inline int getStopNumberIterations() const {
01381         return stopNumberIterations_;
01382     }
01384     inline void setStopNumberIterations(int value) {
01385         stopNumberIterations_ = value;
01386     }
01388 
01391     // Comparison functions (which may be overridden by inheritance)
01392     inline CbcCompareBase * nodeComparison() const {
01393         return nodeCompare_;
01394     }
01395     void setNodeComparison(CbcCompareBase * compare);
01396     void setNodeComparison(CbcCompareBase & compare);
01398 
01401     // Feasibility functions (which may be overridden by inheritance)
01402     inline CbcFeasibilityBase * problemFeasibility() const {
01403         return problemFeasibility_;
01404     }
01405     void setProblemFeasibility(CbcFeasibilityBase * feasibility);
01406     void setProblemFeasibility(CbcFeasibilityBase & feasibility);
01408 
01411 
01412     inline CbcTree * tree() const {
01413         return tree_;
01414     }
01416     void passInTreeHandler(CbcTree & tree);
01420     void passInSubTreeModel(CbcModel & model);
01425     CbcModel * subTreeModel(OsiSolverInterface * solver = NULL) const;
01427     inline int numberStoppedSubTrees() const {
01428         return numberStoppedSubTrees_;
01429     }
01431     inline void incrementSubTreeStopped() {
01432         numberStoppedSubTrees_++;
01433     }
01439     inline int typePresolve() const {
01440         return presolve_;
01441     }
01442     inline void setTypePresolve(int value) {
01443         presolve_ = value;
01444     }
01445 
01447 
01453 
01455     inline CbcBranchDecision * branchingMethod() const {
01456         return branchingMethod_;
01457     }
01459     inline void setBranchingMethod(CbcBranchDecision * method) {
01460         delete branchingMethod_;
01461         branchingMethod_ = method->clone();
01462     }
01467     inline void setBranchingMethod(CbcBranchDecision & method) {
01468         delete branchingMethod_;
01469         branchingMethod_ = method.clone();
01470     }
01472     inline CbcCutModifier * cutModifier() const {
01473         return cutModifier_;
01474     }
01476     void setCutModifier(CbcCutModifier * modifier);
01481     void setCutModifier(CbcCutModifier & modifier);
01483 
01486 
01493     inline int stateOfSearch() const {
01494         return stateOfSearch_;
01495     }
01496     inline void setStateOfSearch(int state) {
01497         stateOfSearch_ = state;
01498     }
01500     inline int searchStrategy() const {
01501         return searchStrategy_;
01502     }
01504     inline void setSearchStrategy(int value) {
01505         searchStrategy_ = value;
01506     }
01507 
01509     inline int numberCutGenerators() const {
01510         return numberCutGenerators_;
01511     }
01513     inline CbcCutGenerator ** cutGenerators() const {
01514         return generator_;
01515     }
01517     inline CbcCutGenerator * cutGenerator(int i) const {
01518         return generator_[i];
01519     }
01521     inline CbcCutGenerator * virginCutGenerator(int i) const {
01522         return virginGenerator_[i];
01523     }
01532     void addCutGenerator(CglCutGenerator * generator,
01533                          int howOften = 1, const char * name = NULL,
01534                          bool normal = true, bool atSolution = false,
01535                          bool infeasible = false, int howOftenInSub = -100,
01536                          int whatDepth = -1, int whatDepthInSub = -1);
01538 
01543 
01545     inline CbcStrategy * strategy() const {
01546         return strategy_;
01547     }
01549     void setStrategy(CbcStrategy & strategy);
01551     inline void setStrategy(CbcStrategy * strategy) {
01552         strategy_ = strategy;
01553     }
01555     inline CbcModel * parentModel() const {
01556         return parentModel_;
01557     }
01559     inline void setParentModel(CbcModel & parentModel) {
01560         parentModel_ = &parentModel;
01561     }
01563 
01564 
01571     void addHeuristic(CbcHeuristic * generator, const char *name = NULL,
01572                       int before = -1);
01574     inline CbcHeuristic * heuristic(int i) const {
01575         return heuristic_[i];
01576     }
01578     inline int numberHeuristics() const {
01579         return numberHeuristics_;
01580     }
01582     inline CbcHeuristic * lastHeuristic() const {
01583         return lastHeuristic_;
01584     }
01586     inline void setLastHeuristic(CbcHeuristic * last) {
01587         lastHeuristic_ = last;
01588     }
01589 
01608     void passInPriorities(const int * priorities, bool ifNotSimpleIntegers);
01609 
01611     inline int priority(int sequence) const {
01612         return object_[sequence]->priority();
01613     }
01614 
01619     void passInEventHandler(const CbcEventHandler *eventHandler) ;
01620 
01622     inline CbcEventHandler* getEventHandler() const {
01623         return (eventHandler_) ;
01624     }
01625 
01627 
01637     void setApplicationData (void * appData);
01638 
01640     void * getApplicationData() const;
01653     void passInSolverCharacteristics(OsiBabSolver * solverCharacteristics);
01655     inline const OsiBabSolver * solverCharacteristics() const {
01656         return solverCharacteristics_;
01657     }
01659 
01660     //---------------------------------------------------------------------------
01661 
01664 
01665     void passInMessageHandler(CoinMessageHandler * handler);
01667     void newLanguage(CoinMessages::Language language);
01668     inline void setLanguage(CoinMessages::Language language) {
01669         newLanguage(language);
01670     }
01672     inline CoinMessageHandler * messageHandler() const {
01673         return handler_;
01674     }
01676     inline CoinMessages & messages() {
01677         return messages_;
01678     }
01680     inline CoinMessages * messagesPointer() {
01681         return &messages_;
01682     }
01684     void setLogLevel(int value);
01686     inline int logLevel() const {
01687         return handler_->logLevel();
01688     }
01694     inline void setDefaultHandler(bool yesNo) {
01695         defaultHandler_ = yesNo;
01696     }
01698     //---------------------------------------------------------------------------
01700 
01701 
01726     inline void setSpecialOptions(int value) {
01727         specialOptions_ = value;
01728     }
01730     inline int specialOptions() const {
01731         return specialOptions_;
01732     }
01734     inline void sayEventHappened()
01735     { eventHappened_=true;}
01737     inline bool normalSolver() const {
01738         return (specialOptions_&16) == 0;
01739     }
01744     inline bool waitingForMiniBranchAndBound() const {
01745         return (specialOptions_&1048576) != 0;
01746     }
01761     inline void setMoreSpecialOptions(int value) {
01762         moreSpecialOptions_ = value;
01763     }
01765     inline int moreSpecialOptions() const {
01766         return moreSpecialOptions_;
01767     }
01769     inline void setUseElapsedTime(bool yesNo) {
01770         if (yesNo)
01771           moreSpecialOptions_ |= 131072;
01772         else
01773           moreSpecialOptions_ &= ~131072;
01774     }
01776     inline bool useElapsedTime() const {
01777         return (moreSpecialOptions_&131072)!=0;
01778     }
01780 #ifdef COIN_HAS_CLP
01781     void goToDantzig(int numberNodes, ClpDualRowPivot *& savePivotMethod);
01782 #endif
01784     inline bool ownObjects() const {
01785         return ownObjects_;
01786     }
01788     void checkModel();
01790     //---------------------------------------------------------------------------
01791 
01793 
01794 
01795     CbcModel();
01796 
01798     CbcModel(const OsiSolverInterface &);
01799 
01808     void assignSolver(OsiSolverInterface *&solver, bool deleteSolver = true);
01809 
01821     inline void setModelOwnsSolver (bool ourSolver) {
01822         ownership_ = ourSolver ? (ownership_ | 0x80000000) : (ownership_ & (~0x80000000)) ;
01823     }
01824 
01830     inline bool modelOwnsSolver () {
01831         return ((ownership_&0x80000000) != 0) ;
01832     }
01833 
01837     CbcModel(const CbcModel & rhs, bool cloneHandler = false);
01838 
01840     CbcModel & operator=(const CbcModel& rhs);
01841 
01843     ~CbcModel ();
01844 
01846     inline OsiSolverInterface * solver() const {
01847         return solver_;
01848     }
01849 
01851     inline OsiSolverInterface * swapSolver(OsiSolverInterface * solver) {
01852         OsiSolverInterface * returnSolver = solver_;
01853         solver_ = solver;
01854         return returnSolver;
01855     }
01856 
01858     inline OsiSolverInterface * continuousSolver() const {
01859         return continuousSolver_;
01860     }
01861 
01863     inline void createContinuousSolver() {
01864         continuousSolver_ = solver_->clone();
01865     }
01867     inline void clearContinuousSolver() {
01868         delete continuousSolver_;
01869         continuousSolver_ = NULL;
01870     }
01871 
01873     inline OsiSolverInterface * referenceSolver() const {
01874         return referenceSolver_;
01875     }
01876 
01878     void saveReferenceSolver();
01879 
01885     void resetToReferenceSolver();
01886 
01888     void gutsOfDestructor();
01891     void gutsOfDestructor2();
01894     void resetModel();
01900     void gutsOfCopy(const CbcModel & rhs, int mode = 0);
01902     void moveInfo(const CbcModel & rhs);
01904 
01906 
01907 
01908     static bool haveMultiThreadSupport();
01910     CbcThread * masterThread() const {
01911         return masterThread_;
01912     }
01914     CbcNodeInfo ** walkback() const {
01915         return walkback_;
01916     }
01918     inline int getNumberThreads() const {
01919         return numberThreads_;
01920     }
01922     inline void setNumberThreads(int value) {
01923         numberThreads_ = value;
01924     }
01926     inline int getThreadMode() const {
01927         return threadMode_;
01928     }
01938     inline void setThreadMode(int value) {
01939         threadMode_ = value;
01940     }
01947     inline int parallelMode() const {
01948         if (!numberThreads_) {
01949             if ((threadMode_&1) == 0)
01950                 return 0;
01951             else
01952                 return -1;
01953             return 0;
01954         } else {
01955             if ((threadMode_&1) == 0)
01956                 return 1;
01957             else
01958                 return -2;
01959         }
01960     }
01963     bool isLocked() const;
01964 #ifdef CBC_THREAD
01965 
01969     void lockThread();
01973     void unlockThread();
01974 #else
01975     inline void lockThread() {}
01976     inline void unlockThread() {}
01977 #endif
01978 
01985     void setInfoInChild(int type, CbcThread * info);
01992     void moveToModel(CbcModel * baseModel, int mode);
01994     int splitModel(int numberModels, CbcModel ** model,
01995                    int numberNodes);
01997     void startSplitModel(int numberIterations);
01999     void mergeModels(int numberModel, CbcModel ** model,
02000                      int numberNodes);
02002 
02004 
02005 
02006     int getNodeCount2() const {
02007         return numberNodes2_;
02008     }
02010     void setPointers(const OsiSolverInterface * solver);
02016     int reducedCostFix() ;
02020     void synchronizeHandlers(int makeDefault);
02022     void saveExtraSolution(const double * solution, double objectiveValue);
02024     void saveBestSolution(const double * solution, double objectiveValue);
02026     void deleteSolutions();
02028     int resolve(OsiSolverInterface * solver);
02029 #ifdef CLP_RESOLVE
02031     int resolveClp(OsiClpSolverInterface * solver, int type);
02032 #endif
02033 
02037     int chooseBranch(CbcNode * & newNode, int numberPassesLeft,
02038                      CbcNode * oldNode, OsiCuts & cuts,
02039                      bool & resolved, CoinWarmStartBasis *lastws,
02040                      const double * lowerBefore, const double * upperBefore,
02041                      OsiSolverBranch * & branches);
02042     int chooseBranch(CbcNode * newNode, int numberPassesLeft, bool & resolved);
02043 
02050     CoinWarmStartBasis *getEmptyBasis(int ns = 0, int na = 0) const ;
02051 
02063     int takeOffCuts(OsiCuts &cuts,
02064                     bool allowResolve, OsiCuts * saveCuts,
02065                     int numberNewCuts = 0, const OsiRowCut ** newCuts = NULL) ;
02066 
02080     int addCuts(CbcNode * node, CoinWarmStartBasis *&lastws, bool canFix);
02081 
02098     bool addCuts1(CbcNode * node, CoinWarmStartBasis *&lastws);
02102     void previousBounds (CbcNode * node, CbcNodeInfo * where, int iColumn,
02103                          double & lower, double & upper, int force);
02108     void setObjectiveValue(CbcNode * thisNode, const CbcNode * parentNode) const;
02109 
02113     void convertToDynamic();
02115     void synchronizeNumberBeforeTrust(int type = 0);
02117     void zapIntegerInformation(bool leaveObjects = true);
02119     int cliquePseudoCosts(int doStatistics);
02121     void pseudoShadow(int type);
02128     void fillPseudoCosts(double * downCosts, double * upCosts,
02129                          int * priority = NULL,
02130                          int * numberDown = NULL, int * numberUp = NULL,
02131                          int * numberDownInfeasible = NULL,
02132                          int * numberUpInfeasible = NULL) const;
02138     void doHeuristicsAtRoot(int deleteHeuristicsAfterwards = 0);
02140     void adjustHeuristics();
02142     inline const double * hotstartSolution() const {
02143         return hotstartSolution_;
02144     }
02146     inline const int * hotstartPriorities() const {
02147         return hotstartPriorities_;
02148     }
02149 
02151     inline CbcCountRowCut ** addedCuts() const {
02152         return addedCuts_;
02153     }
02155     inline int currentNumberCuts() const {
02156         return currentNumberCuts_;
02157     }
02159     inline OsiCuts * globalCuts() {
02160         return &globalCuts_;
02161     }
02163     void setNextRowCut(const OsiRowCut & cut);
02165     inline CbcNode * currentNode() const {
02166         return currentNode_;
02167     }
02169     inline CglTreeProbingInfo * probingInfo() const {
02170         return probingInfo_;
02171     }
02173     inline CoinThreadRandom * randomNumberGenerator() {
02174         return &randomNumberGenerator_;
02175     }
02177     inline void setNumberStrongIterations(int number) {
02178         numberStrongIterations_ = number;
02179     }
02181     inline int numberStrongIterations() const {
02182         return numberStrongIterations_;
02183     }
02185     inline int maximumNumberIterations() const {
02186         return maximumNumberIterations_;
02187     }
02189     inline void setMaximumNumberIterations(int value) {
02190         maximumNumberIterations_ = value;
02191     }
02192 # ifdef COIN_HAS_CLP
02194     inline void setFastNodeDepth(int value) {
02195         fastNodeDepth_ = value;
02196     }
02198     inline int fastNodeDepth() const {
02199         return fastNodeDepth_;
02200     }
02202     inline int continuousPriority() const {
02203         return continuousPriority_;
02204     }
02206     inline void setContinuousPriority(int value) {
02207         continuousPriority_ = value;
02208     }
02209     inline void incrementExtra(int nodes, int iterations) {
02210         numberExtraNodes_ += nodes;
02211         numberExtraIterations_ += iterations;
02212     }
02213 #endif
02215     inline int numberExtraIterations() const {
02216         return numberExtraIterations_;
02217     }
02219     void incrementStrongInfo(int numberTimes, int numberIterations,
02220                              int numberFixed, bool ifInfeasible);
02222     inline const int * strongInfo() const {
02223         return strongInfo_;
02224     }
02225 
02227     inline int * mutableStrongInfo() {
02228         return strongInfo_;
02229     }
02231     CglStored * storedRowCuts() const {
02232         return storedRowCuts_;
02233     }
02235     void setStoredRowCuts(CglStored * cuts) {
02236         storedRowCuts_ = cuts;
02237     }
02239     inline bool allDynamic () const {
02240         return ((ownership_&0x40000000) != 0) ;
02241     }
02243     void generateCpp( FILE * fp, int options);
02245     OsiBranchingInformation usefulInformation() const;
02252     inline void setBestSolutionBasis(const CoinWarmStartBasis & bestSolutionBasis) {
02253         bestSolutionBasis_ = bestSolutionBasis;
02254     }
02256     void redoWalkBack();
02258 
02259 //---------------------------------------------------------------------------
02260 
02261 private:
02263 
02264 
02266     OsiSolverInterface * solver_;
02267 
02273     unsigned int ownership_ ;
02274 
02276     OsiSolverInterface * continuousSolver_;
02277 
02279     OsiSolverInterface * referenceSolver_;
02280 
02282     CoinMessageHandler * handler_;
02283 
02289     bool defaultHandler_;
02290 
02292     CoinMessages messages_;
02293 
02295     int intParam_[CbcLastIntParam];
02296 
02298     double dblParam_[CbcLastDblParam];
02299 
02308     mutable CoinWarmStart *emptyWarmStart_ ;
02309 
02311     double bestObjective_;
02313     double bestPossibleObjective_;
02315     double sumChangeObjective1_;
02317     double sumChangeObjective2_;
02318 
02320     double * bestSolution_;
02322     double ** savedSolutions_;
02323 
02328     double * currentSolution_;
02332     mutable const double * testSolution_;
02339     CoinWarmStartBasis bestSolutionBasis_ ;
02341     OsiCuts globalCuts_;
02342 
02344     double minimumDrop_;
02346     int numberSolutions_;
02348     int numberSavedSolutions_;
02350     int maximumSavedSolutions_;
02357     int stateOfSearch_;
02359     int whenCuts_;
02361     double * hotstartSolution_;
02363     int * hotstartPriorities_;
02365     int numberHeuristicSolutions_;
02367     int numberNodes_;
02371     int numberNodes2_;
02373     int numberIterations_;
02375     int numberSolves_;
02377     int status_;
02388     int secondaryStatus_;
02390     int numberIntegers_;
02392     int numberRowsAtContinuous_;
02394     int maximumNumberCuts_;
02403     int phase_;
02404 
02406     int currentNumberCuts_;
02407 
02412     int maximumDepth_;
02418     CbcNodeInfo ** walkback_;
02419     CbcNodeInfo ** lastNodeInfo_;
02420     const OsiRowCut ** lastCut_;
02421     int lastDepth_;
02422     int lastNumberCuts2_;
02423     int maximumCuts_;
02424     int * lastNumberCuts_;
02425 
02433     CbcCountRowCut ** addedCuts_;
02434 
02438     OsiRowCut * nextRowCut_;
02439 
02441     CbcNode * currentNode_;
02442 
02444     int * integerVariable_;
02446     char * integerInfo_;
02448     double * continuousSolution_;
02450     int * usedInSolution_;
02474     int specialOptions_;
02489     int moreSpecialOptions_;
02491     CbcCompareBase * nodeCompare_;
02493     CbcFeasibilityBase * problemFeasibility_;
02495     CbcTree * tree_;
02497     CbcModel * subTreeModel_;
02499     int numberStoppedSubTrees_;
02501     CbcBranchDecision * branchingMethod_;
02503     CbcCutModifier * cutModifier_;
02505     CbcStrategy * strategy_;
02507     CbcModel * parentModel_;
02513 
02514     const double * cbcColLower_;
02516     const double * cbcColUpper_;
02518     const double * cbcRowLower_;
02520     const double * cbcRowUpper_;
02522     const double * cbcColSolution_;
02524     const double * cbcRowPrice_;
02526     const double * cbcReducedCost_;
02528     const double * cbcRowActivity_;
02530     void * appData_;
02532     int presolve_;
02536     int numberStrong_;
02542     int numberBeforeTrust_;
02546     int numberPenalties_;
02548     int stopNumberIterations_;
02551     double penaltyScaleFactor_;
02553     int numberAnalyzeIterations_;
02555     double * analyzeResults_;
02557     int numberInfeasibleNodes_;
02564     int problemType_;
02566     int printFrequency_;
02568     int numberCutGenerators_;
02569     // Cut generators
02570     CbcCutGenerator ** generator_;
02571     // Cut generators before any changes
02572     CbcCutGenerator ** virginGenerator_;
02574     int numberHeuristics_;
02576     CbcHeuristic ** heuristic_;
02578     CbcHeuristic * lastHeuristic_;
02580     int fastNodeDepth_;
02582 # ifdef CBC_ONLY_CLP
02583     ClpEventHandler *eventHandler_ ;
02584 # else
02585     CbcEventHandler *eventHandler_ ;
02586 # endif
02587 
02589     int numberObjects_;
02590 
02601     OsiObject ** object_;
02603     bool ownObjects_;
02604 
02606     int * originalColumns_;
02608     int howOftenGlobalScan_;
02611     int numberGlobalViolations_;
02613     int numberExtraIterations_;
02615     int numberExtraNodes_;
02619     double continuousObjective_;
02622     double originalContinuousObjective_;
02624     int continuousInfeasibilities_;
02626     int maximumCutPassesAtRoot_;
02628     int maximumCutPasses_;
02630     int preferredWay_;
02632     int currentPassNumber_;
02634     int maximumWhich_;
02636     int maximumRows_;
02638     int currentDepth_;
02640     mutable CoinThreadRandom randomNumberGenerator_;
02642     CoinWarmStartBasis workingBasis_;
02644     int * whichGenerator_;
02646     int maximumStatistics_;
02648     CbcStatistics ** statistics_;
02650     int maximumDepthActual_;
02652     double numberDJFixed_;
02654     CglTreeProbingInfo * probingInfo_;
02656     int numberFixedAtRoot_;
02658     int numberFixedNow_;
02660     bool stoppedOnGap_;
02662     mutable bool eventHappened_;
02664     int numberLongStrong_;
02666     int numberOldActiveCuts_;
02668     int numberNewCuts_;
02670     int searchStrategy_;
02672     int numberStrongIterations_;
02675     int strongInfo_[7];
02682     OsiBabSolver * solverCharacteristics_;
02684     bool resolveAfterTakeOffCuts_;
02686     int maximumNumberIterations_;
02688     int continuousPriority_;
02690     int numberUpdateItems_;
02692     int maximumNumberUpdateItems_;
02694     CbcObjectUpdateData * updateItems_;
02696     CglStored * storedRowCuts_;
02704     int numberThreads_;
02712     int threadMode_;
02714     CbcBaseModel * master_;
02716     CbcThread * masterThread_;
02718 };
02720 void getIntegerInformation(const OsiObject * object, double & originalLower,
02721                            double & originalUpper) ;
02722 // So we can call from other programs
02723 // Real main program
02724 class OsiClpSolverInterface;
02725 int CbcMain (int argc, const char *argv[], OsiClpSolverInterface & solver, CbcModel ** babSolver);
02726 int CbcMain (int argc, const char *argv[], CbcModel & babSolver);
02727 // four ways of calling
02728 int callCbc(const char * input2, OsiClpSolverInterface& solver1);
02729 int callCbc(const char * input2);
02730 int callCbc(const std::string input2, OsiClpSolverInterface& solver1);
02731 int callCbc(const std::string input2) ;
02732 // When we want to load up CbcModel with options first
02733 void CbcMain0 (CbcModel & babSolver);
02734 int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver);
02735 // two ways of calling
02736 int callCbc(const char * input2, CbcModel & babSolver);
02737 int callCbc(const std::string input2, CbcModel & babSolver);
02738 // And when CbcMain0 already called to initialize
02739 int callCbc1(const char * input2, CbcModel & babSolver);
02740 int callCbc1(const std::string input2, CbcModel & babSolver);
02741 // And when CbcMain0 already called to initialize (with call back) (see CbcMain1 for whereFrom)
02742 int callCbc1(const char * input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02743 int callCbc1(const std::string input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02744 int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02745 // For uniform setting of cut and heuristic options
02746 void setCutAndHeuristicOptions(CbcModel & model);
02747 #endif
02748 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 8 Jun 2012 for Cbc by  doxygen 1.6.1