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

- File List
- File Members

# /home/coin/SVN-release/Bcps-0.91.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 int 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     virtual bool isTimeLimitReached() const;
    00096     virtual bool isFeasible() const;
    00098
    00099   //---------------------------------------------------------------------------
    00108   inline CoinWarmStart *getEmptyWarmStart () const
    00109   { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; }
    00111     virtual CoinWarmStart* getWarmStart() const;
    00114     virtual bool setWarmStart(const CoinWarmStart* warmstart);
    00116
    00117   //---------------------------------------------------------------------------
    00124
    00125     virtual void markHotStart();
    00127     virtual void solveFromHotStart();
    00129     virtual void unmarkHotStart();
    00131
    00132   //---------------------------------------------------------------------------
    00147
    00148       virtual int getNumCols() const;
    00149
    00151       virtual int getNumRows() const;
    00152
    00154       virtual int getNumElements() const;
    00155
    00157       virtual const double * getColLower() const;
    00158
    00160       virtual const double * getColUpper() const;
    00161
    00171       virtual const char * getRowSense() const;
    00172
    00181       virtual const double * getRightHandSide() const;
    00182
    00191       virtual const double * getRowRange() const;
    00192
    00194       virtual const double * getRowLower() const;
    00195
    00197       virtual const double * getRowUpper() const;
    00198
    00200       virtual const double * getObjCoefficients() const;
    00201
    00203       virtual double getObjSense() const;
    00204
    00206       virtual bool isContinuous(int colNumber) const;
    00207
    00208 #if 0
    00210       virtual bool isBinary(int columnNumber) const;
    00211
    00216       virtual bool isInteger(int columnNumber) const;
    00217
    00219       virtual bool isIntegerNonBinary(int columnNumber) const;
    00220
    00222       virtual bool isFreeBinary(int columnNumber) const;
    00223 #endif
    00224
    00226       virtual const CoinPackedMatrix * getMatrixByRow() const;
    00227
    00229       virtual const CoinPackedMatrix * getMatrixByCol() const;
    00230
    00232       virtual double getInfinity() const;
    00234
    00237
    00238       virtual const double * getColSolution() const;
    00239
    00241       virtual const double * getRowPrice() const;
    00242
    00244       virtual const double * getReducedCost() const;
    00245
    00248       virtual const double * getRowActivity() const;
    00249
    00251       virtual double getObjValue() const;
    00252
    00255       virtual int getIterationCount() const;
    00256
    00268       virtual std::vector<double*> getDualRays(int maxNumRays) const;
    00280       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
    00281
    00282 #if 0
    00283
    00285       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
    00286         const;
    00287 #endif
    00288
    00289
    00290
    00291   //---------------------------------------------------------------------------
    00292
    00295     //-------------------------------------------------------------------------
    00299       virtual void setObjCoeff( int elementIndex, double elementValue );
    00300
    00301       using OsiSolverInterface::setColLower ;
    00304       virtual void setColLower( int elementIndex, double elementValue );
    00305
    00306       using OsiSolverInterface::setColUpper ;
    00309       virtual void setColUpper( int elementIndex, double elementValue );
    00310
    00314       virtual void setColBounds( int elementIndex,
    00315                                  double lower, double upper );
    00316
    00325       virtual void setColSetBounds(const int* indexFirst,
    00326                                    const int* indexLast,
    00327                                    const double* boundList);
    00328
    00331       virtual void setRowLower( int elementIndex, double elementValue );
    00332
    00335       virtual void setRowUpper( int elementIndex, double elementValue );
    00336
    00340       virtual void setRowBounds( int elementIndex,
    00341                                  double lower, double upper );
    00342
    00344       virtual void setRowType(int index, char sense, double rightHandSide,
    00345                               double range);
    00346
    00355       virtual void setRowSetBounds(const int* indexFirst,
    00356                                    const int* indexLast,
    00357                                    const double* boundList);
    00358
    00369       virtual void setRowSetTypes(const int* indexFirst,
    00370                                   const int* indexLast,
    00371                                   const char* senseList,
    00372                                   const double* rhsList,
    00373                                   const double* rangeList);
    00375
    00376     //-------------------------------------------------------------------------
    00380       virtual void setContinuous(int index);
    00382       virtual void setInteger(int index);
    00385       virtual void setContinuous(const int* indices, int len);
    00388       virtual void setInteger(const int* indices, int len);
    00390
    00391     //-------------------------------------------------------------------------
    00393     virtual void setObjSense(double s);
    00394
    00405     virtual void setColSolution(const double * colsol);
    00406
    00417     virtual void setRowPrice(const double * rowprice);
    00418
    00419     //-------------------------------------------------------------------------
    00424
    00425       using OsiSolverInterface::addCol ;
    00427       virtual void addCol(const CoinPackedVectorBase& vec,
    00428                           const double collb, const double colub,
    00429                           const double obj);
    00430
    00431       using OsiSolverInterface::addCols ;
    00433       virtual void addCols(const int numcols,
    00434                            const CoinPackedVectorBase * const * cols,
    00435                            const double* collb, const double* colub,
    00436                            const double* obj);
    00438       virtual void deleteCols(const int num, const int * colIndices);
    00439
    00440       using OsiSolverInterface::addRow ;
    00442       virtual void addRow(const CoinPackedVectorBase& vec,
    00443                           const double rowlb, const double rowub);
    00445       virtual void addRow(const CoinPackedVectorBase& vec,
    00446                           const char rowsen, const double rowrhs,
    00447                           const double rowrng);
    00448
    00449       using OsiSolverInterface::addRows ;
    00451       virtual void addRows(const int numrows,
    00452                            const CoinPackedVectorBase * const * rows,
    00453                            const double* rowlb, const double* rowub);
    00455       virtual void addRows(const int numrows,
    00456                            const CoinPackedVectorBase * const * rows,
    00457                            const char* rowsen, const double* rowrhs,
    00458                            const double* rowrng);
    00460       virtual void deleteRows(const int num, const int * rowIndices);
    00461
    00462 #if 0
    00463   // ??? implemented in OsiSolverInterface
    00464       //-----------------------------------------------------------------------
    00486       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
    00487                                             double effectivenessLb = 0.0);
    00488 #endif
    00489
    00490
    00491
    00492   //---------------------------------------------------------------------------
    00493
    00507     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00508                              const double* collb, const double* colub,
    00509                              const double* obj,
    00510                              const double* rowlb, const double* rowub);
    00511
    00519     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00520                                double*& collb, double*& colub, double*& obj,
    00521                                double*& rowlb, double*& rowub);
    00522
    00535     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00536                              const double* collb, const double* colub,
    00537                              const double* obj,
    00538                              const char* rowsen, const double* rowrhs,
    00539                              const double* rowrng);
    00540
    00548     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00549                                double*& collb, double*& colub, double*& obj,
    00550                                char*& rowsen, double*& rowrhs,
    00551                                double*& rowrng);
    00552
    00555     virtual void loadProblem(const int numcols, const int numrows,
    00556                              const int* start, const int* index,
    00557                              const double* value,
    00558                              const double* collb, const double* colub,
    00559                              const double* obj,
    00560                              const double* rowlb, const double* rowub);
    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 char* rowsen, const double* rowrhs,
    00570                              const double* rowrng);
    00571
    00572     using OsiSolverInterface::readMps ;
    00574     virtual int readMps(const char *filename,
    00575                          const char *extension = "mps");
    00576
    00581     virtual void writeMps(const char *filename,
    00582                           const char *extension = "mps",
    00583                           double objSense=0.0) const;
    00585
    00586   //---------------------------------------------------------------------------
    00587
    00594
    00597     void setObjName (std::string name) ;
    00598
    00604     void setRowName(int ndx, std::string name) ;
    00605
    00611     void setColName(int ndx, std::string name) ;
    00612
    00614
    00615   //---------------------------------------------------------------------------
    00616
    00619   enum keepCachedFlag
    00620   {
    00622     KEEPCACHED_NONE    = 0,
    00624     KEEPCACHED_COLUMN  = 1,
    00626     KEEPCACHED_ROW     = 2,
    00628     KEEPCACHED_MATRIX  = 4,
    00630     KEEPCACHED_RESULTS = 8,
    00632     KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
    00634     KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
    00636     FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & ~KEEPCACHED_COLUMN,
    00638     FREECACHED_ROW     = KEEPCACHED_PROBLEM & ~KEEPCACHED_ROW,
    00640     FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & ~KEEPCACHED_MATRIX,
    00642     FREECACHED_RESULTS = KEEPCACHED_ALL & ~KEEPCACHED_RESULTS
    00643   };
    00644
    00646   LPX * getModelPtr();
    00647
    00649
    00658   static void incrementInstanceCounter() { ++numInstances_; }
    00659
    00667   static void decrementInstanceCounter();
    00668
    00670   static unsigned int getNumInstances() { return numInstances_; }
    00672
    00673
    00676
    00677   OsiGlpkSolverInterface();
    00678
    00680   virtual OsiSolverInterface * clone(bool copyData = true) const;
    00681
    00683   OsiGlpkSolverInterface( const OsiGlpkSolverInterface& );
    00684
    00686   OsiGlpkSolverInterface& operator=( const OsiGlpkSolverInterface& rhs );
    00687
    00689   virtual ~OsiGlpkSolverInterface();
    00690
    00692   virtual void reset();
    00694
    00695 protected:
    00696
    00699
    00700   virtual void applyRowCut( const OsiRowCut & rc );
    00701
    00705   virtual void applyColCut( const OsiColCut & cc );
    00706
    00708   LPX * getMutableModelPtr() const;
    00709
    00711
    00712 private:
    00715
    00717   void gutsOfCopy( const OsiGlpkSolverInterface & source );
    00718
    00720   void gutsOfConstructor();
    00721
    00723   void gutsOfDestructor();
    00724
    00726   void freeCachedColRim();
    00727
    00729   void freeCachedRowRim();
    00730
    00732   void freeCachedResults();
    00733
    00735   void freeCachedMatrix();
    00736
    00738   void freeCachedData( int keepCached = KEEPCACHED_NONE );
    00739
    00741   void freeAllMemory();
    00742
    00744   void printBounds();
    00745
    00747   void fillColBounds() const;
    00749
    00750
    00753
    00754   mutable LPX* lp_;
    00755
    00757   static unsigned int numInstances_;
    00758
    00759
    00760   // Remember whether simplex or b&b was most recently done
    00761   // 0 = simplex;  1 = b&b
    00762   int bbWasLast_;
    00763
    00764   // Int parameters.
    00766   int maxIteration_;
    00768   int hotStartMaxIteration_;
    00770   int nameDisc_;
    00771
    00772   // Double parameters.
    00774   double dualObjectiveLimit_;
    00776   double primalObjectiveLimit_;
    00778   double dualTolerance_;
    00780   double primalTolerance_;
    00782   double objOffset_;
    00783
    00784   // String parameters
    00786   std::string probName_;
    00787
    00789   mutable void *info_[OsiLastHintParam] ;
    00790
    00791
    00793
    00795   int hotStartCStatSize_;
    00797   int *hotStartCStat_;
    00799   double *hotStartCVal_;
    00801   double *hotStartCDualVal_;
    00802
    00804   int hotStartRStatSize_;
    00806   int *hotStartRStat_;
    00808   double *hotStartRVal_;
    00810   double *hotStartRDualVal_;
    00811
    00812   // Status information
    00814   bool isIterationLimitReached_;
    00816   bool isTimeLimitReached_;
    00818   bool isAbandoned_;
    00824   bool isObjLowerLimitReached_;
    00830   bool isObjUpperLimitReached_;
    00832   bool isPrimInfeasible_;
    00834   bool isDualInfeasible_;
    00836   bool isFeasible_;
    00837
    00840
    00842   mutable int iter_used_;
    00843
    00845   mutable double  *obj_;
    00846
    00848   mutable double  *collower_;
    00849
    00851   mutable double  *colupper_;
    00852
    00854   mutable char    *ctype_;
    00855
    00857   mutable char    *rowsense_;
    00858
    00860   mutable double  *rhs_;
    00861
    00863   mutable double  *rowrange_;
    00864
    00866   mutable double  *rowlower_;
    00867
    00869   mutable double  *rowupper_;
    00870
    00872   mutable double  *colsol_;
    00873
    00875   mutable double  *rowsol_;
    00876
    00878   mutable double  *redcost_;
    00879
    00881   mutable double  *rowact_;
    00882
    00884   mutable CoinPackedMatrix *matrixByRow_;
    00885
    00887   mutable CoinPackedMatrix *matrixByCol_;
    00889
    00890 };
    00891
    00892 //#############################################################################
    00898 int OsiGlpkSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00899
    00900 #endif // OsiGlpkSolverInterface_H