# OsiCbcSolverInterface.hpp

Go to the documentation of this file.

    00001 // $Id: OsiCbcSolverInterface.hpp 1902 2013-04-10 16:58:16Z stefan $
    00002 // Copyright (C) 2000, 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 OsiCbcSolverInterface_H
    00007 #define OsiCbcSolverInterface_H
    00008
    00009 #include <string>
    00010 #include <cfloat>
    00011 #include <map>
    00012 #include "CbcModel.hpp"
    00013 #include "CoinPackedMatrix.hpp"
    00014 #include "OsiSolverInterface.hpp"
    00015 #include "CbcStrategy.hpp"
    00016 #include "CoinWarmStartBasis.hpp"
    00017
    00018 class OsiRowCut;
    00019 class OsiClpSolverInterface;
    00020 static const double OsiCbcInfinity = COIN_DBL_MAX;
    00021
    00022 //#############################################################################
    00023
    00030 class OsiCbcSolverInterface :
    00031   virtual public OsiSolverInterface {
    00032   friend void OsiCbcSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00033
    00034 public:
    00035   //---------------------------------------------------------------------------
    00038
    00039   virtual void initialSolve();
    00040
    00042   virtual void resolve();
    00043
    00045   virtual void branchAndBound();
    00047
    00048   //---------------------------------------------------------------------------
    00064   // Set an integer parameter
    00065   bool setIntParam(OsiIntParam key, int value);
    00066   // Set an double parameter
    00067   bool setDblParam(OsiDblParam key, double value);
    00068   // Set a string parameter
    00069   bool setStrParam(OsiStrParam key, const std::string & value);
    00070   // Get an integer parameter
    00071   bool getIntParam(OsiIntParam key, int& value) const;
    00072   // Get an double parameter
    00073   bool getDblParam(OsiDblParam key, double& value) const;
    00074   // Get a string parameter
    00075   bool getStrParam(OsiStrParam key, std::string& value) const;
    00076   // Set a hint parameter - overrides OsiSolverInterface
    00077   virtual bool setHintParam(OsiHintParam key, bool yesNo=true,
    00078                             OsiHintStrength strength=OsiHintTry,
    00079                             void * otherInformation=NULL);
    00081     virtual bool getHintParam(OsiHintParam key, bool& yesNo,
    00082                               OsiHintStrength& strength,
    00083                               void *& otherInformation) const;
    00084
    00085   using OsiSolverInterface::getHintParam ;
    00087     virtual bool getHintParam(OsiHintParam key, bool& yesNo,
    00088                               OsiHintStrength& strength) const;
    00090
    00091   //---------------------------------------------------------------------------
    00093
    00094
    00095   virtual bool isAbandoned() const;
    00097   virtual bool isProvenOptimal() const;
    00099   virtual bool isProvenPrimalInfeasible() const;
    00101   virtual bool isProvenDualInfeasible() const;
    00103   virtual bool isPrimalObjectiveLimitReached() const;
    00105   virtual bool isDualObjectiveLimitReached() const;
    00107   virtual bool isIterationLimitReached() const;
    00109
    00110   //---------------------------------------------------------------------------
    00113
    00121   virtual CoinWarmStart *getEmptyWarmStart () const;
    00122
    00124   virtual CoinWarmStart* getWarmStart() const;
    00127   virtual bool setWarmStart(const CoinWarmStart* warmstart);
    00129
    00130   //---------------------------------------------------------------------------
    00137
    00138   virtual void markHotStart();
    00140   virtual void solveFromHotStart();
    00142   virtual void unmarkHotStart();
    00144
    00145   //---------------------------------------------------------------------------
    00160
    00161   virtual int getNumCols() const;
    00162
    00164   virtual int getNumRows() const;
    00165
    00167   virtual int getNumElements() const ;
    00168
    00170   virtual const double * getColLower() const;
    00171
    00173   virtual const double * getColUpper() const;
    00174
    00184   virtual const char * getRowSense() const;
    00185
    00194   virtual const double * getRightHandSide() const ;
    00195
    00204   virtual const double * getRowRange() const ;
    00205
    00207   virtual const double * getRowLower() const ;
    00208
    00210   virtual const double * getRowUpper() const ;
    00211
    00213   virtual const double * getObjCoefficients() const;
    00214
    00216   virtual double getObjSense() const ;
    00217
    00219   virtual bool isContinuous(int colNumber) const;
    00220
    00221
    00223   virtual const CoinPackedMatrix * getMatrixByRow() const;
    00224
    00226   virtual const CoinPackedMatrix * getMatrixByCol() const;
    00227
    00229   virtual double getInfinity() const;
    00231
    00234
    00235   virtual const double * getColSolution() const;
    00236
    00238   virtual const double * getRowPrice() const;
    00239
    00241   virtual const double * getReducedCost() const;
    00242
    00245   virtual const double * getRowActivity() const;
    00246
    00248   virtual double getObjValue() const;
    00249
    00252   virtual int getIterationCount() const ;
    00253
    00271   virtual std::vector<double*> getDualRays(int maxNumRays,
    00272                                            bool fullRay = false) const;
    00284   virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
    00285
    00287
    00296
    00299     virtual std::string dfltRowColName(char rc,
    00300                                  int ndx, unsigned digits = 7) const ;
    00301
    00304     virtual std::string getObjName (unsigned maxLen = std::string::npos) const ;
    00305
    00308     virtual void setObjName (std::string name) ;
    00309
    00312     virtual std::string getRowName(int rowIndex,
    00313                                    unsigned maxLen = std::string::npos) const ;
    00314
    00317     virtual const OsiNameVec &getRowNames() ;
    00318
    00321     virtual void setRowName(int ndx, std::string name) ;
    00322
    00325     virtual void setRowNames(OsiNameVec &srcNames,
    00326                      int srcStart, int len, int tgtStart) ;
    00327
    00330     virtual void deleteRowNames(int tgtStart, int len) ;
    00331
    00334     virtual std::string getColName(int colIndex,
    00335                                    unsigned maxLen = std::string::npos) const ;
    00336
    00339     virtual const OsiNameVec &getColNames() ;
    00340
    00343     virtual void setColName(int ndx, std::string name) ;
    00344
    00347     virtual void setColNames(OsiNameVec &srcNames,
    00348                      int srcStart, int len, int tgtStart) ;
    00349
    00351     virtual void deleteColNames(int tgtStart, int len) ;
    00352
    00354
    00356
    00357   //---------------------------------------------------------------------------
    00358
    00361   //-------------------------------------------------------------------------
    00365   virtual void setObjCoeff( int elementIndex, double elementValue );
    00366
    00367   using OsiSolverInterface::setColLower ;
    00370   virtual void setColLower( int elementIndex, double elementValue );
    00371
    00372   using OsiSolverInterface::setColUpper ;
    00375   virtual void setColUpper( int elementIndex, double elementValue );
    00376
    00378   virtual void setColBounds( int elementIndex,
    00379                              double lower, double upper );
    00380
    00389   virtual void setColSetBounds(const int* indexFirst,
    00390                                const int* indexLast,
    00391                                const double* boundList);
    00392
    00395   virtual void setRowLower( int elementIndex, double elementValue );
    00396
    00399   virtual void setRowUpper( int elementIndex, double elementValue ) ;
    00400
    00402   virtual void setRowBounds( int elementIndex,
    00403                              double lower, double upper ) ;
    00404
    00406   virtual void setRowType(int index, char sense, double rightHandSide,
    00407                           double range);
    00408
    00417   virtual void setRowSetBounds(const int* indexFirst,
    00418                                const int* indexLast,
    00419                                const double* boundList);
    00420
    00431   virtual void setRowSetTypes(const int* indexFirst,
    00432                               const int* indexLast,
    00433                               const char* senseList,
    00434                               const double* rhsList,
    00435                               const double* rangeList);
    00437
    00438   //-------------------------------------------------------------------------
    00442   virtual void setContinuous(int index);
    00444   virtual void setInteger(int index);
    00447   virtual void setContinuous(const int* indices, int len);
    00450   virtual void setInteger(const int* indices, int len);
    00452
    00453   //-------------------------------------------------------------------------
    00455   virtual void setObjSense(double s );
    00456
    00467   virtual void setColSolution(const double * colsol);
    00468
    00479   virtual void setRowPrice(const double * rowprice);
    00480
    00481   //-------------------------------------------------------------------------
    00486   using OsiSolverInterface::addCol ;
    00488   virtual void addCol(const CoinPackedVectorBase& vec,
    00489                       const double collb, const double colub,
    00490                       const double obj);
    00492   virtual void addCol(int numberElements, const int * rows, const double * elements,
    00493                       const double collb, const double colub,
    00494                       const double obj) ;
    00495
    00496   using OsiSolverInterface::addCols ;
    00498   virtual void addCols(const int numcols,
    00499                        const CoinPackedVectorBase * const * cols,
    00500                        const double* collb, const double* colub,
    00501                        const double* obj);
    00503   virtual void deleteCols(const int num, const int * colIndices);
    00504
    00505   using OsiSolverInterface::addRow ;
    00507   virtual void addRow(const CoinPackedVectorBase& vec,
    00508                       const double rowlb, const double rowub);
    00510   virtual void addRow(const CoinPackedVectorBase& vec,
    00511                       const char rowsen, const double rowrhs,
    00512                       const double rowrng);
    00513
    00514   using OsiSolverInterface::addRows ;
    00516   virtual void addRows(const int numrows,
    00517                        const CoinPackedVectorBase * const * rows,
    00518                        const double* rowlb, const double* rowub);
    00520   virtual void addRows(const int numrows,
    00521                        const CoinPackedVectorBase * const * rows,
    00522                        const char* rowsen, const double* rowrhs,
    00523                        const double* rowrng);
    00525   virtual void deleteRows(const int num, const int * rowIndices);
    00526
    00527   //-----------------------------------------------------------------------
    00531   virtual void applyRowCuts(int numberCuts, const OsiRowCut * cuts);
    00536   virtual void applyRowCuts(int numberCuts, const OsiRowCut ** cuts);
    00538
    00539
    00540   //---------------------------------------------------------------------------
    00541
    00542 public:
    00543
    00557   virtual void loadProblem(const CoinPackedMatrix& matrix,
    00558                            const double* collb, const double* colub,
    00559                            const double* obj,
    00560                            const double* rowlb, const double* rowub);
    00561
    00569   virtual void assignProblem(CoinPackedMatrix*& matrix,
    00570                              double*& collb, double*& colub, double*& obj,
    00571                              double*& rowlb, double*& rowub);
    00572
    00585   virtual void loadProblem(const CoinPackedMatrix& matrix,
    00586                            const double* collb, const double* colub,
    00587                            const double* obj,
    00588                            const char* rowsen, const double* rowrhs,
    00589                            const double* rowrng);
    00590
    00598   virtual void assignProblem(CoinPackedMatrix*& matrix,
    00599                              double*& collb, double*& colub, double*& obj,
    00600                              char*& rowsen, double*& rowrhs,
    00601                              double*& rowrng);
    00602
    00605   virtual void loadProblem(const int numcols, const int numrows,
    00606                            const CoinBigIndex * start, const int* index,
    00607                            const double* value,
    00608                            const double* collb, const double* colub,
    00609                            const double* obj,
    00610                            const double* rowlb, const double* rowub);
    00611
    00614   virtual void loadProblem(const int numcols, const int numrows,
    00615                            const CoinBigIndex * start, const int* index,
    00616                            const double* value,
    00617                            const double* collb, const double* colub,
    00618                            const double* obj,
    00619                            const char* rowsen, const double* rowrhs,
    00620                            const double* rowrng);
    00621
    00622   using OsiSolverInterface::readMps ;
    00625   virtual int readMps(const char *filename,
    00626                       const char *extension = "mps") ;
    00627
    00632   virtual void writeMps(const char *filename,
    00633                         const char *extension = "mps",
    00634                         double objSense=0.0) const;
    00643   virtual int writeMpsNative(const char *filename,
    00644                              const char ** rowNames, const char ** columnNames,
    00645                              int formatType=0,int numberAcross=2,
    00646                              double objSense=0.0) const ;
    00648
    00653
    00654   void newLanguage(CoinMessages::Language language);
    00655   void setLanguage(CoinMessages::Language language)
    00656   {newLanguage(language);}
    00658   //---------------------------------------------------------------------------
    00659
    00662
    00663   inline CbcModel * getModelPtr() const
    00664   { return modelPtr_;}
    00666   inline OsiSolverInterface * getRealSolverPtr() const
    00667   { return modelPtr_->solver();}
    00669   inline void setCutoff(double value)
    00670   { modelPtr_->setCutoff(value);}
    00672   inline double getCutoff() const
    00673   { return modelPtr_->getCutoff();}
    00675   inline void setMaximumNodes( int value)
    00676   { modelPtr_->setMaximumNodes(value);}
    00678   inline int getMaximumNodes() const
    00679   { return modelPtr_->getMaximumNodes();}
    00681   inline void setMaximumSolutions( int value)
    00682   { modelPtr_->setMaximumSolutions(value);}
    00684   inline int getMaximumSolutions() const
    00685   { return modelPtr_->getMaximumSolutions();}
    00687   inline void setMaximumSeconds( double value)
    00688   { modelPtr_->setMaximumSeconds(value);}
    00690   inline double getMaximumSeconds() const
    00691   { return modelPtr_->getMaximumSeconds();}
    00693   inline bool isNodeLimitReached() const
    00694   { return modelPtr_->isNodeLimitReached();}
    00696   inline bool isSolutionLimitReached() const
    00697   { return modelPtr_->isSolutionLimitReached();}
    00699   inline int getNodeCount() const
    00700   { return modelPtr_->getNodeCount();}
    00702     inline int status() const
    00703   { return modelPtr_->status();}
    00710   virtual void passInMessageHandler(CoinMessageHandler * handler);
    00712
    00713   //---------------------------------------------------------------------------
    00714
    00717
    00718   OsiCbcSolverInterface (OsiSolverInterface * solver=NULL,
    00719                          CbcStrategy * strategy=NULL);
    00720
    00722   virtual OsiSolverInterface * clone(bool copyData = true) const;
    00723
    00725   OsiCbcSolverInterface (const OsiCbcSolverInterface &);
    00726 #if 0
    00728   OsiCbcSolverInterface (CbcModel * rhs, bool reallyOwn=false);
    00729
    00731   void releaseCbc();
    00732 #endif
    00734   OsiCbcSolverInterface & operator=(const OsiCbcSolverInterface& rhs);
    00735
    00737   virtual ~OsiCbcSolverInterface ();
    00738
    00740   //---------------------------------------------------------------------------
    00741
    00742 protected:
    00744
    00745
    00746   virtual void applyRowCut(const OsiRowCut& rc);
    00747
    00749   virtual void applyColCut(const OsiColCut& cc);
    00751
    00753
    00754   mutable CbcModel * modelPtr_;
    00756 };
    00757 // So unit test can find out if NDEBUG set
    00758 bool OsiCbcHasNDEBUG();
    00759
    00760 //#############################################################################
    00762 void OsiCbcSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00763
    00764 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines