/home/coin/SVN-release/Cbc-1.1.1/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     // Get an integer parameter
00066     bool getIntParam(OsiIntParam key, int& value) const;
00067     // Get an double parameter
00068     bool getDblParam(OsiDblParam key, double& value) const;
00069     // Get a string parameter
00070     bool getStrParam(OsiStrParam key, std::string& value) const;
00072 
00073   //---------------------------------------------------------------------------
00075 
00076 
00077     virtual bool isAbandoned() const;
00079     virtual bool isProvenOptimal() const;
00081     virtual bool isProvenPrimalInfeasible() const;
00083     virtual bool isProvenDualInfeasible() const;
00085     virtual bool isPrimalObjectiveLimitReached() const;
00087     virtual bool isDualObjectiveLimitReached() const;
00089     virtual bool isIterationLimitReached() const;
00091 
00092   //---------------------------------------------------------------------------
00101   inline CoinWarmStart *getEmptyWarmStart () const
00102   { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; }
00104     virtual CoinWarmStart* getWarmStart() const;
00107     virtual bool setWarmStart(const CoinWarmStart* warmstart);
00109 
00110   //---------------------------------------------------------------------------
00117 
00118     virtual void markHotStart();
00120     virtual void solveFromHotStart();
00122     virtual void unmarkHotStart();
00124 
00125   //---------------------------------------------------------------------------
00140 
00141       virtual int getNumCols() const;
00142   
00144       virtual int getNumRows() const;
00145   
00147       virtual int getNumElements() const;
00148           
00150       virtual const double * getColLower() const;
00151   
00153       virtual const double * getColUpper() const;
00154   
00164       virtual const char * getRowSense() const;
00165   
00174       virtual const double * getRightHandSide() const;
00175   
00184       virtual const double * getRowRange() const;
00185   
00187       virtual const double * getRowLower() const;
00188   
00190       virtual const double * getRowUpper() const;
00191   
00193       virtual const double * getObjCoefficients() const;
00194   
00196       virtual double getObjSense() const;
00197 
00199       virtual bool isContinuous(int colNumber) const;
00200 
00201 #if 0
00203       virtual bool isBinary(int columnNumber) const;
00204   
00209       virtual bool isInteger(int columnNumber) const;
00210   
00212       virtual bool isIntegerNonBinary(int columnNumber) const;
00213   
00215       virtual bool isFreeBinary(int columnNumber) const;
00216 #endif
00217   
00219       virtual const CoinPackedMatrix * getMatrixByRow() const;
00220   
00222       virtual const CoinPackedMatrix * getMatrixByCol() const;
00223   
00225       virtual double getInfinity() const;
00227     
00230 
00231       virtual const double * getColSolution() const;
00232   
00234       virtual const double * getRowPrice() const;
00235   
00237       virtual const double * getReducedCost() const;
00238   
00241       virtual const double * getRowActivity() const;
00242   
00244       virtual double getObjValue() const;
00245   
00248       virtual int getIterationCount() const;
00249   
00261       virtual std::vector<double*> getDualRays(int maxNumRays) const;
00273       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
00274   
00275 #if 0
00276 
00278       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
00279         const;
00280 #endif
00281 
00282 
00283   
00284   //---------------------------------------------------------------------------
00285 
00288     //-------------------------------------------------------------------------
00292       virtual void setObjCoeff( int elementIndex, double elementValue );
00293 
00296       virtual void setColLower( int elementIndex, double elementValue );
00297       
00300       virtual void setColUpper( int elementIndex, double elementValue );
00301       
00305       virtual void setColBounds( int elementIndex,
00306                                  double lower, double upper );
00307     
00316       virtual void setColSetBounds(const int* indexFirst,
00317                                    const int* indexLast,
00318                                    const double* boundList);
00319       
00322       virtual void setRowLower( int elementIndex, double elementValue );
00323       
00326       virtual void setRowUpper( int elementIndex, double elementValue );
00327     
00331       virtual void setRowBounds( int elementIndex,
00332                                  double lower, double upper );
00333     
00335       virtual void setRowType(int index, char sense, double rightHandSide,
00336                               double range);
00337     
00346       virtual void setRowSetBounds(const int* indexFirst,
00347                                    const int* indexLast,
00348                                    const double* boundList);
00349     
00360       virtual void setRowSetTypes(const int* indexFirst,
00361                                   const int* indexLast,
00362                                   const char* senseList,
00363                                   const double* rhsList,
00364                                   const double* rangeList);
00366     
00367     //-------------------------------------------------------------------------
00371       virtual void setContinuous(int index);
00373       virtual void setInteger(int index);
00376       virtual void setContinuous(const int* indices, int len);
00379       virtual void setInteger(const int* indices, int len);
00381     
00382     //-------------------------------------------------------------------------
00384     virtual void setObjSense(double s);
00385     
00396     virtual void setColSolution(const double * colsol);
00397     
00408     virtual void setRowPrice(const double * rowprice);
00409     
00410     //-------------------------------------------------------------------------
00416       virtual void addCol(const CoinPackedVectorBase& vec,
00417                           const double collb, const double colub,   
00418                           const double obj);
00420       virtual void addCols(const int numcols,
00421                            const CoinPackedVectorBase * const * cols,
00422                            const double* collb, const double* colub,   
00423                            const double* obj);
00425       virtual void deleteCols(const int num, const int * colIndices);
00426     
00428       virtual void addRow(const CoinPackedVectorBase& vec,
00429                           const double rowlb, const double rowub);
00431       virtual void addRow(const CoinPackedVectorBase& vec,
00432                           const char rowsen, const double rowrhs,   
00433                           const double rowrng);
00435       virtual void addRows(const int numrows,
00436                            const CoinPackedVectorBase * const * rows,
00437                            const double* rowlb, const double* rowub);
00439       virtual void addRows(const int numrows,
00440                            const CoinPackedVectorBase * const * rows,
00441                            const char* rowsen, const double* rowrhs,   
00442                            const double* rowrng);
00444       virtual void deleteRows(const int num, const int * rowIndices);
00445     
00446 #if 0
00447   // ??? implemented in OsiSolverInterface
00448       //-----------------------------------------------------------------------
00470       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
00471                                             double effectivenessLb = 0.0);
00472 #endif
00473 
00474 
00475 
00476   //---------------------------------------------------------------------------
00477 
00491     virtual void loadProblem(const CoinPackedMatrix& matrix,
00492                              const double* collb, const double* colub,   
00493                              const double* obj,
00494                              const double* rowlb, const double* rowub);
00495                             
00503     virtual void assignProblem(CoinPackedMatrix*& matrix,
00504                                double*& collb, double*& colub, double*& obj,
00505                                double*& rowlb, double*& rowub);
00506 
00519     virtual void loadProblem(const CoinPackedMatrix& matrix,
00520                              const double* collb, const double* colub,
00521                              const double* obj,
00522                              const char* rowsen, const double* rowrhs,   
00523                              const double* rowrng);
00524 
00532     virtual void assignProblem(CoinPackedMatrix*& matrix,
00533                                double*& collb, double*& colub, double*& obj,
00534                                char*& rowsen, double*& rowrhs,
00535                                double*& rowrng);
00536 
00539     virtual void loadProblem(const int numcols, const int numrows,
00540                              const int* start, const int* index,
00541                              const double* value,
00542                              const double* collb, const double* colub,   
00543                              const double* obj,
00544                              const double* rowlb, const double* rowub);
00545 
00548     virtual void loadProblem(const int numcols, const int numrows,
00549                              const int* start, const int* index,
00550                              const double* value,
00551                              const double* collb, const double* colub,   
00552                              const double* obj,
00553                              const char* rowsen, const double* rowrhs,   
00554                              const double* rowrng);
00555 
00557     virtual int readMps(const char *filename,
00558                          const char *extension = "mps");
00559 
00564     virtual void writeMps(const char *filename,
00565                           const char *extension = "mps",
00566                           double objSense=0.0) const;
00568 
00569   //---------------------------------------------------------------------------
00570 
00573   enum keepCachedFlag
00574   {
00576     KEEPCACHED_NONE    = 0,
00578     KEEPCACHED_COLUMN  = 1,
00580     KEEPCACHED_ROW     = 2,
00582     KEEPCACHED_MATRIX  = 4,
00584     KEEPCACHED_RESULTS = 8,
00586     KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
00588     KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
00590     FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & ~KEEPCACHED_COLUMN,
00592     FREECACHED_ROW     = KEEPCACHED_PROBLEM & ~KEEPCACHED_ROW,
00594     FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & ~KEEPCACHED_MATRIX,
00596     FREECACHED_RESULTS = KEEPCACHED_ALL & ~KEEPCACHED_RESULTS
00597   };
00598 
00600   LPX * getModelPtr();
00601 
00603 
00606 
00607   OsiGlpkSolverInterface(); 
00608   
00610   virtual OsiSolverInterface * clone(bool copyData = true) const;
00611   
00613   OsiGlpkSolverInterface( const OsiGlpkSolverInterface& );
00614   
00616   OsiGlpkSolverInterface& operator=( const OsiGlpkSolverInterface& rhs );
00617   
00619   virtual ~OsiGlpkSolverInterface();
00620 
00622   virtual void reset();
00624   
00625 protected:
00626   
00629 
00630   virtual void applyRowCut( const OsiRowCut & rc );
00631   
00635   virtual void applyColCut( const OsiColCut & cc );
00636 
00638   LPX * getMutableModelPtr() const;
00639 
00641  
00642 private: 
00645     
00647   void gutsOfCopy( const OsiGlpkSolverInterface & source );
00648   
00650   void gutsOfConstructor();
00651   
00653   void gutsOfDestructor();
00654 
00656   void freeCachedColRim();
00657 
00659   void freeCachedRowRim();
00660 
00662   void freeCachedResults();
00663   
00665   void freeCachedMatrix();
00666 
00668   void freeCachedData( int keepCached = KEEPCACHED_NONE );
00669 
00671   void freeAllMemory();
00672 
00674   void printBounds(); 
00675 
00677   void fillColBounds() const;
00679   
00680   
00683 
00684   mutable LPX* lp_;
00685 
00686   // Remember whether simplex or b&b was most recently done
00687   // 0 = simplex;  1 = b&b
00688   int bbWasLast_; 
00689 
00690   // Int parameters.
00691   int maxIteration_;
00692   int hotStartMaxIteration_;
00693 
00694   // Double parameters.
00695   double dualObjectiveLimit_;
00696   double primalObjectiveLimit_;
00697   double dualTolerance_;
00698   double primalTolerance_;
00699 
00701 
00702   int hotStartCStatSize_;
00703   int *hotStartCStat_;
00704   double *hotStartCVal_;
00705   double *hotStartCDualVal_;
00706 
00707   int hotStartRStatSize_;
00708   int *hotStartRStat_;
00709   double *hotStartRVal_;
00710   double *hotStartRDualVal_;
00711 
00712   bool isIterationLimitReached_;
00713   bool isAbandoned_;
00714   bool isObjLowerLimitReached_;
00715   bool isObjUpperLimitReached_;
00716   bool isPrimInfeasible_;
00717   bool isDualInfeasible_;
00718 
00721 
00723   mutable int iter_used_;
00724 
00726   mutable double  *obj_;
00727   
00729   mutable double  *collower_;
00730   
00732   mutable double  *colupper_;
00733   
00735   mutable char    *ctype_;
00736   
00738   mutable char    *rowsense_;
00739   
00741   mutable double  *rhs_;
00742   
00744   mutable double  *rowrange_;
00745   
00747   mutable double  *rowlower_;
00748   
00750   mutable double  *rowupper_;
00751   
00753   mutable double  *colsol_;
00754   
00756   mutable double  *rowsol_;
00757 
00759   mutable double  *redcost_;
00760 
00762   mutable double  *rowact_;
00763 
00765   mutable CoinPackedMatrix *matrixByRow_;  
00766   
00768   mutable CoinPackedMatrix *matrixByCol_;  
00770 
00771 };
00772 
00773 //#############################################################################
00779 void OsiGlpkSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00780 
00781 #endif // OsiGlpkSolverInterface_H

Generated on Thu May 15 21:59:06 2008 by  doxygen 1.4.7