/home/coin/DyLP-1.3.0/1.3/Osi/src/OsiGlpk/OsiGlpkSolverInterface.hpp

Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 // name:     OSI Interface for GLPK
00003 //-----------------------------------------------------------------------------
00004 // Copyright (C) 2001, Vivian De Smedt, Braden Hunsaker
00005 // Copyright (C) 2003  University of Pittsburgh
00006 //   University of Pittsburgh coding done by Brady Hunsaker
00007 // All Rights Reserved.
00008 
00009 #ifndef OsiGlpkSolverInterface_H
00010 #define OsiGlpkSolverInterface_H
00011 
00012 #include <string>
00013 extern "C" {
00014 #include "glpk.h"
00015 }
00016 #include "OsiSolverInterface.hpp"
00017 #include "CoinPackedMatrix.hpp"
00018 #include "CoinWarmStartBasis.hpp"
00019 
00025 class OsiGlpkSolverInterface : virtual public OsiSolverInterface {
00026   friend void OsiGlpkSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00027   
00028 public:
00029   
00030   //---------------------------------------------------------------------------
00033 
00034   virtual void initialSolve();
00035   
00037   virtual void resolve();
00038   
00040   virtual void branchAndBound();
00042   
00043   //---------------------------------------------------------------------------
00059     // Set an integer parameter
00060     bool setIntParam(OsiIntParam key, int value);
00061     // Set an double parameter
00062     bool setDblParam(OsiDblParam key, double value);
00063     // Set a string parameter
00064     bool setStrParam(OsiStrParam key, const std::string & value);
00065     // Set a hint parameter
00066     bool setHintParam(OsiHintParam key, bool sense = true,
00067                       OsiHintStrength strength = OsiHintTry, void *info = 0) ;
00068     // Get an integer parameter
00069     bool getIntParam(OsiIntParam key, int& value) const;
00070     // Get an double parameter
00071     bool getDblParam(OsiDblParam key, double& value) const;
00072     // Get a string parameter
00073     bool getStrParam(OsiStrParam key, std::string& value) const;
00075 
00076   //---------------------------------------------------------------------------
00078 
00079 
00080     virtual bool isAbandoned() const;
00082     virtual bool isProvenOptimal() const;
00084     virtual bool isProvenPrimalInfeasible() const;
00086     virtual bool isProvenDualInfeasible() const;
00088     virtual bool isPrimalObjectiveLimitReached() const;
00090     virtual bool isDualObjectiveLimitReached() const;
00092     virtual bool isIterationLimitReached() const;
00094 
00095   //---------------------------------------------------------------------------
00104   inline CoinWarmStart *getEmptyWarmStart () const
00105   { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; }
00107     virtual CoinWarmStart* getWarmStart() const;
00110     virtual bool setWarmStart(const CoinWarmStart* warmstart);
00112 
00113   //---------------------------------------------------------------------------
00120 
00121     virtual void markHotStart();
00123     virtual void solveFromHotStart();
00125     virtual void unmarkHotStart();
00127 
00128   //---------------------------------------------------------------------------
00143 
00144       virtual int getNumCols() const;
00145   
00147       virtual int getNumRows() const;
00148   
00150       virtual int getNumElements() const;
00151           
00153       virtual const double * getColLower() const;
00154   
00156       virtual const double * getColUpper() const;
00157   
00167       virtual const char * getRowSense() const;
00168   
00177       virtual const double * getRightHandSide() const;
00178   
00187       virtual const double * getRowRange() const;
00188   
00190       virtual const double * getRowLower() const;
00191   
00193       virtual const double * getRowUpper() const;
00194   
00196       virtual const double * getObjCoefficients() const;
00197   
00199       virtual double getObjSense() const;
00200 
00202       virtual bool isContinuous(int colNumber) const;
00203 
00204 #if 0
00206       virtual bool isBinary(int columnNumber) const;
00207   
00212       virtual bool isInteger(int columnNumber) const;
00213   
00215       virtual bool isIntegerNonBinary(int columnNumber) const;
00216   
00218       virtual bool isFreeBinary(int columnNumber) const;
00219 #endif
00220   
00222       virtual const CoinPackedMatrix * getMatrixByRow() const;
00223   
00225       virtual const CoinPackedMatrix * getMatrixByCol() const;
00226   
00228       virtual double getInfinity() const;
00230     
00233 
00234       virtual const double * getColSolution() const;
00235   
00237       virtual const double * getRowPrice() const;
00238   
00240       virtual const double * getReducedCost() const;
00241   
00244       virtual const double * getRowActivity() const;
00245   
00247       virtual double getObjValue() const;
00248   
00251       virtual int getIterationCount() const;
00252   
00264       virtual std::vector<double*> getDualRays(int maxNumRays) const;
00276       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
00277   
00278 #if 0
00279 
00281       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
00282         const;
00283 #endif
00284 
00285 
00286   
00287   //---------------------------------------------------------------------------
00288 
00291     //-------------------------------------------------------------------------
00295       virtual void setObjCoeff( int elementIndex, double elementValue );
00296 
00297       using OsiSolverInterface::setColLower ;
00300       virtual void setColLower( int elementIndex, double elementValue );
00301       
00302       using OsiSolverInterface::setColUpper ;
00305       virtual void setColUpper( int elementIndex, double elementValue );
00306       
00310       virtual void setColBounds( int elementIndex,
00311                                  double lower, double upper );
00312     
00321       virtual void setColSetBounds(const int* indexFirst,
00322                                    const int* indexLast,
00323                                    const double* boundList);
00324       
00327       virtual void setRowLower( int elementIndex, double elementValue );
00328       
00331       virtual void setRowUpper( int elementIndex, double elementValue );
00332     
00336       virtual void setRowBounds( int elementIndex,
00337                                  double lower, double upper );
00338     
00340       virtual void setRowType(int index, char sense, double rightHandSide,
00341                               double range);
00342     
00351       virtual void setRowSetBounds(const int* indexFirst,
00352                                    const int* indexLast,
00353                                    const double* boundList);
00354     
00365       virtual void setRowSetTypes(const int* indexFirst,
00366                                   const int* indexLast,
00367                                   const char* senseList,
00368                                   const double* rhsList,
00369                                   const double* rangeList);
00371     
00372     //-------------------------------------------------------------------------
00376       virtual void setContinuous(int index);
00378       virtual void setInteger(int index);
00381       virtual void setContinuous(const int* indices, int len);
00384       virtual void setInteger(const int* indices, int len);
00386     
00387     //-------------------------------------------------------------------------
00389     virtual void setObjSense(double s);
00390     
00401     virtual void setColSolution(const double * colsol);
00402     
00413     virtual void setRowPrice(const double * rowprice);
00414     
00415     //-------------------------------------------------------------------------
00420 
00421       using OsiSolverInterface::addCol ;
00423       virtual void addCol(const CoinPackedVectorBase& vec,
00424                           const double collb, const double colub,   
00425                           const double obj);
00426 
00427       using OsiSolverInterface::addCols ;
00429       virtual void addCols(const int numcols,
00430                            const CoinPackedVectorBase * const * cols,
00431                            const double* collb, const double* colub,   
00432                            const double* obj);
00434       virtual void deleteCols(const int num, const int * colIndices);
00435     
00436       using OsiSolverInterface::addRow ;
00438       virtual void addRow(const CoinPackedVectorBase& vec,
00439                           const double rowlb, const double rowub);
00441       virtual void addRow(const CoinPackedVectorBase& vec,
00442                           const char rowsen, const double rowrhs,   
00443                           const double rowrng);
00444 
00445       using OsiSolverInterface::addRows ;
00447       virtual void addRows(const int numrows,
00448                            const CoinPackedVectorBase * const * rows,
00449                            const double* rowlb, const double* rowub);
00451       virtual void addRows(const int numrows,
00452                            const CoinPackedVectorBase * const * rows,
00453                            const char* rowsen, const double* rowrhs,   
00454                            const double* rowrng);
00456       virtual void deleteRows(const int num, const int * rowIndices);
00457     
00458 #if 0
00459   // ??? implemented in OsiSolverInterface
00460       //-----------------------------------------------------------------------
00482       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
00483                                             double effectivenessLb = 0.0);
00484 #endif
00485 
00486 
00487 
00488   //---------------------------------------------------------------------------
00489 
00503     virtual void loadProblem(const CoinPackedMatrix& matrix,
00504                              const double* collb, const double* colub,   
00505                              const double* obj,
00506                              const double* rowlb, const double* rowub);
00507                             
00515     virtual void assignProblem(CoinPackedMatrix*& matrix,
00516                                double*& collb, double*& colub, double*& obj,
00517                                double*& rowlb, double*& rowub);
00518 
00531     virtual void loadProblem(const CoinPackedMatrix& matrix,
00532                              const double* collb, const double* colub,
00533                              const double* obj,
00534                              const char* rowsen, const double* rowrhs,   
00535                              const double* rowrng);
00536 
00544     virtual void assignProblem(CoinPackedMatrix*& matrix,
00545                                double*& collb, double*& colub, double*& obj,
00546                                char*& rowsen, double*& rowrhs,
00547                                double*& rowrng);
00548 
00551     virtual void loadProblem(const int numcols, const int numrows,
00552                              const int* start, const int* index,
00553                              const double* value,
00554                              const double* collb, const double* colub,   
00555                              const double* obj,
00556                              const double* rowlb, const double* rowub);
00557 
00560     virtual void loadProblem(const int numcols, const int numrows,
00561                              const int* start, const int* index,
00562                              const double* value,
00563                              const double* collb, const double* colub,   
00564                              const double* obj,
00565                              const char* rowsen, const double* rowrhs,   
00566                              const double* rowrng);
00567 
00568     using OsiSolverInterface::readMps ;
00570     virtual int readMps(const char *filename,
00571                          const char *extension = "mps");
00572 
00577     virtual void writeMps(const char *filename,
00578                           const char *extension = "mps",
00579                           double objSense=0.0) const;
00581 
00582   //---------------------------------------------------------------------------
00583 
00590 
00593     void setObjName (std::string name) ;
00594 
00600     void setRowName(int ndx, std::string name) ;
00601 
00607     void setColName(int ndx, std::string name) ;
00608 
00610 
00611   //---------------------------------------------------------------------------
00612 
00615   enum keepCachedFlag
00616   {
00618     KEEPCACHED_NONE    = 0,
00620     KEEPCACHED_COLUMN  = 1,
00622     KEEPCACHED_ROW     = 2,
00624     KEEPCACHED_MATRIX  = 4,
00626     KEEPCACHED_RESULTS = 8,
00628     KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
00630     KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
00632     FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & ~KEEPCACHED_COLUMN,
00634     FREECACHED_ROW     = KEEPCACHED_PROBLEM & ~KEEPCACHED_ROW,
00636     FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & ~KEEPCACHED_MATRIX,
00638     FREECACHED_RESULTS = KEEPCACHED_ALL & ~KEEPCACHED_RESULTS
00639   };
00640 
00642   LPX * getModelPtr();
00643 
00645 
00648 
00649   OsiGlpkSolverInterface(); 
00650   
00652   virtual OsiSolverInterface * clone(bool copyData = true) const;
00653   
00655   OsiGlpkSolverInterface( const OsiGlpkSolverInterface& );
00656   
00658   OsiGlpkSolverInterface& operator=( const OsiGlpkSolverInterface& rhs );
00659   
00661   virtual ~OsiGlpkSolverInterface();
00662 
00664   virtual void reset();
00666   
00667 protected:
00668   
00671 
00672   virtual void applyRowCut( const OsiRowCut & rc );
00673   
00677   virtual void applyColCut( const OsiColCut & cc );
00678 
00680   LPX * getMutableModelPtr() const;
00681 
00683  
00684 private: 
00687     
00689   void gutsOfCopy( const OsiGlpkSolverInterface & source );
00690   
00692   void gutsOfConstructor();
00693   
00695   void gutsOfDestructor();
00696 
00698   void freeCachedColRim();
00699 
00701   void freeCachedRowRim();
00702 
00704   void freeCachedResults();
00705   
00707   void freeCachedMatrix();
00708 
00710   void freeCachedData( int keepCached = KEEPCACHED_NONE );
00711 
00713   void freeAllMemory();
00714 
00716   void printBounds(); 
00717 
00719   void fillColBounds() const;
00721   
00722   
00725 
00726   mutable LPX* lp_;
00727 
00728   // Remember whether simplex or b&b was most recently done
00729   // 0 = simplex;  1 = b&b
00730   int bbWasLast_; 
00731 
00732   // Int parameters.
00734   int maxIteration_;
00736   int hotStartMaxIteration_;
00738   int nameDisc_;
00739 
00740   // Double parameters.
00742   double dualObjectiveLimit_;
00744   double primalObjectiveLimit_;
00746   double dualTolerance_;
00748   double primalTolerance_;
00750   double objOffset_;
00751 
00752   // String parameters
00754   std::string probName_;
00755 
00757   mutable void *info_[OsiLastHintParam] ;
00758 
00759 
00761 
00763   int hotStartCStatSize_;
00765   int *hotStartCStat_;
00767   double *hotStartCVal_;
00769   double *hotStartCDualVal_;
00770 
00772   int hotStartRStatSize_;
00774   int *hotStartRStat_;
00776   double *hotStartRVal_;
00778   double *hotStartRDualVal_;
00779 
00780   // Status information
00782   bool isIterationLimitReached_;
00784   bool isAbandoned_;
00790   bool isObjLowerLimitReached_;
00796   bool isObjUpperLimitReached_;
00798   bool isPrimInfeasible_;
00800   bool isDualInfeasible_;
00801 
00804 
00806   mutable int iter_used_;
00807 
00809   mutable double  *obj_;
00810   
00812   mutable double  *collower_;
00813   
00815   mutable double  *colupper_;
00816   
00818   mutable char    *ctype_;
00819   
00821   mutable char    *rowsense_;
00822   
00824   mutable double  *rhs_;
00825   
00827   mutable double  *rowrange_;
00828   
00830   mutable double  *rowlower_;
00831   
00833   mutable double  *rowupper_;
00834   
00836   mutable double  *colsol_;
00837   
00839   mutable double  *rowsol_;
00840 
00842   mutable double  *redcost_;
00843 
00845   mutable double  *rowact_;
00846 
00848   mutable CoinPackedMatrix *matrixByRow_;  
00849   
00851   mutable CoinPackedMatrix *matrixByCol_;  
00853 
00854 };
00855 
00856 //#############################################################################
00862 void OsiGlpkSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00863 
00864 #endif // OsiGlpkSolverInterface_H

Generated on Fri Oct 26 03:03:49 2007 by  doxygen 1.4.7