CbcModel.hpp

Go to the documentation of this file.
00001 /* $Id: CbcModel.hpp 1973 2013-10-19 15:59:44Z 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 "CbcCountRowCut.hpp"
00017 #include "CbcMessage.hpp"
00018 #include "CbcEventHandler.hpp"
00019 #include "ClpDualRowPivot.hpp"
00020 
00021 
00022 class CbcCutGenerator;
00023 class CbcBaseModel;
00024 class OsiRowCut;
00025 class OsiBabSolver;
00026 class OsiRowCutDebugger;
00027 class CglCutGenerator;
00028 class CglStored;
00029 class CbcCutModifier;
00030 class CglTreeProbingInfo;
00031 class CbcHeuristic;
00032 class OsiObject;
00033 class CbcThread;
00034 class CbcTree;
00035 class CbcStrategy;
00036 class CbcFeasibilityBase;
00037 class CbcStatistics;
00038 class CbcFullNodeInfo;
00039 class CbcEventHandler ;
00040 class CglPreProcess;
00041 class OsiClpSolverInterface;
00042 class ClpNodeStuff;
00043 
00044 // #define CBC_CHECK_BASIS 1
00045 
00046 //#############################################################################
00047 
00100 class CbcModel  {
00101 
00102 public:
00103 
00104     enum CbcIntParam {
00106         CbcMaxNumNode = 0,
00108         CbcMaxNumSol,
00118         CbcFathomDiscipline,
00122         CbcPrinting,
00125         CbcNumberBranches,
00127         CbcLastIntParam
00128     };
00129 
00130     enum CbcDblParam {
00133         CbcIntegerTolerance = 0,
00136         CbcInfeasibilityWeight,
00139         CbcCutoffIncrement,
00146         CbcAllowableGap,
00153         CbcAllowableFractionGap,
00156         CbcMaximumSeconds,
00158         CbcCurrentCutoff,
00160         CbcOptimizationDirection,
00162         CbcCurrentObjectiveValue,
00164         CbcCurrentMinimizationObjectiveValue,
00167         CbcStartSeconds,
00175         CbcHeuristicGap,
00183         CbcHeuristicFractionGap,
00185         CbcSmallestChange,
00187         CbcSumChange,
00189         CbcLargestChange,
00191         CbcSmallChange,
00193         CbcLastDblParam
00194     };
00195 
00196     //---------------------------------------------------------------------------
00197 
00198 public:
00200 
00201 
00205     void initialSolve();
00206 
00217     void branchAndBound(int doStatistics = 0);
00218 private:
00219 
00227     bool solveWithCuts(OsiCuts & cuts, int numberTries, CbcNode * node);
00235     int serialCuts(OsiCuts & cuts, CbcNode * node, OsiCuts & slackCuts, int lastNumberCuts);
00243     int parallelCuts(CbcBaseModel * master, OsiCuts & cuts, CbcNode * node, OsiCuts & slackCuts, int lastNumberCuts);
00250     CbcNode ** solveOneNode(int whichSolver, CbcNode * node,
00251                             int & numberNodesOutput, int & status) ;
00253     void resizeWhichGenerator(int numberNow, int numberAfter);
00254 public:
00255 #ifdef CBC_KEEP_DEPRECATED
00256     // See if anyone is using these any more!!
00261     CbcModel *  cleanModel(const double * lower, const double * upper);
00278     int subBranchAndBound(CbcModel * model2,
00279                           CbcModel * presolvedModel,
00280                           int maximumNodes);
00296     int subBranchAndBound(const double * lower, const double * upper,
00297                           int maximumNodes);
00298 
00305     OsiSolverInterface *  strengthenedModel();
00315     CglPreProcess * preProcess( int makeEquality = 0, int numberPasses = 5,
00316                                 int tuning = 5);
00319     void postProcess(CglPreProcess * process);
00320 #endif
00322     void addUpdateInformation(const CbcObjectUpdateData & data);
00323 
00329     int doOneNode(CbcModel * baseModel, CbcNode * & node, CbcNode * & newNode);
00330 
00331 public:
00345     int resolve(CbcNodeInfo * parent, int whereFrom,
00346                 double * saveSolution = NULL,
00347                 double * saveLower = NULL,
00348                 double * saveUpper = NULL);
00350     void makeGlobalCuts(int numberRows, const int * which);
00352     void makeGlobalCut(const OsiRowCut * cut);
00354     void makeGlobalCut(const OsiRowCut & cut);
00356     void makeGlobalCut(const OsiColCut * cut);
00358     void makeGlobalCut(const OsiColCut & cut);
00360   void makePartialCut(const OsiRowCut * cut, const OsiSolverInterface * solver=NULL);
00362     void makeGlobalCuts();
00364     inline const int * whichGenerator() const
00365     { return whichGenerator_;}
00367 
00370 
00382     CbcModel * findCliques(bool makeEquality, int atLeastThisMany,
00383                            int lessThanThis, int defaultValue = 1000);
00384 
00393     CbcModel * integerPresolve(bool weak = false);
00394 
00399     bool integerPresolveThisModel(OsiSolverInterface * originalSolver, bool weak = false);
00400 
00401 
00403     void originalModel(CbcModel * presolvedModel, bool weak);
00404 
00425     bool tightenVubs(int type, bool allowMultipleBinary = false,
00426                      double useCutoff = 1.0e50);
00427 
00433     bool tightenVubs(int numberVubs, const int * which,
00434                      double useCutoff = 1.0e50);
00438     void analyzeObjective();
00439 
00443     void AddIntegers();
00447     void saveModel(OsiSolverInterface * saveSolver, double * checkCutoffForRestart, bool * feasible);
00451     void flipModel();
00452 
00454 
00460 
00462     inline int numberObjects() const {
00463         return numberObjects_;
00464     }
00466     inline void setNumberObjects(int number) {
00467         numberObjects_ = number;
00468     }
00469 
00471     inline OsiObject ** objects() const {
00472         return object_;
00473     }
00474 
00476     const inline OsiObject * object(int which) const {
00477         return object_[which];
00478     }
00480     inline OsiObject * modifiableObject(int which) const {
00481         return object_[which];
00482     }
00483 
00484     void setOptionalInteger(int index);
00485 
00487     void deleteObjects(bool findIntegers = true);
00488 
00493     void addObjects(int numberObjects, OsiObject ** objects);
00494 
00499     void addObjects(int numberObjects, CbcObject ** objects);
00500 
00502     void synchronizeModel() ;
00503 
00513     void findIntegers(bool startAgain, int type = 0);
00514 
00516 
00517     //---------------------------------------------------------------------------
00518 
00528 
00529     inline bool setIntParam(CbcIntParam key, int value) {
00530         intParam_[key] = value;
00531         return true;
00532     }
00534     inline bool setDblParam(CbcDblParam key, double value) {
00535         dblParam_[key] = value;
00536         return true;
00537     }
00539     inline int getIntParam(CbcIntParam key) const {
00540         return intParam_[key];
00541     }
00543     inline double getDblParam(CbcDblParam key) const {
00544         return dblParam_[key];
00545     }
00551     void setCutoff(double value) ;
00552 
00554     inline double getCutoff() const { //double value ;
00555         //solver_->getDblParam(OsiDualObjectiveLimit,value) ;
00556         //assert( dblParam_[CbcCurrentCutoff]== value * solver_->getObjSense());
00557         return dblParam_[CbcCurrentCutoff];
00558     }
00559 
00561     inline bool setMaximumNodes( int value) {
00562         return setIntParam(CbcMaxNumNode, value);
00563     }
00564 
00566     inline int getMaximumNodes() const {
00567         return getIntParam(CbcMaxNumNode);
00568     }
00569 
00574     inline bool setMaximumSolutions( int value) {
00575         return setIntParam(CbcMaxNumSol, value);
00576     }
00581     inline int getMaximumSolutions() const {
00582         return getIntParam(CbcMaxNumSol);
00583     }
00585     inline bool setPrintingMode( int value) {
00586         return setIntParam(CbcPrinting, value);
00587     }
00588 
00590     inline int getPrintingMode() const {
00591         return getIntParam(CbcPrinting);
00592     }
00593 
00598     inline bool setMaximumSeconds( double value) {
00599         return setDblParam(CbcMaximumSeconds, value);
00600     }
00605     inline double getMaximumSeconds() const {
00606         return getDblParam(CbcMaximumSeconds);
00607     }
00609     double getCurrentSeconds() const ;
00610 
00612     bool maximumSecondsReached() const ;
00613 
00617     inline bool setIntegerTolerance( double value) {
00618         return setDblParam(CbcIntegerTolerance, value);
00619     }
00623     inline double getIntegerTolerance() const {
00624         return getDblParam(CbcIntegerTolerance);
00625     }
00626 
00631     inline bool setInfeasibilityWeight( double value) {
00632         return setDblParam(CbcInfeasibilityWeight, value);
00633     }
00638     inline double getInfeasibilityWeight() const {
00639         return getDblParam(CbcInfeasibilityWeight);
00640     }
00641 
00645     inline bool setAllowableGap( double value) {
00646         return setDblParam(CbcAllowableGap, value);
00647     }
00651     inline double getAllowableGap() const {
00652         return getDblParam(CbcAllowableGap);
00653     }
00654 
00658     inline bool setAllowableFractionGap( double value) {
00659         return setDblParam(CbcAllowableFractionGap, value);
00660     }
00664     inline double getAllowableFractionGap() const {
00665         return getDblParam(CbcAllowableFractionGap);
00666     }
00670     inline bool setAllowablePercentageGap( double value) {
00671         return setDblParam(CbcAllowableFractionGap, value*0.01);
00672     }
00676     inline double getAllowablePercentageGap() const {
00677         return 100.0*getDblParam(CbcAllowableFractionGap);
00678     }
00682     inline bool setHeuristicGap( double value) {
00683         return setDblParam(CbcHeuristicGap, value);
00684     }
00688     inline double getHeuristicGap() const {
00689         return getDblParam(CbcHeuristicGap);
00690     }
00691 
00695     inline bool setHeuristicFractionGap( double value) {
00696         return setDblParam(CbcHeuristicFractionGap, value);
00697     }
00701     inline double getHeuristicFractionGap() const {
00702         return getDblParam(CbcHeuristicFractionGap);
00703     }
00708     inline bool setCutoffIncrement( double value) {
00709         return setDblParam(CbcCutoffIncrement, value);
00710     }
00715     inline double getCutoffIncrement() const {
00716         return getDblParam(CbcCutoffIncrement);
00717     }
00719     bool canStopOnGap() const;
00720 
00725     void setHotstartSolution(const double * solution, const int * priorities = NULL) ;
00726 
00728     inline void setMinimumDrop(double value) {
00729         minimumDrop_ = value;
00730     }
00732     inline double getMinimumDrop() const {
00733         return minimumDrop_;
00734     }
00735 
00738     inline void setMaximumCutPassesAtRoot(int value) {
00739         maximumCutPassesAtRoot_ = value;
00740     }
00742     inline int getMaximumCutPassesAtRoot() const {
00743         return maximumCutPassesAtRoot_;
00744     }
00745 
00748     inline void setMaximumCutPasses(int value) {
00749         maximumCutPasses_ = value;
00750     }
00752     inline int getMaximumCutPasses() const {
00753         return maximumCutPasses_;
00754     }
00757     inline int getCurrentPassNumber() const {
00758         return currentPassNumber_;
00759     }
00760 
00766     void setNumberStrong(int number);
00770     inline int numberStrong() const {
00771         return numberStrong_;
00772     }
00775     inline void setPreferredWay(int value) {
00776         preferredWay_ = value;
00777     }
00779     inline int getPreferredWay() const {
00780         return preferredWay_;
00781     }
00783     inline int whenCuts() const {
00784         return whenCuts_;
00785     }
00787     inline void setWhenCuts(int value) {
00788         whenCuts_ = value;
00789     }
00795     bool doCutsNow(int allowForTopOfTree) const;
00796 
00802     void setNumberBeforeTrust(int number);
00805     inline int numberBeforeTrust() const {
00806         return numberBeforeTrust_;
00807     }
00813     void setNumberPenalties(int number);
00816     inline int numberPenalties() const {
00817         return numberPenalties_;
00818     }
00820     inline const CbcFullNodeInfo * topOfTree() const
00821     { return topOfTree_;}
00823     inline void setNumberAnalyzeIterations(int number) {
00824         numberAnalyzeIterations_ = number;
00825     }
00826     inline int numberAnalyzeIterations() const {
00827         return numberAnalyzeIterations_;
00828     }
00831     inline double penaltyScaleFactor() const {
00832         return penaltyScaleFactor_;
00833     }
00836     void setPenaltyScaleFactor(double value);
00844     void inline setProblemType(int number) {
00845         problemType_ = number;
00846     }
00847     inline int problemType() const {
00848         return problemType_;
00849     }
00851     inline int currentDepth() const {
00852         return currentDepth_;
00853     }
00854 
00856     void setHowOftenGlobalScan(int number);
00858     inline int howOftenGlobalScan() const {
00859         return howOftenGlobalScan_;
00860     }
00862     inline int * originalColumns() const {
00863         return originalColumns_;
00864     }
00866     void setOriginalColumns(const int * originalColumns,
00867                             int numberGood=COIN_INT_MAX) ;
00869     OsiRowCut * conflictCut(const OsiSolverInterface * solver, bool & localCuts);
00870 
00878     inline void setPrintFrequency(int number) {
00879         printFrequency_ = number;
00880     }
00882     inline int printFrequency() const {
00883         return printFrequency_;
00884     }
00886 
00887     //---------------------------------------------------------------------------
00889 
00890 
00891     bool isAbandoned() const;
00893     bool isProvenOptimal() const;
00895     bool isProvenInfeasible() const;
00897     bool isContinuousUnbounded() const;
00899     bool isProvenDualInfeasible() const;
00901     bool isNodeLimitReached() const;
00903     bool isSecondsLimitReached() const;
00905     bool isSolutionLimitReached() const;
00907     inline int getIterationCount() const {
00908         return numberIterations_;
00909     }
00911     inline void incrementIterationCount(int value) {
00912         numberIterations_ += value;
00913     }
00915     inline int getNodeCount() const {
00916         return numberNodes_;
00917     }
00919     inline void incrementNodeCount(int value) {
00920         numberNodes_ += value;
00921     }
00923     inline int getExtraNodeCount() const {
00924        return numberExtraNodes_;
00925     }
00935     inline int status() const {
00936         return status_;
00937     }
00938     inline void setProblemStatus(int value) {
00939         status_ = value;
00940     }
00953     inline int secondaryStatus() const {
00954         return secondaryStatus_;
00955     }
00956     inline void setSecondaryStatus(int value) {
00957         secondaryStatus_ = value;
00958     }
00960     bool isInitialSolveAbandoned() const ;
00962     bool isInitialSolveProvenOptimal() const ;
00964     bool isInitialSolveProvenPrimalInfeasible() const ;
00966     bool isInitialSolveProvenDualInfeasible() const ;
00967 
00969 
00970     //---------------------------------------------------------------------------
00983 
00984     inline int numberRowsAtContinuous() const {
00985         return numberRowsAtContinuous_;
00986     }
00987 
00989     inline int getNumCols() const {
00990         return solver_->getNumCols();
00991     }
00992 
00994     inline int getNumRows() const {
00995         return solver_->getNumRows();
00996     }
00997 
00999     inline CoinBigIndex getNumElements() const {
01000         return solver_->getNumElements();
01001     }
01002 
01004     inline int numberIntegers() const {
01005         return numberIntegers_;
01006     }
01007     // Integer variables
01008     inline const int * integerVariable() const {
01009         return integerVariable_;
01010     }
01012     inline char integerType(int i) const {
01013         assert (integerInfo_);
01014         assert (integerInfo_[i] == 0 || integerInfo_[i] == 1);
01015         return integerInfo_[i];
01016     }
01018     inline const char * integerType() const {
01019         return integerInfo_;
01020     }
01021 
01023     inline const double * getColLower() const {
01024         return solver_->getColLower();
01025     }
01026 
01028     inline const double * getColUpper() const {
01029         return solver_->getColUpper();
01030     }
01031 
01041     inline const char * getRowSense() const {
01042         return solver_->getRowSense();
01043     }
01044 
01053     inline const double * getRightHandSide() const {
01054         return solver_->getRightHandSide();
01055     }
01056 
01065     inline const double * getRowRange() const {
01066         return solver_->getRowRange();
01067     }
01068 
01070     inline const double * getRowLower() const {
01071         return solver_->getRowLower();
01072     }
01073 
01075     inline const double * getRowUpper() const {
01076         return solver_->getRowUpper();
01077     }
01078 
01080     inline const double * getObjCoefficients() const {
01081         return solver_->getObjCoefficients();
01082     }
01083 
01085     inline double getObjSense() const {
01086         //assert (dblParam_[CbcOptimizationDirection]== solver_->getObjSense());
01087         return dblParam_[CbcOptimizationDirection];
01088     }
01089 
01091     inline bool isContinuous(int colIndex) const {
01092         return solver_->isContinuous(colIndex);
01093     }
01094 
01096     inline bool isBinary(int colIndex) const {
01097         return solver_->isBinary(colIndex);
01098     }
01099 
01104     inline bool isInteger(int colIndex) const {
01105         return solver_->isInteger(colIndex);
01106     }
01107 
01109     inline bool isIntegerNonBinary(int colIndex) const {
01110         return solver_->isIntegerNonBinary(colIndex);
01111     }
01112 
01114     inline bool isFreeBinary(int colIndex) const {
01115         return solver_->isFreeBinary(colIndex) ;
01116     }
01117 
01119     inline const CoinPackedMatrix * getMatrixByRow() const {
01120         return solver_->getMatrixByRow();
01121     }
01122 
01124     inline const CoinPackedMatrix * getMatrixByCol() const {
01125         return solver_->getMatrixByCol();
01126     }
01127 
01129     inline double getInfinity() const {
01130         return solver_->getInfinity();
01131     }
01133     inline const double * getCbcColLower() const {
01134         return cbcColLower_;
01135     }
01137     inline const double * getCbcColUpper() const {
01138         return cbcColUpper_;
01139     }
01141     inline const double * getCbcRowLower() const {
01142         return cbcRowLower_;
01143     }
01145     inline const double * getCbcRowUpper() const {
01146         return cbcRowUpper_;
01147     }
01149     inline const double * getCbcColSolution() const {
01150         return cbcColSolution_;
01151     }
01153     inline const double * getCbcRowPrice() const {
01154         return cbcRowPrice_;
01155     }
01157     inline const double * getCbcReducedCost() const {
01158         return cbcReducedCost_;
01159     }
01161     inline const double * getCbcRowActivity() const {
01162         return cbcRowActivity_;
01163     }
01165 
01166 
01169 
01170     inline double * continuousSolution() const {
01171         return continuousSolution_;
01172     }
01177     inline int * usedInSolution() const {
01178         return usedInSolution_;
01179     }
01181     void incrementUsed(const double * solution);
01183     void setBestSolution(CBC_Message how,
01184                          double & objectiveValue, const double *solution,
01185                          int fixVariables = 0);
01187     void setBestObjectiveValue( double objectiveValue);
01189     CbcEventHandler::CbcAction dealWithEventHandler(CbcEventHandler::CbcEvent event,
01190             double objValue,
01191             const double * solution);
01192 
01200     virtual double checkSolution(double cutoff, double * solution,
01201                          int fixVariables, double originalObjValue);
01208     bool feasibleSolution(int & numberIntegerInfeasibilities,
01209                           int & numberObjectInfeasibilities) const;
01210 
01216     inline double * currentSolution() const {
01217         return currentSolution_;
01218     }
01222     inline const double * testSolution() const {
01223         return testSolution_;
01224     }
01225     inline void setTestSolution(const double * solution) {
01226         testSolution_ = solution;
01227     }
01229     void reserveCurrentSolution(const double * solution = NULL);
01230 
01232     inline const double * getColSolution() const {
01233         return solver_->getColSolution();
01234     }
01235 
01237     inline const double * getRowPrice() const {
01238         return solver_->getRowPrice();
01239     }
01240 
01242     inline const double * getReducedCost() const {
01243         return solver_->getReducedCost();
01244     }
01245 
01247     inline const double * getRowActivity() const {
01248         return solver_->getRowActivity();
01249     }
01250 
01252     inline double getCurrentObjValue() const {
01253         return dblParam_[CbcCurrentObjectiveValue];
01254     }
01256     inline double getCurrentMinimizationObjValue() const {
01257         return dblParam_[CbcCurrentMinimizationObjectiveValue];
01258     }
01259 
01261     inline double getMinimizationObjValue() const {
01262         return bestObjective_;
01263     }
01265     inline void setMinimizationObjValue(double value) {
01266         bestObjective_ = value;
01267     }
01268 
01270     inline double getObjValue() const {
01271         return bestObjective_ * solver_->getObjSense() ;
01272     }
01278     double getBestPossibleObjValue() const;
01280     inline void setObjValue(double value) {
01281         bestObjective_ = value * solver_->getObjSense() ;
01282     }
01284     inline double getSolverObjValue() const {
01285         return solver_->getObjValue() * solver_->getObjSense() ;
01286     }
01287 
01294     inline double * bestSolution() const {
01295         return bestSolution_;
01296     }
01303     void setBestSolution(const double * solution, int numberColumns,
01304                          double objectiveValue, bool check = false);
01305 
01307     inline int getSolutionCount() const {
01308         return numberSolutions_;
01309     }
01310 
01312     inline void setSolutionCount(int value) {
01313         numberSolutions_ = value;
01314     }
01316     int numberSavedSolutions() const;
01318     inline int maximumSavedSolutions() const {
01319         return maximumSavedSolutions_;
01320     }
01322     void setMaximumSavedSolutions(int value);
01324     const double * savedSolution(int which) const;
01326     double savedSolutionObjective(int which) const;
01328     void deleteSavedSolution(int which);
01329 
01338     inline int phase() const {
01339         return phase_;
01340     }
01341 
01343     inline int getNumberHeuristicSolutions() const {
01344         return numberHeuristicSolutions_;
01345     }
01347     inline void setNumberHeuristicSolutions(int value) {
01348         numberHeuristicSolutions_ = value;
01349     }
01350 
01352     inline void setObjSense(double s) {
01353         dblParam_[CbcOptimizationDirection] = s;
01354         solver_->setObjSense(s);
01355     }
01356 
01358     inline double getContinuousObjective() const {
01359         return originalContinuousObjective_;
01360     }
01361     inline void setContinuousObjective(double value) {
01362         originalContinuousObjective_ = value;
01363     }
01365     inline int getContinuousInfeasibilities() const {
01366         return continuousInfeasibilities_;
01367     }
01368     inline void setContinuousInfeasibilities(int value) {
01369         continuousInfeasibilities_ = value;
01370     }
01372     inline double rootObjectiveAfterCuts() const {
01373         return continuousObjective_;
01374     }
01376     inline double sumChangeObjective() const {
01377         return sumChangeObjective1_;
01378     }
01381     inline int numberGlobalViolations() const {
01382         return numberGlobalViolations_;
01383     }
01384     inline void clearNumberGlobalViolations() {
01385         numberGlobalViolations_ = 0;
01386     }
01388     inline bool resolveAfterTakeOffCuts() const {
01389         return resolveAfterTakeOffCuts_;
01390     }
01391     inline void setResolveAfterTakeOffCuts(bool yesNo) {
01392         resolveAfterTakeOffCuts_ = yesNo;
01393     }
01395     inline int maximumRows() const {
01396         return maximumRows_;
01397     }
01399     inline CoinWarmStartBasis & workingBasis() {
01400         return workingBasis_;
01401     }
01403     inline int getStopNumberIterations() const {
01404         return stopNumberIterations_;
01405     }
01407     inline void setStopNumberIterations(int value) {
01408         stopNumberIterations_ = value;
01409     }
01411     inline CbcModel * heuristicModel() const
01412     { return heuristicModel_;}
01414     inline void setHeuristicModel(CbcModel * model)
01415     { heuristicModel_ = model;}
01417 
01420     // Comparison functions (which may be overridden by inheritance)
01421     inline CbcCompareBase * nodeComparison() const {
01422         return nodeCompare_;
01423     }
01424     void setNodeComparison(CbcCompareBase * compare);
01425     void setNodeComparison(CbcCompareBase & compare);
01427 
01430     // Feasibility functions (which may be overridden by inheritance)
01431     inline CbcFeasibilityBase * problemFeasibility() const {
01432         return problemFeasibility_;
01433     }
01434     void setProblemFeasibility(CbcFeasibilityBase * feasibility);
01435     void setProblemFeasibility(CbcFeasibilityBase & feasibility);
01437 
01440 
01441     inline CbcTree * tree() const {
01442         return tree_;
01443     }
01445     void passInTreeHandler(CbcTree & tree);
01449     void passInSubTreeModel(CbcModel & model);
01454     CbcModel * subTreeModel(OsiSolverInterface * solver = NULL) const;
01456     inline int numberStoppedSubTrees() const {
01457         return numberStoppedSubTrees_;
01458     }
01460     inline void incrementSubTreeStopped() {
01461         numberStoppedSubTrees_++;
01462     }
01468     inline int typePresolve() const {
01469         return presolve_;
01470     }
01471     inline void setTypePresolve(int value) {
01472         presolve_ = value;
01473     }
01474 
01476 
01482 
01484     inline CbcBranchDecision * branchingMethod() const {
01485         return branchingMethod_;
01486     }
01488     inline void setBranchingMethod(CbcBranchDecision * method) {
01489         delete branchingMethod_;
01490         branchingMethod_ = method->clone();
01491     }
01496     inline void setBranchingMethod(CbcBranchDecision & method) {
01497         delete branchingMethod_;
01498         branchingMethod_ = method.clone();
01499     }
01501     inline CbcCutModifier * cutModifier() const {
01502         return cutModifier_;
01503     }
01505     void setCutModifier(CbcCutModifier * modifier);
01510     void setCutModifier(CbcCutModifier & modifier);
01512 
01515 
01522     inline int stateOfSearch() const {
01523         return stateOfSearch_;
01524     }
01525     inline void setStateOfSearch(int state) {
01526         stateOfSearch_ = state;
01527     }
01529     inline int searchStrategy() const {
01530         return searchStrategy_;
01531     }
01533     inline void setSearchStrategy(int value) {
01534         searchStrategy_ = value;
01535     }
01537     inline int strongStrategy() const {
01538         return strongStrategy_;
01539     }
01541     inline void setStrongStrategy(int value) {
01542         strongStrategy_ = value;
01543     }
01544 
01546     inline int numberCutGenerators() const {
01547         return numberCutGenerators_;
01548     }
01550     inline CbcCutGenerator ** cutGenerators() const {
01551         return generator_;
01552     }
01554     inline CbcCutGenerator * cutGenerator(int i) const {
01555         return generator_[i];
01556     }
01558     inline CbcCutGenerator * virginCutGenerator(int i) const {
01559         return virginGenerator_[i];
01560     }
01569     void addCutGenerator(CglCutGenerator * generator,
01570                          int howOften = 1, const char * name = NULL,
01571                          bool normal = true, bool atSolution = false,
01572                          bool infeasible = false, int howOftenInSub = -100,
01573                          int whatDepth = -1, int whatDepthInSub = -1);
01575 
01580 
01582     inline CbcStrategy * strategy() const {
01583         return strategy_;
01584     }
01586     void setStrategy(CbcStrategy & strategy);
01588     inline void setStrategy(CbcStrategy * strategy) {
01589         strategy_ = strategy;
01590     }
01592     inline CbcModel * parentModel() const {
01593         return parentModel_;
01594     }
01596     inline void setParentModel(CbcModel & parentModel) {
01597         parentModel_ = &parentModel;
01598     }
01600 
01601 
01608     void addHeuristic(CbcHeuristic * generator, const char *name = NULL,
01609                       int before = -1);
01611     inline CbcHeuristic * heuristic(int i) const {
01612         return heuristic_[i];
01613     }
01615     inline int numberHeuristics() const {
01616         return numberHeuristics_;
01617     }
01619     inline void setNumberHeuristics(int value) {
01620         numberHeuristics_ = value;
01621     }
01623     inline CbcHeuristic * lastHeuristic() const {
01624         return lastHeuristic_;
01625     }
01627     inline void setLastHeuristic(CbcHeuristic * last) {
01628         lastHeuristic_ = last;
01629     }
01630 
01649     void passInPriorities(const int * priorities, bool ifNotSimpleIntegers);
01650 
01652     inline int priority(int sequence) const {
01653         return object_[sequence]->priority();
01654     }
01655 
01660     void passInEventHandler(const CbcEventHandler *eventHandler) ;
01661 
01663     inline CbcEventHandler* getEventHandler() const {
01664         return (eventHandler_) ;
01665     }
01666 
01668 
01678     void setApplicationData (void * appData);
01679 
01681     void * getApplicationData() const;
01694     void passInSolverCharacteristics(OsiBabSolver * solverCharacteristics);
01696     inline const OsiBabSolver * solverCharacteristics() const {
01697         return solverCharacteristics_;
01698     }
01700 
01701     //---------------------------------------------------------------------------
01702 
01705 
01706     void passInMessageHandler(CoinMessageHandler * handler);
01708     void newLanguage(CoinMessages::Language language);
01709     inline void setLanguage(CoinMessages::Language language) {
01710         newLanguage(language);
01711     }
01713     inline CoinMessageHandler * messageHandler() const {
01714         return handler_;
01715     }
01717     inline CoinMessages & messages() {
01718         return messages_;
01719     }
01721     inline CoinMessages * messagesPointer() {
01722         return &messages_;
01723     }
01725     void setLogLevel(int value);
01727     inline int logLevel() const {
01728         return handler_->logLevel();
01729     }
01735     inline void setDefaultHandler(bool yesNo) {
01736         defaultHandler_ = yesNo;
01737     }
01739     inline bool defaultHandler() const {
01740         return defaultHandler_;
01741     }
01743     //---------------------------------------------------------------------------
01745 
01746 
01773     inline void setSpecialOptions(int value) {
01774         specialOptions_ = value;
01775     }
01777     inline int specialOptions() const {
01778         return specialOptions_;
01779     }
01781     inline void setRandomSeed(int value) {
01782         randomSeed_ = value;
01783     }
01785     inline int getRandomSeed() const {
01786         return randomSeed_;
01787     }
01789     inline void setMultipleRootTries(int value) {
01790         multipleRootTries_ = value;
01791     }
01793     inline int getMultipleRootTries() const {
01794         return multipleRootTries_;
01795     }
01797     inline void sayEventHappened()
01798     { eventHappened_=true;}
01800     inline bool normalSolver() const {
01801         return (specialOptions_&16) == 0;
01802     }
01807     inline bool waitingForMiniBranchAndBound() const {
01808         return (specialOptions_&1048576) != 0;
01809     }
01832     inline void setMoreSpecialOptions(int value) {
01833         moreSpecialOptions_ = value;
01834     }
01836     inline int moreSpecialOptions() const {
01837         return moreSpecialOptions_;
01838     }
01840     inline void setCutoffAsConstraint(bool yesNo) {
01841       cutoffRowNumber_ = (yesNo) ? -2 : -1;
01842     }
01844     inline void setUseElapsedTime(bool yesNo) {
01845         if (yesNo)
01846           moreSpecialOptions_ |= 131072;
01847         else
01848           moreSpecialOptions_ &= ~131072;
01849     }
01851     inline bool useElapsedTime() const {
01852         return (moreSpecialOptions_&131072)!=0;
01853     }
01855     inline void * temporaryPointer() const
01856     { return temporaryPointer_;}
01858     inline void setTemporaryPointer(void * pointer)
01859     { temporaryPointer_=pointer;}
01861     void goToDantzig(int numberNodes, ClpDualRowPivot *& savePivotMethod);
01863     inline bool ownObjects() const {
01864         return ownObjects_;
01865     }
01867     void checkModel();
01869     //---------------------------------------------------------------------------
01870 
01872 
01873 
01874     CbcModel();
01875 
01877     CbcModel(const OsiSolverInterface &);
01878 
01887     void assignSolver(OsiSolverInterface *&solver, bool deleteSolver = true);
01888 
01900     inline void setModelOwnsSolver (bool ourSolver) {
01901         ownership_ = ourSolver ? (ownership_ | 0x80000000) : (ownership_ & (~0x80000000)) ;
01902     }
01903 
01909     inline bool modelOwnsSolver () {
01910         return ((ownership_&0x80000000) != 0) ;
01911     }
01912 
01916     CbcModel(const CbcModel & rhs, bool cloneHandler = false);
01917 
01919     virtual CbcModel *clone (bool cloneHandler);
01920 
01922     CbcModel & operator=(const CbcModel& rhs);
01923 
01925     virtual ~CbcModel ();
01926 
01928     inline OsiSolverInterface * solver() const {
01929         return solver_;
01930     }
01931 
01933     inline OsiSolverInterface * swapSolver(OsiSolverInterface * solver) {
01934         OsiSolverInterface * returnSolver = solver_;
01935         solver_ = solver;
01936         return returnSolver;
01937     }
01938 
01940     inline OsiSolverInterface * continuousSolver() const {
01941         return continuousSolver_;
01942     }
01943 
01945     inline void createContinuousSolver() {
01946         continuousSolver_ = solver_->clone();
01947     }
01949     inline void clearContinuousSolver() {
01950         delete continuousSolver_;
01951         continuousSolver_ = NULL;
01952     }
01953 
01955     inline OsiSolverInterface * referenceSolver() const {
01956         return referenceSolver_;
01957     }
01958 
01960     void saveReferenceSolver();
01961 
01967     void resetToReferenceSolver();
01968 
01970     void gutsOfDestructor();
01973     void gutsOfDestructor2();
01976     void resetModel();
01982     void gutsOfCopy(const CbcModel & rhs, int mode = 0);
01984     void moveInfo(const CbcModel & rhs);
01986 
01988 
01989 
01990     static bool haveMultiThreadSupport();
01992     CbcThread * masterThread() const {
01993         return masterThread_;
01994     }
01996     CbcNodeInfo ** walkback() const {
01997         return walkback_;
01998     }
02000     inline int getNumberThreads() const {
02001         return numberThreads_;
02002     }
02004     inline void setNumberThreads(int value) {
02005         numberThreads_ = value;
02006     }
02008     inline int getThreadMode() const {
02009         return threadMode_;
02010     }
02020     inline void setThreadMode(int value) {
02021         threadMode_ = value;
02022     }
02029     inline int parallelMode() const {
02030         if (!numberThreads_) {
02031             if ((threadMode_&1) == 0)
02032                 return 0;
02033             else
02034                 return -1;
02035             return 0;
02036         } else {
02037             if ((threadMode_&1) == 0)
02038                 return 1;
02039             else
02040                 return -2;
02041         }
02042     }
02045     bool isLocked() const;
02046 #ifdef CBC_THREAD
02047 
02051     void lockThread();
02055     void unlockThread();
02056 #else
02057     inline void lockThread() {}
02058     inline void unlockThread() {}
02059 #endif
02060 
02067     void setInfoInChild(int type, CbcThread * info);
02074     void moveToModel(CbcModel * baseModel, int mode);
02076     int splitModel(int numberModels, CbcModel ** model,
02077                    int numberNodes);
02079     void startSplitModel(int numberIterations);
02081     void mergeModels(int numberModel, CbcModel ** model,
02082                      int numberNodes);
02084 
02086 
02087 
02088     int getNodeCount2() const {
02089         return numberNodes2_;
02090     }
02092     void setPointers(const OsiSolverInterface * solver);
02098     int reducedCostFix() ;
02102     void synchronizeHandlers(int makeDefault);
02104     void saveExtraSolution(const double * solution, double objectiveValue);
02106     void saveBestSolution(const double * solution, double objectiveValue);
02108     void deleteSolutions();
02110     int resolve(OsiSolverInterface * solver);
02111 #ifdef CLP_RESOLVE
02113     int resolveClp(OsiClpSolverInterface * solver, int type);
02114 #endif
02115 
02119     int chooseBranch(CbcNode * & newNode, int numberPassesLeft,
02120                      CbcNode * oldNode, OsiCuts & cuts,
02121                      bool & resolved, CoinWarmStartBasis *lastws,
02122                      const double * lowerBefore, const double * upperBefore,
02123                      OsiSolverBranch * & branches);
02124     int chooseBranch(CbcNode * newNode, int numberPassesLeft, bool & resolved);
02125 
02132     CoinWarmStartBasis *getEmptyBasis(int ns = 0, int na = 0) const ;
02133 
02145     int takeOffCuts(OsiCuts &cuts,
02146                     bool allowResolve, OsiCuts * saveCuts,
02147                     int numberNewCuts = 0, const OsiRowCut ** newCuts = NULL) ;
02148 
02162     int addCuts(CbcNode * node, CoinWarmStartBasis *&lastws, bool canFix);
02163 
02180     bool addCuts1(CbcNode * node, CoinWarmStartBasis *&lastws);
02184     void previousBounds (CbcNode * node, CbcNodeInfo * where, int iColumn,
02185                          double & lower, double & upper, int force);
02190     void setObjectiveValue(CbcNode * thisNode, const CbcNode * parentNode) const;
02191 
02195     void convertToDynamic();
02197     void synchronizeNumberBeforeTrust(int type = 0);
02199     void zapIntegerInformation(bool leaveObjects = true);
02201     int cliquePseudoCosts(int doStatistics);
02203     void pseudoShadow(int type);
02210     void fillPseudoCosts(double * downCosts, double * upCosts,
02211                          int * priority = NULL,
02212                          int * numberDown = NULL, int * numberUp = NULL,
02213                          int * numberDownInfeasible = NULL,
02214                          int * numberUpInfeasible = NULL) const;
02220     void doHeuristicsAtRoot(int deleteHeuristicsAfterwards = 0);
02222     void adjustHeuristics();
02224     inline const double * hotstartSolution() const {
02225         return hotstartSolution_;
02226     }
02228     inline const int * hotstartPriorities() const {
02229         return hotstartPriorities_;
02230     }
02231 
02233     inline CbcCountRowCut ** addedCuts() const {
02234         return addedCuts_;
02235     }
02237     inline int currentNumberCuts() const {
02238         return currentNumberCuts_;
02239     }
02241     inline CbcRowCuts * globalCuts() {
02242         return &globalCuts_;
02243     }
02245     void setNextRowCut(const OsiRowCut & cut);
02247     inline CbcNode * currentNode() const {
02248         return currentNode_;
02249     }
02251     inline CglTreeProbingInfo * probingInfo() const {
02252         return probingInfo_;
02253     }
02255     inline CoinThreadRandom * randomNumberGenerator() {
02256         return &randomNumberGenerator_;
02257     }
02259     inline void setNumberStrongIterations(int number) {
02260         numberStrongIterations_ = number;
02261     }
02263     inline int numberStrongIterations() const {
02264         return numberStrongIterations_;
02265     }
02267     inline int maximumNumberIterations() const {
02268         return maximumNumberIterations_;
02269     }
02271     inline void setMaximumNumberIterations(int value) {
02272         maximumNumberIterations_ = value;
02273     }
02275     inline void setFastNodeDepth(int value) {
02276         fastNodeDepth_ = value;
02277     }
02279     inline int fastNodeDepth() const {
02280         return fastNodeDepth_;
02281     }
02283     inline int continuousPriority() const {
02284         return continuousPriority_;
02285     }
02287     inline void setContinuousPriority(int value) {
02288         continuousPriority_ = value;
02289     }
02290     inline void incrementExtra(int nodes, int iterations) {
02291         numberExtraNodes_ += nodes;
02292         numberExtraIterations_ += iterations;
02293     }
02295     inline int numberExtraIterations() const {
02296         return numberExtraIterations_;
02297     }
02299     void incrementStrongInfo(int numberTimes, int numberIterations,
02300                              int numberFixed, bool ifInfeasible);
02302     inline const int * strongInfo() const {
02303         return strongInfo_;
02304     }
02305 
02307     inline int * mutableStrongInfo() {
02308         return strongInfo_;
02309     }
02311     CglStored * storedRowCuts() const {
02312         return storedRowCuts_;
02313     }
02315     void setStoredRowCuts(CglStored * cuts) {
02316         storedRowCuts_ = cuts;
02317     }
02319     inline bool allDynamic () const {
02320         return ((ownership_&0x40000000) != 0) ;
02321     }
02323     void generateCpp( FILE * fp, int options);
02325     OsiBranchingInformation usefulInformation() const;
02332     inline void setBestSolutionBasis(const CoinWarmStartBasis & bestSolutionBasis) {
02333         bestSolutionBasis_ = bestSolutionBasis;
02334     }
02336     void redoWalkBack();
02338 
02339 //---------------------------------------------------------------------------
02340 
02341 private:
02343 
02344 
02346     OsiSolverInterface * solver_;
02347 
02353     unsigned int ownership_ ;
02354 
02356     OsiSolverInterface * continuousSolver_;
02357 
02359     OsiSolverInterface * referenceSolver_;
02360 
02362     CoinMessageHandler * handler_;
02363 
02369     bool defaultHandler_;
02370 
02372     CoinMessages messages_;
02373 
02375     int intParam_[CbcLastIntParam];
02376 
02378     double dblParam_[CbcLastDblParam];
02379 
02388     mutable CoinWarmStart *emptyWarmStart_ ;
02389 
02391     double bestObjective_;
02393     double bestPossibleObjective_;
02395     double sumChangeObjective1_;
02397     double sumChangeObjective2_;
02398 
02400     double * bestSolution_;
02402     double ** savedSolutions_;
02403 
02408     double * currentSolution_;
02412     mutable const double * testSolution_;
02419     CoinWarmStartBasis bestSolutionBasis_ ;
02421     CbcRowCuts globalCuts_;
02423     CbcRowCuts * globalConflictCuts_;
02424 
02426     double minimumDrop_;
02428     int numberSolutions_;
02430     int numberSavedSolutions_;
02432     int maximumSavedSolutions_;
02439     int stateOfSearch_;
02441     int whenCuts_;
02443     double * hotstartSolution_;
02445     int * hotstartPriorities_;
02447     int numberHeuristicSolutions_;
02449     int numberNodes_;
02453     int numberNodes2_;
02455     int numberIterations_;
02457     int numberSolves_;
02459     int status_;
02470     int secondaryStatus_;
02472     int numberIntegers_;
02474     int numberRowsAtContinuous_;
02480     int cutoffRowNumber_;
02482     int maximumNumberCuts_;
02491     int phase_;
02492 
02494     int currentNumberCuts_;
02495 
02500     int maximumDepth_;
02506     CbcNodeInfo ** walkback_;
02507     CbcNodeInfo ** lastNodeInfo_;
02508     const OsiRowCut ** lastCut_;
02509     int lastDepth_;
02510     int lastNumberCuts2_;
02511     int maximumCuts_;
02512     int * lastNumberCuts_;
02513 
02521     CbcCountRowCut ** addedCuts_;
02522 
02526     OsiRowCut * nextRowCut_;
02527 
02529     CbcNode * currentNode_;
02530 
02532     int * integerVariable_;
02534     char * integerInfo_;
02536     double * continuousSolution_;
02538     int * usedInSolution_;
02562     int specialOptions_;
02577     int moreSpecialOptions_;
02579     CbcCompareBase * nodeCompare_;
02581     CbcFeasibilityBase * problemFeasibility_;
02583     CbcTree * tree_;
02585     CbcFullNodeInfo * topOfTree_;
02587     CbcModel * subTreeModel_;
02589     CbcModel * heuristicModel_;
02591     int numberStoppedSubTrees_;
02593     CbcBranchDecision * branchingMethod_;
02595     CbcCutModifier * cutModifier_;
02597     CbcStrategy * strategy_;
02599     CbcModel * parentModel_;
02605 
02606     const double * cbcColLower_;
02608     const double * cbcColUpper_;
02610     const double * cbcRowLower_;
02612     const double * cbcRowUpper_;
02614     const double * cbcColSolution_;
02616     const double * cbcRowPrice_;
02618     const double * cbcReducedCost_;
02620     const double * cbcRowActivity_;
02622     void * appData_;
02624     int presolve_;
02628     int numberStrong_;
02634     int numberBeforeTrust_;
02638     int numberPenalties_;
02640     int stopNumberIterations_;
02643     double penaltyScaleFactor_;
02645     int numberAnalyzeIterations_;
02647     double * analyzeResults_;
02649     void * temporaryPointer_;
02651     int numberInfeasibleNodes_;
02658     int problemType_;
02660     int printFrequency_;
02662     int numberCutGenerators_;
02663     // Cut generators
02664     CbcCutGenerator ** generator_;
02665     // Cut generators before any changes
02666     CbcCutGenerator ** virginGenerator_;
02668     int numberHeuristics_;
02670     CbcHeuristic ** heuristic_;
02672     CbcHeuristic * lastHeuristic_;
02674     int fastNodeDepth_;
02676 # ifdef CBC_ONLY_CLP
02677     ClpEventHandler *eventHandler_ ;
02678 # else
02679     CbcEventHandler *eventHandler_ ;
02680 # endif
02681 
02683     int numberObjects_;
02684 
02695     OsiObject ** object_;
02697     bool ownObjects_;
02698 
02700     int * originalColumns_;
02702     int howOftenGlobalScan_;
02705     int numberGlobalViolations_;
02707     int numberExtraIterations_;
02709     int numberExtraNodes_;
02713     double continuousObjective_;
02716     double originalContinuousObjective_;
02718     int continuousInfeasibilities_;
02720     int maximumCutPassesAtRoot_;
02722     int maximumCutPasses_;
02724     int preferredWay_;
02726     int currentPassNumber_;
02728     int maximumWhich_;
02730     int maximumRows_;
02732     int randomSeed_;
02734     int multipleRootTries_;
02736     int currentDepth_;
02738     mutable CoinThreadRandom randomNumberGenerator_;
02740     CoinWarmStartBasis workingBasis_;
02742     int * whichGenerator_;
02744     int maximumStatistics_;
02746     CbcStatistics ** statistics_;
02748     int maximumDepthActual_;
02750     double numberDJFixed_;
02752     CglTreeProbingInfo * probingInfo_;
02754     int numberFixedAtRoot_;
02756     int numberFixedNow_;
02758     bool stoppedOnGap_;
02760     mutable bool eventHappened_;
02762     int numberLongStrong_;
02764     int numberOldActiveCuts_;
02766     int numberNewCuts_;
02768     int searchStrategy_;
02780     int strongStrategy_;
02782     int numberStrongIterations_;
02785     int strongInfo_[7];
02792     OsiBabSolver * solverCharacteristics_;
02794     bool resolveAfterTakeOffCuts_;
02796     int maximumNumberIterations_;
02798     int continuousPriority_;
02800     int numberUpdateItems_;
02802     int maximumNumberUpdateItems_;
02804     CbcObjectUpdateData * updateItems_;
02806     CglStored * storedRowCuts_;
02814     int numberThreads_;
02822     int threadMode_;
02824     CbcBaseModel * master_;
02826     CbcThread * masterThread_;
02828 };
02830 void getIntegerInformation(const OsiObject * object, double & originalLower,
02831                            double & originalUpper) ;
02832 // So we can call from other programs
02833 // Real main program
02834 class OsiClpSolverInterface;
02835 int CbcMain (int argc, const char *argv[], OsiClpSolverInterface & solver, CbcModel ** babSolver);
02836 int CbcMain (int argc, const char *argv[], CbcModel & babSolver);
02837 // four ways of calling
02838 int callCbc(const char * input2, OsiClpSolverInterface& solver1);
02839 int callCbc(const char * input2);
02840 int callCbc(const std::string input2, OsiClpSolverInterface& solver1);
02841 int callCbc(const std::string input2) ;
02842 // When we want to load up CbcModel with options first
02843 void CbcMain0 (CbcModel & babSolver);
02844 int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver);
02845 // two ways of calling
02846 int callCbc(const char * input2, CbcModel & babSolver);
02847 int callCbc(const std::string input2, CbcModel & babSolver);
02848 // And when CbcMain0 already called to initialize
02849 int callCbc1(const char * input2, CbcModel & babSolver);
02850 int callCbc1(const std::string input2, CbcModel & babSolver);
02851 // And when CbcMain0 already called to initialize (with call back) (see CbcMain1 for whereFrom)
02852 int callCbc1(const char * input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02853 int callCbc1(const std::string input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02854 int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02855 // For uniform setting of cut and heuristic options
02856 void setCutAndHeuristicOptions(CbcModel & model);
02857 #endif
02858 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 15 Nov 2013 for Cbc by  doxygen 1.6.1