Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

OsiCpxSolverInterface.hpp

00001 //  LAST EDIT: Fri Aug 31 13:54:15 2001 by Tobias Pfender (opt14!bzfpfend) 
00002 //-----------------------------------------------------------------------------
00003 // name:     OSI Interface for CPLEX
00004 // author:   Tobias Pfender
00005 //           Konrad-Zuse-Zentrum Berlin (Germany)
00006 //           email: pfender@zib.de
00007 // date:     09/25/2000
00008 // license:  this file may be freely distributed under the terms of CPL
00009 // comments: please scan this file for '???' and read the comments
00010 //-----------------------------------------------------------------------------
00011 // Copyright (C) 2000, Tobias Pfender, International Business Machines
00012 // Corporation and others.  All Rights Reserved.
00013 
00014 #ifndef OsiCpxSolverInterface_H
00015 #define OsiCpxSolverInterface_H
00016 
00017 #include <string>
00018 #include "cplex.h"
00019 #include "OsiSolverInterface.hpp"
00020 #include "CoinPackedMatrix.hpp"
00021 #include "CoinWarmStartBasis.hpp"
00022 
00028 class OsiCpxSolverInterface : public OsiSolverInterface {
00029   friend void OsiCpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00030   
00031 public:
00032   
00033   //---------------------------------------------------------------------------
00036 
00037   virtual void initialSolve();
00038   
00040   virtual void resolve();
00041   
00043   virtual void branchAndBound();
00045   
00046   //---------------------------------------------------------------------------
00062     // Set an integer parameter
00063     bool setIntParam(OsiIntParam key, int value);
00064     // Set an double parameter
00065     bool setDblParam(OsiDblParam key, double value);
00066     // Set a string parameter
00067     bool setStrParam(OsiStrParam key, const std::string & value);
00068     // Get an integer parameter
00069     bool getIntParam(OsiIntParam key, int& value) const;
00070     // Get an double parameter
00071     bool getDblParam(OsiDblParam key, double& value) const;
00072     // Get a string parameter
00073     bool getStrParam(OsiStrParam key, std::string& value) const;
00075 
00076   //---------------------------------------------------------------------------
00078 
00079 
00080     virtual bool isAbandoned() const;
00082     virtual bool isProvenOptimal() const;
00084     virtual bool isProvenPrimalInfeasible() const;
00086     virtual bool isProvenDualInfeasible() const;
00088     virtual bool isPrimalObjectiveLimitReached() const;
00090     virtual bool isDualObjectiveLimitReached() const;
00092     virtual bool isIterationLimitReached() const;
00094 
00095   //---------------------------------------------------------------------------
00098 
00105   inline CoinWarmStart *getEmptyWarmStart () const
00106   { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; }
00107 
00109     virtual CoinWarmStart* getWarmStart() const;
00112     virtual bool setWarmStart(const CoinWarmStart* warmstart);
00114 
00115   //---------------------------------------------------------------------------
00122 
00123     virtual void markHotStart();
00125     virtual void solveFromHotStart();
00127     virtual void unmarkHotStart();
00129 
00130   //---------------------------------------------------------------------------
00145 
00146       virtual int getNumCols() const;
00147   
00149       virtual int getNumRows() const;
00150   
00152       virtual int getNumElements() const;
00153   
00155       virtual const double * getColLower() const;
00156   
00158       virtual const double * getColUpper() const;
00159   
00169       virtual const char * getRowSense() const;
00170   
00179       virtual const double * getRightHandSide() const;
00180   
00189       virtual const double * getRowRange() const;
00190   
00192       virtual const double * getRowLower() const;
00193   
00195       virtual const double * getRowUpper() const;
00196   
00198       virtual const double * getObjCoefficients() const;
00199   
00201       virtual double getObjSense() const;
00202 
00204       virtual bool isContinuous(int colNumber) const;
00205 
00206 #if 0
00207 
00208       virtual bool isBinary(int columnNumber) const;
00209   
00214       virtual bool isInteger(int columnNumber) const;
00215   
00217       virtual bool isIntegerNonBinary(int columnNumber) const;
00218   
00220       virtual bool isFreeBinary(int columnNumber) const;
00221 #endif
00222   
00224       virtual const CoinPackedMatrix * getMatrixByRow() const;
00225   
00227       virtual const CoinPackedMatrix * getMatrixByCol() const;
00228   
00230       virtual double getInfinity() const;
00232     
00235 
00236       virtual const double * getColSolution() const;
00237   
00239       virtual const double * getRowPrice() const;
00240   
00242       virtual const double * getReducedCost() const;
00243   
00246       virtual const double * getRowActivity() const;
00247   
00249       virtual double getObjValue() const;
00250   
00253       virtual int getIterationCount() const;
00254   
00266       virtual std::vector<double*> getDualRays(int maxNumRays) const;
00278       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
00279   
00280 #if 0
00281 
00283       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
00284         const;
00285 #endif
00286 
00287 
00288   
00289   //---------------------------------------------------------------------------
00290 
00293     //-------------------------------------------------------------------------
00297       virtual void setObjCoeff( int elementIndex, double elementValue );
00298 
00300       virtual void setObjCoeffSet(const int* indexFirst,
00301                                   const int* indexLast,
00302                                   const double* coeffList);
00303 
00306       virtual void setColLower( int elementIndex, double elementValue );
00307       
00310       virtual void setColUpper( int elementIndex, double elementValue );
00311       
00315       virtual void setColBounds( int elementIndex,
00316                                  double lower, double upper );
00317     
00325       virtual void setColSetBounds(const int* indexFirst,
00326                                    const int* indexLast,
00327                                    const double* boundList);
00328       
00331       virtual void setRowLower( int elementIndex, double elementValue );
00332       
00335       virtual void setRowUpper( int elementIndex, double elementValue );
00336     
00340       virtual void setRowBounds( int elementIndex,
00341                                  double lower, double upper );
00342     
00344       virtual void setRowType(int index, char sense, double rightHandSide,
00345                               double range);
00346     
00354       virtual void setRowSetBounds(const int* indexFirst,
00355                                    const int* indexLast,
00356                                    const double* boundList);
00357     
00367       virtual void setRowSetTypes(const int* indexFirst,
00368                                   const int* indexLast,
00369                                   const char* senseList,
00370                                   const double* rhsList,
00371                                   const double* rangeList);
00373     
00374     //-------------------------------------------------------------------------
00378       virtual void setContinuous(int index);
00380       virtual void setInteger(int index);
00383       virtual void setContinuous(const int* indices, int len);
00386       virtual void setInteger(const int* indices, int len);
00388     
00389     //-------------------------------------------------------------------------
00391     virtual void setObjSense(double s);
00392     
00403     virtual void setColSolution(const double * colsol);
00404     
00415     virtual void setRowPrice(const double * rowprice);
00416     
00417     //-------------------------------------------------------------------------
00423       virtual void addCol(const CoinPackedVectorBase& vec,
00424                           const double collb, const double colub,   
00425                           const double obj);
00427       virtual void addCols(const int numcols,
00428                            const CoinPackedVectorBase * const * cols,
00429                            const double* collb, const double* colub,   
00430                            const double* obj);
00432       virtual void deleteCols(const int num, const int * colIndices);
00433     
00435       virtual void addRow(const CoinPackedVectorBase& vec,
00436                           const double rowlb, const double rowub);
00438       virtual void addRow(const CoinPackedVectorBase& vec,
00439                           const char rowsen, const double rowrhs,   
00440                           const double rowrng);
00442       virtual void addRows(const int numrows,
00443                            const CoinPackedVectorBase * const * rows,
00444                            const double* rowlb, const double* rowub);
00446       virtual void addRows(const int numrows,
00447                            const CoinPackedVectorBase * const * rows,
00448                            const char* rowsen, const double* rowrhs,   
00449                            const double* rowrng);
00451       virtual void deleteRows(const int num, const int * rowIndices);
00452     
00453 #if 0
00454   // ??? implemented in OsiSolverInterface
00455       //-----------------------------------------------------------------------
00477       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
00478                                             double effectivenessLb = 0.0);
00479 #endif
00480 
00481 
00482 
00483   //---------------------------------------------------------------------------
00484 
00498     virtual void loadProblem(const CoinPackedMatrix& matrix,
00499                              const double* collb, const double* colub,   
00500                              const double* obj,
00501                              const double* rowlb, const double* rowub);
00502                             
00510     virtual void assignProblem(CoinPackedMatrix*& matrix,
00511                                double*& collb, double*& colub, double*& obj,
00512                                double*& rowlb, double*& rowub);
00513 
00526     virtual void loadProblem(const CoinPackedMatrix& matrix,
00527                              const double* collb, const double* colub,
00528                              const double* obj,
00529                              const char* rowsen, const double* rowrhs,   
00530                              const double* rowrng);
00531 
00539     virtual void assignProblem(CoinPackedMatrix*& matrix,
00540                                double*& collb, double*& colub, double*& obj,
00541                                char*& rowsen, double*& rowrhs,
00542                                double*& rowrng);
00543 
00546     virtual void loadProblem(const int numcols, const int numrows,
00547                              const int* start, const int* index,
00548                              const double* value,
00549                              const double* collb, const double* colub,   
00550                              const double* obj,
00551                              const double* rowlb, const double* rowub);
00552 
00555     virtual void loadProblem(const int numcols, const int numrows,
00556                              const int* start, const int* index,
00557                              const double* value,
00558                              const double* collb, const double* colub,   
00559                              const double* obj,
00560                              const char* rowsen, const double* rowrhs,   
00561                              const double* rowrng);
00562 
00564     virtual int readMps(const char *filename,
00565                          const char *extension = "mps");
00566 
00571     virtual void writeMps(const char *filename,
00572                           const char *extension = "mps",
00573                           double objSense=0.0) const;
00575 
00576   //---------------------------------------------------------------------------
00577 
00583   enum keepCachedFlag
00584   {
00586     KEEPCACHED_NONE    = 0,
00588     KEEPCACHED_COLUMN  = 1,
00590     KEEPCACHED_ROW     = 2,
00592     KEEPCACHED_MATRIX  = 4,
00594     KEEPCACHED_RESULTS = 8,
00596     KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
00598     KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
00600     FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & !KEEPCACHED_COLUMN,
00602     FREECACHED_ROW     = KEEPCACHED_PROBLEM & !KEEPCACHED_ROW,
00604     FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & !KEEPCACHED_MATRIX,
00606     FREECACHED_RESULTS = KEEPCACHED_ALL & !KEEPCACHED_RESULTS
00607   };
00608   CPXLPptr getLpPtr( int keepCached = KEEPCACHED_NONE );
00609   
00611 
00612   CPXENVptr getEnvironmentPtr();
00614 
00616   const char* getCtype() const;
00617   
00627   static void incrementInstanceCounter(); 
00628   
00637   static void decrementInstanceCounter();
00638   
00640   static unsigned int getNumInstances();
00642 
00643   
00646 
00647   OsiCpxSolverInterface(); 
00648   
00650   virtual OsiSolverInterface * clone(bool copyData = true) const;
00651   
00653   OsiCpxSolverInterface( const OsiCpxSolverInterface& );
00654   
00656   OsiCpxSolverInterface& operator=( const OsiCpxSolverInterface& rhs );
00657   
00659   virtual ~OsiCpxSolverInterface();
00660 
00662   virtual void reset();
00664   
00665 protected:
00666   
00669 
00670   virtual void applyRowCut( const OsiRowCut & rc );
00671   
00675   virtual void applyColCut( const OsiColCut & cc );
00677   
00678 private:
00681 
00682   void switchToLP();
00683 
00685   void switchToMIP();
00686 
00688   void resizeColType( int minsize );
00689 
00691   void freeColType();
00693 
00696 
00697   static CPXENVptr env_;
00699   static int cpxVersionMajor_;
00700   static int cpxVersionMinor_;
00701   static int cpxVersionMinorMinor_;
00703   static unsigned int numInstances_;
00705   
00706   
00709   
00711   CPXLPptr getMutableLpPtr() const;
00712   
00714   void gutsOfCopy( const OsiCpxSolverInterface & source );
00715   
00717   void gutsOfConstructor();
00718   
00720   void gutsOfDestructor();
00721 
00723   void freeCachedColRim();
00724 
00726   void freeCachedRowRim();
00727 
00729   void freeCachedResults();
00730   
00732   void freeCachedMatrix();
00733 
00735   void freeCachedData( int keepCached = KEEPCACHED_NONE );
00736 
00738   void freeAllMemory();
00739 
00741   void printBounds(); 
00743   
00744   
00747 
00748   mutable CPXLPptr lp_;
00749 
00751   int *hotStartCStat_;
00752   int hotStartCStatSize_;
00753   int *hotStartRStat_;
00754   int hotStartRStatSize_;
00755   int hotStartMaxIteration_;
00756 
00759 
00760   mutable double  *obj_;
00761   
00763   mutable double  *collower_;
00764   
00766   mutable double  *colupper_;
00767   
00769   mutable char    *rowsense_;
00770   
00772   mutable double  *rhs_;
00773   
00775   mutable double  *rowrange_;
00776   
00778   mutable double  *rowlower_;
00779   
00781   mutable double  *rowupper_;
00782   
00784   mutable double  *colsol_;
00785   
00787   mutable double  *rowsol_;
00788 
00790   mutable double  *redcost_;
00791 
00793   mutable double  *rowact_;
00794 
00796   mutable CoinPackedMatrix *matrixByRow_;  
00797   
00799   mutable CoinPackedMatrix *matrixByCol_;  
00801 
00804 
00805   char            *coltype_;
00806 
00808   int             coltypesize_;
00809   
00811   mutable bool    probtypemip_;
00812 
00814 };
00815 
00816 //#############################################################################
00822 void OsiCpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00823 
00824 #endif

Generated on Wed Dec 3 14:35:30 2003 for Osi by doxygen 1.3.5