/home/coin/SVN-release/Cbc-1.1.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 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 
00281   
00282   //---------------------------------------------------------------------------
00283   
00286   //-------------------------------------------------------------------------
00290   virtual void setObjCoeff( int elementIndex, double elementValue );
00291   
00294   virtual void setColLower( int elementIndex, double elementValue );
00295   
00298   virtual void setColUpper( int elementIndex, double elementValue );
00299   
00301   virtual void setColBounds( int elementIndex,
00302                              double lower, double upper );
00303   
00312   virtual void setColSetBounds(const int* indexFirst,
00313                                const int* indexLast,
00314                                const double* boundList);
00315   
00318   virtual void setRowLower( int elementIndex, double elementValue );
00319   
00322   virtual void setRowUpper( int elementIndex, double elementValue ) ;
00323   
00325   virtual void setRowBounds( int elementIndex,
00326                              double lower, double upper ) ;
00327   
00329   virtual void setRowType(int index, char sense, double rightHandSide,
00330                           double range);
00331   
00340   virtual void setRowSetBounds(const int* indexFirst,
00341                                const int* indexLast,
00342                                const double* boundList);
00343   
00354   virtual void setRowSetTypes(const int* indexFirst,
00355                               const int* indexLast,
00356                               const char* senseList,
00357                               const double* rhsList,
00358                               const double* rangeList);
00360   
00361   //-------------------------------------------------------------------------
00365   virtual void setContinuous(int index);
00367   virtual void setInteger(int index);
00370   virtual void setContinuous(const int* indices, int len);
00373   virtual void setInteger(const int* indices, int len);
00375   
00376   //-------------------------------------------------------------------------
00378   virtual void setObjSense(double s ); 
00379   
00390   virtual void setColSolution(const double * colsol);
00391   
00402   virtual void setRowPrice(const double * rowprice);
00403   
00404   //-------------------------------------------------------------------------
00410   virtual void addCol(const CoinPackedVectorBase& vec,
00411                       const double collb, const double colub,   
00412                       const double obj);
00414   virtual void addCol(int numberElements, const int * rows, const double * elements,
00415                       const double collb, const double colub,   
00416                       const double obj) ;
00418   virtual void addCols(const int numcols,
00419                        const CoinPackedVectorBase * const * cols,
00420                        const double* collb, const double* colub,   
00421                        const double* obj);
00423   virtual void deleteCols(const int num, const int * colIndices);
00424   
00426   virtual void addRow(const CoinPackedVectorBase& vec,
00427                       const double rowlb, const double rowub);
00429   virtual void addRow(const CoinPackedVectorBase& vec,
00430                       const char rowsen, const double rowrhs,   
00431                       const double rowrng);
00433   virtual void addRows(const int numrows,
00434                        const CoinPackedVectorBase * const * rows,
00435                        const double* rowlb, const double* rowub);
00437   virtual void addRows(const int numrows,
00438                        const CoinPackedVectorBase * const * rows,
00439                        const char* rowsen, const double* rowrhs,   
00440                        const double* rowrng);
00442   virtual void deleteRows(const int num, const int * rowIndices);
00443   
00444   //-----------------------------------------------------------------------
00448   virtual void applyRowCuts(int numberCuts, const OsiRowCut * cuts);
00453   virtual void applyRowCuts(int numberCuts, const OsiRowCut ** cuts);
00455 
00456   
00457   //---------------------------------------------------------------------------
00458   
00459 public:
00460   
00474   virtual void loadProblem(const CoinPackedMatrix& matrix,
00475                            const double* collb, const double* colub,   
00476                            const double* obj,
00477                            const double* rowlb, const double* rowub);
00478   
00486   virtual void assignProblem(CoinPackedMatrix*& matrix,
00487                              double*& collb, double*& colub, double*& obj,
00488                              double*& rowlb, double*& rowub);
00489   
00502   virtual void loadProblem(const CoinPackedMatrix& matrix,
00503                            const double* collb, const double* colub,
00504                            const double* obj,
00505                            const char* rowsen, const double* rowrhs,   
00506                            const double* rowrng);
00507   
00515   virtual void assignProblem(CoinPackedMatrix*& matrix,
00516                              double*& collb, double*& colub, double*& obj,
00517                              char*& rowsen, double*& rowrhs,
00518                              double*& rowrng);
00519   
00522   virtual void loadProblem(const int numcols, const int numrows,
00523                            const CoinBigIndex * start, const int* index,
00524                            const double* value,
00525                            const double* collb, const double* colub,   
00526                            const double* obj,
00527                            const double* rowlb, const double* rowub);
00528   
00531   virtual void loadProblem(const int numcols, const int numrows,
00532                            const CoinBigIndex * start, const int* index,
00533                            const double* value,
00534                            const double* collb, const double* colub,   
00535                            const double* obj,
00536                            const char* rowsen, const double* rowrhs,   
00537                            const double* rowrng);
00540   virtual int readMps(const char *filename,
00541                       const char *extension = "mps") ;
00542   
00547   virtual void writeMps(const char *filename,
00548                         const char *extension = "mps",
00549                         double objSense=0.0) const;
00558   virtual int writeMpsNative(const char *filename, 
00559                              const char ** rowNames, const char ** columnNames,
00560                              int formatType=0,int numberAcross=2,
00561                              double objSense=0.0) const ;
00563   
00568 
00569   void newLanguage(CoinMessages::Language language);
00570   void setLanguage(CoinMessages::Language language)
00571   {newLanguage(language);};
00573   //---------------------------------------------------------------------------
00574   
00577 
00578   inline CbcModel * getModelPtr() const 
00579   { return modelPtr_;};
00581   inline OsiSolverInterface * getRealSolverPtr() const 
00582   { return modelPtr_->solver();};
00584   inline void setCutoff(double value) 
00585   { modelPtr_->setCutoff(value);};
00587   inline double getCutoff() const
00588   { return modelPtr_->getCutoff();};
00590   inline void setMaximumNodes( int value)
00591   { modelPtr_->setMaximumNodes(value);};
00593   inline int getMaximumNodes() const
00594   { return modelPtr_->getMaximumNodes();};
00596   inline void setMaximumSolutions( int value) 
00597   { modelPtr_->setMaximumSolutions(value);};
00599   inline int getMaximumSolutions() const 
00600   { return modelPtr_->getMaximumSolutions();};
00602   inline void setMaximumSeconds( double value) 
00603   { modelPtr_->setMaximumSeconds(value);};
00605   inline double getMaximumSeconds() const 
00606   { return modelPtr_->getMaximumSeconds();};
00608   inline bool isNodeLimitReached() const
00609   { return modelPtr_->isNodeLimitReached();};
00611   inline bool isSolutionLimitReached() const
00612   { return modelPtr_->isSolutionLimitReached();};
00614   inline int getNodeCount() const
00615   { return modelPtr_->getNodeCount();};
00617     inline int status() const
00618   { return modelPtr_->status();};
00620   
00621   //---------------------------------------------------------------------------
00622   
00625 
00626   OsiCbcSolverInterface (OsiSolverInterface * solver=NULL,
00627                          CbcStrategy * strategy=NULL);
00628   
00630   virtual OsiSolverInterface * clone(bool copyData = true) const;
00631   
00633   OsiCbcSolverInterface (const OsiCbcSolverInterface &);
00634 #if 0    
00636   OsiCbcSolverInterface (CbcModel * rhs, bool reallyOwn=false);
00637   
00639   void releaseCbc();
00640 #endif    
00642   OsiCbcSolverInterface & operator=(const OsiCbcSolverInterface& rhs);
00643   
00645   virtual ~OsiCbcSolverInterface ();
00646   
00648   //---------------------------------------------------------------------------
00649   
00650 protected:
00652 
00653 
00654   virtual void applyRowCut(const OsiRowCut& rc);
00655   
00657   virtual void applyColCut(const OsiColCut& cc);
00659 
00661 
00662   mutable CbcModel * modelPtr_;
00664 };
00665 
00666 //#############################################################################
00674 void
00675 OsiCbcSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00676 
00677 #endif

Generated on Thu May 15 21:59:05 2008 by  doxygen 1.4.7