/home/coin/SVN-release/Osi-0.96.0/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 
00299       virtual void setColLower( int elementIndex, double elementValue );
00300       
00303       virtual void setColUpper( int elementIndex, double elementValue );
00304       
00308       virtual void setColBounds( int elementIndex,
00309                                  double lower, double upper );
00310     
00319       virtual void setColSetBounds(const int* indexFirst,
00320                                    const int* indexLast,
00321                                    const double* boundList);
00322       
00325       virtual void setRowLower( int elementIndex, double elementValue );
00326       
00329       virtual void setRowUpper( int elementIndex, double elementValue );
00330     
00334       virtual void setRowBounds( int elementIndex,
00335                                  double lower, double upper );
00336     
00338       virtual void setRowType(int index, char sense, double rightHandSide,
00339                               double range);
00340     
00349       virtual void setRowSetBounds(const int* indexFirst,
00350                                    const int* indexLast,
00351                                    const double* boundList);
00352     
00363       virtual void setRowSetTypes(const int* indexFirst,
00364                                   const int* indexLast,
00365                                   const char* senseList,
00366                                   const double* rhsList,
00367                                   const double* rangeList);
00369     
00370     //-------------------------------------------------------------------------
00374       virtual void setContinuous(int index);
00376       virtual void setInteger(int index);
00379       virtual void setContinuous(const int* indices, int len);
00382       virtual void setInteger(const int* indices, int len);
00384     
00385     //-------------------------------------------------------------------------
00387     virtual void setObjSense(double s);
00388     
00399     virtual void setColSolution(const double * colsol);
00400     
00411     virtual void setRowPrice(const double * rowprice);
00412     
00413     //-------------------------------------------------------------------------
00419       virtual void addCol(const CoinPackedVectorBase& vec,
00420                           const double collb, const double colub,   
00421                           const double obj);
00423       virtual void addCols(const int numcols,
00424                            const CoinPackedVectorBase * const * cols,
00425                            const double* collb, const double* colub,   
00426                            const double* obj);
00428       virtual void deleteCols(const int num, const int * colIndices);
00429     
00431       virtual void addRow(const CoinPackedVectorBase& vec,
00432                           const double rowlb, const double rowub);
00434       virtual void addRow(const CoinPackedVectorBase& vec,
00435                           const char rowsen, const double rowrhs,   
00436                           const double rowrng);
00438       virtual void addRows(const int numrows,
00439                            const CoinPackedVectorBase * const * rows,
00440                            const double* rowlb, const double* rowub);
00442       virtual void addRows(const int numrows,
00443                            const CoinPackedVectorBase * const * rows,
00444                            const char* rowsen, const double* rowrhs,   
00445                            const double* rowrng);
00447       virtual void deleteRows(const int num, const int * rowIndices);
00448     
00449 #if 0
00450   // ??? implemented in OsiSolverInterface
00451       //-----------------------------------------------------------------------
00473       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
00474                                             double effectivenessLb = 0.0);
00475 #endif
00476 
00477 
00478 
00479   //---------------------------------------------------------------------------
00480 
00494     virtual void loadProblem(const CoinPackedMatrix& matrix,
00495                              const double* collb, const double* colub,   
00496                              const double* obj,
00497                              const double* rowlb, const double* rowub);
00498                             
00506     virtual void assignProblem(CoinPackedMatrix*& matrix,
00507                                double*& collb, double*& colub, double*& obj,
00508                                double*& rowlb, double*& rowub);
00509 
00522     virtual void loadProblem(const CoinPackedMatrix& matrix,
00523                              const double* collb, const double* colub,
00524                              const double* obj,
00525                              const char* rowsen, const double* rowrhs,   
00526                              const double* rowrng);
00527 
00535     virtual void assignProblem(CoinPackedMatrix*& matrix,
00536                                double*& collb, double*& colub, double*& obj,
00537                                char*& rowsen, double*& rowrhs,
00538                                double*& rowrng);
00539 
00542     virtual void loadProblem(const int numcols, const int numrows,
00543                              const int* start, const int* index,
00544                              const double* value,
00545                              const double* collb, const double* colub,   
00546                              const double* obj,
00547                              const double* rowlb, const double* rowub);
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 char* rowsen, const double* rowrhs,   
00557                              const double* rowrng);
00558 
00560     virtual int readMps(const char *filename,
00561                          const char *extension = "mps");
00562 
00567     virtual void writeMps(const char *filename,
00568                           const char *extension = "mps",
00569                           double objSense=0.0) const;
00571 
00572   //---------------------------------------------------------------------------
00573 
00580 
00583     void setObjName (std::string name) ;
00584 
00590     void setRowName(int ndx, std::string name) ;
00591 
00597     void setColName(int ndx, std::string name) ;
00598 
00600 
00601   //---------------------------------------------------------------------------
00602 
00605   enum keepCachedFlag
00606   {
00608     KEEPCACHED_NONE    = 0,
00610     KEEPCACHED_COLUMN  = 1,
00612     KEEPCACHED_ROW     = 2,
00614     KEEPCACHED_MATRIX  = 4,
00616     KEEPCACHED_RESULTS = 8,
00618     KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
00620     KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
00622     FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & ~KEEPCACHED_COLUMN,
00624     FREECACHED_ROW     = KEEPCACHED_PROBLEM & ~KEEPCACHED_ROW,
00626     FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & ~KEEPCACHED_MATRIX,
00628     FREECACHED_RESULTS = KEEPCACHED_ALL & ~KEEPCACHED_RESULTS
00629   };
00630 
00632   LPX * getModelPtr();
00633 
00635 
00638 
00639   OsiGlpkSolverInterface(); 
00640   
00642   virtual OsiSolverInterface * clone(bool copyData = true) const;
00643   
00645   OsiGlpkSolverInterface( const OsiGlpkSolverInterface& );
00646   
00648   OsiGlpkSolverInterface& operator=( const OsiGlpkSolverInterface& rhs );
00649   
00651   virtual ~OsiGlpkSolverInterface();
00652 
00654   virtual void reset();
00656   
00657 protected:
00658   
00661 
00662   virtual void applyRowCut( const OsiRowCut & rc );
00663   
00667   virtual void applyColCut( const OsiColCut & cc );
00668 
00670   LPX * getMutableModelPtr() const;
00671 
00673  
00674 private: 
00677     
00679   void gutsOfCopy( const OsiGlpkSolverInterface & source );
00680   
00682   void gutsOfConstructor();
00683   
00685   void gutsOfDestructor();
00686 
00688   void freeCachedColRim();
00689 
00691   void freeCachedRowRim();
00692 
00694   void freeCachedResults();
00695   
00697   void freeCachedMatrix();
00698 
00700   void freeCachedData( int keepCached = KEEPCACHED_NONE );
00701 
00703   void freeAllMemory();
00704 
00706   void printBounds(); 
00707 
00709   void fillColBounds() const;
00711   
00712   
00715 
00716   mutable LPX* lp_;
00717 
00718   // Remember whether simplex or b&b was most recently done
00719   // 0 = simplex;  1 = b&b
00720   int bbWasLast_; 
00721 
00722   // Int parameters.
00724   int maxIteration_;
00726   int hotStartMaxIteration_;
00728   int nameDisc_;
00729 
00730   // Double parameters.
00732   double dualObjectiveLimit_;
00734   double primalObjectiveLimit_;
00736   double dualTolerance_;
00738   double primalTolerance_;
00740   double objOffset_;
00741 
00742   // String parameters
00744   std::string probName_;
00745 
00747   mutable void *info_[OsiLastHintParam] ;
00748 
00749 
00751 
00753   int hotStartCStatSize_;
00755   int *hotStartCStat_;
00757   double *hotStartCVal_;
00759   double *hotStartCDualVal_;
00760 
00762   int hotStartRStatSize_;
00764   int *hotStartRStat_;
00766   double *hotStartRVal_;
00768   double *hotStartRDualVal_;
00769 
00770   // Status information
00772   bool isIterationLimitReached_;
00774   bool isAbandoned_;
00780   bool isObjLowerLimitReached_;
00786   bool isObjUpperLimitReached_;
00788   bool isPrimInfeasible_;
00790   bool isDualInfeasible_;
00791 
00794 
00796   mutable int iter_used_;
00797 
00799   mutable double  *obj_;
00800   
00802   mutable double  *collower_;
00803   
00805   mutable double  *colupper_;
00806   
00808   mutable char    *ctype_;
00809   
00811   mutable char    *rowsense_;
00812   
00814   mutable double  *rhs_;
00815   
00817   mutable double  *rowrange_;
00818   
00820   mutable double  *rowlower_;
00821   
00823   mutable double  *rowupper_;
00824   
00826   mutable double  *colsol_;
00827   
00829   mutable double  *rowsol_;
00830 
00832   mutable double  *redcost_;
00833 
00835   mutable double  *rowact_;
00836 
00838   mutable CoinPackedMatrix *matrixByRow_;  
00839   
00841   mutable CoinPackedMatrix *matrixByCol_;  
00843 
00844 };
00845 
00846 //#############################################################################
00852 void OsiGlpkSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00853 
00854 #endif // OsiGlpkSolverInterface_H

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