- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# /home/coin/svn-release/Alps-1.5.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 // This code is licensed under the terms of the Eclipse Public License (EPL).
    00009
    00010 #ifndef OsiGlpkSolverInterface_H
    00011 #define OsiGlpkSolverInterface_H
    00012
    00013 #include <string>
    00014 #include "OsiSolverInterface.hpp"
    00015 #include "CoinPackedMatrix.hpp"
    00016 #include "CoinWarmStartBasis.hpp"
    00017
    00023 #ifndef LPX
    00024 #define LPX glp_prob
    00025 #endif
    00026
    00027 #ifndef GLP_PROB_DEFINED
    00028 #define GLP_PROB_DEFINED
    00029 // Glpk < 4.48:
    00030 typedef struct { double _opaque_prob[100]; } glp_prob;
    00031 // Glpk 4.48: typedef struct glp_prob glp_prob;
    00032 #endif
    00033
    00034 class OsiGlpkSolverInterface : virtual public OsiSolverInterface {
    00035   friend void OsiGlpkSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00036
    00037 public:
    00038
    00039   //---------------------------------------------------------------------------
    00042
    00043   virtual void initialSolve();
    00044
    00046   virtual void resolve();
    00047
    00049   virtual void branchAndBound();
    00051
    00052   //---------------------------------------------------------------------------
    00068     // Set an integer parameter
    00069     bool setIntParam(OsiIntParam key, int value);
    00070     // Set an double parameter
    00071     bool setDblParam(OsiDblParam key, double value);
    00072     // Set a string parameter
    00073     bool setStrParam(OsiStrParam key, const std::string & value);
    00074     // Set a hint parameter
    00075     bool setHintParam(OsiHintParam key, bool sense = true,
    00076                       OsiHintStrength strength = OsiHintTry, void *info = 0) ;
    00077     // Get an integer parameter
    00078     bool getIntParam(OsiIntParam key, int& value) const;
    00079     // Get an double parameter
    00080     bool getDblParam(OsiDblParam key, double& value) const;
    00081     // Get a string parameter
    00082     bool getStrParam(OsiStrParam key, std::string& value) const;
    00084
    00085   //---------------------------------------------------------------------------
    00087
    00088
    00089     virtual bool isAbandoned() const;
    00091     virtual bool isProvenOptimal() const;
    00093     virtual bool isProvenPrimalInfeasible() const;
    00095     virtual bool isProvenDualInfeasible() const;
    00097     virtual bool isPrimalObjectiveLimitReached() const;
    00099     virtual bool isDualObjectiveLimitReached() const;
    00101     virtual bool isIterationLimitReached() const;
    00103     virtual bool isTimeLimitReached() const;
    00105     virtual bool isFeasible() const;
    00107
    00108   //---------------------------------------------------------------------------
    00117   inline CoinWarmStart *getEmptyWarmStart () const
    00118   { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; }
    00120     virtual CoinWarmStart* getWarmStart() const;
    00123     virtual bool setWarmStart(const CoinWarmStart* warmstart);
    00125
    00126   //---------------------------------------------------------------------------
    00133
    00134     virtual void markHotStart();
    00136     virtual void solveFromHotStart();
    00138     virtual void unmarkHotStart();
    00140
    00141   //---------------------------------------------------------------------------
    00156
    00157       virtual int getNumCols() const;
    00158
    00160       virtual int getNumRows() const;
    00161
    00163       virtual int getNumElements() const;
    00164
    00166       virtual const double * getColLower() const;
    00167
    00169       virtual const double * getColUpper() const;
    00170
    00180       virtual const char * getRowSense() const;
    00181
    00190       virtual const double * getRightHandSide() const;
    00191
    00200       virtual const double * getRowRange() const;
    00201
    00203       virtual const double * getRowLower() const;
    00204
    00206       virtual const double * getRowUpper() const;
    00207
    00209       virtual const double * getObjCoefficients() const;
    00210
    00212       virtual double getObjSense() const;
    00213
    00215       virtual bool isContinuous(int colNumber) const;
    00216
    00217 #if 0
    00219       virtual bool isBinary(int columnNumber) const;
    00220
    00225       virtual bool isInteger(int columnNumber) const;
    00226
    00228       virtual bool isIntegerNonBinary(int columnNumber) const;
    00229
    00231       virtual bool isFreeBinary(int columnNumber) const;
    00232 #endif
    00233
    00235       virtual const CoinPackedMatrix * getMatrixByRow() const;
    00236
    00238       virtual const CoinPackedMatrix * getMatrixByCol() const;
    00239
    00241       virtual double getInfinity() const;
    00243
    00246
    00247       virtual const double * getColSolution() const;
    00248
    00250       virtual const double * getRowPrice() const;
    00251
    00253       virtual const double * getReducedCost() const;
    00254
    00257       virtual const double * getRowActivity() const;
    00258
    00260       virtual double getObjValue() const;
    00261
    00264       virtual int getIterationCount() const;
    00265
    00277       virtual std::vector<double*> getDualRays(int maxNumRays,
    00278                                                bool fullRay=false) const;
    00296       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
    00297
    00298 #if 0
    00299
    00301       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
    00302         const;
    00303 #endif
    00304
    00305
    00306
    00307   //---------------------------------------------------------------------------
    00308
    00311     //-------------------------------------------------------------------------
    00315       virtual void setObjCoeff( int elementIndex, double elementValue );
    00316
    00317       using OsiSolverInterface::setColLower ;
    00320       virtual void setColLower( int elementIndex, double elementValue );
    00321
    00322       using OsiSolverInterface::setColUpper ;
    00325       virtual void setColUpper( int elementIndex, double elementValue );
    00326
    00330       virtual void setColBounds( int elementIndex,
    00331                                  double lower, double upper );
    00332
    00341       virtual void setColSetBounds(const int* indexFirst,
    00342                                    const int* indexLast,
    00343                                    const double* boundList);
    00344
    00347       virtual void setRowLower( int elementIndex, double elementValue );
    00348
    00351       virtual void setRowUpper( int elementIndex, double elementValue );
    00352
    00356       virtual void setRowBounds( int elementIndex,
    00357                                  double lower, double upper );
    00358
    00360       virtual void setRowType(int index, char sense, double rightHandSide,
    00361                               double range);
    00362
    00371       virtual void setRowSetBounds(const int* indexFirst,
    00372                                    const int* indexLast,
    00373                                    const double* boundList);
    00374
    00385       virtual void setRowSetTypes(const int* indexFirst,
    00386                                   const int* indexLast,
    00387                                   const char* senseList,
    00388                                   const double* rhsList,
    00389                                   const double* rangeList);
    00391
    00392     //-------------------------------------------------------------------------
    00396       virtual void setContinuous(int index);
    00398       virtual void setInteger(int index);
    00401       virtual void setContinuous(const int* indices, int len);
    00404       virtual void setInteger(const int* indices, int len);
    00406
    00407     //-------------------------------------------------------------------------
    00409     virtual void setObjSense(double s);
    00410
    00421     virtual void setColSolution(const double * colsol);
    00422
    00433     virtual void setRowPrice(const double * rowprice);
    00434
    00435     //-------------------------------------------------------------------------
    00440
    00441       using OsiSolverInterface::addCol ;
    00443       virtual void addCol(const CoinPackedVectorBase& vec,
    00444                           const double collb, const double colub,
    00445                           const double obj);
    00446
    00447       using OsiSolverInterface::addCols ;
    00449       virtual void addCols(const int numcols,
    00450                            const CoinPackedVectorBase * const * cols,
    00451                            const double* collb, const double* colub,
    00452                            const double* obj);
    00454       virtual void deleteCols(const int num, const int * colIndices);
    00455
    00456       using OsiSolverInterface::addRow ;
    00458       virtual void addRow(const CoinPackedVectorBase& vec,
    00459                           const double rowlb, const double rowub);
    00461       virtual void addRow(const CoinPackedVectorBase& vec,
    00462                           const char rowsen, const double rowrhs,
    00463                           const double rowrng);
    00464
    00465       using OsiSolverInterface::addRows ;
    00467       virtual void addRows(const int numrows,
    00468                            const CoinPackedVectorBase * const * rows,
    00469                            const double* rowlb, const double* rowub);
    00471       virtual void addRows(const int numrows,
    00472                            const CoinPackedVectorBase * const * rows,
    00473                            const char* rowsen, const double* rowrhs,
    00474                            const double* rowrng);
    00476       virtual void deleteRows(const int num, const int * rowIndices);
    00477
    00478 #if 0
    00479   // ??? implemented in OsiSolverInterface
    00480       //-----------------------------------------------------------------------
    00502       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
    00503                                             double effectivenessLb = 0.0);
    00504 #endif
    00505
    00506
    00507
    00508   //---------------------------------------------------------------------------
    00509
    00523     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00524                              const double* collb, const double* colub,
    00525                              const double* obj,
    00526                              const double* rowlb, const double* rowub);
    00527
    00535     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00536                                double*& collb, double*& colub, double*& obj,
    00537                                double*& rowlb, double*& rowub);
    00538
    00551     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00552                              const double* collb, const double* colub,
    00553                              const double* obj,
    00554                              const char* rowsen, const double* rowrhs,
    00555                              const double* rowrng);
    00556
    00564     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00565                                double*& collb, double*& colub, double*& obj,
    00566                                char*& rowsen, double*& rowrhs,
    00567                                double*& rowrng);
    00568
    00571     virtual void loadProblem(const int numcols, const int numrows,
    00572                              const int* start, const int* index,
    00573                              const double* value,
    00574                              const double* collb, const double* colub,
    00575                              const double* obj,
    00576                              const double* rowlb, const double* rowub);
    00577
    00580     virtual void loadProblem(const int numcols, const int numrows,
    00581                              const int* start, const int* index,
    00582                              const double* value,
    00583                              const double* collb, const double* colub,
    00584                              const double* obj,
    00585                              const char* rowsen, const double* rowrhs,
    00586                              const double* rowrng);
    00587
    00588     using OsiSolverInterface::readMps ;
    00590     virtual int readMps(const char *filename,
    00591                          const char *extension = "mps");
    00592
    00597     virtual void writeMps(const char *filename,
    00598                           const char *extension = "mps",
    00599                           double objSense=0.0) const;
    00601
    00602   //---------------------------------------------------------------------------
    00603
    00610
    00613     void setObjName (std::string name) ;
    00614
    00620     void setRowName(int ndx, std::string name) ;
    00621
    00627     void setColName(int ndx, std::string name) ;
    00628
    00630
    00631   //---------------------------------------------------------------------------
    00632
    00635   enum keepCachedFlag
    00636   {
    00638     KEEPCACHED_NONE    = 0,
    00640     KEEPCACHED_COLUMN  = 1,
    00642     KEEPCACHED_ROW     = 2,
    00644     KEEPCACHED_MATRIX  = 4,
    00646     KEEPCACHED_RESULTS = 8,
    00648     KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
    00650     KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
    00652     FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & ~KEEPCACHED_COLUMN,
    00654     FREECACHED_ROW     = KEEPCACHED_PROBLEM & ~KEEPCACHED_ROW,
    00656     FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & ~KEEPCACHED_MATRIX,
    00658     FREECACHED_RESULTS = KEEPCACHED_ALL & ~KEEPCACHED_RESULTS
    00659   };
    00660
    00662   LPX * getModelPtr();
    00663
    00665
    00674   static void incrementInstanceCounter() { ++numInstances_; }
    00675
    00683   static void decrementInstanceCounter();
    00684
    00686   static unsigned int getNumInstances() { return numInstances_; }
    00688
    00689
    00692
    00693   OsiGlpkSolverInterface();
    00694
    00696   virtual OsiSolverInterface * clone(bool copyData = true) const;
    00697
    00699   OsiGlpkSolverInterface( const OsiGlpkSolverInterface& );
    00700
    00702   OsiGlpkSolverInterface& operator=( const OsiGlpkSolverInterface& rhs );
    00703
    00705   virtual ~OsiGlpkSolverInterface();
    00706
    00708   virtual void reset();
    00710
    00711 protected:
    00712
    00715
    00716   virtual void applyRowCut( const OsiRowCut & rc );
    00717
    00721   virtual void applyColCut( const OsiColCut & cc );
    00722
    00724   LPX * getMutableModelPtr() const;
    00725
    00727
    00728 private:
    00731
    00733   void gutsOfCopy( const OsiGlpkSolverInterface & source );
    00734
    00736   void gutsOfConstructor();
    00737
    00739   void gutsOfDestructor();
    00740
    00742   void freeCachedColRim();
    00743
    00745   void freeCachedRowRim();
    00746
    00748   void freeCachedResults();
    00749
    00751   void freeCachedMatrix();
    00752
    00754   void freeCachedData( int keepCached = KEEPCACHED_NONE );
    00755
    00757   void freeAllMemory();
    00758
    00760   void printBounds();
    00761
    00763   void fillColBounds() const;
    00765
    00766
    00769
    00770   mutable LPX* lp_;
    00771
    00773   static unsigned int numInstances_;
    00774
    00775
    00776   // Remember whether simplex or b&b was most recently done
    00777   // 0 = simplex;  1 = b&b
    00778   int bbWasLast_;
    00779
    00780   // Int parameters.
    00782   int maxIteration_;
    00784   int hotStartMaxIteration_;
    00786   int nameDisc_;
    00787
    00788   // Double parameters.
    00790   double dualObjectiveLimit_;
    00792   double primalObjectiveLimit_;
    00794   double dualTolerance_;
    00796   double primalTolerance_;
    00798   double objOffset_;
    00799
    00800   // String parameters
    00802   std::string probName_;
    00803
    00805   mutable void *info_[OsiLastHintParam] ;
    00806
    00807
    00809
    00811   int hotStartCStatSize_;
    00813   int *hotStartCStat_;
    00815   double *hotStartCVal_;
    00817   double *hotStartCDualVal_;
    00818
    00820   int hotStartRStatSize_;
    00822   int *hotStartRStat_;
    00824   double *hotStartRVal_;
    00826   double *hotStartRDualVal_;
    00827
    00828   // Status information
    00830   bool isIterationLimitReached_;
    00832   bool isTimeLimitReached_;
    00834   bool isAbandoned_;
    00840   bool isObjLowerLimitReached_;
    00846   bool isObjUpperLimitReached_;
    00848   bool isPrimInfeasible_;
    00850   bool isDualInfeasible_;
    00852   bool isFeasible_;
    00853
    00856
    00858   mutable int iter_used_;
    00859
    00861   mutable double  *obj_;
    00862
    00864   mutable double  *collower_;
    00865
    00867   mutable double  *colupper_;
    00868
    00870   mutable char    *ctype_;
    00871
    00873   mutable char    *rowsense_;
    00874
    00876   mutable double  *rhs_;
    00877
    00879   mutable double  *rowrange_;
    00880
    00882   mutable double  *rowlower_;
    00883
    00885   mutable double  *rowupper_;
    00886
    00888   mutable double  *colsol_;
    00889
    00891   mutable double  *rowsol_;
    00892
    00894   mutable double  *redcost_;
    00895
    00897   mutable double  *rowact_;
    00898
    00900   mutable CoinPackedMatrix *matrixByRow_;
    00901
    00903   mutable CoinPackedMatrix *matrixByCol_;
    00905
    00906 };
    00907
    00908 //#############################################################################
    00910 void OsiGlpkSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00911
    00912 #endif // OsiGlpkSolverInterface_H