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

- File List
- File Members

# /home/coin/SVN-release/Alps-1.2.1/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
    00269       virtual std::vector<double*> getDualRays(int maxNumRays,
    00270                                                bool fullRay = false) const;
    00282       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
    00283
    00284 #if 0
    00285
    00287       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
    00288         const;
    00289 #endif
    00290
    00291
    00292
    00293   //---------------------------------------------------------------------------
    00294
    00297     //-------------------------------------------------------------------------
    00301       virtual void setObjCoeff( int elementIndex, double elementValue );
    00302
    00304       virtual void setObjCoeffSet(const int* indexFirst,
    00305                                   const int* indexLast,
    00306                                   const double* coeffList);
    00307
    00308       using OsiSolverInterface::setColLower ;
    00311       virtual void setColLower( int elementIndex, double elementValue );
    00312
    00313       using OsiSolverInterface::setColUpper ;
    00316       virtual void setColUpper( int elementIndex, double elementValue );
    00317
    00321       virtual void setColBounds( int elementIndex,
    00322                                  double lower, double upper );
    00323
    00331       virtual void setColSetBounds(const int* indexFirst,
    00332                                    const int* indexLast,
    00333                                    const double* boundList);
    00334
    00337       virtual void setRowLower( int elementIndex, double elementValue );
    00338
    00341       virtual void setRowUpper( int elementIndex, double elementValue );
    00342
    00346       virtual void setRowBounds( int elementIndex,
    00347                                  double lower, double upper );
    00348
    00350       virtual void setRowType(int index, char sense, double rightHandSide,
    00351                               double range);
    00352
    00360       virtual void setRowSetBounds(const int* indexFirst,
    00361                                    const int* indexLast,
    00362                                    const double* boundList);
    00363
    00373       virtual void setRowSetTypes(const int* indexFirst,
    00374                                   const int* indexLast,
    00375                                   const char* senseList,
    00376                                   const double* rhsList,
    00377                                   const double* rangeList);
    00379
    00380     //-------------------------------------------------------------------------
    00384       virtual void setContinuous(int index);
    00386       virtual void setInteger(int index);
    00389       virtual void setContinuous(const int* indices, int len);
    00392       virtual void setInteger(const int* indices, int len);
    00394
    00395     //-------------------------------------------------------------------------
    00397     virtual void setObjSense(double s);
    00398
    00409     virtual void setColSolution(const double * colsol);
    00410
    00421     virtual void setRowPrice(const double * rowprice);
    00422
    00423     //-------------------------------------------------------------------------
    00428       using OsiSolverInterface::addCol ;
    00430       virtual void addCol(const CoinPackedVectorBase& vec,
    00431                           const double collb, const double colub,
    00432                           const double obj);
    00433
    00434       using OsiSolverInterface::addCols ;
    00436       virtual void addCols(const int numcols,
    00437                            const CoinPackedVectorBase * const * cols,
    00438                            const double* collb, const double* colub,
    00439                            const double* obj);
    00441       virtual void deleteCols(const int num, const int * colIndices);
    00442
    00443       using OsiSolverInterface::addRow ;
    00445       virtual void addRow(const CoinPackedVectorBase& vec,
    00446                           const double rowlb, const double rowub);
    00448       virtual void addRow(const CoinPackedVectorBase& vec,
    00449                           const char rowsen, const double rowrhs,
    00450                           const double rowrng);
    00451
    00452       using OsiSolverInterface::addRows ;
    00454       virtual void addRows(const int numrows,
    00455                            const CoinPackedVectorBase * const * rows,
    00456                            const double* rowlb, const double* rowub);
    00458       virtual void addRows(const int numrows,
    00459                            const CoinPackedVectorBase * const * rows,
    00460                            const char* rowsen, const double* rowrhs,
    00461                            const double* rowrng);
    00463       virtual void deleteRows(const int num, const int * rowIndices);
    00464
    00465 #if 0
    00466   // ??? implemented in OsiSolverInterface
    00467       //-----------------------------------------------------------------------
    00489       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
    00490                                             double effectivenessLb = 0.0);
    00491 #endif
    00492
    00493
    00494
    00495   //---------------------------------------------------------------------------
    00496
    00510     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00511                              const double* collb, const double* colub,
    00512                              const double* obj,
    00513                              const double* rowlb, const double* rowub);
    00514
    00522     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00523                                double*& collb, double*& colub, double*& obj,
    00524                                double*& rowlb, double*& rowub);
    00525
    00538     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00539                              const double* collb, const double* colub,
    00540                              const double* obj,
    00541                              const char* rowsen, const double* rowrhs,
    00542                              const double* rowrng);
    00543
    00551     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00552                                double*& collb, double*& colub, double*& obj,
    00553                                char*& rowsen, double*& rowrhs,
    00554                                double*& rowrng);
    00555
    00558     virtual void loadProblem(const int numcols, const int numrows,
    00559                              const int* start, const int* index,
    00560                              const double* value,
    00561                              const double* collb, const double* colub,
    00562                              const double* obj,
    00563                              const double* rowlb, const double* rowub);
    00564
    00567     virtual void loadProblem(const int numcols, const int numrows,
    00568                              const int* start, const int* index,
    00569                              const double* value,
    00570                              const double* collb, const double* colub,
    00571                              const double* obj,
    00572                              const char* rowsen, const double* rowrhs,
    00573                              const double* rowrng);
    00574
    00575     using OsiSolverInterface::readMps ;
    00577     virtual int readMps(const char *filename,
    00578                          const char *extension = "mps");
    00579
    00584     virtual void writeMps(const char *filename,
    00585                           const char *extension = "mps",
    00586                           double objSense=0.0) const;
    00587
    00589
    00597     void passInMessageHandler(CoinMessageHandler * handler);
    00599
    00600   //---------------------------------------------------------------------------
    00601
    00607   enum keepCachedFlag
    00608   {
    00610     KEEPCACHED_NONE    = 0,
    00612     KEEPCACHED_COLUMN  = 1,
    00614     KEEPCACHED_ROW     = 2,
    00616     KEEPCACHED_MATRIX  = 4,
    00618     KEEPCACHED_RESULTS = 8,
    00620     KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
    00622     KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
    00624     FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & ~KEEPCACHED_COLUMN,
    00626     FREECACHED_ROW     = KEEPCACHED_PROBLEM & ~KEEPCACHED_ROW,
    00628     FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & ~KEEPCACHED_MATRIX,
    00630     FREECACHED_RESULTS = KEEPCACHED_ALL & ~KEEPCACHED_RESULTS
    00631   };
    00632   CPXLPptr getLpPtr( int keepCached = KEEPCACHED_NONE );
    00633
    00635
    00636   CPXENVptr getEnvironmentPtr();
    00638
    00640   const char* getCtype() const;
    00641
    00644
    00645   OsiCpxSolverInterface();
    00646
    00648   virtual OsiSolverInterface * clone(bool copyData = true) const;
    00649
    00651   OsiCpxSolverInterface( const OsiCpxSolverInterface& );
    00652
    00654   OsiCpxSolverInterface& operator=( const OsiCpxSolverInterface& rhs );
    00655
    00657   virtual ~OsiCpxSolverInterface();
    00658
    00660   virtual void reset();
    00662
    00663 /***************************************************************************/
    00683
    00687   virtual int canDoSimplexInterface() const;
    00688
    00689   using OsiSolverInterface::enableSimplexInterface ;
    00693   virtual void enableSimplexInterface(int doingPrimal) {};
    00694
    00698   virtual void disableSimplexInterface() {};
    00699
    00703   virtual void enableFactorization() const {};
    00704
    00708   virtual void disableFactorization() const {};
    00709
    00711   virtual bool basisIsAvailable() const;
    00712
    00716    virtual void getBasisStatus(int* cstat, int* rstat) const;
    00717
    00719   virtual void getBInvARow(int row, double* z, double * slack=NULL) const;
    00720
    00722   virtual void getBInvRow(int row, double* z) const;
    00723
    00725   virtual void getBInvACol(int col, double* vec) const;
    00726
    00728   virtual void getBInvCol(int col, double* vec) const;
    00729
    00735   virtual void getBasics(int* index) const;
    00737   void switchToLP();
    00738
    00740   void switchToMIP();
    00741
    00743 /***************************************************************************/
    00744
    00745 protected:
    00746
    00749
    00750   virtual void applyRowCut( const OsiRowCut & rc );
    00751
    00755   virtual void applyColCut( const OsiColCut & cc );
    00757
    00758 private:
    00761
    00762   void resizeColType( int minsize );
    00763
    00765   void freeColType();
    00767
    00768
    00771
    00773   CPXLPptr getMutableLpPtr() const;
    00774
    00776   void gutsOfCopy( const OsiCpxSolverInterface & source );
    00777
    00779   void gutsOfConstructor();
    00780
    00782   void gutsOfDestructor();
    00783
    00785   void freeCachedColRim();
    00786
    00788   void freeCachedRowRim();
    00789
    00791   void freeCachedResults();
    00792
    00794   void freeCachedMatrix();
    00795
    00797   void freeCachedData( int keepCached = KEEPCACHED_NONE );
    00798
    00800   void freeAllMemory();
    00801
    00802
    00804   void printBounds();
    00806
    00807
    00810
    00811   mutable CPXENVptr env_;
    00813   mutable CPXLPptr lp_;
    00814
    00816   int *hotStartCStat_;
    00817   int hotStartCStatSize_;
    00818   int *hotStartRStat_;
    00819   int hotStartRStatSize_;
    00820   int hotStartMaxIteration_;
    00821
    00824
    00825   mutable double  *obj_;
    00826
    00828   mutable double  *collower_;
    00829
    00831   mutable double  *colupper_;
    00832
    00834   mutable char    *rowsense_;
    00835
    00837   mutable double  *rhs_;
    00838
    00840   mutable double  *rowrange_;
    00841
    00843   mutable double  *rowlower_;
    00844
    00846   mutable double  *rowupper_;
    00847
    00849   mutable double  *colsol_;
    00850
    00852   mutable double  *rowsol_;
    00853
    00855   mutable double  *redcost_;
    00856
    00858   mutable double  *rowact_;
    00859
    00861   mutable CoinPackedMatrix *matrixByRow_;
    00862
    00864   mutable CoinPackedMatrix *matrixByCol_;
    00866
    00869
    00870   char            *coltype_;
    00871
    00873   int             coltypesize_;
    00874
    00876   mutable bool    probtypemip_;
    00877
    00879 };
    00880
    00881 //#############################################################################
    00887 void OsiCpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00888
    00889 #endif