CbcModel.hpp

Go to the documentation of this file.
00001 /* $Id: CbcModel.hpp 1902 2013-04-10 16:58:16Z 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     CbcModel & operator=(const CbcModel& rhs);
01920 
01922     virtual ~CbcModel ();
01923 
01925     inline OsiSolverInterface * solver() const {
01926         return solver_;
01927     }
01928 
01930     inline OsiSolverInterface * swapSolver(OsiSolverInterface * solver) {
01931         OsiSolverInterface * returnSolver = solver_;
01932         solver_ = solver;
01933         return returnSolver;
01934     }
01935 
01937     inline OsiSolverInterface * continuousSolver() const {
01938         return continuousSolver_;
01939     }
01940 
01942     inline void createContinuousSolver() {
01943         continuousSolver_ = solver_->clone();
01944     }
01946     inline void clearContinuousSolver() {
01947         delete continuousSolver_;
01948         continuousSolver_ = NULL;
01949     }
01950 
01952     inline OsiSolverInterface * referenceSolver() const {
01953         return referenceSolver_;
01954     }
01955 
01957     void saveReferenceSolver();
01958 
01964     void resetToReferenceSolver();
01965 
01967     void gutsOfDestructor();
01970     void gutsOfDestructor2();
01973     void resetModel();
01979     void gutsOfCopy(const CbcModel & rhs, int mode = 0);
01981     void moveInfo(const CbcModel & rhs);
01983 
01985 
01986 
01987     static bool haveMultiThreadSupport();
01989     CbcThread * masterThread() const {
01990         return masterThread_;
01991     }
01993     CbcNodeInfo ** walkback() const {
01994         return walkback_;
01995     }
01997     inline int getNumberThreads() const {
01998         return numberThreads_;
01999     }
02001     inline void setNumberThreads(int value) {
02002         numberThreads_ = value;
02003     }
02005     inline int getThreadMode() const {
02006         return threadMode_;
02007     }
02017     inline void setThreadMode(int value) {
02018         threadMode_ = value;
02019     }
02026     inline int parallelMode() const {
02027         if (!numberThreads_) {
02028             if ((threadMode_&1) == 0)
02029                 return 0;
02030             else
02031                 return -1;
02032             return 0;
02033         } else {
02034             if ((threadMode_&1) == 0)
02035                 return 1;
02036             else
02037                 return -2;
02038         }
02039     }
02042     bool isLocked() const;
02043 #ifdef CBC_THREAD
02044 
02048     void lockThread();
02052     void unlockThread();
02053 #else
02054     inline void lockThread() {}
02055     inline void unlockThread() {}
02056 #endif
02057 
02064     void setInfoInChild(int type, CbcThread * info);
02071     void moveToModel(CbcModel * baseModel, int mode);
02073     int splitModel(int numberModels, CbcModel ** model,
02074                    int numberNodes);
02076     void startSplitModel(int numberIterations);
02078     void mergeModels(int numberModel, CbcModel ** model,
02079                      int numberNodes);
02081 
02083 
02084 
02085     int getNodeCount2() const {
02086         return numberNodes2_;
02087     }
02089     void setPointers(const OsiSolverInterface * solver);
02095     int reducedCostFix() ;
02099     void synchronizeHandlers(int makeDefault);
02101     void saveExtraSolution(const double * solution, double objectiveValue);
02103     void saveBestSolution(const double * solution, double objectiveValue);
02105     void deleteSolutions();
02107     int resolve(OsiSolverInterface * solver);
02108 #ifdef CLP_RESOLVE
02110     int resolveClp(OsiClpSolverInterface * solver, int type);
02111 #endif
02112 
02116     int chooseBranch(CbcNode * & newNode, int numberPassesLeft,
02117                      CbcNode * oldNode, OsiCuts & cuts,
02118                      bool & resolved, CoinWarmStartBasis *lastws,
02119                      const double * lowerBefore, const double * upperBefore,
02120                      OsiSolverBranch * & branches);
02121     int chooseBranch(CbcNode * newNode, int numberPassesLeft, bool & resolved);
02122 
02129     CoinWarmStartBasis *getEmptyBasis(int ns = 0, int na = 0) const ;
02130 
02142     int takeOffCuts(OsiCuts &cuts,
02143                     bool allowResolve, OsiCuts * saveCuts,
02144                     int numberNewCuts = 0, const OsiRowCut ** newCuts = NULL) ;
02145 
02159     int addCuts(CbcNode * node, CoinWarmStartBasis *&lastws, bool canFix);
02160 
02177     bool addCuts1(CbcNode * node, CoinWarmStartBasis *&lastws);
02181     void previousBounds (CbcNode * node, CbcNodeInfo * where, int iColumn,
02182                          double & lower, double & upper, int force);
02187     void setObjectiveValue(CbcNode * thisNode, const CbcNode * parentNode) const;
02188 
02192     void convertToDynamic();
02194     void synchronizeNumberBeforeTrust(int type = 0);
02196     void zapIntegerInformation(bool leaveObjects = true);
02198     int cliquePseudoCosts(int doStatistics);
02200     void pseudoShadow(int type);
02207     void fillPseudoCosts(double * downCosts, double * upCosts,
02208                          int * priority = NULL,
02209                          int * numberDown = NULL, int * numberUp = NULL,
02210                          int * numberDownInfeasible = NULL,
02211                          int * numberUpInfeasible = NULL) const;
02217     void doHeuristicsAtRoot(int deleteHeuristicsAfterwards = 0);
02219     void adjustHeuristics();
02221     inline const double * hotstartSolution() const {
02222         return hotstartSolution_;
02223     }
02225     inline const int * hotstartPriorities() const {
02226         return hotstartPriorities_;
02227     }
02228 
02230     inline CbcCountRowCut ** addedCuts() const {
02231         return addedCuts_;
02232     }
02234     inline int currentNumberCuts() const {
02235         return currentNumberCuts_;
02236     }
02238     inline CbcRowCuts * globalCuts() {
02239         return &globalCuts_;
02240     }
02242     void setNextRowCut(const OsiRowCut & cut);
02244     inline CbcNode * currentNode() const {
02245         return currentNode_;
02246     }
02248     inline CglTreeProbingInfo * probingInfo() const {
02249         return probingInfo_;
02250     }
02252     inline CoinThreadRandom * randomNumberGenerator() {
02253         return &randomNumberGenerator_;
02254     }
02256     inline void setNumberStrongIterations(int number) {
02257         numberStrongIterations_ = number;
02258     }
02260     inline int numberStrongIterations() const {
02261         return numberStrongIterations_;
02262     }
02264     inline int maximumNumberIterations() const {
02265         return maximumNumberIterations_;
02266     }
02268     inline void setMaximumNumberIterations(int value) {
02269         maximumNumberIterations_ = value;
02270     }
02272     inline void setFastNodeDepth(int value) {
02273         fastNodeDepth_ = value;
02274     }
02276     inline int fastNodeDepth() const {
02277         return fastNodeDepth_;
02278     }
02280     inline int continuousPriority() const {
02281         return continuousPriority_;
02282     }
02284     inline void setContinuousPriority(int value) {
02285         continuousPriority_ = value;
02286     }
02287     inline void incrementExtra(int nodes, int iterations) {
02288         numberExtraNodes_ += nodes;
02289         numberExtraIterations_ += iterations;
02290     }
02292     inline int numberExtraIterations() const {
02293         return numberExtraIterations_;
02294     }
02296     void incrementStrongInfo(int numberTimes, int numberIterations,
02297                              int numberFixed, bool ifInfeasible);
02299     inline const int * strongInfo() const {
02300         return strongInfo_;
02301     }
02302 
02304     inline int * mutableStrongInfo() {
02305         return strongInfo_;
02306     }
02308     CglStored * storedRowCuts() const {
02309         return storedRowCuts_;
02310     }
02312     void setStoredRowCuts(CglStored * cuts) {
02313         storedRowCuts_ = cuts;
02314     }
02316     inline bool allDynamic () const {
02317         return ((ownership_&0x40000000) != 0) ;
02318     }
02320     void generateCpp( FILE * fp, int options);
02322     OsiBranchingInformation usefulInformation() const;
02329     inline void setBestSolutionBasis(const CoinWarmStartBasis & bestSolutionBasis) {
02330         bestSolutionBasis_ = bestSolutionBasis;
02331     }
02333     void redoWalkBack();
02335 
02336 //---------------------------------------------------------------------------
02337 
02338 private:
02340 
02341 
02343     OsiSolverInterface * solver_;
02344 
02350     unsigned int ownership_ ;
02351 
02353     OsiSolverInterface * continuousSolver_;
02354 
02356     OsiSolverInterface * referenceSolver_;
02357 
02359     CoinMessageHandler * handler_;
02360 
02366     bool defaultHandler_;
02367 
02369     CoinMessages messages_;
02370 
02372     int intParam_[CbcLastIntParam];
02373 
02375     double dblParam_[CbcLastDblParam];
02376 
02385     mutable CoinWarmStart *emptyWarmStart_ ;
02386 
02388     double bestObjective_;
02390     double bestPossibleObjective_;
02392     double sumChangeObjective1_;
02394     double sumChangeObjective2_;
02395 
02397     double * bestSolution_;
02399     double ** savedSolutions_;
02400 
02405     double * currentSolution_;
02409     mutable const double * testSolution_;
02416     CoinWarmStartBasis bestSolutionBasis_ ;
02418     CbcRowCuts globalCuts_;
02420     CbcRowCuts * globalConflictCuts_;
02421 
02423     double minimumDrop_;
02425     int numberSolutions_;
02427     int numberSavedSolutions_;
02429     int maximumSavedSolutions_;
02436     int stateOfSearch_;
02438     int whenCuts_;
02440     double * hotstartSolution_;
02442     int * hotstartPriorities_;
02444     int numberHeuristicSolutions_;
02446     int numberNodes_;
02450     int numberNodes2_;
02452     int numberIterations_;
02454     int numberSolves_;
02456     int status_;
02467     int secondaryStatus_;
02469     int numberIntegers_;
02471     int numberRowsAtContinuous_;
02477     int cutoffRowNumber_;
02479     int maximumNumberCuts_;
02488     int phase_;
02489 
02491     int currentNumberCuts_;
02492 
02497     int maximumDepth_;
02503     CbcNodeInfo ** walkback_;
02504     CbcNodeInfo ** lastNodeInfo_;
02505     const OsiRowCut ** lastCut_;
02506     int lastDepth_;
02507     int lastNumberCuts2_;
02508     int maximumCuts_;
02509     int * lastNumberCuts_;
02510 
02518     CbcCountRowCut ** addedCuts_;
02519 
02523     OsiRowCut * nextRowCut_;
02524 
02526     CbcNode * currentNode_;
02527 
02529     int * integerVariable_;
02531     char * integerInfo_;
02533     double * continuousSolution_;
02535     int * usedInSolution_;
02559     int specialOptions_;
02574     int moreSpecialOptions_;
02576     CbcCompareBase * nodeCompare_;
02578     CbcFeasibilityBase * problemFeasibility_;
02580     CbcTree * tree_;
02582     CbcFullNodeInfo * topOfTree_;
02584     CbcModel * subTreeModel_;
02586     CbcModel * heuristicModel_;
02588     int numberStoppedSubTrees_;
02590     CbcBranchDecision * branchingMethod_;
02592     CbcCutModifier * cutModifier_;
02594     CbcStrategy * strategy_;
02596     CbcModel * parentModel_;
02602 
02603     const double * cbcColLower_;
02605     const double * cbcColUpper_;
02607     const double * cbcRowLower_;
02609     const double * cbcRowUpper_;
02611     const double * cbcColSolution_;
02613     const double * cbcRowPrice_;
02615     const double * cbcReducedCost_;
02617     const double * cbcRowActivity_;
02619     void * appData_;
02621     int presolve_;
02625     int numberStrong_;
02631     int numberBeforeTrust_;
02635     int numberPenalties_;
02637     int stopNumberIterations_;
02640     double penaltyScaleFactor_;
02642     int numberAnalyzeIterations_;
02644     double * analyzeResults_;
02646     void * temporaryPointer_;
02648     int numberInfeasibleNodes_;
02655     int problemType_;
02657     int printFrequency_;
02659     int numberCutGenerators_;
02660     // Cut generators
02661     CbcCutGenerator ** generator_;
02662     // Cut generators before any changes
02663     CbcCutGenerator ** virginGenerator_;
02665     int numberHeuristics_;
02667     CbcHeuristic ** heuristic_;
02669     CbcHeuristic * lastHeuristic_;
02671     int fastNodeDepth_;
02673 # ifdef CBC_ONLY_CLP
02674     ClpEventHandler *eventHandler_ ;
02675 # else
02676     CbcEventHandler *eventHandler_ ;
02677 # endif
02678 
02680     int numberObjects_;
02681 
02692     OsiObject ** object_;
02694     bool ownObjects_;
02695 
02697     int * originalColumns_;
02699     int howOftenGlobalScan_;
02702     int numberGlobalViolations_;
02704     int numberExtraIterations_;
02706     int numberExtraNodes_;
02710     double continuousObjective_;
02713     double originalContinuousObjective_;
02715     int continuousInfeasibilities_;
02717     int maximumCutPassesAtRoot_;
02719     int maximumCutPasses_;
02721     int preferredWay_;
02723     int currentPassNumber_;
02725     int maximumWhich_;
02727     int maximumRows_;
02729     int randomSeed_;
02731     int multipleRootTries_;
02733     int currentDepth_;
02735     mutable CoinThreadRandom randomNumberGenerator_;
02737     CoinWarmStartBasis workingBasis_;
02739     int * whichGenerator_;
02741     int maximumStatistics_;
02743     CbcStatistics ** statistics_;
02745     int maximumDepthActual_;
02747     double numberDJFixed_;
02749     CglTreeProbingInfo * probingInfo_;
02751     int numberFixedAtRoot_;
02753     int numberFixedNow_;
02755     bool stoppedOnGap_;
02757     mutable bool eventHappened_;
02759     int numberLongStrong_;
02761     int numberOldActiveCuts_;
02763     int numberNewCuts_;
02765     int searchStrategy_;
02777     int strongStrategy_;
02779     int numberStrongIterations_;
02782     int strongInfo_[7];
02789     OsiBabSolver * solverCharacteristics_;
02791     bool resolveAfterTakeOffCuts_;
02793     int maximumNumberIterations_;
02795     int continuousPriority_;
02797     int numberUpdateItems_;
02799     int maximumNumberUpdateItems_;
02801     CbcObjectUpdateData * updateItems_;
02803     CglStored * storedRowCuts_;
02811     int numberThreads_;
02819     int threadMode_;
02821     CbcBaseModel * master_;
02823     CbcThread * masterThread_;
02825 };
02827 void getIntegerInformation(const OsiObject * object, double & originalLower,
02828                            double & originalUpper) ;
02829 // So we can call from other programs
02830 // Real main program
02831 class OsiClpSolverInterface;
02832 int CbcMain (int argc, const char *argv[], OsiClpSolverInterface & solver, CbcModel ** babSolver);
02833 int CbcMain (int argc, const char *argv[], CbcModel & babSolver);
02834 // four ways of calling
02835 int callCbc(const char * input2, OsiClpSolverInterface& solver1);
02836 int callCbc(const char * input2);
02837 int callCbc(const std::string input2, OsiClpSolverInterface& solver1);
02838 int callCbc(const std::string input2) ;
02839 // When we want to load up CbcModel with options first
02840 void CbcMain0 (CbcModel & babSolver);
02841 int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver);
02842 // two ways of calling
02843 int callCbc(const char * input2, CbcModel & babSolver);
02844 int callCbc(const std::string input2, CbcModel & babSolver);
02845 // And when CbcMain0 already called to initialize
02846 int callCbc1(const char * input2, CbcModel & babSolver);
02847 int callCbc1(const std::string input2, CbcModel & babSolver);
02848 // And when CbcMain0 already called to initialize (with call back) (see CbcMain1 for whereFrom)
02849 int callCbc1(const char * input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02850 int callCbc1(const std::string input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02851 int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
02852 // For uniform setting of cut and heuristic options
02853 void setCutAndHeuristicOptions(CbcModel & model);
02854 #endif
02855 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 14 Sep 2013 for Cbc by  doxygen 1.6.1