/home/coin/SVN-release/Cbc-1.2.0/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 void 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;
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   
00265   virtual std::vector<double*> getDualRays(int maxNumRays) const;
00277   virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
00278   
00280 
00289 
00292     virtual std::string dfltRowColName(char rc,
00293                                  int ndx, unsigned digits = 7) const ;
00294 
00297     virtual std::string getObjName (unsigned maxLen = std::string::npos) const ;
00298 
00301     virtual void setObjName (std::string name) ;
00302 
00305     virtual std::string getRowName(int rowIndex,
00306                                    unsigned maxLen = std::string::npos) const ;
00307 
00310     virtual const OsiNameVec &getRowNames() ;
00311 
00314     virtual void setRowName(int ndx, std::string name) ;
00315 
00318     virtual void setRowNames(OsiNameVec &srcNames,
00319                      int srcStart, int len, int tgtStart) ;
00320 
00323     virtual void deleteRowNames(int tgtStart, int len) ;
00324   
00327     virtual std::string getColName(int colIndex,
00328                                    unsigned maxLen = std::string::npos) const ;
00329 
00332     virtual const OsiNameVec &getColNames() ;
00333 
00336     virtual void setColName(int ndx, std::string name) ;
00337 
00340     virtual void setColNames(OsiNameVec &srcNames,
00341                      int srcStart, int len, int tgtStart) ;
00342 
00344     virtual void deleteColNames(int tgtStart, int len) ;
00345 
00347 
00349   
00350   //---------------------------------------------------------------------------
00351   
00354   //-------------------------------------------------------------------------
00358   virtual void setObjCoeff( int elementIndex, double elementValue );
00359   
00362   virtual void setColLower( int elementIndex, double elementValue );
00363   
00366   virtual void setColUpper( int elementIndex, double elementValue );
00367   
00369   virtual void setColBounds( int elementIndex,
00370                              double lower, double upper );
00371   
00380   virtual void setColSetBounds(const int* indexFirst,
00381                                const int* indexLast,
00382                                const double* boundList);
00383   
00386   virtual void setRowLower( int elementIndex, double elementValue );
00387   
00390   virtual void setRowUpper( int elementIndex, double elementValue ) ;
00391   
00393   virtual void setRowBounds( int elementIndex,
00394                              double lower, double upper ) ;
00395   
00397   virtual void setRowType(int index, char sense, double rightHandSide,
00398                           double range);
00399   
00408   virtual void setRowSetBounds(const int* indexFirst,
00409                                const int* indexLast,
00410                                const double* boundList);
00411   
00422   virtual void setRowSetTypes(const int* indexFirst,
00423                               const int* indexLast,
00424                               const char* senseList,
00425                               const double* rhsList,
00426                               const double* rangeList);
00428   
00429   //-------------------------------------------------------------------------
00433   virtual void setContinuous(int index);
00435   virtual void setInteger(int index);
00438   virtual void setContinuous(const int* indices, int len);
00441   virtual void setInteger(const int* indices, int len);
00443   
00444   //-------------------------------------------------------------------------
00446   virtual void setObjSense(double s ); 
00447   
00458   virtual void setColSolution(const double * colsol);
00459   
00470   virtual void setRowPrice(const double * rowprice);
00471   
00472   //-------------------------------------------------------------------------
00478   virtual void addCol(const CoinPackedVectorBase& vec,
00479                       const double collb, const double colub,   
00480                       const double obj);
00482   virtual void addCol(int numberElements, const int * rows, const double * elements,
00483                       const double collb, const double colub,   
00484                       const double obj) ;
00486   virtual void addCols(const int numcols,
00487                        const CoinPackedVectorBase * const * cols,
00488                        const double* collb, const double* colub,   
00489                        const double* obj);
00491   virtual void deleteCols(const int num, const int * colIndices);
00492   
00494   virtual void addRow(const CoinPackedVectorBase& vec,
00495                       const double rowlb, const double rowub);
00497   virtual void addRow(const CoinPackedVectorBase& vec,
00498                       const char rowsen, const double rowrhs,   
00499                       const double rowrng);
00501   virtual void addRows(const int numrows,
00502                        const CoinPackedVectorBase * const * rows,
00503                        const double* rowlb, const double* rowub);
00505   virtual void addRows(const int numrows,
00506                        const CoinPackedVectorBase * const * rows,
00507                        const char* rowsen, const double* rowrhs,   
00508                        const double* rowrng);
00510   virtual void deleteRows(const int num, const int * rowIndices);
00511   
00512   //-----------------------------------------------------------------------
00516   virtual void applyRowCuts(int numberCuts, const OsiRowCut * cuts);
00521   virtual void applyRowCuts(int numberCuts, const OsiRowCut ** cuts);
00523 
00524   
00525   //---------------------------------------------------------------------------
00526   
00527 public:
00528   
00542   virtual void loadProblem(const CoinPackedMatrix& matrix,
00543                            const double* collb, const double* colub,   
00544                            const double* obj,
00545                            const double* rowlb, const double* rowub);
00546   
00554   virtual void assignProblem(CoinPackedMatrix*& matrix,
00555                              double*& collb, double*& colub, double*& obj,
00556                              double*& rowlb, double*& rowub);
00557   
00570   virtual void loadProblem(const CoinPackedMatrix& matrix,
00571                            const double* collb, const double* colub,
00572                            const double* obj,
00573                            const char* rowsen, const double* rowrhs,   
00574                            const double* rowrng);
00575   
00583   virtual void assignProblem(CoinPackedMatrix*& matrix,
00584                              double*& collb, double*& colub, double*& obj,
00585                              char*& rowsen, double*& rowrhs,
00586                              double*& rowrng);
00587   
00590   virtual void loadProblem(const int numcols, const int numrows,
00591                            const CoinBigIndex * start, const int* index,
00592                            const double* value,
00593                            const double* collb, const double* colub,   
00594                            const double* obj,
00595                            const double* rowlb, const double* rowub);
00596   
00599   virtual void loadProblem(const int numcols, const int numrows,
00600                            const CoinBigIndex * start, const int* index,
00601                            const double* value,
00602                            const double* collb, const double* colub,   
00603                            const double* obj,
00604                            const char* rowsen, const double* rowrhs,   
00605                            const double* rowrng);
00608   virtual int readMps(const char *filename,
00609                       const char *extension = "mps") ;
00610   
00615   virtual void writeMps(const char *filename,
00616                         const char *extension = "mps",
00617                         double objSense=0.0) const;
00626   virtual int writeMpsNative(const char *filename, 
00627                              const char ** rowNames, const char ** columnNames,
00628                              int formatType=0,int numberAcross=2,
00629                              double objSense=0.0) const ;
00631   
00636 
00637   void newLanguage(CoinMessages::Language language);
00638   void setLanguage(CoinMessages::Language language)
00639   {newLanguage(language);};
00641   //---------------------------------------------------------------------------
00642   
00645 
00646   inline CbcModel * getModelPtr() const 
00647   { return modelPtr_;};
00649   inline OsiSolverInterface * getRealSolverPtr() const 
00650   { return modelPtr_->solver();};
00652   inline void setCutoff(double value) 
00653   { modelPtr_->setCutoff(value);};
00655   inline double getCutoff() const
00656   { return modelPtr_->getCutoff();};
00658   inline void setMaximumNodes( int value)
00659   { modelPtr_->setMaximumNodes(value);};
00661   inline int getMaximumNodes() const
00662   { return modelPtr_->getMaximumNodes();};
00664   inline void setMaximumSolutions( int value) 
00665   { modelPtr_->setMaximumSolutions(value);};
00667   inline int getMaximumSolutions() const 
00668   { return modelPtr_->getMaximumSolutions();};
00670   inline void setMaximumSeconds( double value) 
00671   { modelPtr_->setMaximumSeconds(value);};
00673   inline double getMaximumSeconds() const 
00674   { return modelPtr_->getMaximumSeconds();};
00676   inline bool isNodeLimitReached() const
00677   { return modelPtr_->isNodeLimitReached();};
00679   inline bool isSolutionLimitReached() const
00680   { return modelPtr_->isSolutionLimitReached();};
00682   inline int getNodeCount() const
00683   { return modelPtr_->getNodeCount();};
00685     inline int status() const
00686   { return modelPtr_->status();};
00688   
00689   //---------------------------------------------------------------------------
00690   
00693 
00694   OsiCbcSolverInterface (OsiSolverInterface * solver=NULL,
00695                          CbcStrategy * strategy=NULL);
00696   
00698   virtual OsiSolverInterface * clone(bool copyData = true) const;
00699   
00701   OsiCbcSolverInterface (const OsiCbcSolverInterface &);
00702 #if 0    
00704   OsiCbcSolverInterface (CbcModel * rhs, bool reallyOwn=false);
00705   
00707   void releaseCbc();
00708 #endif    
00710   OsiCbcSolverInterface & operator=(const OsiCbcSolverInterface& rhs);
00711   
00713   virtual ~OsiCbcSolverInterface ();
00714   
00716   //---------------------------------------------------------------------------
00717   
00718 protected:
00720 
00721 
00722   virtual void applyRowCut(const OsiRowCut& rc);
00723   
00725   virtual void applyColCut(const OsiColCut& cc);
00727 
00729 
00730   mutable CbcModel * modelPtr_;
00732 };
00733 
00734 //#############################################################################
00742 void
00743 OsiCbcSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00744 
00745 #endif

Generated on Thu May 15 22:04:43 2008 by  doxygen 1.4.7