- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# /home/coin/SVN-release/Cgl-0.53.1/Osi/src/OsiCbc/OsiCbcSolverInterface.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2000, International Business Machines
    00002 // Corporation and others.  All Rights Reserved.
    00003
    00004 #ifndef OsiCbcSolverInterface_H
    00005 #define OsiCbcSolverInterface_H
    00006
    00007 #include <string>
    00008 #include <cfloat>
    00009 #include <map>
    00010 #include "CbcModel.hpp"
    00011 #include "CoinPackedMatrix.hpp"
    00012 #include "OsiSolverInterface.hpp"
    00013 #include "CbcStrategy.hpp"
    00014 #include "CoinWarmStartBasis.hpp"
    00015
    00016 class OsiRowCut;
    00017 class OsiClpSolverInterface;
    00018 #ifndef COIN_DBL_MAX
    00019 static const double OsiCbcInfinity = DBL_MAX;
    00020 #else
    00021 static const double OsiCbcInfinity = COIN_DBL_MAX;
    00022 #endif
    00023
    00024 //#############################################################################
    00025
    00032 class OsiCbcSolverInterface :
    00033   virtual public OsiSolverInterface {
    00034   friend int OsiCbcSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00035
    00036 public:
    00037   //---------------------------------------------------------------------------
    00040
    00041   virtual void initialSolve();
    00042
    00044   virtual void resolve();
    00045
    00047   virtual void branchAndBound();
    00049
    00050   //---------------------------------------------------------------------------
    00066   // Set an integer parameter
    00067   bool setIntParam(OsiIntParam key, int value);
    00068   // Set an double parameter
    00069   bool setDblParam(OsiDblParam key, double value);
    00070   // Set a string parameter
    00071   bool setStrParam(OsiStrParam key, const std::string & value);
    00072   // Get an integer parameter
    00073   bool getIntParam(OsiIntParam key, int& value) const;
    00074   // Get an double parameter
    00075   bool getDblParam(OsiDblParam key, double& value) const;
    00076   // Get a string parameter
    00077   bool getStrParam(OsiStrParam key, std::string& value) const;
    00078   // Set a hint parameter - overrides OsiSolverInterface
    00079   virtual bool setHintParam(OsiHintParam key, bool yesNo=true,
    00080                             OsiHintStrength strength=OsiHintTry,
    00081                             void * otherInformation=NULL);
    00083     virtual bool getHintParam(OsiHintParam key, bool& yesNo,
    00084                               OsiHintStrength& strength,
    00085                               void *& otherInformation) const;
    00086
    00087   using OsiSolverInterface::getHintParam ;
    00089     virtual bool getHintParam(OsiHintParam key, bool& yesNo,
    00090                               OsiHintStrength& strength) const;
    00092
    00093   //---------------------------------------------------------------------------
    00095
    00096
    00097   virtual bool isAbandoned() const;
    00099   virtual bool isProvenOptimal() const;
    00101   virtual bool isProvenPrimalInfeasible() const;
    00103   virtual bool isProvenDualInfeasible() const;
    00105   virtual bool isPrimalObjectiveLimitReached() const;
    00107   virtual bool isDualObjectiveLimitReached() const;
    00109   virtual bool isIterationLimitReached() const;
    00111
    00112   //---------------------------------------------------------------------------
    00115
    00123   virtual CoinWarmStart *getEmptyWarmStart () const;
    00124
    00126   virtual CoinWarmStart* getWarmStart() const;
    00129   virtual bool setWarmStart(const CoinWarmStart* warmstart);
    00131
    00132   //---------------------------------------------------------------------------
    00139
    00140   virtual void markHotStart();
    00142   virtual void solveFromHotStart();
    00144   virtual void unmarkHotStart();
    00146
    00147   //---------------------------------------------------------------------------
    00162
    00163   virtual int getNumCols() const;
    00164
    00166   virtual int getNumRows() const;
    00167
    00169   virtual int getNumElements() const ;
    00170
    00172   virtual const double * getColLower() const;
    00173
    00175   virtual const double * getColUpper() const;
    00176
    00186   virtual const char * getRowSense() const;
    00187
    00196   virtual const double * getRightHandSide() const ;
    00197
    00206   virtual const double * getRowRange() const ;
    00207
    00209   virtual const double * getRowLower() const ;
    00210
    00212   virtual const double * getRowUpper() const ;
    00213
    00215   virtual const double * getObjCoefficients() const;
    00216
    00218   virtual double getObjSense() const ;
    00219
    00221   virtual bool isContinuous(int colNumber) const;
    00222
    00223
    00225   virtual const CoinPackedMatrix * getMatrixByRow() const;
    00226
    00228   virtual const CoinPackedMatrix * getMatrixByCol() const;
    00229
    00231   virtual double getInfinity() const;
    00233
    00236
    00237   virtual const double * getColSolution() const;
    00238
    00240   virtual const double * getRowPrice() const;
    00241
    00243   virtual const double * getReducedCost() const;
    00244
    00247   virtual const double * getRowActivity() const;
    00248
    00250   virtual double getObjValue() const;
    00251
    00254   virtual int getIterationCount() const ;
    00255
    00267   virtual std::vector<double*> getDualRays(int maxNumRays) const;
    00279   virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
    00280
    00282
    00291
    00294     virtual std::string dfltRowColName(char rc,
    00295                                  int ndx, unsigned digits = 7) const ;
    00296
    00299     virtual std::string getObjName (unsigned maxLen = std::string::npos) const ;
    00300
    00303     virtual void setObjName (std::string name) ;
    00304
    00307     virtual std::string getRowName(int rowIndex,
    00308                                    unsigned maxLen = std::string::npos) const ;
    00309
    00312     virtual const OsiNameVec &getRowNames() ;
    00313
    00316     virtual void setRowName(int ndx, std::string name) ;
    00317
    00320     virtual void setRowNames(OsiNameVec &srcNames,
    00321                      int srcStart, int len, int tgtStart) ;
    00322
    00325     virtual void deleteRowNames(int tgtStart, int len) ;
    00326
    00329     virtual std::string getColName(int colIndex,
    00330                                    unsigned maxLen = std::string::npos) const ;
    00331
    00334     virtual const OsiNameVec &getColNames() ;
    00335
    00338     virtual void setColName(int ndx, std::string name) ;
    00339
    00342     virtual void setColNames(OsiNameVec &srcNames,
    00343                      int srcStart, int len, int tgtStart) ;
    00344
    00346     virtual void deleteColNames(int tgtStart, int len) ;
    00347
    00349
    00351
    00352   //---------------------------------------------------------------------------
    00353
    00356   //-------------------------------------------------------------------------
    00360   virtual void setObjCoeff( int elementIndex, double elementValue );
    00361
    00362   using OsiSolverInterface::setColLower ;
    00365   virtual void setColLower( int elementIndex, double elementValue );
    00366
    00367   using OsiSolverInterface::setColUpper ;
    00370   virtual void setColUpper( int elementIndex, double elementValue );
    00371
    00373   virtual void setColBounds( int elementIndex,
    00374                              double lower, double upper );
    00375
    00384   virtual void setColSetBounds(const int* indexFirst,
    00385                                const int* indexLast,
    00386                                const double* boundList);
    00387
    00390   virtual void setRowLower( int elementIndex, double elementValue );
    00391
    00394   virtual void setRowUpper( int elementIndex, double elementValue ) ;
    00395
    00397   virtual void setRowBounds( int elementIndex,
    00398                              double lower, double upper ) ;
    00399
    00401   virtual void setRowType(int index, char sense, double rightHandSide,
    00402                           double range);
    00403
    00412   virtual void setRowSetBounds(const int* indexFirst,
    00413                                const int* indexLast,
    00414                                const double* boundList);
    00415
    00426   virtual void setRowSetTypes(const int* indexFirst,
    00427                               const int* indexLast,
    00428                               const char* senseList,
    00429                               const double* rhsList,
    00430                               const double* rangeList);
    00432
    00433   //-------------------------------------------------------------------------
    00437   virtual void setContinuous(int index);
    00439   virtual void setInteger(int index);
    00442   virtual void setContinuous(const int* indices, int len);
    00445   virtual void setInteger(const int* indices, int len);
    00447
    00448   //-------------------------------------------------------------------------
    00450   virtual void setObjSense(double s );
    00451
    00462   virtual void setColSolution(const double * colsol);
    00463
    00474   virtual void setRowPrice(const double * rowprice);
    00475
    00476   //-------------------------------------------------------------------------
    00481   using OsiSolverInterface::addCol ;
    00483   virtual void addCol(const CoinPackedVectorBase& vec,
    00484                       const double collb, const double colub,
    00485                       const double obj);
    00487   virtual void addCol(int numberElements, const int * rows, const double * elements,
    00488                       const double collb, const double colub,
    00489                       const double obj) ;
    00490
    00491   using OsiSolverInterface::addCols ;
    00493   virtual void addCols(const int numcols,
    00494                        const CoinPackedVectorBase * const * cols,
    00495                        const double* collb, const double* colub,
    00496                        const double* obj);
    00498   virtual void deleteCols(const int num, const int * colIndices);
    00499
    00500   using OsiSolverInterface::addRow ;
    00502   virtual void addRow(const CoinPackedVectorBase& vec,
    00503                       const double rowlb, const double rowub);
    00505   virtual void addRow(const CoinPackedVectorBase& vec,
    00506                       const char rowsen, const double rowrhs,
    00507                       const double rowrng);
    00508
    00509   using OsiSolverInterface::addRows ;
    00511   virtual void addRows(const int numrows,
    00512                        const CoinPackedVectorBase * const * rows,
    00513                        const double* rowlb, const double* rowub);
    00515   virtual void addRows(const int numrows,
    00516                        const CoinPackedVectorBase * const * rows,
    00517                        const char* rowsen, const double* rowrhs,
    00518                        const double* rowrng);
    00520   virtual void deleteRows(const int num, const int * rowIndices);
    00521
    00522   //-----------------------------------------------------------------------
    00526   virtual void applyRowCuts(int numberCuts, const OsiRowCut * cuts);
    00531   virtual void applyRowCuts(int numberCuts, const OsiRowCut ** cuts);
    00533
    00534
    00535   //---------------------------------------------------------------------------
    00536
    00537 public:
    00538
    00552   virtual void loadProblem(const CoinPackedMatrix& matrix,
    00553                            const double* collb, const double* colub,
    00554                            const double* obj,
    00555                            const double* rowlb, const double* rowub);
    00556
    00564   virtual void assignProblem(CoinPackedMatrix*& matrix,
    00565                              double*& collb, double*& colub, double*& obj,
    00566                              double*& rowlb, double*& rowub);
    00567
    00580   virtual void loadProblem(const CoinPackedMatrix& matrix,
    00581                            const double* collb, const double* colub,
    00582                            const double* obj,
    00583                            const char* rowsen, const double* rowrhs,
    00584                            const double* rowrng);
    00585
    00593   virtual void assignProblem(CoinPackedMatrix*& matrix,
    00594                              double*& collb, double*& colub, double*& obj,
    00595                              char*& rowsen, double*& rowrhs,
    00596                              double*& rowrng);
    00597
    00600   virtual void loadProblem(const int numcols, const int numrows,
    00601                            const CoinBigIndex * start, const int* index,
    00602                            const double* value,
    00603                            const double* collb, const double* colub,
    00604                            const double* obj,
    00605                            const double* rowlb, const double* rowub);
    00606
    00609   virtual void loadProblem(const int numcols, const int numrows,
    00610                            const CoinBigIndex * start, const int* index,
    00611                            const double* value,
    00612                            const double* collb, const double* colub,
    00613                            const double* obj,
    00614                            const char* rowsen, const double* rowrhs,
    00615                            const double* rowrng);
    00616
    00617   using OsiSolverInterface::readMps ;
    00620   virtual int readMps(const char *filename,
    00621                       const char *extension = "mps") ;
    00622
    00627   virtual void writeMps(const char *filename,
    00628                         const char *extension = "mps",
    00629                         double objSense=0.0) const;
    00638   virtual int writeMpsNative(const char *filename,
    00639                              const char ** rowNames, const char ** columnNames,
    00640                              int formatType=0,int numberAcross=2,
    00641                              double objSense=0.0) const ;
    00643
    00648
    00649   void newLanguage(CoinMessages::Language language);
    00650   void setLanguage(CoinMessages::Language language)
    00651   {newLanguage(language);}
    00653   //---------------------------------------------------------------------------
    00654
    00657
    00658   inline CbcModel * getModelPtr() const
    00659   { return modelPtr_;}
    00661   inline OsiSolverInterface * getRealSolverPtr() const
    00662   { return modelPtr_->solver();}
    00664   inline void setCutoff(double value)
    00665   { modelPtr_->setCutoff(value);}
    00667   inline double getCutoff() const
    00668   { return modelPtr_->getCutoff();}
    00670   inline void setMaximumNodes( int value)
    00671   { modelPtr_->setMaximumNodes(value);}
    00673   inline int getMaximumNodes() const
    00674   { return modelPtr_->getMaximumNodes();}
    00676   inline void setMaximumSolutions( int value)
    00677   { modelPtr_->setMaximumSolutions(value);}
    00679   inline int getMaximumSolutions() const
    00680   { return modelPtr_->getMaximumSolutions();}
    00682   inline void setMaximumSeconds( double value)
    00683   { modelPtr_->setMaximumSeconds(value);}
    00685   inline double getMaximumSeconds() const
    00686   { return modelPtr_->getMaximumSeconds();}
    00688   inline bool isNodeLimitReached() const
    00689   { return modelPtr_->isNodeLimitReached();}
    00691   inline bool isSolutionLimitReached() const
    00692   { return modelPtr_->isSolutionLimitReached();}
    00694   inline int getNodeCount() const
    00695   { return modelPtr_->getNodeCount();}
    00697     inline int status() const
    00698   { return modelPtr_->status();}
    00700
    00701   //---------------------------------------------------------------------------
    00702
    00705
    00706   OsiCbcSolverInterface (OsiSolverInterface * solver=NULL,
    00707                          CbcStrategy * strategy=NULL);
    00708
    00710   virtual OsiSolverInterface * clone(bool copyData = true) const;
    00711
    00713   OsiCbcSolverInterface (const OsiCbcSolverInterface &);
    00714 #if 0
    00716   OsiCbcSolverInterface (CbcModel * rhs, bool reallyOwn=false);
    00717
    00719   void releaseCbc();
    00720 #endif
    00722   OsiCbcSolverInterface & operator=(const OsiCbcSolverInterface& rhs);
    00723
    00725   virtual ~OsiCbcSolverInterface ();
    00726
    00728   //---------------------------------------------------------------------------
    00729
    00730 protected:
    00732
    00733
    00734   virtual void applyRowCut(const OsiRowCut& rc);
    00735
    00737   virtual void applyColCut(const OsiColCut& cc);
    00739
    00741
    00742   mutable CbcModel * modelPtr_;
    00744 };
    00745
    00746 //#############################################################################
    00754 int
    00755 OsiCbcSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00756
    00757 #endif