/home/coin/SVN-release/Cbc-1.1.1/Osi/src/OsiClp/OsiClpSolverInterface.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 OsiClpSolverInterface_H
00005 #define OsiClpSolverInterface_H
00006 
00007 #include <string>
00008 #include <cfloat>
00009 #include <map>
00010 
00011 #include "ClpSimplex.hpp"
00012 #include "CoinPackedMatrix.hpp"
00013 #include "OsiSolverInterface.hpp"
00014 #include "CoinWarmStartBasis.hpp"
00015 
00016 class OsiRowCut;
00017 class OsiClpUserSolver;
00018 #ifndef COIN_DBL_MAX
00019 static const double OsiClpInfinity = DBL_MAX;
00020 #else
00021 static const double OsiClpInfinity = COIN_DBL_MAX;
00022 #endif
00023 
00024 //#############################################################################
00025 
00032 class OsiClpSolverInterface :
00033   virtual public OsiSolverInterface {
00034   friend void OsiClpSolverInterfaceUnitTest(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   
00051 
00052   
00058   virtual void enableSimplexInterface(bool doingPrimal);
00059   
00061   virtual void disableSimplexInterface();
00065   virtual int canDoSimplexInterface() const;
00072   virtual void enableFactorization() const;
00074   virtual void disableFactorization() const;
00075   
00091   void setupForRepeatedUse(int senseOfAdventure=0, int printOut=0);
00093   virtual void synchronizeModel();
00094   // Sleazy methods to fool const requirements (no less safe as modelPtr_ mutable)
00095   void setSpecialOptionsMutable(unsigned int value) const;
00096 
00101   virtual bool basisIsAvailable() const;
00102   
00118   virtual void getBasisStatus(int* cstat, int* rstat) const;
00119   
00129   virtual int setBasisStatus(const int* cstat, const int* rstat);
00130   
00138   virtual int pivot(int colIn, int colOut, int outStatus);
00139   
00151   virtual int primalPivotResult(int colIn, int sign, 
00152                                 int& colOut, int& outStatus, 
00153                                 double& t, CoinPackedVector* dx);
00154   
00161   virtual int dualPivotResult(int& colIn, int& sign, 
00162                               int colOut, int outStatus, 
00163                               double& t, CoinPackedVector* dx);
00164   
00166   virtual void getReducedGradient(double* columnReducedCosts, 
00167                                   double * duals,
00168                                   const double * c);
00169   
00172   virtual void setObjectiveAndRefresh(double* c);
00173   
00175   virtual void getBInvARow(int row, double* z, double * slack=NULL) const;
00176   
00178   virtual void getBInvRow(int row, double* z) const;
00179   
00181   virtual void getBInvACol(int col, double* vec) const ;
00182   
00184   virtual void getBInvCol(int col, double* vec) const ;
00185   
00190   virtual void getBasics(int* index) const;
00191   
00193   //---------------------------------------------------------------------------
00209   // Set an integer parameter
00210   bool setIntParam(OsiIntParam key, int value);
00211   // Set an double parameter
00212   bool setDblParam(OsiDblParam key, double value);
00213   // Set a string parameter
00214   bool setStrParam(OsiStrParam key, const std::string & value);
00215   // Get an integer parameter
00216   bool getIntParam(OsiIntParam key, int& value) const;
00217   // Get an double parameter
00218   bool getDblParam(OsiDblParam key, double& value) const;
00219   // Get a string parameter
00220   bool getStrParam(OsiStrParam key, std::string& value) const;
00221   // Set a hint parameter - overrides OsiSolverInterface
00222   virtual bool setHintParam(OsiHintParam key, bool yesNo=true,
00223                             OsiHintStrength strength=OsiHintTry,
00224                             void * otherInformation=NULL);
00226   
00227   //---------------------------------------------------------------------------
00229 
00230 
00231   virtual bool isAbandoned() const;
00233   virtual bool isProvenOptimal() const;
00235   virtual bool isProvenPrimalInfeasible() const;
00237   virtual bool isProvenDualInfeasible() const;
00239   virtual bool isPrimalObjectiveLimitReached() const;
00241   virtual bool isDualObjectiveLimitReached() const;
00243   virtual bool isIterationLimitReached() const;
00245   
00246   //---------------------------------------------------------------------------
00249   
00257   virtual CoinWarmStart *getEmptyWarmStart () const;
00258   
00260   virtual CoinWarmStart* getWarmStart() const;
00263   virtual bool setWarmStart(const CoinWarmStart* warmstart);
00265   
00266   //---------------------------------------------------------------------------
00273 
00274   virtual void markHotStart();
00276   virtual void solveFromHotStart();
00278   virtual void unmarkHotStart();
00280   
00281   //---------------------------------------------------------------------------
00296 
00297   virtual int getNumCols() const {
00298     return modelPtr_->numberColumns(); }
00299   
00301   virtual int getNumRows() const {
00302     return modelPtr_->numberRows(); }
00303   
00305   virtual int getNumElements() const {
00306     int retVal = 0;
00307     const CoinPackedMatrix * matrix =modelPtr_->matrix();
00308     if ( matrix != NULL ) retVal=matrix->getNumElements();
00309     return retVal; }
00310 
00312     virtual std::string getRowName(int rowIndex) const;
00313     
00315     virtual std::string getColName(int colIndex) const;
00316     
00317   
00319   virtual const double * getColLower() const { return modelPtr_->columnLower(); }
00320   
00322   virtual const double * getColUpper() const { return modelPtr_->columnUpper(); }
00323   
00333   virtual const char * getRowSense() const;
00334   
00343   virtual const double * getRightHandSide() const ;
00344   
00353   virtual const double * getRowRange() const ;
00354   
00356   virtual const double * getRowLower() const { return modelPtr_->rowLower(); }
00357   
00359   virtual const double * getRowUpper() const { return modelPtr_->rowUpper(); }
00360   
00362   virtual const double * getObjCoefficients() const 
00363   { return modelPtr_->objective(); }
00364   
00366   virtual double getObjSense() const 
00367   { return modelPtr_->optimizationDirection(); }
00368   
00370   virtual bool isContinuous(int colNumber) const;
00371   
00372   
00374   virtual const CoinPackedMatrix * getMatrixByRow() const;
00375   
00377   virtual const CoinPackedMatrix * getMatrixByCol() const;
00378   
00380   virtual double getInfinity() const { return OsiClpInfinity; }
00382   
00385 
00386   virtual const double * getColSolution() const; 
00387   
00389   virtual const double * getRowPrice() const;
00390   
00392   virtual const double * getReducedCost() const; 
00393   
00396   virtual const double * getRowActivity() const; 
00397   
00399   virtual double getObjValue() const;
00400   
00403   virtual int getIterationCount() const 
00404   { return modelPtr_->numberIterations(); }
00405   
00417   virtual std::vector<double*> getDualRays(int maxNumRays) const;
00429   virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
00430   
00432 
00433   
00434   //---------------------------------------------------------------------------
00435   
00438   //-------------------------------------------------------------------------
00442   virtual void setObjCoeff( int elementIndex, double elementValue );
00443   
00446   virtual void setColLower( int elementIndex, double elementValue );
00447   
00450   virtual void setColUpper( int elementIndex, double elementValue );
00451   
00453   virtual void setColBounds( int elementIndex,
00454                              double lower, double upper );
00455   
00464   virtual void setColSetBounds(const int* indexFirst,
00465                                const int* indexLast,
00466                                const double* boundList);
00467   
00470   virtual void setRowLower( int elementIndex, double elementValue );
00471   
00474   virtual void setRowUpper( int elementIndex, double elementValue ) ;
00475   
00477   virtual void setRowBounds( int elementIndex,
00478                              double lower, double upper ) ;
00479   
00481   virtual void setRowType(int index, char sense, double rightHandSide,
00482                           double range);
00483   
00492   virtual void setRowSetBounds(const int* indexFirst,
00493                                const int* indexLast,
00494                                const double* boundList);
00495   
00506   virtual void setRowSetTypes(const int* indexFirst,
00507                               const int* indexLast,
00508                               const char* senseList,
00509                               const double* rhsList,
00510                               const double* rangeList);
00515     virtual void setObjective(const double * array);
00516 
00521     virtual void setColLower(const double * array);
00522 
00527     virtual void setColUpper(const double * array);
00529       virtual void setRowName(int rowIndex, std::string & name) ;
00530     
00532       virtual void setColName(int colIndex, std::string & name) ;
00533     
00535   
00536   //-------------------------------------------------------------------------
00540   virtual void setContinuous(int index);
00542   virtual void setInteger(int index);
00545   virtual void setContinuous(const int* indices, int len);
00548   virtual void setInteger(const int* indices, int len);
00550   
00551   //-------------------------------------------------------------------------
00553   virtual void setObjSense(double s ) 
00554   { modelPtr_->setOptimizationDirection( s < 0 ? -1 : 1); }
00555   
00566   virtual void setColSolution(const double * colsol);
00567   
00578   virtual void setRowPrice(const double * rowprice);
00579   
00580   //-------------------------------------------------------------------------
00586   virtual void addCol(const CoinPackedVectorBase& vec,
00587                       const double collb, const double colub,   
00588                       const double obj);
00590   virtual void addCol(int numberElements, const int * rows, const double * elements,
00591                       const double collb, const double colub,   
00592                       const double obj) ;
00594   virtual void addCols(const int numcols,
00595                        const CoinPackedVectorBase * const * cols,
00596                        const double* collb, const double* colub,   
00597                        const double* obj);
00599   virtual void deleteCols(const int num, const int * colIndices);
00600   
00602   virtual void addRow(const CoinPackedVectorBase& vec,
00603                       const double rowlb, const double rowub);
00605   virtual void addRow(const CoinPackedVectorBase& vec,
00606                       const char rowsen, const double rowrhs,   
00607                       const double rowrng);
00609   virtual void addRows(const int numrows,
00610                        const CoinPackedVectorBase * const * rows,
00611                        const double* rowlb, const double* rowub);
00613   virtual void addRows(const int numrows,
00614                        const CoinPackedVectorBase * const * rows,
00615                        const char* rowsen, const double* rowrhs,   
00616                        const double* rowrng);
00617 
00619   void modifyCoefficient(int row, int column, double newElement,
00620                         bool keepZero=false)
00621         {modelPtr_->modifyCoefficient(row,column,newElement, keepZero);}
00622 
00624   virtual void deleteRows(const int num, const int * rowIndices);
00625   
00626   //-----------------------------------------------------------------------
00630   virtual void applyRowCuts(int numberCuts, const OsiRowCut * cuts);
00635   virtual void applyRowCuts(int numberCuts, const OsiRowCut ** cuts);
00637 
00638   
00639   //---------------------------------------------------------------------------
00640   
00641 public:
00642   
00656   virtual void loadProblem(const CoinPackedMatrix& matrix,
00657                            const double* collb, const double* colub,   
00658                            const double* obj,
00659                            const double* rowlb, const double* rowub);
00660   
00668   virtual void assignProblem(CoinPackedMatrix*& matrix,
00669                              double*& collb, double*& colub, double*& obj,
00670                              double*& rowlb, double*& rowub);
00671   
00684   virtual void loadProblem(const CoinPackedMatrix& matrix,
00685                            const double* collb, const double* colub,
00686                            const double* obj,
00687                            const char* rowsen, const double* rowrhs,   
00688                            const double* rowrng);
00689   
00697   virtual void assignProblem(CoinPackedMatrix*& matrix,
00698                              double*& collb, double*& colub, double*& obj,
00699                              char*& rowsen, double*& rowrhs,
00700                              double*& rowrng);
00701   
00704   virtual void loadProblem(const int numcols, const int numrows,
00705                            const CoinBigIndex * start, const int* index,
00706                            const double* value,
00707                            const double* collb, const double* colub,   
00708                            const double* obj,
00709                            const double* rowlb, const double* rowub);
00710   
00713   virtual void loadProblem(const int numcols, const int numrows,
00714                            const CoinBigIndex * start, const int* index,
00715                            const double* value,
00716                            const double* collb, const double* colub,   
00717                            const double* obj,
00718                            const char* rowsen, const double* rowrhs,   
00719                            const double* rowrng);
00721   virtual int loadFromCoinModel (  CoinModel & modelObject, bool keepSolution=false);
00724   virtual int readMps(const char *filename,
00725                       const char *extension = "mps") ;
00726   
00731   virtual void writeMps(const char *filename,
00732                         const char *extension = "mps",
00733                         double objSense=0.0) const;
00742   virtual int writeMpsNative(const char *filename, 
00743                              const char ** rowNames, const char ** columnNames,
00744                              int formatType=0,int numberAcross=2,
00745                              double objSense=0.0) const ;
00747   virtual int readLp(const char *filename, const double epsilon = 1e-5);
00753   virtual void writeLp(const char *filename,
00754                        const char *extension = "lp",
00755                        double epsilon = 1e-5,
00756                        int numberAcross = 10,
00757                        int decimals = 5,
00758                        double objSense = 0.0,
00759                        bool useRowNames = true) const;
00764   virtual void writeLp(FILE *fp,
00765                double epsilon = 1e-5,
00766                int numberAcross = 10,
00767                int decimals = 5,
00768                double objSense = 0.0,
00769                bool useRowNames = true) const;
00775   virtual void replaceMatrixOptional(const CoinPackedMatrix & matrix);
00777   virtual void replaceMatrix(const CoinPackedMatrix & matrix) ;
00779   
00784 
00785   void newLanguage(CoinMessages::Language language);
00786   void setLanguage(CoinMessages::Language language)
00787   {newLanguage(language);};
00789     void generateCpp( FILE * fp);
00791   //---------------------------------------------------------------------------
00792   
00795 
00796   ClpSimplex * getModelPtr() const ;
00798   inline unsigned int specialOptions() const
00799   { return specialOptions_;};
00800   void setSpecialOptions(unsigned int value);
00802   inline int cleanupScaling() const
00803   { return cleanupScaling_;};
00816   inline void setCleanupScaling(int value)
00817   { cleanupScaling_=value;};
00820   inline double smallestElementInCut() const
00821   { return smallestElementInCut_;};
00824   inline void setSmallestElementInCut(double value)
00825   { smallestElementInCut_=value;};
00832   inline double smallestChangeInCut() const
00833   { return smallestChangeInCut_;};
00840   inline void setSmallestChangeInCut(double value)
00841   { smallestChangeInCut_=value;};
00843   
00844   //---------------------------------------------------------------------------
00845   
00848 
00849   OsiClpSolverInterface ();
00850   
00852   virtual OsiSolverInterface * clone(bool copyData = true) const;
00853   
00855   OsiClpSolverInterface (const OsiClpSolverInterface &);
00856   
00858   OsiClpSolverInterface (ClpSimplex * rhs, bool reallyOwn=false);
00859   
00861   void releaseClp();
00862   
00864   OsiClpSolverInterface & operator=(const OsiClpSolverInterface& rhs);
00865   
00867   virtual ~OsiClpSolverInterface ();
00868   
00870   virtual void reset();
00872   
00873   //---------------------------------------------------------------------------
00874   
00875 protected:
00877 
00878 
00879   virtual void applyRowCut(const OsiRowCut& rc);
00880   
00882   virtual void applyColCut(const OsiColCut& cc);
00884   
00885   //---------------------------------------------------------------------------
00886   
00887 protected:
00890 
00891   void gutsOfDestructor();
00892   
00894   void freeCachedResults() const;
00895   
00897   void extractSenseRhsRange() const;
00898   
00900   void fillParamMaps();
00909   CoinWarmStartBasis getBasis(ClpSimplex * model) const;
00918   void setBasis( const CoinWarmStartBasis & basis, ClpSimplex * model);
00920   void crunch();
00921 public:
00923   inline const double * upRange() const
00924   { return rowActivity_;};
00925   inline const double * downRange() const
00926   { return columnActivity_;};
00928   inline void passInRanges(int * array)
00929   { whichRange_=array;};
00930 protected:
00932   
00935 
00936   mutable ClpSimplex * modelPtr_;
00938   double * linearObjective_;
00941 
00942   mutable char    *rowsense_;
00943   
00945   mutable double  *rhs_;
00946   
00950   mutable double  *rowrange_;
00951   
00954   mutable CoinWarmStartBasis* ws_;
00957   mutable double * rowActivity_;
00958   mutable double * columnActivity_;
00960   ClpSimplex * smallModel_;
00962   ClpFactorization * factorization_;
00965   double smallestElementInCut_;
00969   double smallestChangeInCut_;
00971   char * spareArrays_;
00973   CoinWarmStartBasis basis_;
00975   int itlimOrig_;
00976   
00978   mutable int lastAlgorithm_;
00979   
00981   bool notOwned_;
00982   
00984   mutable CoinPackedMatrix *matrixByRow_;  
00985   
00987   char * integerInformation_;
00988   
00993   int * whichRange_;
00994 
00995   //std::map<OsiIntParam, ClpIntParam> intParamMap_;
00996   //std::map<OsiDblParam, ClpDblParam> dblParamMap_;
00997   //std::map<OsiStrParam, ClpStrParam> strParamMap_;
00998   
01000   mutable ClpDataSave saveData_;
01013   int cleanupScaling_;
01030   mutable unsigned int specialOptions_;
01032 };
01033 
01034 //#############################################################################
01042 void
01043 OsiClpSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
01044 
01045 #endif

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