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

- File List
- File Members

# /home/coin/SVN-release/Osi-0.98.1/Osi/src/OsiCpx/OsiCpxSolverInterface.hpp

Go to the documentation of this file.

    00001 //  LAST EDIT: Fri Aug 31 13:54:15 2001 by Tobias Pfender (opt14!bzfpfend)
    00002 //  Last edit to OsiSimplexMethods: 10/7/05 by F. Margot
    00003 //-----------------------------------------------------------------------------
    00004 // name:     OSI Interface for CPLEX
    00005 // author:   Tobias Pfender
    00006 //           Konrad-Zuse-Zentrum Berlin (Germany)
    00007 //           email: pfender@zib.de
    00008 // date:     09/25/2000
    00009 // license:  this file may be freely distributed under the terms of CPL
    00010 // comments: please scan this file for '???' and read the comments
    00011 //-----------------------------------------------------------------------------
    00012 // Copyright (C) 2000, Tobias Pfender, International Business Machines
    00013 // Corporation and others.  All Rights Reserved.
    00014
    00015 #ifndef OsiCpxSolverInterface_H
    00016 #define OsiCpxSolverInterface_H
    00017
    00018 #include <string>
    00019 #include "cplex.h"
    00020 #include "OsiSolverInterface.hpp"
    00021 #include "CoinPackedMatrix.hpp"
    00022 #include "CoinWarmStartBasis.hpp"
    00023
    00024 // CPLEX 10.0 removed CPXERR_NO_INT_SOLN
    00025 #if !defined(CPXERR_NO_INT_SOLN)
    00026 #define CPXERR_NO_INT_SOLN CPXERR_NO_SOLN
    00027 #endif
    00028
    00029
    00035 class OsiCpxSolverInterface : virtual public OsiSolverInterface {
    00036   friend void OsiCpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00037
    00038 public:
    00039
    00040   //---------------------------------------------------------------------------
    00043
    00044   virtual void initialSolve();
    00045
    00047   virtual void resolve();
    00048
    00050   virtual void branchAndBound();
    00052
    00053   //---------------------------------------------------------------------------
    00069     // Set an integer parameter
    00070     bool setIntParam(OsiIntParam key, int value);
    00071     // Set an double parameter
    00072     bool setDblParam(OsiDblParam key, double value);
    00073     // Set a string parameter
    00074     bool setStrParam(OsiStrParam key, const std::string & value);
    00075     // Get an integer parameter
    00076     bool getIntParam(OsiIntParam key, int& value) const;
    00077     // Get an double parameter
    00078     bool getDblParam(OsiDblParam key, double& value) const;
    00079     // Get a string parameter
    00080     bool getStrParam(OsiStrParam key, std::string& value) const;
    00082
    00083   //---------------------------------------------------------------------------
    00085
    00086
    00087     virtual bool isAbandoned() const;
    00089     virtual bool isProvenOptimal() const;
    00091     virtual bool isProvenPrimalInfeasible() const;
    00093     virtual bool isProvenDualInfeasible() const;
    00095     virtual bool isPrimalObjectiveLimitReached() const;
    00097     virtual bool isDualObjectiveLimitReached() const;
    00099     virtual bool isIterationLimitReached() const;
    00101
    00102   //---------------------------------------------------------------------------
    00105
    00112   inline CoinWarmStart *getEmptyWarmStart () const
    00113   { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; }
    00114
    00116     virtual CoinWarmStart* getWarmStart() const;
    00119     virtual bool setWarmStart(const CoinWarmStart* warmstart);
    00121
    00122   //---------------------------------------------------------------------------
    00129
    00130     virtual void markHotStart();
    00132     virtual void solveFromHotStart();
    00134     virtual void unmarkHotStart();
    00136
    00137   //---------------------------------------------------------------------------
    00152
    00153       virtual int getNumCols() const;
    00154
    00156       virtual int getNumRows() const;
    00157
    00159       virtual int getNumElements() const;
    00160
    00162       virtual const double * getColLower() const;
    00163
    00165       virtual const double * getColUpper() const;
    00166
    00176       virtual const char * getRowSense() const;
    00177
    00186       virtual const double * getRightHandSide() const;
    00187
    00196       virtual const double * getRowRange() const;
    00197
    00199       virtual const double * getRowLower() const;
    00200
    00202       virtual const double * getRowUpper() const;
    00203
    00205       virtual const double * getObjCoefficients() const;
    00206
    00208       virtual double getObjSense() const;
    00209
    00211       virtual bool isContinuous(int colNumber) const;
    00212
    00213 #if 0
    00215       virtual bool isBinary(int columnNumber) const;
    00216
    00221       virtual bool isInteger(int columnNumber) const;
    00222
    00224       virtual bool isIntegerNonBinary(int columnNumber) const;
    00225
    00227       virtual bool isFreeBinary(int columnNumber) const;
    00228 #endif
    00229
    00231       virtual const CoinPackedMatrix * getMatrixByRow() const;
    00232
    00234       virtual const CoinPackedMatrix * getMatrixByCol() const;
    00235
    00237       virtual double getInfinity() const;
    00239
    00242
    00243       virtual const double * getColSolution() const;
    00244
    00246       virtual const double * getRowPrice() const;
    00247
    00249       virtual const double * getReducedCost() const;
    00250
    00253       virtual const double * getRowActivity() const;
    00254
    00256       virtual double getObjValue() const;
    00257
    00260       virtual int getIterationCount() const;
    00261
    00273       virtual std::vector<double*> getDualRays(int maxNumRays) const;
    00285       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
    00286
    00287 #if 0
    00288
    00290       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
    00291         const;
    00292 #endif
    00293
    00294
    00295
    00296   //---------------------------------------------------------------------------
    00297
    00300     //-------------------------------------------------------------------------
    00304       virtual void setObjCoeff( int elementIndex, double elementValue );
    00305
    00307       virtual void setObjCoeffSet(const int* indexFirst,
    00308                                   const int* indexLast,
    00309                                   const double* coeffList);
    00310
    00311       using OsiSolverInterface::setColLower ;
    00314       virtual void setColLower( int elementIndex, double elementValue );
    00315
    00316       using OsiSolverInterface::setColUpper ;
    00319       virtual void setColUpper( int elementIndex, double elementValue );
    00320
    00324       virtual void setColBounds( int elementIndex,
    00325                                  double lower, double upper );
    00326
    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
    00363       virtual void setRowSetBounds(const int* indexFirst,
    00364                                    const int* indexLast,
    00365                                    const double* boundList);
    00366
    00376       virtual void setRowSetTypes(const int* indexFirst,
    00377                                   const int* indexLast,
    00378                                   const char* senseList,
    00379                                   const double* rhsList,
    00380                                   const double* rangeList);
    00382
    00383     //-------------------------------------------------------------------------
    00387       virtual void setContinuous(int index);
    00389       virtual void setInteger(int index);
    00392       virtual void setContinuous(const int* indices, int len);
    00395       virtual void setInteger(const int* indices, int len);
    00397
    00398     //-------------------------------------------------------------------------
    00400     virtual void setObjSense(double s);
    00401
    00412     virtual void setColSolution(const double * colsol);
    00413
    00424     virtual void setRowPrice(const double * rowprice);
    00425
    00426     //-------------------------------------------------------------------------
    00431       using OsiSolverInterface::addCol ;
    00433       virtual void addCol(const CoinPackedVectorBase& vec,
    00434                           const double collb, const double colub,
    00435                           const double obj);
    00436
    00437       using OsiSolverInterface::addCols ;
    00439       virtual void addCols(const int numcols,
    00440                            const CoinPackedVectorBase * const * cols,
    00441                            const double* collb, const double* colub,
    00442                            const double* obj);
    00444       virtual void deleteCols(const int num, const int * colIndices);
    00445
    00446       using OsiSolverInterface::addRow ;
    00448       virtual void addRow(const CoinPackedVectorBase& vec,
    00449                           const double rowlb, const double rowub);
    00451       virtual void addRow(const CoinPackedVectorBase& vec,
    00452                           const char rowsen, const double rowrhs,
    00453                           const double rowrng);
    00454
    00455       using OsiSolverInterface::addRows ;
    00457       virtual void addRows(const int numrows,
    00458                            const CoinPackedVectorBase * const * rows,
    00459                            const double* rowlb, const double* rowub);
    00461       virtual void addRows(const int numrows,
    00462                            const CoinPackedVectorBase * const * rows,
    00463                            const char* rowsen, const double* rowrhs,
    00464                            const double* rowrng);
    00466       virtual void deleteRows(const int num, const int * rowIndices);
    00467
    00468 #if 0
    00469   // ??? implemented in OsiSolverInterface
    00470       //-----------------------------------------------------------------------
    00492       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
    00493                                             double effectivenessLb = 0.0);
    00494 #endif
    00495
    00496
    00497
    00498   //---------------------------------------------------------------------------
    00499
    00513     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00514                              const double* collb, const double* colub,
    00515                              const double* obj,
    00516                              const double* rowlb, const double* rowub);
    00517
    00525     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00526                                double*& collb, double*& colub, double*& obj,
    00527                                double*& rowlb, double*& rowub);
    00528
    00541     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00542                              const double* collb, const double* colub,
    00543                              const double* obj,
    00544                              const char* rowsen, const double* rowrhs,
    00545                              const double* rowrng);
    00546
    00554     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00555                                double*& collb, double*& colub, double*& obj,
    00556                                char*& rowsen, double*& rowrhs,
    00557                                double*& rowrng);
    00558
    00561     virtual void loadProblem(const int numcols, const int numrows,
    00562                              const int* start, const int* index,
    00563                              const double* value,
    00564                              const double* collb, const double* colub,
    00565                              const double* obj,
    00566                              const double* rowlb, const double* rowub);
    00567
    00570     virtual void loadProblem(const int numcols, const int numrows,
    00571                              const int* start, const int* index,
    00572                              const double* value,
    00573                              const double* collb, const double* colub,
    00574                              const double* obj,
    00575                              const char* rowsen, const double* rowrhs,
    00576                              const double* rowrng);
    00577
    00578     using OsiSolverInterface::readMps ;
    00580     virtual int readMps(const char *filename,
    00581                          const char *extension = "mps");
    00582
    00587     virtual void writeMps(const char *filename,
    00588                           const char *extension = "mps",
    00589                           double objSense=0.0) const;
    00590
    00592
    00593   //---------------------------------------------------------------------------
    00594
    00600   enum keepCachedFlag
    00601   {
    00603     KEEPCACHED_NONE    = 0,
    00605     KEEPCACHED_COLUMN  = 1,
    00607     KEEPCACHED_ROW     = 2,
    00609     KEEPCACHED_MATRIX  = 4,
    00611     KEEPCACHED_RESULTS = 8,
    00613     KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
    00615     KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
    00617     FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & ~KEEPCACHED_COLUMN,
    00619     FREECACHED_ROW     = KEEPCACHED_PROBLEM & ~KEEPCACHED_ROW,
    00621     FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & ~KEEPCACHED_MATRIX,
    00623     FREECACHED_RESULTS = KEEPCACHED_ALL & ~KEEPCACHED_RESULTS
    00624   };
    00625   CPXLPptr getLpPtr( int keepCached = KEEPCACHED_NONE );
    00626
    00628
    00629   CPXENVptr getEnvironmentPtr();
    00631
    00633   const char* getCtype() const;
    00634
    00644   static void incrementInstanceCounter();
    00645
    00654   static void decrementInstanceCounter();
    00655
    00657   static unsigned int getNumInstances();
    00659
    00660
    00663
    00664   OsiCpxSolverInterface();
    00665
    00667   virtual OsiSolverInterface * clone(bool copyData = true) const;
    00668
    00670   OsiCpxSolverInterface( const OsiCpxSolverInterface& );
    00671
    00673   OsiCpxSolverInterface& operator=( const OsiCpxSolverInterface& rhs );
    00674
    00676   virtual ~OsiCpxSolverInterface();
    00677
    00679   virtual void reset();
    00681
    00682 /***************************************************************************/
    00702
    00706   virtual int canDoSimplexInterface() const;
    00707
    00708   using OsiSolverInterface::enableSimplexInterface ;
    00712   virtual void enableSimplexInterface(int doingPrimal) {};
    00713
    00717   virtual void disableSimplexInterface() {};
    00718
    00722   virtual void enableFactorization() const {};
    00723
    00727   virtual void disableFactorization() const {};
    00728
    00730   virtual bool basisIsAvailable() const;
    00731
    00735    virtual void getBasisStatus(int* cstat, int* rstat) const;
    00736
    00738   virtual void getBInvARow(int row, double* z, double * slack=NULL) const;
    00739
    00741   virtual void getBInvRow(int row, double* z) const;
    00742
    00744   virtual void getBInvACol(int col, double* vec) const;
    00745
    00747   virtual void getBInvCol(int col, double* vec) const;
    00748
    00754   virtual void getBasics(int* index) const;
    00756 /***************************************************************************/
    00757
    00758 protected:
    00759
    00762
    00763   virtual void applyRowCut( const OsiRowCut & rc );
    00764
    00768   virtual void applyColCut( const OsiColCut & cc );
    00770
    00771 private:
    00774
    00775   void switchToLP();
    00776
    00778   void switchToMIP();
    00779
    00781   void resizeColType( int minsize );
    00782
    00784   void freeColType();
    00786
    00789
    00790   static CPXENVptr env_;
    00792   static int cpxVersionMajor_;
    00793   static int cpxVersionMinor_;
    00794   static int cpxVersionMinorMinor_;
    00796   static unsigned int numInstances_;
    00798
    00799
    00802
    00804   CPXLPptr getMutableLpPtr() const;
    00805
    00807   void gutsOfCopy( const OsiCpxSolverInterface & source );
    00808
    00810   void gutsOfConstructor();
    00811
    00813   void gutsOfDestructor();
    00814
    00816   void freeCachedColRim();
    00817
    00819   void freeCachedRowRim();
    00820
    00822   void freeCachedResults();
    00823
    00825   void freeCachedMatrix();
    00826
    00828   void freeCachedData( int keepCached = KEEPCACHED_NONE );
    00829
    00831   void freeAllMemory();
    00832
    00834   void printBounds();
    00836
    00837
    00840
    00841   mutable CPXLPptr lp_;
    00842
    00844   int *hotStartCStat_;
    00845   int hotStartCStatSize_;
    00846   int *hotStartRStat_;
    00847   int hotStartRStatSize_;
    00848   int hotStartMaxIteration_;
    00849
    00852
    00853   mutable double  *obj_;
    00854
    00856   mutable double  *collower_;
    00857
    00859   mutable double  *colupper_;
    00860
    00862   mutable char    *rowsense_;
    00863
    00865   mutable double  *rhs_;
    00866
    00868   mutable double  *rowrange_;
    00869
    00871   mutable double  *rowlower_;
    00872
    00874   mutable double  *rowupper_;
    00875
    00877   mutable double  *colsol_;
    00878
    00880   mutable double  *rowsol_;
    00881
    00883   mutable double  *redcost_;
    00884
    00886   mutable double  *rowact_;
    00887
    00889   mutable CoinPackedMatrix *matrixByRow_;
    00890
    00892   mutable CoinPackedMatrix *matrixByCol_;
    00894
    00897
    00898   char            *coltype_;
    00899
    00901   int             coltypesize_;
    00902
    00904   mutable bool    probtypemip_;
    00905
    00907 };
    00908
    00909 //#############################################################################
    00915 void OsiCpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00916
    00917 #endif
    00918