/home/coin/SVN-release/Osi-0.96.0/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 
00181   virtual void getBInvARow(int row, CoinIndexedVector * z, CoinIndexedVector * slack=NULL,
00182                            bool keepScaled=false) const;
00183   
00185   virtual void getBInvRow(int row, double* z) const;
00186   
00188   virtual void getBInvACol(int col, double* vec) const ;
00189   
00190   
00192   virtual void getBInvACol(int col, CoinIndexedVector * vec) const ;
00197   virtual void getBInvACol(CoinIndexedVector * vec) const ;
00198   
00200   virtual void getBInvCol(int col, double* vec) const ;
00201   
00206   virtual void getBasics(int* index) const;
00207   
00209   //---------------------------------------------------------------------------
00225   // Set an integer parameter
00226   bool setIntParam(OsiIntParam key, int value);
00227   // Set an double parameter
00228   bool setDblParam(OsiDblParam key, double value);
00229   // Set a string parameter
00230   bool setStrParam(OsiStrParam key, const std::string & value);
00231   // Get an integer parameter
00232   bool getIntParam(OsiIntParam key, int& value) const;
00233   // Get an double parameter
00234   bool getDblParam(OsiDblParam key, double& value) const;
00235   // Get a string parameter
00236   bool getStrParam(OsiStrParam key, std::string& value) const;
00237   // Set a hint parameter - overrides OsiSolverInterface
00238   virtual bool setHintParam(OsiHintParam key, bool yesNo=true,
00239                             OsiHintStrength strength=OsiHintTry,
00240                             void * otherInformation=NULL);
00242   
00243   //---------------------------------------------------------------------------
00245 
00246 
00247   virtual bool isAbandoned() const;
00249   virtual bool isProvenOptimal() const;
00251   virtual bool isProvenPrimalInfeasible() const;
00253   virtual bool isProvenDualInfeasible() const;
00255   virtual bool isPrimalObjectiveLimitReached() const;
00257   virtual bool isDualObjectiveLimitReached() const;
00259   virtual bool isIterationLimitReached() const;
00261   
00262   //---------------------------------------------------------------------------
00265   
00273   virtual CoinWarmStart *getEmptyWarmStart () const;
00274   
00276   virtual CoinWarmStart* getWarmStart() const;
00279   virtual bool setWarmStart(const CoinWarmStart* warmstart);
00281   
00282   //---------------------------------------------------------------------------
00289 
00290   virtual void markHotStart();
00292   virtual void solveFromHotStart();
00294   virtual void unmarkHotStart();
00296   
00297   //---------------------------------------------------------------------------
00312 
00313   virtual int getNumCols() const {
00314     return modelPtr_->numberColumns(); }
00315   
00317   virtual int getNumRows() const {
00318     return modelPtr_->numberRows(); }
00319   
00321   virtual int getNumElements() const {
00322     int retVal = 0;
00323     const CoinPackedMatrix * matrix =modelPtr_->matrix();
00324     if ( matrix != NULL ) retVal=matrix->getNumElements();
00325     return retVal; }
00326 
00328     virtual std::string getRowName(int rowIndex) const;
00329     
00331     virtual std::string getColName(int colIndex) const;
00332     
00333   
00335   virtual const double * getColLower() const { return modelPtr_->columnLower(); }
00336   
00338   virtual const double * getColUpper() const { return modelPtr_->columnUpper(); }
00339   
00349   virtual const char * getRowSense() const;
00350   
00359   virtual const double * getRightHandSide() const ;
00360   
00369   virtual const double * getRowRange() const ;
00370   
00372   virtual const double * getRowLower() const { return modelPtr_->rowLower(); }
00373   
00375   virtual const double * getRowUpper() const { return modelPtr_->rowUpper(); }
00376   
00378   virtual const double * getObjCoefficients() const 
00379   { return modelPtr_->objective(); }
00380   
00382   virtual double getObjSense() const 
00383   { return modelPtr_->optimizationDirection(); }
00384   
00386   virtual bool isContinuous(int colNumber) const;
00387   
00388   
00390   virtual const CoinPackedMatrix * getMatrixByRow() const;
00391   
00393   virtual const CoinPackedMatrix * getMatrixByCol() const;
00394   
00396   virtual double getInfinity() const { return OsiClpInfinity; }
00398   
00401 
00402   virtual const double * getColSolution() const; 
00403   
00405   virtual const double * getRowPrice() const;
00406   
00408   virtual const double * getReducedCost() const; 
00409   
00412   virtual const double * getRowActivity() const; 
00413   
00415   virtual double getObjValue() const;
00416   
00419   virtual int getIterationCount() const 
00420   { return modelPtr_->numberIterations(); }
00421   
00433   virtual std::vector<double*> getDualRays(int maxNumRays) const;
00445   virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
00446   
00448 
00449   
00450   //---------------------------------------------------------------------------
00451   
00454   //-------------------------------------------------------------------------
00458   virtual void setObjCoeff( int elementIndex, double elementValue );
00459   
00462   virtual void setColLower( int elementIndex, double elementValue );
00463   
00466   virtual void setColUpper( int elementIndex, double elementValue );
00467   
00469   virtual void setColBounds( int elementIndex,
00470                              double lower, double upper );
00471   
00480   virtual void setColSetBounds(const int* indexFirst,
00481                                const int* indexLast,
00482                                const double* boundList);
00483   
00486   virtual void setRowLower( int elementIndex, double elementValue );
00487   
00490   virtual void setRowUpper( int elementIndex, double elementValue ) ;
00491   
00493   virtual void setRowBounds( int elementIndex,
00494                              double lower, double upper ) ;
00495   
00497   virtual void setRowType(int index, char sense, double rightHandSide,
00498                           double range);
00499   
00508   virtual void setRowSetBounds(const int* indexFirst,
00509                                const int* indexLast,
00510                                const double* boundList);
00511   
00522   virtual void setRowSetTypes(const int* indexFirst,
00523                               const int* indexLast,
00524                               const char* senseList,
00525                               const double* rhsList,
00526                               const double* rangeList);
00531     virtual void setObjective(const double * array);
00532 
00537     virtual void setColLower(const double * array);
00538 
00543     virtual void setColUpper(const double * array);
00545       virtual void setRowName(int rowIndex, std::string & name) ;
00546     
00548       virtual void setColName(int colIndex, std::string & name) ;
00549     
00551   
00552   //-------------------------------------------------------------------------
00556   virtual void setContinuous(int index);
00558   virtual void setInteger(int index);
00561   virtual void setContinuous(const int* indices, int len);
00564   virtual void setInteger(const int* indices, int len);
00566   
00567   //-------------------------------------------------------------------------
00569   virtual void setObjSense(double s ) 
00570   { modelPtr_->setOptimizationDirection( s < 0 ? -1 : 1); }
00571   
00582   virtual void setColSolution(const double * colsol);
00583   
00594   virtual void setRowPrice(const double * rowprice);
00595   
00596   //-------------------------------------------------------------------------
00602   virtual void addCol(const CoinPackedVectorBase& vec,
00603                       const double collb, const double colub,   
00604                       const double obj);
00606   virtual void addCol(int numberElements, const int * rows, const double * elements,
00607                       const double collb, const double colub,   
00608                       const double obj) ;
00610   virtual void addCols(const int numcols,
00611                        const CoinPackedVectorBase * const * cols,
00612                        const double* collb, const double* colub,   
00613                        const double* obj);
00615   virtual void deleteCols(const int num, const int * colIndices);
00616   
00618   virtual void addRow(const CoinPackedVectorBase& vec,
00619                       const double rowlb, const double rowub);
00621   virtual void addRow(const CoinPackedVectorBase& vec,
00622                       const char rowsen, const double rowrhs,   
00623                       const double rowrng);
00625   virtual void addRows(const int numrows,
00626                        const CoinPackedVectorBase * const * rows,
00627                        const double* rowlb, const double* rowub);
00629   virtual void addRows(const int numrows,
00630                        const CoinPackedVectorBase * const * rows,
00631                        const char* rowsen, const double* rowrhs,   
00632                        const double* rowrng);
00633 
00635   virtual void addRows(const int numrows,
00636                        const int * rowStarts, const int * columns, const double * element,
00637                        const double* rowlb, const double* rowub);
00639   void modifyCoefficient(int row, int column, double newElement,
00640                         bool keepZero=false)
00641         {modelPtr_->modifyCoefficient(row,column,newElement, keepZero);}
00642 
00644   virtual void deleteRows(const int num, const int * rowIndices);
00645   
00646   //-----------------------------------------------------------------------
00650   virtual void applyRowCuts(int numberCuts, const OsiRowCut * cuts);
00655   virtual void applyRowCuts(int numberCuts, const OsiRowCut ** cuts);
00657 
00658   
00659   //---------------------------------------------------------------------------
00660   
00661 public:
00662   
00676   virtual void loadProblem(const CoinPackedMatrix& matrix,
00677                            const double* collb, const double* colub,   
00678                            const double* obj,
00679                            const double* rowlb, const double* rowub);
00680   
00688   virtual void assignProblem(CoinPackedMatrix*& matrix,
00689                              double*& collb, double*& colub, double*& obj,
00690                              double*& rowlb, double*& rowub);
00691   
00704   virtual void loadProblem(const CoinPackedMatrix& matrix,
00705                            const double* collb, const double* colub,
00706                            const double* obj,
00707                            const char* rowsen, const double* rowrhs,   
00708                            const double* rowrng);
00709   
00717   virtual void assignProblem(CoinPackedMatrix*& matrix,
00718                              double*& collb, double*& colub, double*& obj,
00719                              char*& rowsen, double*& rowrhs,
00720                              double*& rowrng);
00721   
00724   virtual void loadProblem(const int numcols, const int numrows,
00725                            const CoinBigIndex * start, const int* index,
00726                            const double* value,
00727                            const double* collb, const double* colub,   
00728                            const double* obj,
00729                            const double* rowlb, const double* rowub);
00730   
00733   virtual void loadProblem(const int numcols, const int numrows,
00734                            const CoinBigIndex * start, const int* index,
00735                            const double* value,
00736                            const double* collb, const double* colub,   
00737                            const double* obj,
00738                            const char* rowsen, const double* rowrhs,   
00739                            const double* rowrng);
00741   virtual int loadFromCoinModel (  CoinModel & modelObject, bool keepSolution=false);
00744   virtual int readMps(const char *filename,
00745                       const char *extension = "mps") ;
00748   int readMps(const char *filename,bool keepNames,bool allowErrors);
00749   
00750 
00755   virtual void writeMps(const char *filename,
00756                         const char *extension = "mps",
00757                         double objSense=0.0) const;
00766   virtual int writeMpsNative(const char *filename, 
00767                              const char ** rowNames, const char ** columnNames,
00768                              int formatType=0,int numberAcross=2,
00769                              double objSense=0.0) const ;
00771   virtual int readLp(const char *filename, const double epsilon = 1e-5);
00777   virtual void writeLp(const char *filename,
00778                        const char *extension = "lp",
00779                        double epsilon = 1e-5,
00780                        int numberAcross = 10,
00781                        int decimals = 5,
00782                        double objSense = 0.0,
00783                        bool useRowNames = true) const;
00788   virtual void writeLp(FILE *fp,
00789                double epsilon = 1e-5,
00790                int numberAcross = 10,
00791                int decimals = 5,
00792                double objSense = 0.0,
00793                bool useRowNames = true) const;
00799   virtual void replaceMatrixOptional(const CoinPackedMatrix & matrix);
00801   virtual void replaceMatrix(const CoinPackedMatrix & matrix) ;
00803   
00808 
00809   void newLanguage(CoinMessages::Language language);
00810   void setLanguage(CoinMessages::Language language)
00811   {newLanguage(language);};
00813     void generateCpp( FILE * fp);
00815   //---------------------------------------------------------------------------
00816   
00819 
00820   ClpSimplex * getModelPtr() const ;
00822   inline unsigned int specialOptions() const
00823   { return specialOptions_;};
00824   void setSpecialOptions(unsigned int value);
00826   inline int cleanupScaling() const
00827   { return cleanupScaling_;};
00840   inline void setCleanupScaling(int value)
00841   { cleanupScaling_=value;};
00844   inline double smallestElementInCut() const
00845   { return smallestElementInCut_;};
00848   inline void setSmallestElementInCut(double value)
00849   { smallestElementInCut_=value;};
00856   inline double smallestChangeInCut() const
00857   { return smallestChangeInCut_;};
00864   inline void setSmallestChangeInCut(double value)
00865   { smallestChangeInCut_=value;};
00867   inline void setSolveOptions(const ClpSolve & options)
00868   { solveOptions_ = options;};
00870   
00871   //---------------------------------------------------------------------------
00872   
00875 
00876   OsiClpSolverInterface ();
00877   
00879   virtual OsiSolverInterface * clone(bool copyData = true) const;
00880   
00882   OsiClpSolverInterface (const OsiClpSolverInterface &);
00883   
00885   OsiClpSolverInterface (ClpSimplex * rhs, bool reallyOwn=false);
00886   
00888   void releaseClp();
00889   
00891   OsiClpSolverInterface & operator=(const OsiClpSolverInterface& rhs);
00892   
00894   virtual ~OsiClpSolverInterface ();
00895   
00897   virtual void reset();
00899   
00900   //---------------------------------------------------------------------------
00901   
00902 protected:
00904 
00905 
00906   virtual void applyRowCut(const OsiRowCut& rc);
00907   
00909   virtual void applyColCut(const OsiColCut& cc);
00911   
00912   //---------------------------------------------------------------------------
00913   
00914 protected:
00917 
00918   void gutsOfDestructor();
00919   
00921   void freeCachedResults() const;
00922   
00924   void extractSenseRhsRange() const;
00925   
00927   void fillParamMaps();
00936   CoinWarmStartBasis getBasis(ClpSimplex * model) const;
00945   void setBasis( const CoinWarmStartBasis & basis, ClpSimplex * model);
00947   void crunch();
00948 public:
00950   inline const double * upRange() const
00951   { return rowActivity_;};
00952   inline const double * downRange() const
00953   { return columnActivity_;};
00955   inline void passInRanges(int * array)
00956   { whichRange_=array;};
00957   // Next few for compatibility
00959   inline void deleteScaleFactors() {};
00961   inline int numberSOS() const
00962   { return 0;};
00964   inline const CoinSet * setInfo() const
00965   { return NULL;};
00966 protected:
00968   
00971 
00972   mutable ClpSimplex * modelPtr_;
00974   double * linearObjective_;
00977 
00978   mutable char    *rowsense_;
00979   
00981   mutable double  *rhs_;
00982   
00986   mutable double  *rowrange_;
00987   
00990   mutable CoinWarmStartBasis* ws_;
00993   mutable double * rowActivity_;
00994   mutable double * columnActivity_;
00996   ClpSimplex * smallModel_;
00998   ClpFactorization * factorization_;
01001   double smallestElementInCut_;
01005   double smallestChangeInCut_;
01007   char * spareArrays_;
01009   CoinWarmStartBasis basis_;
01011   int itlimOrig_;
01012   
01014   mutable int lastAlgorithm_;
01015   
01017   bool notOwned_;
01018   
01020   mutable CoinPackedMatrix *matrixByRow_;  
01021   
01023   char * integerInformation_;
01024   
01029   int * whichRange_;
01030 
01031   //std::map<OsiIntParam, ClpIntParam> intParamMap_;
01032   //std::map<OsiDblParam, ClpDblParam> dblParamMap_;
01033   //std::map<OsiStrParam, ClpStrParam> strParamMap_;
01034   
01036   mutable ClpDataSave saveData_;
01038   ClpSolve solveOptions_;
01051   int cleanupScaling_;
01068   mutable unsigned int specialOptions_;
01070 };
01071 
01072 //#############################################################################
01080 void
01081 OsiClpSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
01082 
01083 #endif

Generated on Fri May 16 00:11:08 2008 by  doxygen 1.4.7