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

- File List
- File Members

# /home/coin/SVN-release/Blis-0.91.2/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 CPL
    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
    00018 typedef struct cpxlp*  CPXLPptr;
    00019 typedef struct cpxenv* CPXENVptr;
    00020
    00026 class OsiCpxSolverInterface : virtual public OsiSolverInterface {
    00027   friend void OsiCpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00028
    00029 public:
    00030
    00031   //---------------------------------------------------------------------------
    00034
    00035   virtual void initialSolve();
    00036
    00038   virtual void resolve();
    00039
    00041   virtual void branchAndBound();
    00043
    00044   //---------------------------------------------------------------------------
    00060     // Set an integer parameter
    00061     bool setIntParam(OsiIntParam key, int value);
    00062     // Set an double parameter
    00063     bool setDblParam(OsiDblParam key, double value);
    00064     // Set a string parameter
    00065     bool setStrParam(OsiStrParam key, const std::string & value);
    00066     // Get an integer parameter
    00067     bool getIntParam(OsiIntParam key, int& value) const;
    00068     // Get an double parameter
    00069     bool getDblParam(OsiDblParam key, double& value) const;
    00070     // Get a string parameter
    00071     bool getStrParam(OsiStrParam key, std::string& value) const;
    00073
    00074   //---------------------------------------------------------------------------
    00076
    00077
    00078     virtual bool isAbandoned() const;
    00080     virtual bool isProvenOptimal() const;
    00082     virtual bool isProvenPrimalInfeasible() const;
    00084     virtual bool isProvenDualInfeasible() const;
    00086     virtual bool isPrimalObjectiveLimitReached() const;
    00088     virtual bool isDualObjectiveLimitReached() const;
    00090     virtual bool isIterationLimitReached() const;
    00092
    00093   //---------------------------------------------------------------------------
    00096
    00103   CoinWarmStart *getEmptyWarmStart () const;
    00104
    00106     virtual CoinWarmStart* getWarmStart() const;
    00109     virtual bool setWarmStart(const CoinWarmStart* warmstart);
    00111
    00112   //---------------------------------------------------------------------------
    00119
    00120     virtual void markHotStart();
    00122     virtual void solveFromHotStart();
    00124     virtual void unmarkHotStart();
    00126
    00127   //---------------------------------------------------------------------------
    00142
    00143       virtual int getNumCols() const;
    00144
    00146       virtual int getNumRows() const;
    00147
    00149       virtual int getNumElements() const;
    00150
    00152       virtual const double * getColLower() const;
    00153
    00155       virtual const double * getColUpper() const;
    00156
    00166       virtual const char * getRowSense() const;
    00167
    00176       virtual const double * getRightHandSide() const;
    00177
    00186       virtual const double * getRowRange() const;
    00187
    00189       virtual const double * getRowLower() const;
    00190
    00192       virtual const double * getRowUpper() const;
    00193
    00195       virtual const double * getObjCoefficients() const;
    00196
    00198       virtual double getObjSense() const;
    00199
    00201       virtual bool isContinuous(int colNumber) const;
    00202
    00203 #if 0
    00205       virtual bool isBinary(int columnNumber) const;
    00206
    00211       virtual bool isInteger(int columnNumber) const;
    00212
    00214       virtual bool isIntegerNonBinary(int columnNumber) const;
    00215
    00217       virtual bool isFreeBinary(int columnNumber) const;
    00218 #endif
    00219
    00221       virtual const CoinPackedMatrix * getMatrixByRow() const;
    00222
    00224       virtual const CoinPackedMatrix * getMatrixByCol() const;
    00225
    00227       virtual double getInfinity() const;
    00229
    00232
    00233       virtual const double * getColSolution() const;
    00234
    00236       virtual const double * getRowPrice() const;
    00237
    00239       virtual const double * getReducedCost() const;
    00240
    00243       virtual const double * getRowActivity() const;
    00244
    00246       virtual double getObjValue() const;
    00247
    00250       virtual int getIterationCount() const;
    00251
    00263       virtual std::vector<double*> getDualRays(int maxNumRays) const;
    00275       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
    00276
    00277 #if 0
    00278
    00280       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
    00281         const;
    00282 #endif
    00283
    00284
    00285
    00286   //---------------------------------------------------------------------------
    00287
    00290     //-------------------------------------------------------------------------
    00294       virtual void setObjCoeff( int elementIndex, double elementValue );
    00295
    00297       virtual void setObjCoeffSet(const int* indexFirst,
    00298                                   const int* indexLast,
    00299                                   const double* coeffList);
    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
    00324       virtual void setColSetBounds(const int* indexFirst,
    00325                                    const int* indexLast,
    00326                                    const double* boundList);
    00327
    00330       virtual void setRowLower( int elementIndex, double elementValue );
    00331
    00334       virtual void setRowUpper( int elementIndex, double elementValue );
    00335
    00339       virtual void setRowBounds( int elementIndex,
    00340                                  double lower, double upper );
    00341
    00343       virtual void setRowType(int index, char sense, double rightHandSide,
    00344                               double range);
    00345
    00353       virtual void setRowSetBounds(const int* indexFirst,
    00354                                    const int* indexLast,
    00355                                    const double* boundList);
    00356
    00366       virtual void setRowSetTypes(const int* indexFirst,
    00367                                   const int* indexLast,
    00368                                   const char* senseList,
    00369                                   const double* rhsList,
    00370                                   const double* rangeList);
    00372
    00373     //-------------------------------------------------------------------------
    00377       virtual void setContinuous(int index);
    00379       virtual void setInteger(int index);
    00382       virtual void setContinuous(const int* indices, int len);
    00385       virtual void setInteger(const int* indices, int len);
    00387
    00388     //-------------------------------------------------------------------------
    00390     virtual void setObjSense(double s);
    00391
    00402     virtual void setColSolution(const double * colsol);
    00403
    00414     virtual void setRowPrice(const double * rowprice);
    00415
    00416     //-------------------------------------------------------------------------
    00421       using OsiSolverInterface::addCol ;
    00423       virtual void addCol(const CoinPackedVectorBase& vec,
    00424                           const double collb, const double colub,
    00425                           const double obj);
    00426
    00427       using OsiSolverInterface::addCols ;
    00429       virtual void addCols(const int numcols,
    00430                            const CoinPackedVectorBase * const * cols,
    00431                            const double* collb, const double* colub,
    00432                            const double* obj);
    00434       virtual void deleteCols(const int num, const int * colIndices);
    00435
    00436       using OsiSolverInterface::addRow ;
    00438       virtual void addRow(const CoinPackedVectorBase& vec,
    00439                           const double rowlb, const double rowub);
    00441       virtual void addRow(const CoinPackedVectorBase& vec,
    00442                           const char rowsen, const double rowrhs,
    00443                           const double rowrng);
    00444
    00445       using OsiSolverInterface::addRows ;
    00447       virtual void addRows(const int numrows,
    00448                            const CoinPackedVectorBase * const * rows,
    00449                            const double* rowlb, const double* rowub);
    00451       virtual void addRows(const int numrows,
    00452                            const CoinPackedVectorBase * const * rows,
    00453                            const char* rowsen, const double* rowrhs,
    00454                            const double* rowrng);
    00456       virtual void deleteRows(const int num, const int * rowIndices);
    00457
    00458 #if 0
    00459   // ??? implemented in OsiSolverInterface
    00460       //-----------------------------------------------------------------------
    00482       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
    00483                                             double effectivenessLb = 0.0);
    00484 #endif
    00485
    00486
    00487
    00488   //---------------------------------------------------------------------------
    00489
    00503     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00504                              const double* collb, const double* colub,
    00505                              const double* obj,
    00506                              const double* rowlb, const double* rowub);
    00507
    00515     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00516                                double*& collb, double*& colub, double*& obj,
    00517                                double*& rowlb, double*& rowub);
    00518
    00531     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00532                              const double* collb, const double* colub,
    00533                              const double* obj,
    00534                              const char* rowsen, const double* rowrhs,
    00535                              const double* rowrng);
    00536
    00544     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00545                                double*& collb, double*& colub, double*& obj,
    00546                                char*& rowsen, double*& rowrhs,
    00547                                double*& rowrng);
    00548
    00551     virtual void loadProblem(const int numcols, const int numrows,
    00552                              const int* start, const int* index,
    00553                              const double* value,
    00554                              const double* collb, const double* colub,
    00555                              const double* obj,
    00556                              const double* rowlb, const double* rowub);
    00557
    00560     virtual void loadProblem(const int numcols, const int numrows,
    00561                              const int* start, const int* index,
    00562                              const double* value,
    00563                              const double* collb, const double* colub,
    00564                              const double* obj,
    00565                              const char* rowsen, const double* rowrhs,
    00566                              const double* rowrng);
    00567
    00568     using OsiSolverInterface::readMps ;
    00570     virtual int readMps(const char *filename,
    00571                          const char *extension = "mps");
    00572
    00577     virtual void writeMps(const char *filename,
    00578                           const char *extension = "mps",
    00579                           double objSense=0.0) const;
    00580
    00582
    00590     void passInMessageHandler(CoinMessageHandler * handler);
    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
    00637
    00638   OsiCpxSolverInterface();
    00639
    00641   virtual OsiSolverInterface * clone(bool copyData = true) const;
    00642
    00644   OsiCpxSolverInterface( const OsiCpxSolverInterface& );
    00645
    00647   OsiCpxSolverInterface& operator=( const OsiCpxSolverInterface& rhs );
    00648
    00650   virtual ~OsiCpxSolverInterface();
    00651
    00653   virtual void reset();
    00655
    00656 /***************************************************************************/
    00676
    00680   virtual int canDoSimplexInterface() const;
    00681
    00682   using OsiSolverInterface::enableSimplexInterface ;
    00686   virtual void enableSimplexInterface(int doingPrimal) {};
    00687
    00691   virtual void disableSimplexInterface() {};
    00692
    00696   virtual void enableFactorization() const {};
    00697
    00701   virtual void disableFactorization() const {};
    00702
    00704   virtual bool basisIsAvailable() const;
    00705
    00709    virtual void getBasisStatus(int* cstat, int* rstat) const;
    00710
    00712   virtual void getBInvARow(int row, double* z, double * slack=NULL) const;
    00713
    00715   virtual void getBInvRow(int row, double* z) const;
    00716
    00718   virtual void getBInvACol(int col, double* vec) const;
    00719
    00721   virtual void getBInvCol(int col, double* vec) const;
    00722
    00728   virtual void getBasics(int* index) const;
    00730   void switchToLP();
    00731
    00733   void switchToMIP();
    00734
    00736 /***************************************************************************/
    00737
    00738 protected:
    00739
    00742
    00743   virtual void applyRowCut( const OsiRowCut & rc );
    00744
    00748   virtual void applyColCut( const OsiColCut & cc );
    00750
    00751 private:
    00754
    00755   void resizeColType( int minsize );
    00756
    00758   void freeColType();
    00760
    00761
    00764
    00766   CPXLPptr getMutableLpPtr() const;
    00767
    00769   void gutsOfCopy( const OsiCpxSolverInterface & source );
    00770
    00772   void gutsOfConstructor();
    00773
    00775   void gutsOfDestructor();
    00776
    00778   void freeCachedColRim();
    00779
    00781   void freeCachedRowRim();
    00782
    00784   void freeCachedResults();
    00785
    00787   void freeCachedMatrix();
    00788
    00790   void freeCachedData( int keepCached = KEEPCACHED_NONE );
    00791
    00793   void freeAllMemory();
    00794
    00795
    00797   void printBounds();
    00799
    00800
    00803
    00804   mutable CPXENVptr env_;
    00806   mutable CPXLPptr lp_;
    00807
    00809   int *hotStartCStat_;
    00810   int hotStartCStatSize_;
    00811   int *hotStartRStat_;
    00812   int hotStartRStatSize_;
    00813   int hotStartMaxIteration_;
    00814
    00817
    00818   mutable double  *obj_;
    00819
    00821   mutable double  *collower_;
    00822
    00824   mutable double  *colupper_;
    00825
    00827   mutable char    *rowsense_;
    00828
    00830   mutable double  *rhs_;
    00831
    00833   mutable double  *rowrange_;
    00834
    00836   mutable double  *rowlower_;
    00837
    00839   mutable double  *rowupper_;
    00840
    00842   mutable double  *colsol_;
    00843
    00845   mutable double  *rowsol_;
    00846
    00848   mutable double  *redcost_;
    00849
    00851   mutable double  *rowact_;
    00852
    00854   mutable CoinPackedMatrix *matrixByRow_;
    00855
    00857   mutable CoinPackedMatrix *matrixByCol_;
    00859
    00862
    00863   char            *coltype_;
    00864
    00866   int             coltypesize_;
    00867
    00869   mutable bool    probtypemip_;
    00870
    00872 };
    00873
    00874 //#############################################################################
    00880 void OsiCpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00881
    00882 #endif