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

- File List
- File Members

# /home/coin/svn-release/Alps-1.4.5/Osi/src/OsiCpx/OsiCpxSolverInterface.hpp

Go to the documentation of this file.

    00001 //-----------------------------------------------------------------------------
    00002 // name:     OSI Interface for CPLEX
    00003 // author:   Tobias Pfender
    00004 //           Konrad-Zuse-Zentrum Berlin (Germany)
    00005 //           email: pfender@zib.de
    00006 // date:     09/25/2000
    00007 // license:  this file may be freely distributed under the terms of EPL
    00008 // comments: please scan this file for '???' and read the comments
    00009 //-----------------------------------------------------------------------------
    00010 // Copyright (C) 2000, Tobias Pfender, International Business Machines
    00011 // Corporation and others.  All Rights Reserved.
    00012
    00013 #ifndef OsiCpxSolverInterface_H
    00014 #define OsiCpxSolverInterface_H
    00015
    00016 #include "OsiSolverInterface.hpp"
    00017 #include "CoinWarmStartBasis.hpp"
    00018 #include "OsiColCut.hpp"
    00019 #include "OsiRowCut.hpp"
    00020
    00021 typedef struct cpxlp*  CPXLPptr;
    00022 typedef struct cpxenv* CPXENVptr;
    00023
    00029 class OsiCpxSolverInterface : virtual public OsiSolverInterface {
    00030   friend void OsiCpxSolverInterfaceUnitTest(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     // Get an integer parameter
    00070     bool getIntParam(OsiIntParam key, int& value) const;
    00071     // Get an double parameter
    00072     bool getDblParam(OsiDblParam key, double& value) const;
    00073     // Get a string parameter
    00074     bool getStrParam(OsiStrParam key, std::string& value) const;
    00075     // Set mipstart option (pass column solution to CPLEX before MIP start)
    00076     void setMipStart(bool value) { domipstart = value; }
    00077     // Get mipstart option value
    00078     bool getMipStart() const { return domipstart; }
    00080
    00081   //---------------------------------------------------------------------------
    00083
    00084
    00085     virtual bool isAbandoned() const;
    00087     virtual bool isProvenOptimal() const;
    00089     virtual bool isProvenPrimalInfeasible() const;
    00091     virtual bool isProvenDualInfeasible() const;
    00093     virtual bool isPrimalObjectiveLimitReached() const;
    00095     virtual bool isDualObjectiveLimitReached() const;
    00097     virtual bool isIterationLimitReached() const;
    00099
    00100   //---------------------------------------------------------------------------
    00103
    00110   CoinWarmStart *getEmptyWarmStart () const;
    00111
    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
    00276       virtual std::vector<double*> getDualRays(int maxNumRays,
    00277                                                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
    00311       virtual void setObjCoeffSet(const int* indexFirst,
    00312                                   const int* indexLast,
    00313                                   const double* coeffList);
    00314
    00315       using OsiSolverInterface::setColLower ;
    00318       virtual void setColLower( int elementIndex, double elementValue );
    00319
    00320       using OsiSolverInterface::setColUpper ;
    00323       virtual void setColUpper( int elementIndex, double elementValue );
    00324
    00328       virtual void setColBounds( int elementIndex,
    00329                                  double lower, double upper );
    00330
    00338       virtual void setColSetBounds(const int* indexFirst,
    00339                                    const int* indexLast,
    00340                                    const double* boundList);
    00341
    00344       virtual void setRowLower( int elementIndex, double elementValue );
    00345
    00348       virtual void setRowUpper( int elementIndex, double elementValue );
    00349
    00353       virtual void setRowBounds( int elementIndex,
    00354                                  double lower, double upper );
    00355
    00357       virtual void setRowType(int index, char sense, double rightHandSide,
    00358                               double range);
    00359
    00367       virtual void setRowSetBounds(const int* indexFirst,
    00368                                    const int* indexLast,
    00369                                    const double* boundList);
    00370
    00380       virtual void setRowSetTypes(const int* indexFirst,
    00381                                   const int* indexLast,
    00382                                   const char* senseList,
    00383                                   const double* rhsList,
    00384                                   const double* rangeList);
    00386
    00387     //-------------------------------------------------------------------------
    00391       virtual void setContinuous(int index);
    00393       virtual void setInteger(int index);
    00396       virtual void setContinuous(const int* indices, int len);
    00399       virtual void setInteger(const int* indices, int len);
    00401
    00402     //-------------------------------------------------------------------------
    00404     virtual void setObjSense(double s);
    00405
    00416     virtual void setColSolution(const double * colsol);
    00417
    00428     virtual void setRowPrice(const double * rowprice);
    00429
    00430     //-------------------------------------------------------------------------
    00435       using OsiSolverInterface::addCol ;
    00437       virtual void addCol(const CoinPackedVectorBase& vec,
    00438                           const double collb, const double colub,
    00439                           const double obj);
    00440
    00441       using OsiSolverInterface::addCols ;
    00443       virtual void addCols(const int numcols,
    00444                            const CoinPackedVectorBase * const * cols,
    00445                            const double* collb, const double* colub,
    00446                            const double* obj);
    00448       virtual void deleteCols(const int num, const int * colIndices);
    00449
    00450       using OsiSolverInterface::addRow ;
    00452       virtual void addRow(const CoinPackedVectorBase& vec,
    00453                           const double rowlb, const double rowub);
    00455       virtual void addRow(const CoinPackedVectorBase& vec,
    00456                           const char rowsen, const double rowrhs,
    00457                           const double rowrng);
    00458
    00459       using OsiSolverInterface::addRows ;
    00461       virtual void addRows(const int numrows,
    00462                            const CoinPackedVectorBase * const * rows,
    00463                            const double* rowlb, const double* rowub);
    00465       virtual void addRows(const int numrows,
    00466                            const CoinPackedVectorBase * const * rows,
    00467                            const char* rowsen, const double* rowrhs,
    00468                            const double* rowrng);
    00470       virtual void deleteRows(const int num, const int * rowIndices);
    00471
    00472 #if 0
    00473   // ??? implemented in OsiSolverInterface
    00474       //-----------------------------------------------------------------------
    00496       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
    00497                                             double effectivenessLb = 0.0);
    00498 #endif
    00499
    00500
    00501
    00502   //---------------------------------------------------------------------------
    00503
    00517     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00518                              const double* collb, const double* colub,
    00519                              const double* obj,
    00520                              const double* rowlb, const double* rowub);
    00521
    00529     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00530                                double*& collb, double*& colub, double*& obj,
    00531                                double*& rowlb, double*& rowub);
    00532
    00545     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00546                              const double* collb, const double* colub,
    00547                              const double* obj,
    00548                              const char* rowsen, const double* rowrhs,
    00549                              const double* rowrng);
    00550
    00558     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00559                                double*& collb, double*& colub, double*& obj,
    00560                                char*& rowsen, double*& rowrhs,
    00561                                double*& rowrng);
    00562
    00565     virtual void loadProblem(const int numcols, const int numrows,
    00566                              const int* start, const int* index,
    00567                              const double* value,
    00568                              const double* collb, const double* colub,
    00569                              const double* obj,
    00570                              const double* rowlb, const double* rowub);
    00571
    00574     virtual void loadProblem(const int numcols, const int numrows,
    00575                              const int* start, const int* index,
    00576                              const double* value,
    00577                              const double* collb, const double* colub,
    00578                              const double* obj,
    00579                              const char* rowsen, const double* rowrhs,
    00580                              const double* rowrng);
    00581
    00582     using OsiSolverInterface::readMps ;
    00584     virtual int readMps(const char *filename,
    00585                          const char *extension = "mps");
    00586
    00591     virtual void writeMps(const char *filename,
    00592                           const char *extension = "mps",
    00593                           double objSense=0.0) const;
    00594
    00596
    00604     void passInMessageHandler(CoinMessageHandler * handler);
    00606
    00607   //---------------------------------------------------------------------------
    00608
    00614   enum keepCachedFlag
    00615   {
    00617     KEEPCACHED_NONE    = 0,
    00619     KEEPCACHED_COLUMN  = 1,
    00621     KEEPCACHED_ROW     = 2,
    00623     KEEPCACHED_MATRIX  = 4,
    00625     KEEPCACHED_RESULTS = 8,
    00627     KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
    00629     KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
    00631     FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & ~KEEPCACHED_COLUMN,
    00633     FREECACHED_ROW     = KEEPCACHED_PROBLEM & ~KEEPCACHED_ROW,
    00635     FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & ~KEEPCACHED_MATRIX,
    00637     FREECACHED_RESULTS = KEEPCACHED_ALL & ~KEEPCACHED_RESULTS
    00638   };
    00639   CPXLPptr getLpPtr( int keepCached = KEEPCACHED_NONE );
    00640
    00642
    00643   CPXENVptr getEnvironmentPtr();
    00645
    00647   const char* getCtype() const;
    00648
    00651
    00652   OsiCpxSolverInterface();
    00653
    00655   virtual OsiSolverInterface * clone(bool copyData = true) const;
    00656
    00658   OsiCpxSolverInterface( const OsiCpxSolverInterface& );
    00659
    00661   OsiCpxSolverInterface& operator=( const OsiCpxSolverInterface& rhs );
    00662
    00664   virtual ~OsiCpxSolverInterface();
    00665
    00667   virtual void reset();
    00669
    00670 /***************************************************************************/
    00690
    00694   virtual int canDoSimplexInterface() const;
    00695
    00696   using OsiSolverInterface::enableSimplexInterface ;
    00700   virtual void enableSimplexInterface(int doingPrimal) {};
    00701
    00705   virtual void disableSimplexInterface() {};
    00706
    00710   virtual void enableFactorization() const {};
    00711
    00715   virtual void disableFactorization() const {};
    00716
    00718   virtual bool basisIsAvailable() const;
    00719
    00723    virtual void getBasisStatus(int* cstat, int* rstat) const;
    00724
    00726   virtual void getBInvARow(int row, double* z, double * slack=NULL) const;
    00727
    00729   virtual void getBInvRow(int row, double* z) const;
    00730
    00732   virtual void getBInvACol(int col, double* vec) const;
    00733
    00735   virtual void getBInvCol(int col, double* vec) const;
    00736
    00742   virtual void getBasics(int* index) const;
    00744   void switchToLP();
    00745
    00747   void switchToMIP();
    00748
    00750 /***************************************************************************/
    00751
    00752 protected:
    00753
    00756
    00757   virtual void applyRowCut( const OsiRowCut & rc );
    00758
    00762   virtual void applyColCut( const OsiColCut & cc );
    00764
    00765 private:
    00768
    00769   void resizeColType( int minsize );
    00770
    00772   void freeColType();
    00774
    00775
    00778
    00780   CPXLPptr getMutableLpPtr() const;
    00781
    00783   void gutsOfCopy( const OsiCpxSolverInterface & source );
    00784
    00786   void gutsOfConstructor();
    00787
    00789   void gutsOfDestructor();
    00790
    00792   void freeCachedColRim();
    00793
    00795   void freeCachedRowRim();
    00796
    00798   void freeCachedResults();
    00799
    00801   void freeCachedMatrix();
    00802
    00804   void freeCachedData( int keepCached = KEEPCACHED_NONE );
    00805
    00807   void freeAllMemory();
    00808
    00810
    00811
    00814
    00815   mutable CPXENVptr env_;
    00817   mutable CPXLPptr lp_;
    00818
    00820   int *hotStartCStat_;
    00821   int hotStartCStatSize_;
    00822   int *hotStartRStat_;
    00823   int hotStartRStatSize_;
    00824   int hotStartMaxIteration_;
    00825
    00828
    00829   mutable double  *obj_;
    00830
    00832   mutable double  *collower_;
    00833
    00835   mutable double  *colupper_;
    00836
    00838   mutable char    *rowsense_;
    00839
    00841   mutable double  *rhs_;
    00842
    00844   mutable double  *rowrange_;
    00845
    00847   mutable double  *rowlower_;
    00848
    00850   mutable double  *rowupper_;
    00851
    00853   mutable double  *colsol_;
    00854
    00856   mutable double  *rowsol_;
    00857
    00859   mutable double  *redcost_;
    00860
    00862   mutable double  *rowact_;
    00863
    00865   mutable CoinPackedMatrix *matrixByRow_;
    00866
    00868   mutable CoinPackedMatrix *matrixByCol_;
    00870
    00873
    00874   char            *coltype_;
    00875
    00877   int             coltypesize_;
    00878
    00880   mutable bool    probtypemip_;
    00881
    00883   bool            domipstart;
    00884
    00886   bool            disableadvbasis;
    00887
    00889 };
    00890
    00891 //#############################################################################
    00893 void OsiCpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00894
    00895 #endif