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

- File List
- File Members

# /home/coin/SVN-release/Cgl-0.55.0/Osi/src/OsiGrb/OsiGrbSolverInterface.hpp

Go to the documentation of this file.

    00001 //-----------------------------------------------------------------------------
    00002 // name:     OSI Interface for Gurobi
    00003 // template: OSI Cplex Interface written by T. Achterberg
    00004 // author:   Stefan Vigerske
    00005 //           Humboldt University Berlin
    00006 // date:     09/02/2009
    00007 // license:  this file may be freely distributed under the terms of CPL
    00008 // comments: please scan this file for '???' and read the comments
    00009 //-----------------------------------------------------------------------------
    00010 // Copyright (C) 2009 Humboldt University Berlin and others.
    00011 // All Rights Reserved.
    00012
    00013 // $Id: OsiGrbSolverInterface.hpp 1445 2010-01-09 20:33:43Z stefan $
    00014
    00015 #ifndef OsiGrbSolverInterface_H
    00016 #define OsiGrbSolverInterface_H
    00017
    00018 #include <string>
    00019 #include "OsiSolverInterface.hpp"
    00020
    00021 typedef struct _GRBmodel GRBmodel;
    00022 typedef struct _GRBenv GRBenv;
    00023
    00029 class OsiGrbSolverInterface : virtual public OsiSolverInterface {
    00030   friend void OsiGrbSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00031
    00032 public:
    00033
    00034         //---------------------------------------------------------------------------
    00037
    00038         virtual void initialSolve();
    00039
    00041         virtual void resolve();
    00042
    00044         virtual void branchAndBound();
    00046
    00047         //---------------------------------------------------------------------------
    00063         // Set an integer parameter
    00064         bool setIntParam(OsiIntParam key, int value);
    00065         // Set an double parameter
    00066         bool setDblParam(OsiDblParam key, double value);
    00067         // Set a string parameter
    00068         bool setStrParam(OsiStrParam key, const std::string & value);
    00069         // Set a hint parameter
    00070         bool setHintParam(OsiHintParam key, bool yesNo = true, OsiHintStrength strength = OsiHintTry, void* = NULL);
    00071         // Get an integer parameter
    00072         bool getIntParam(OsiIntParam key, int& value) const;
    00073         // Get an double parameter
    00074         bool getDblParam(OsiDblParam key, double& value) const;
    00075         // Get a string parameter
    00076         bool getStrParam(OsiStrParam key, std::string& value) const;
    00077         // Get a hint parameter
    00078         bool getHintParam(OsiHintParam key, bool& yesNo, OsiHintStrength& strength, void*& otherInformation) const;
    00079         // Get a hint parameter
    00080         bool getHintParam(OsiHintParam key, bool& yesNo, OsiHintStrength& strength) const;
    00081         // Get a hint parameter
    00082         bool getHintParam(OsiHintParam key, bool& yesNo) 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
    00104         //---------------------------------------------------------------------------
    00107
    00114         CoinWarmStart* getEmptyWarmStart() const;
    00115
    00117         virtual CoinWarmStart* getWarmStart() const;
    00120         virtual bool setWarmStart(const CoinWarmStart* warmstart);
    00122
    00123         //---------------------------------------------------------------------------
    00130
    00131         virtual void markHotStart();
    00133         virtual void solveFromHotStart();
    00135         virtual void unmarkHotStart();
    00137
    00138         //---------------------------------------------------------------------------
    00153
    00154         virtual int getNumCols() const;
    00155
    00157         virtual int getNumRows() const;
    00158
    00160         virtual int getNumElements() const;
    00161
    00163         virtual const double * getColLower() const;
    00164
    00166         virtual const double * getColUpper() const;
    00167
    00177         virtual const char * getRowSense() const;
    00178
    00187         virtual const double * getRightHandSide() const;
    00188
    00197         virtual const double * getRowRange() const;
    00198
    00200         virtual const double * getRowLower() const;
    00201
    00203         virtual const double * getRowUpper() const;
    00204
    00206         virtual const double * getObjCoefficients() const;
    00207
    00209         virtual double getObjSense() const;
    00210
    00212         virtual bool isContinuous(int colNumber) const;
    00213
    00215         virtual const CoinPackedMatrix * getMatrixByRow() const;
    00216
    00218         virtual const CoinPackedMatrix * getMatrixByCol() const;
    00219
    00221         virtual double getInfinity() const;
    00223
    00226
    00227         virtual const double * getColSolution() const;
    00228
    00230         virtual const double * getRowPrice() const;
    00231
    00233         virtual const double * getReducedCost() const;
    00234
    00237         virtual const double * getRowActivity() const;
    00238
    00240         virtual double getObjValue() const;
    00241
    00244         virtual int getIterationCount() const;
    00245
    00257         virtual std::vector<double*> getDualRays(int maxNumRays) const;
    00269         virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
    00271
    00272
    00273         //---------------------------------------------------------------------------
    00274
    00277         //-------------------------------------------------------------------------
    00281         virtual void setObjCoeff(int elementIndex, double elementValue);
    00282
    00284         virtual void setObjCoeffSet(const int* indexFirst, const int* indexLast,
    00285                         const double* coeffList);
    00286
    00287         using OsiSolverInterface::setColLower;
    00290         virtual void setColLower(int elementIndex, double elementValue);
    00291
    00292         using OsiSolverInterface::setColUpper;
    00295         virtual void setColUpper(int elementIndex, double elementValue);
    00296
    00300         virtual void setColBounds(int elementIndex, double lower, double upper);
    00301
    00309         virtual void setColSetBounds(const int* indexFirst, const int* indexLast,
    00310                         const double* boundList);
    00311
    00314         virtual void setRowLower(int elementIndex, double elementValue);
    00315
    00318         virtual void setRowUpper(int elementIndex, double elementValue);
    00319
    00323         virtual void setRowBounds(int elementIndex, double lower, double upper);
    00324
    00326         virtual void setRowType(int index, char sense, double rightHandSide,
    00327                         double range);
    00328
    00336         virtual void setRowSetBounds(const int* indexFirst, const int* indexLast,
    00337                         const double* boundList);
    00338
    00348         virtual void setRowSetTypes(const int* indexFirst, const int* indexLast,
    00349                         const char* senseList, const double* rhsList, const double* rangeList);
    00351
    00352         //-------------------------------------------------------------------------
    00356         virtual void setContinuous(int index);
    00358         virtual void setInteger(int index);
    00361         virtual void setContinuous(const int* indices, int len);
    00364         virtual void setInteger(const int* indices, int len);
    00366
    00367   //-------------------------------------------------------------------------
    00371   virtual void setRowName(int ndx, std::string name) ;
    00372
    00374   virtual void setColName(int ndx, std::string name) ;
    00376
    00377         //-------------------------------------------------------------------------
    00379         virtual void setObjSense(double s);
    00380
    00391         virtual void setColSolution(const double * colsol);
    00392
    00403         virtual void setRowPrice(const double * rowprice);
    00404
    00405         //-------------------------------------------------------------------------
    00410         using OsiSolverInterface::addCol;
    00412         virtual void addCol(const CoinPackedVectorBase& vec, const double collb,
    00413                         const double colub, const double obj);
    00414
    00415         using OsiSolverInterface::addCols;
    00417         virtual void addCols(const int numcols,
    00418                         const CoinPackedVectorBase * const * cols, const double* collb,
    00419                         const double* colub, const double* obj);
    00421         virtual void deleteCols(const int num, const int * colIndices);
    00422
    00423         using OsiSolverInterface::addRow;
    00425         virtual void addRow(const CoinPackedVectorBase& vec, const double rowlb,
    00426                         const double rowub);
    00428         virtual void addRow(const CoinPackedVectorBase& vec, const char rowsen,
    00429                         const double rowrhs, const double rowrng);
    00430
    00431         using OsiSolverInterface::addRows;
    00433         virtual void addRows(const int numrows,
    00434                         const CoinPackedVectorBase * const * rows, const double* rowlb,
    00435                         const double* rowub);
    00437         virtual void addRows(const int numrows,
    00438                         const CoinPackedVectorBase * const * rows, const char* rowsen,
    00439                         const double* rowrhs, const double* rowrng);
    00441         virtual void deleteRows(const int num, const int * rowIndices);
    00443
    00444
    00445         //---------------------------------------------------------------------------
    00446
    00460         virtual void loadProblem(const CoinPackedMatrix& matrix, const double* collb,
    00461                         const double* colub, const double* obj, const double* rowlb,
    00462                         const double* rowub);
    00463
    00471         virtual void assignProblem(CoinPackedMatrix*& matrix, double*& collb,
    00472                         double*& colub, double*& obj, double*& rowlb, double*& rowub);
    00473
    00486         virtual void loadProblem(const CoinPackedMatrix& matrix, const double* collb,
    00487                         const double* colub, const double* obj, const char* rowsen,
    00488                         const double* rowrhs, const double* rowrng);
    00489
    00497         virtual void assignProblem(CoinPackedMatrix*& matrix, double*& collb,
    00498                         double*& colub, double*& obj, char*& rowsen, double*& rowrhs,
    00499                         double*& rowrng);
    00500
    00503         virtual void loadProblem(const int numcols, const int numrows,
    00504                         const int* start, const int* index, const double* value,
    00505                         const double* collb, const double* colub, const double* obj,
    00506                         const double* rowlb, const double* rowub);
    00507
    00510         virtual void loadProblem(const int numcols, const int numrows,
    00511                         const int* start, const int* index, const double* value,
    00512                         const double* collb, const double* colub, const double* obj,
    00513                         const char* rowsen, const double* rowrhs, const double* rowrng);
    00514
    00515         using OsiSolverInterface::readMps;
    00517         virtual int readMps(const char *filename, const char *extension = "mps");
    00518
    00523         virtual void writeMps(const char *filename, const char *extension = "mps",
    00524                         double objSense=0.0) const;
    00525
    00527
    00528         //---------------------------------------------------------------------------
    00529
    00535         enum keepCachedFlag
    00536         {
    00538                 KEEPCACHED_NONE = 0,
    00540                 KEEPCACHED_COLUMN = 1,
    00542                 KEEPCACHED_ROW = 2,
    00544                 KEEPCACHED_MATRIX = 4,
    00546                 KEEPCACHED_RESULTS = 8,
    00548                 KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
    00550                 KEEPCACHED_ALL = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
    00552                 FREECACHED_COLUMN = KEEPCACHED_PROBLEM & ~KEEPCACHED_COLUMN,
    00554                 FREECACHED_ROW = KEEPCACHED_PROBLEM & ~KEEPCACHED_ROW,
    00556                 FREECACHED_MATRIX = KEEPCACHED_PROBLEM & ~KEEPCACHED_MATRIX,
    00558                 FREECACHED_RESULTS = KEEPCACHED_ALL & ~KEEPCACHED_RESULTS
    00559         };
    00560
    00561         GRBmodel* getLpPtr(int keepCached = KEEPCACHED_NONE);
    00562
    00564
    00565         GRBenv* getEnvironmentPtr() const;
    00566
    00568   bool isDemoLicense() const;
    00570
    00572         const char* getCtype() const;
    00573
    00583         static void incrementInstanceCounter();
    00584
    00593         static void decrementInstanceCounter();
    00594
    00596         static void setEnvironment(GRBenv* globalenv);
    00597
    00599         static unsigned int getNumInstances();
    00601
    00602
    00605
    00606         OsiGrbSolverInterface(bool use_local_env = false);
    00607
    00609         OsiGrbSolverInterface(GRBenv* localgrbenv);
    00610
    00612         virtual OsiSolverInterface * clone(bool copyData = true) const;
    00613
    00615         OsiGrbSolverInterface(const OsiGrbSolverInterface&);
    00616
    00618         OsiGrbSolverInterface& operator=(const OsiGrbSolverInterface& rhs);
    00619
    00621         virtual ~OsiGrbSolverInterface();
    00622
    00624         virtual void reset();
    00626
    00627         /***************************************************************************/
    00644
    00648         virtual int canDoSimplexInterface() const;
    00649
    00650         using OsiSolverInterface::enableSimplexInterface;
    00654         virtual void enableSimplexInterface(int doingPrimal) {
    00655         }
    00656         ;
    00657
    00661         virtual void disableSimplexInterface() {
    00662         }
    00663         ;
    00664
    00668         virtual void enableFactorization() const {
    00669         }
    00670         ;
    00671
    00675         virtual void disableFactorization() const {
    00676         }
    00677         ;
    00678
    00680         virtual bool basisIsAvailable() const;
    00681
    00685         virtual void getBasisStatus(int* cstat, int* rstat) const;
    00686
    00687         //  ///Get a row of the tableau (slack part in slack if not NULL)
    00688         //  virtual void getBInvARow(int row, double* z, double * slack=NULL) const;
    00689         //
    00690         //  ///Get a row of the basis inverse
    00691         //  virtual void getBInvRow(int row, double* z) const;
    00692         //
    00693         //  ///Get a column of the tableau
    00694         //  virtual void getBInvACol(int col, double* vec) const;
    00695         //
    00696         //  ///Get a column of the basis inverse
    00697         //  virtual void getBInvCol(int col, double* vec) const;
    00698         //
    00699         //  /**  Get indices of the pivot variable in each row
    00700         //      (order of indices corresponds to the
    00701         //      order of elements in a vector retured by getBInvACol() and
    00702         //      getBInvCol()).
    00703         //  */
    00704         //  virtual void getBasics(int* index) const;
    00706         void switchToLP();
    00707
    00709         void switchToMIP();
    00710
    00712         /***************************************************************************/
    00713
    00714 protected:
    00715
    00718
    00719         virtual void applyRowCut(const OsiRowCut & rc);
    00720
    00724         virtual void applyColCut(const OsiColCut & cc);
    00726
    00727 private:
    00730
    00731         void resizeColSpace(int minsize);
    00732
    00734         void freeColSpace();
    00735
    00737         void resizeAuxColSpace(int minsize);
    00738
    00740         void resizeAuxColIndSpace();
    00742
    00745
    00746         static GRBenv* globalenv_;
    00748         static bool globalenv_is_ours;
    00750         static unsigned int numInstances_;
    00752
    00755
    00757         GRBmodel* getMutableLpPtr() const;
    00758
    00760         void gutsOfCopy(const OsiGrbSolverInterface & source);
    00761
    00763         void gutsOfConstructor();
    00764
    00766         void gutsOfDestructor();
    00767
    00769         void freeCachedColRim();
    00770
    00772         void freeCachedRowRim();
    00773
    00775         void freeCachedResults();
    00776
    00778         void freeCachedMatrix();
    00779
    00781         void freeCachedData(int keepCached = KEEPCACHED_NONE);
    00782
    00784         void freeAllMemory();
    00785
    00787         void convertToRangedRow(int rowidx, double rhs, double range);
    00788
    00790         void convertToNormalRow(int rowidx, char sense, double rhs);
    00792
    00793
    00796
    00797         mutable GRBenv* localenv_;
    00798
    00800         mutable GRBmodel* lp_;
    00801
    00803         int *hotStartCStat_;
    00804         int hotStartCStatSize_;
    00805         int *hotStartRStat_;
    00806         int hotStartRStatSize_;
    00807         int hotStartMaxIteration_;
    00808
    00810   int nameDisc_;
    00811
    00814
    00815         mutable double *obj_;
    00816
    00818         mutable double *collower_;
    00819
    00821         mutable double *colupper_;
    00822
    00824         mutable char *rowsense_;
    00825
    00827         mutable double *rhs_;
    00828
    00830         mutable double *rowrange_;
    00831
    00833         mutable double *rowlower_;
    00834
    00836         mutable double *rowupper_;
    00837
    00839         mutable double *colsol_;
    00840
    00842         mutable double *rowsol_;
    00843
    00845         mutable double *redcost_;
    00846
    00848         mutable double *rowact_;
    00849
    00851         mutable CoinPackedMatrix *matrixByRow_;
    00852
    00854         mutable CoinPackedMatrix *matrixByCol_;
    00856
    00859
    00860   mutable bool probtypemip_;
    00861
    00863   int colspace_;
    00864
    00866         char *coltype_;
    00867
    00869         int nauxcols;
    00870
    00872         int auxcolspace;
    00873
    00876         int* colmap_O2G;
    00877
    00882         int* colmap_G2O;
    00883
    00885         int auxcolindspace;
    00886
    00890         int* auxcolind;
    00892 };
    00893
    00894 //#############################################################################
    00900 void OsiGrbSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00901
    00902 #endif