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

- File List
- File Members

# /home/coin/SVN-release/Vol-1.2.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 #include "OsiSolverInterface.hpp"
    00014 #include "CoinPackedMatrix.hpp"
    00015 #include "CoinWarmStartBasis.hpp"
    00016
    00022 #ifndef LPX
    00023 #define LPX glp_prob
    00024 typedef struct { double _opaque_prob[100]; } glp_prob;
    00025 #endif
    00026
    00027 class OsiGlpkSolverInterface : virtual public OsiSolverInterface {
    00028   friend int OsiGlpkSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00029
    00030 public:
    00031
    00032   //---------------------------------------------------------------------------
    00035
    00036   virtual void initialSolve();
    00037
    00039   virtual void resolve();
    00040
    00042   virtual void branchAndBound();
    00044
    00045   //---------------------------------------------------------------------------
    00061     // Set an integer parameter
    00062     bool setIntParam(OsiIntParam key, int value);
    00063     // Set an double parameter
    00064     bool setDblParam(OsiDblParam key, double value);
    00065     // Set a string parameter
    00066     bool setStrParam(OsiStrParam key, const std::string & value);
    00067     // Set a hint parameter
    00068     bool setHintParam(OsiHintParam key, bool sense = true,
    00069                       OsiHintStrength strength = OsiHintTry, void *info = 0) ;
    00070     // Get an integer parameter
    00071     bool getIntParam(OsiIntParam key, int& value) const;
    00072     // Get an double parameter
    00073     bool getDblParam(OsiDblParam key, double& value) const;
    00074     // Get a string parameter
    00075     bool getStrParam(OsiStrParam key, std::string& value) const;
    00077
    00078   //---------------------------------------------------------------------------
    00080
    00081
    00082     virtual bool isAbandoned() const;
    00084     virtual bool isProvenOptimal() const;
    00086     virtual bool isProvenPrimalInfeasible() const;
    00088     virtual bool isProvenDualInfeasible() const;
    00090     virtual bool isPrimalObjectiveLimitReached() const;
    00092     virtual bool isDualObjectiveLimitReached() const;
    00094     virtual bool isIterationLimitReached() const;
    00096     virtual bool isTimeLimitReached() const;
    00098     virtual bool isFeasible() const;
    00100
    00101   //---------------------------------------------------------------------------
    00110   inline CoinWarmStart *getEmptyWarmStart () const
    00111   { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; }
    00113     virtual CoinWarmStart* getWarmStart() const;
    00116     virtual bool setWarmStart(const CoinWarmStart* warmstart);
    00118
    00119   //---------------------------------------------------------------------------
    00126
    00127     virtual void markHotStart();
    00129     virtual void solveFromHotStart();
    00131     virtual void unmarkHotStart();
    00133
    00134   //---------------------------------------------------------------------------
    00149
    00150       virtual int getNumCols() const;
    00151
    00153       virtual int getNumRows() const;
    00154
    00156       virtual int getNumElements() const;
    00157
    00159       virtual const double * getColLower() const;
    00160
    00162       virtual const double * getColUpper() const;
    00163
    00173       virtual const char * getRowSense() const;
    00174
    00183       virtual const double * getRightHandSide() const;
    00184
    00193       virtual const double * getRowRange() const;
    00194
    00196       virtual const double * getRowLower() const;
    00197
    00199       virtual const double * getRowUpper() const;
    00200
    00202       virtual const double * getObjCoefficients() const;
    00203
    00205       virtual double getObjSense() const;
    00206
    00208       virtual bool isContinuous(int colNumber) const;
    00209
    00210 #if 0
    00212       virtual bool isBinary(int columnNumber) const;
    00213
    00218       virtual bool isInteger(int columnNumber) const;
    00219
    00221       virtual bool isIntegerNonBinary(int columnNumber) const;
    00222
    00224       virtual bool isFreeBinary(int columnNumber) const;
    00225 #endif
    00226
    00228       virtual const CoinPackedMatrix * getMatrixByRow() const;
    00229
    00231       virtual const CoinPackedMatrix * getMatrixByCol() const;
    00232
    00234       virtual double getInfinity() const;
    00236
    00239
    00240       virtual const double * getColSolution() const;
    00241
    00243       virtual const double * getRowPrice() const;
    00244
    00246       virtual const double * getReducedCost() const;
    00247
    00250       virtual const double * getRowActivity() const;
    00251
    00253       virtual double getObjValue() const;
    00254
    00257       virtual int getIterationCount() const;
    00258
    00270       virtual std::vector<double*> getDualRays(int maxNumRays,
    00271                                                bool fullRay=false) const;
    00289       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
    00290
    00291 #if 0
    00292
    00294       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
    00295         const;
    00296 #endif
    00297
    00298
    00299
    00300   //---------------------------------------------------------------------------
    00301
    00304     //-------------------------------------------------------------------------
    00308       virtual void setObjCoeff( int elementIndex, double elementValue );
    00309
    00310       using OsiSolverInterface::setColLower ;
    00313       virtual void setColLower( int elementIndex, double elementValue );
    00314
    00315       using OsiSolverInterface::setColUpper ;
    00318       virtual void setColUpper( int elementIndex, double elementValue );
    00319
    00323       virtual void setColBounds( int elementIndex,
    00324                                  double lower, double upper );
    00325
    00334       virtual void setColSetBounds(const int* indexFirst,
    00335                                    const int* indexLast,
    00336                                    const double* boundList);
    00337
    00340       virtual void setRowLower( int elementIndex, double elementValue );
    00341
    00344       virtual void setRowUpper( int elementIndex, double elementValue );
    00345
    00349       virtual void setRowBounds( int elementIndex,
    00350                                  double lower, double upper );
    00351
    00353       virtual void setRowType(int index, char sense, double rightHandSide,
    00354                               double range);
    00355
    00364       virtual void setRowSetBounds(const int* indexFirst,
    00365                                    const int* indexLast,
    00366                                    const double* boundList);
    00367
    00378       virtual void setRowSetTypes(const int* indexFirst,
    00379                                   const int* indexLast,
    00380                                   const char* senseList,
    00381                                   const double* rhsList,
    00382                                   const double* rangeList);
    00384
    00385     //-------------------------------------------------------------------------
    00389       virtual void setContinuous(int index);
    00391       virtual void setInteger(int index);
    00394       virtual void setContinuous(const int* indices, int len);
    00397       virtual void setInteger(const int* indices, int len);
    00399
    00400     //-------------------------------------------------------------------------
    00402     virtual void setObjSense(double s);
    00403
    00414     virtual void setColSolution(const double * colsol);
    00415
    00426     virtual void setRowPrice(const double * rowprice);
    00427
    00428     //-------------------------------------------------------------------------
    00433
    00434       using OsiSolverInterface::addCol ;
    00436       virtual void addCol(const CoinPackedVectorBase& vec,
    00437                           const double collb, const double colub,
    00438                           const double obj);
    00439
    00440       using OsiSolverInterface::addCols ;
    00442       virtual void addCols(const int numcols,
    00443                            const CoinPackedVectorBase * const * cols,
    00444                            const double* collb, const double* colub,
    00445                            const double* obj);
    00447       virtual void deleteCols(const int num, const int * colIndices);
    00448
    00449       using OsiSolverInterface::addRow ;
    00451       virtual void addRow(const CoinPackedVectorBase& vec,
    00452                           const double rowlb, const double rowub);
    00454       virtual void addRow(const CoinPackedVectorBase& vec,
    00455                           const char rowsen, const double rowrhs,
    00456                           const double rowrng);
    00457
    00458       using OsiSolverInterface::addRows ;
    00460       virtual void addRows(const int numrows,
    00461                            const CoinPackedVectorBase * const * rows,
    00462                            const double* rowlb, const double* rowub);
    00464       virtual void addRows(const int numrows,
    00465                            const CoinPackedVectorBase * const * rows,
    00466                            const char* rowsen, const double* rowrhs,
    00467                            const double* rowrng);
    00469       virtual void deleteRows(const int num, const int * rowIndices);
    00470
    00471 #if 0
    00472   // ??? implemented in OsiSolverInterface
    00473       //-----------------------------------------------------------------------
    00495       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
    00496                                             double effectivenessLb = 0.0);
    00497 #endif
    00498
    00499
    00500
    00501   //---------------------------------------------------------------------------
    00502
    00516     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00517                              const double* collb, const double* colub,
    00518                              const double* obj,
    00519                              const double* rowlb, const double* rowub);
    00520
    00528     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00529                                double*& collb, double*& colub, double*& obj,
    00530                                double*& rowlb, double*& rowub);
    00531
    00544     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00545                              const double* collb, const double* colub,
    00546                              const double* obj,
    00547                              const char* rowsen, const double* rowrhs,
    00548                              const double* rowrng);
    00549
    00557     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00558                                double*& collb, double*& colub, double*& obj,
    00559                                char*& rowsen, double*& rowrhs,
    00560                                double*& rowrng);
    00561
    00564     virtual void loadProblem(const int numcols, const int numrows,
    00565                              const int* start, const int* index,
    00566                              const double* value,
    00567                              const double* collb, const double* colub,
    00568                              const double* obj,
    00569                              const double* rowlb, const double* rowub);
    00570
    00573     virtual void loadProblem(const int numcols, const int numrows,
    00574                              const int* start, const int* index,
    00575                              const double* value,
    00576                              const double* collb, const double* colub,
    00577                              const double* obj,
    00578                              const char* rowsen, const double* rowrhs,
    00579                              const double* rowrng);
    00580
    00581     using OsiSolverInterface::readMps ;
    00583     virtual int readMps(const char *filename,
    00584                          const char *extension = "mps");
    00585
    00590     virtual void writeMps(const char *filename,
    00591                           const char *extension = "mps",
    00592                           double objSense=0.0) const;
    00594
    00595   //---------------------------------------------------------------------------
    00596
    00603
    00606     void setObjName (std::string name) ;
    00607
    00613     void setRowName(int ndx, std::string name) ;
    00614
    00620     void setColName(int ndx, std::string name) ;
    00621
    00623
    00624   //---------------------------------------------------------------------------
    00625
    00628   enum keepCachedFlag
    00629   {
    00631     KEEPCACHED_NONE    = 0,
    00633     KEEPCACHED_COLUMN  = 1,
    00635     KEEPCACHED_ROW     = 2,
    00637     KEEPCACHED_MATRIX  = 4,
    00639     KEEPCACHED_RESULTS = 8,
    00641     KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
    00643     KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
    00645     FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & ~KEEPCACHED_COLUMN,
    00647     FREECACHED_ROW     = KEEPCACHED_PROBLEM & ~KEEPCACHED_ROW,
    00649     FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & ~KEEPCACHED_MATRIX,
    00651     FREECACHED_RESULTS = KEEPCACHED_ALL & ~KEEPCACHED_RESULTS
    00652   };
    00653
    00655   LPX * getModelPtr();
    00656
    00658
    00667   static void incrementInstanceCounter() { ++numInstances_; }
    00668
    00676   static void decrementInstanceCounter();
    00677
    00679   static unsigned int getNumInstances() { return numInstances_; }
    00681
    00682
    00685
    00686   OsiGlpkSolverInterface();
    00687
    00689   virtual OsiSolverInterface * clone(bool copyData = true) const;
    00690
    00692   OsiGlpkSolverInterface( const OsiGlpkSolverInterface& );
    00693
    00695   OsiGlpkSolverInterface& operator=( const OsiGlpkSolverInterface& rhs );
    00696
    00698   virtual ~OsiGlpkSolverInterface();
    00699
    00701   virtual void reset();
    00703
    00704 protected:
    00705
    00708
    00709   virtual void applyRowCut( const OsiRowCut & rc );
    00710
    00714   virtual void applyColCut( const OsiColCut & cc );
    00715
    00717   LPX * getMutableModelPtr() const;
    00718
    00720
    00721 private:
    00724
    00726   void gutsOfCopy( const OsiGlpkSolverInterface & source );
    00727
    00729   void gutsOfConstructor();
    00730
    00732   void gutsOfDestructor();
    00733
    00735   void freeCachedColRim();
    00736
    00738   void freeCachedRowRim();
    00739
    00741   void freeCachedResults();
    00742
    00744   void freeCachedMatrix();
    00745
    00747   void freeCachedData( int keepCached = KEEPCACHED_NONE );
    00748
    00750   void freeAllMemory();
    00751
    00753   void printBounds();
    00754
    00756   void fillColBounds() const;
    00758
    00759
    00762
    00763   mutable LPX* lp_;
    00764
    00766   static unsigned int numInstances_;
    00767
    00768
    00769   // Remember whether simplex or b&b was most recently done
    00770   // 0 = simplex;  1 = b&b
    00771   int bbWasLast_;
    00772
    00773   // Int parameters.
    00775   int maxIteration_;
    00777   int hotStartMaxIteration_;
    00779   int nameDisc_;
    00780
    00781   // Double parameters.
    00783   double dualObjectiveLimit_;
    00785   double primalObjectiveLimit_;
    00787   double dualTolerance_;
    00789   double primalTolerance_;
    00791   double objOffset_;
    00792
    00793   // String parameters
    00795   std::string probName_;
    00796
    00798   mutable void *info_[OsiLastHintParam] ;
    00799
    00800
    00802
    00804   int hotStartCStatSize_;
    00806   int *hotStartCStat_;
    00808   double *hotStartCVal_;
    00810   double *hotStartCDualVal_;
    00811
    00813   int hotStartRStatSize_;
    00815   int *hotStartRStat_;
    00817   double *hotStartRVal_;
    00819   double *hotStartRDualVal_;
    00820
    00821   // Status information
    00823   bool isIterationLimitReached_;
    00825   bool isTimeLimitReached_;
    00827   bool isAbandoned_;
    00833   bool isObjLowerLimitReached_;
    00839   bool isObjUpperLimitReached_;
    00841   bool isPrimInfeasible_;
    00843   bool isDualInfeasible_;
    00845   bool isFeasible_;
    00846
    00849
    00851   mutable int iter_used_;
    00852
    00854   mutable double  *obj_;
    00855
    00857   mutable double  *collower_;
    00858
    00860   mutable double  *colupper_;
    00861
    00863   mutable char    *ctype_;
    00864
    00866   mutable char    *rowsense_;
    00867
    00869   mutable double  *rhs_;
    00870
    00872   mutable double  *rowrange_;
    00873
    00875   mutable double  *rowlower_;
    00876
    00878   mutable double  *rowupper_;
    00879
    00881   mutable double  *colsol_;
    00882
    00884   mutable double  *rowsol_;
    00885
    00887   mutable double  *redcost_;
    00888
    00890   mutable double  *rowact_;
    00891
    00893   mutable CoinPackedMatrix *matrixByRow_;
    00894
    00896   mutable CoinPackedMatrix *matrixByCol_;
    00898
    00899 };
    00900
    00901 //#############################################################################
    00907 int OsiGlpkSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00908
    00909 #endif // OsiGlpkSolverInterface_H