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

- File List
- File Members

# /home/coin/SVN-release/Cgl-0.53.1/Osi/src/OsiClp/OsiClpSolverInterface.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2000, International Business Machines
    00002 // Corporation and others.  All Rights Reserved.
    00003
    00004 #ifndef OsiClpSolverInterface_H
    00005 #define OsiClpSolverInterface_H
    00006
    00007 #include <string>
    00008 #include <cfloat>
    00009 #include <map>
    00010
    00011 #include "ClpSimplex.hpp"
    00012 #include "CoinPackedMatrix.hpp"
    00013 #include "OsiSolverInterface.hpp"
    00014 #include "CoinWarmStartBasis.hpp"
    00015 #include "ClpEventHandler.hpp"
    00016 #include "ClpNode.hpp"
    00017 #include "CoinIndexedVector.hpp"
    00018
    00019 class OsiRowCut;
    00020 class OsiClpUserSolver;
    00021 class CoinSet;
    00022 #ifndef COIN_DBL_MAX
    00023 static const double OsiClpInfinity = DBL_MAX;
    00024 #else
    00025 static const double OsiClpInfinity = COIN_DBL_MAX;
    00026 #endif
    00027
    00028 //#############################################################################
    00029
    00036 class OsiClpSolverInterface :
    00037   virtual public OsiSolverInterface {
    00038   friend int OsiClpSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00039
    00040 public:
    00041   //---------------------------------------------------------------------------
    00044
    00045   virtual void initialSolve();
    00046
    00048   virtual void resolve();
    00049
    00051   virtual void branchAndBound();
    00052
    00054
    00056
    00057
    00063   virtual void enableSimplexInterface(bool doingPrimal);
    00064
    00066   virtual void disableSimplexInterface();
    00070   virtual int canDoSimplexInterface() const;
    00077   virtual void enableFactorization() const;
    00079   virtual void disableFactorization() const;
    00080
    00096   void setupForRepeatedUse(int senseOfAdventure=0, int printOut=0);
    00098   virtual void synchronizeModel();
    00099   // Sleazy methods to fool const requirements (no less safe as modelPtr_ mutable)
    00100   void setSpecialOptionsMutable(unsigned int value) const;
    00101
    00106   virtual bool basisIsAvailable() const;
    00107
    00123   virtual void getBasisStatus(int* cstat, int* rstat) const;
    00124
    00135   virtual int setBasisStatus(const int* cstat, const int* rstat);
    00136
    00144   virtual int pivot(int colIn, int colOut, int outStatus);
    00145
    00157   virtual int primalPivotResult(int colIn, int sign,
    00158                                 int& colOut, int& outStatus,
    00159                                 double& t, CoinPackedVector* dx);
    00160
    00167   virtual int dualPivotResult(int& colIn, int& sign,
    00168                               int colOut, int outStatus,
    00169                               double& t, CoinPackedVector* dx);
    00170
    00172   virtual void getReducedGradient(double* columnReducedCosts,
    00173                                   double * duals,
    00174                                   const double * c);
    00175
    00178   virtual void setObjectiveAndRefresh(double* c);
    00179
    00181   virtual void getBInvARow(int row, double* z, double * slack=NULL) const;
    00182
    00187   virtual void getBInvARow(int row, CoinIndexedVector * z, CoinIndexedVector * slack=NULL,
    00188                            bool keepScaled=false) const;
    00189
    00191   virtual void getBInvRow(int row, double* z) const;
    00192
    00194   virtual void getBInvACol(int col, double* vec) const ;
    00195
    00197   virtual void getBInvACol(int col, CoinIndexedVector * vec) const ;
    00198
    00203   virtual void getBInvACol(CoinIndexedVector * vec) const ;
    00204
    00206   virtual void getBInvCol(int col, double* vec) const ;
    00207
    00212   virtual void getBasics(int* index) const;
    00213
    00215   //---------------------------------------------------------------------------
    00231   // Set an integer parameter
    00232   bool setIntParam(OsiIntParam key, int value);
    00233   // Set an double parameter
    00234   bool setDblParam(OsiDblParam key, double value);
    00235   // Set a string parameter
    00236   bool setStrParam(OsiStrParam key, const std::string & value);
    00237   // Get an integer parameter
    00238   bool getIntParam(OsiIntParam key, int& value) const;
    00239   // Get an double parameter
    00240   bool getDblParam(OsiDblParam key, double& value) const;
    00241   // Get a string parameter
    00242   bool getStrParam(OsiStrParam key, std::string& value) const;
    00243   // Set a hint parameter - overrides OsiSolverInterface
    00244   virtual bool setHintParam(OsiHintParam key, bool yesNo=true,
    00245                             OsiHintStrength strength=OsiHintTry,
    00246                             void * otherInformation=NULL);
    00248
    00249   //---------------------------------------------------------------------------
    00251
    00252
    00253   virtual bool isAbandoned() const;
    00255   virtual bool isProvenOptimal() const;
    00257   virtual bool isProvenPrimalInfeasible() const;
    00259   virtual bool isProvenDualInfeasible() const;
    00261   virtual bool isPrimalObjectiveLimitReached() const;
    00263   virtual bool isDualObjectiveLimitReached() const;
    00265   virtual bool isIterationLimitReached() const;
    00267
    00268   //---------------------------------------------------------------------------
    00271
    00279   virtual CoinWarmStart *getEmptyWarmStart () const;
    00280
    00282   virtual CoinWarmStart* getWarmStart() const;
    00284   inline CoinWarmStartBasis* getPointerToWarmStart()
    00285   { return &basis_;}
    00288   virtual bool setWarmStart(const CoinWarmStart* warmstart);
    00298   virtual CoinWarmStart* getPointerToWarmStart(bool & mustDelete) ;
    00299
    00301
    00302   //---------------------------------------------------------------------------
    00309
    00310   virtual void markHotStart();
    00312   virtual void solveFromHotStart();
    00314   virtual void unmarkHotStart();
    00323   int startFastDual(int options);
    00325   void stopFastDual();
    00327   void setStuff(double tolerance,double increment);
    00329
    00330   //---------------------------------------------------------------------------
    00345
    00346   virtual int getNumCols() const {
    00347     return modelPtr_->numberColumns(); }
    00348
    00350   virtual int getNumRows() const {
    00351     return modelPtr_->numberRows(); }
    00352
    00354   virtual int getNumElements() const {
    00355     int retVal = 0;
    00356     const CoinPackedMatrix * matrix =modelPtr_->matrix();
    00357     if ( matrix != NULL ) retVal=matrix->getNumElements();
    00358     return retVal; }
    00359
    00362     virtual std::string getRowName(int rowIndex,
    00363                                    unsigned maxLen = std::string::npos) const;
    00364
    00367     virtual std::string getColName(int colIndex,
    00368                                    unsigned maxLen = std::string::npos) const;
    00369
    00370
    00372   virtual const double * getColLower() const { return modelPtr_->columnLower(); }
    00373
    00375   virtual const double * getColUpper() const { return modelPtr_->columnUpper(); }
    00376
    00386   virtual const char * getRowSense() const;
    00387
    00396   virtual const double * getRightHandSide() const ;
    00397
    00406   virtual const double * getRowRange() const ;
    00407
    00409   virtual const double * getRowLower() const { return modelPtr_->rowLower(); }
    00410
    00412   virtual const double * getRowUpper() const { return modelPtr_->rowUpper(); }
    00413
    00415   virtual const double * getObjCoefficients() const
    00416   { return modelPtr_->objective(); }
    00417
    00419   virtual double getObjSense() const
    00420   { return modelPtr_->optimizationDirection(); }
    00421
    00423   virtual bool isContinuous(int colNumber) const;
    00425   virtual bool isBinary(int colIndex) const;
    00426
    00431   virtual bool isInteger(int colIndex) const;
    00432
    00434   virtual bool isIntegerNonBinary(int colIndex) const;
    00435
    00437   virtual bool isFreeBinary(int colIndex) const;
    00443   virtual const char * getColType(bool refresh=false) const;
    00444
    00445
    00447   virtual const CoinPackedMatrix * getMatrixByRow() const;
    00448
    00450   virtual const CoinPackedMatrix * getMatrixByCol() const;
    00451
    00453   virtual CoinPackedMatrix * getMutableMatrixByCol() const;
    00454
    00456   virtual double getInfinity() const { return OsiClpInfinity; }
    00458
    00461
    00462   virtual const double * getColSolution() const;
    00463
    00465   virtual const double * getRowPrice() const;
    00466
    00468   virtual const double * getReducedCost() const;
    00469
    00472   virtual const double * getRowActivity() const;
    00473
    00475   virtual double getObjValue() const;
    00476
    00479   virtual int getIterationCount() const
    00480   { return modelPtr_->numberIterations(); }
    00481
    00493   virtual std::vector<double*> getDualRays(int maxNumRays) const;
    00505   virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
    00506
    00508
    00509
    00510   //---------------------------------------------------------------------------
    00511
    00514   //-------------------------------------------------------------------------
    00518   virtual void setObjCoeff( int elementIndex, double elementValue );
    00519
    00522   virtual void setColLower( int elementIndex, double elementValue );
    00523
    00526   virtual void setColUpper( int elementIndex, double elementValue );
    00527
    00529   virtual void setColBounds( int elementIndex,
    00530                              double lower, double upper );
    00531
    00540   virtual void setColSetBounds(const int* indexFirst,
    00541                                const int* indexLast,
    00542                                const double* boundList);
    00543
    00546   virtual void setRowLower( int elementIndex, double elementValue );
    00547
    00550   virtual void setRowUpper( int elementIndex, double elementValue ) ;
    00551
    00553   virtual void setRowBounds( int elementIndex,
    00554                              double lower, double upper ) ;
    00555
    00557   virtual void setRowType(int index, char sense, double rightHandSide,
    00558                           double range);
    00559
    00568   virtual void setRowSetBounds(const int* indexFirst,
    00569                                const int* indexLast,
    00570                                const double* boundList);
    00571
    00582   virtual void setRowSetTypes(const int* indexFirst,
    00583                               const int* indexLast,
    00584                               const char* senseList,
    00585                               const double* rhsList,
    00586                               const double* rangeList);
    00591     virtual void setObjective(const double * array);
    00592
    00597     virtual void setColLower(const double * array);
    00598
    00603     virtual void setColUpper(const double * array);
    00604
    00605 //    using OsiSolverInterface::setRowName ;
    00607 //    virtual void setRowName(int rowIndex, std::string & name) ;
    00608     virtual void setRowName(int rowIndex, std::string  name) ;
    00609
    00610 //    using OsiSolverInterface::setColName ;
    00612 //    virtual void setColName(int colIndex, std::string & name) ;
    00613     virtual void setColName(int colIndex, std::string  name) ;
    00614
    00616
    00617   //-------------------------------------------------------------------------
    00621   virtual void setContinuous(int index);
    00623   virtual void setInteger(int index);
    00626   virtual void setContinuous(const int* indices, int len);
    00629   virtual void setInteger(const int* indices, int len);
    00631   inline int numberSOS() const
    00632   { return numberSOS_;}
    00634   inline const CoinSet * setInfo() const
    00635   { return setInfo_;}
    00645   virtual int findIntegersAndSOS(bool justCount);
    00647
    00648   //-------------------------------------------------------------------------
    00650   virtual void setObjSense(double s )
    00651   { modelPtr_->setOptimizationDirection( s < 0 ? -1 : 1); }
    00652
    00663   virtual void setColSolution(const double * colsol);
    00664
    00675   virtual void setRowPrice(const double * rowprice);
    00676
    00677   //-------------------------------------------------------------------------
    00682
    00683   using OsiSolverInterface::addCol ;
    00685   virtual void addCol(const CoinPackedVectorBase& vec,
    00686                       const double collb, const double colub,
    00687                       const double obj);
    00689   virtual void addCol(int numberElements, const int * rows, const double * elements,
    00690                       const double collb, const double colub,
    00691                       const double obj) ;
    00693   virtual void addCols(const int numcols,
    00694                        const CoinPackedVectorBase * const * cols,
    00695                        const double* collb, const double* colub,
    00696                        const double* obj);
    00698   virtual void addCols(const int numcols,
    00699                        const int * columnStarts, const int * rows, const double * elements,
    00700                        const double* collb, const double* colub,
    00701                        const double* obj);
    00703   virtual void deleteCols(const int num, const int * colIndices);
    00704
    00705   using OsiSolverInterface::addRow ;
    00707   virtual void addRow(const CoinPackedVectorBase& vec,
    00708                       const double rowlb, const double rowub);
    00710   virtual void addRow(const CoinPackedVectorBase& vec,
    00711                       const char rowsen, const double rowrhs,
    00712                       const double rowrng);
    00714   virtual void addRow(int numberElements, const int * columns, const double * element,
    00715                       const double rowlb, const double rowub) ;
    00717   virtual void addRows(const int numrows,
    00718                        const CoinPackedVectorBase * const * rows,
    00719                        const double* rowlb, const double* rowub);
    00721   virtual void addRows(const int numrows,
    00722                        const CoinPackedVectorBase * const * rows,
    00723                        const char* rowsen, const double* rowrhs,
    00724                        const double* rowrng);
    00725
    00727   virtual void addRows(const int numrows,
    00728                        const int * rowStarts, const int * columns, const double * element,
    00729                        const double* rowlb, const double* rowub);
    00731   void modifyCoefficient(int row, int column, double newElement,
    00732                         bool keepZero=false)
    00733         {modelPtr_->modifyCoefficient(row,column,newElement, keepZero);}
    00734
    00736   virtual void deleteRows(const int num, const int * rowIndices);
    00739   virtual void saveBaseModel() ;
    00743   virtual void restoreBaseModel(int numberRows);
    00744
    00745   //-----------------------------------------------------------------------
    00749   virtual void applyRowCuts(int numberCuts, const OsiRowCut * cuts);
    00754   virtual void applyRowCuts(int numberCuts, const OsiRowCut ** cuts);
    00756
    00757
    00758   //---------------------------------------------------------------------------
    00759
    00760 public:
    00761
    00775   virtual void loadProblem(const CoinPackedMatrix& matrix,
    00776                            const double* collb, const double* colub,
    00777                            const double* obj,
    00778                            const double* rowlb, const double* rowub);
    00779
    00787   virtual void assignProblem(CoinPackedMatrix*& matrix,
    00788                              double*& collb, double*& colub, double*& obj,
    00789                              double*& rowlb, double*& rowub);
    00790
    00803   virtual void loadProblem(const CoinPackedMatrix& matrix,
    00804                            const double* collb, const double* colub,
    00805                            const double* obj,
    00806                            const char* rowsen, const double* rowrhs,
    00807                            const double* rowrng);
    00808
    00816   virtual void assignProblem(CoinPackedMatrix*& matrix,
    00817                              double*& collb, double*& colub, double*& obj,
    00818                              char*& rowsen, double*& rowrhs,
    00819                              double*& rowrng);
    00820
    00823   virtual void loadProblem(const int numcols, const int numrows,
    00824                            const CoinBigIndex * start, const int* index,
    00825                            const double* value,
    00826                            const double* collb, const double* colub,
    00827                            const double* obj,
    00828                            const double* rowlb, const double* rowub);
    00829
    00832   virtual void loadProblem(const int numcols, const int numrows,
    00833                            const CoinBigIndex * start, const int* index,
    00834                            const double* value,
    00835                            const double* collb, const double* colub,
    00836                            const double* obj,
    00837                            const char* rowsen, const double* rowrhs,
    00838                            const double* rowrng);
    00840   virtual int loadFromCoinModel (  CoinModel & modelObject, bool keepSolution=false);
    00841
    00842   using OsiSolverInterface::readMps ;
    00845   virtual int readMps(const char *filename,
    00846                       const char *extension = "mps") ;
    00849   int readMps(const char *filename,bool keepNames,bool allowErrors);
    00850
    00855   virtual void writeMps(const char *filename,
    00856                         const char *extension = "mps",
    00857                         double objSense=0.0) const;
    00866   virtual int writeMpsNative(const char *filename,
    00867                              const char ** rowNames, const char ** columnNames,
    00868                              int formatType=0,int numberAcross=2,
    00869                              double objSense=0.0) const ;
    00871   virtual int readLp(const char *filename, const double epsilon = 1e-5);
    00877   virtual void writeLp(const char *filename,
    00878                        const char *extension = "lp",
    00879                        double epsilon = 1e-5,
    00880                        int numberAcross = 10,
    00881                        int decimals = 5,
    00882                        double objSense = 0.0,
    00883                        bool useRowNames = true) const;
    00888   virtual void writeLp(FILE *fp,
    00889                double epsilon = 1e-5,
    00890                int numberAcross = 10,
    00891                int decimals = 5,
    00892                double objSense = 0.0,
    00893                bool useRowNames = true) const;
    00899   virtual void replaceMatrixOptional(const CoinPackedMatrix & matrix);
    00901   virtual void replaceMatrix(const CoinPackedMatrix & matrix) ;
    00903
    00914   virtual void passInMessageHandler(CoinMessageHandler * handler);
    00916   void newLanguage(CoinMessages::Language language);
    00917   void setLanguage(CoinMessages::Language language)
    00918   {newLanguage(language);}
    00920   void setLogLevel(int value);
    00922   void generateCpp( FILE * fp);
    00924   //---------------------------------------------------------------------------
    00925
    00928
    00929   ClpSimplex * getModelPtr() const ;
    00931   inline ClpSimplex * swapModelPtr(ClpSimplex * newModel)
    00932   { ClpSimplex * model = modelPtr_; modelPtr_=newModel;return model;}
    00934   inline unsigned int specialOptions() const
    00935   { return specialOptions_;}
    00936   void setSpecialOptions(unsigned int value);
    00938   inline int lastAlgorithm() const
    00939   { return lastAlgorithm_;}
    00941   inline int cleanupScaling() const
    00942   { return cleanupScaling_;}
    00955   inline void setCleanupScaling(int value)
    00956   { cleanupScaling_=value;}
    00959   inline double smallestElementInCut() const
    00960   { return smallestElementInCut_;}
    00963   inline void setSmallestElementInCut(double value)
    00964   { smallestElementInCut_=value;}
    00971   inline double smallestChangeInCut() const
    00972   { return smallestChangeInCut_;}
    00979   inline void setSmallestChangeInCut(double value)
    00980   { smallestChangeInCut_=value;}
    00982   inline void setSolveOptions(const ClpSolve & options)
    00983   { solveOptions_ = options;}
    00987   virtual int tightenBounds(int lightweight=0);
    00989
    00990   //---------------------------------------------------------------------------
    00991
    00994
    00995   OsiClpSolverInterface ();
    00996
    00998   virtual OsiSolverInterface * clone(bool copyData = true) const;
    00999
    01001   OsiClpSolverInterface (const OsiClpSolverInterface &);
    01002
    01004   OsiClpSolverInterface (ClpSimplex * rhs, bool reallyOwn=false);
    01005
    01007   void releaseClp();
    01008
    01010   OsiClpSolverInterface & operator=(const OsiClpSolverInterface& rhs);
    01011
    01013   virtual ~OsiClpSolverInterface ();
    01014
    01016   virtual void reset();
    01018
    01019   //---------------------------------------------------------------------------
    01020
    01021 protected:
    01023
    01024
    01025   virtual void applyRowCut(const OsiRowCut& rc);
    01026
    01028   virtual void applyColCut(const OsiColCut& cc);
    01030
    01031   //---------------------------------------------------------------------------
    01032
    01033 protected:
    01036
    01037   void gutsOfDestructor();
    01038
    01040   void freeCachedResults() const;
    01041
    01043   void freeCachedResults0() const;
    01044
    01046   void freeCachedResults1() const;
    01047
    01049   void extractSenseRhsRange() const;
    01050
    01052   void fillParamMaps();
    01061   CoinWarmStartBasis getBasis(ClpSimplex * model) const;
    01070   void setBasis( const CoinWarmStartBasis & basis, ClpSimplex * model);
    01072   void crunch();
    01074   void redoScaleFactors(int numberRows,const CoinBigIndex * starts,
    01075                         const int * indices, const double * elements);
    01076 public:
    01079   void setBasis( const CoinWarmStartBasis & basis);
    01081   inline void setBasis( )
    01082   { setBasis(basis_,modelPtr_);}
    01084   CoinWarmStartDiff * getBasisDiff(const unsigned char * statusArray) const ;
    01086   void deleteScaleFactors();
    01088   inline const double * upRange() const
    01089   { return rowActivity_;}
    01090   inline const double * downRange() const
    01091   { return columnActivity_;}
    01093   inline void passInRanges(int * array)
    01094   { whichRange_=array;}
    01096   void setSOSData(int numberSOS,const char * type,
    01097                   const int * start,const int * indices, const double * weights=NULL);
    01099   void computeLargestAway();
    01101   inline double largestAway() const
    01102   { return largestAway_;}
    01104   inline void setLargestAway(double value)
    01105   { largestAway_ = value;}
    01107   void lexSolve();
    01108 protected:
    01110
    01113
    01114   mutable ClpSimplex * modelPtr_;
    01116   double * linearObjective_;
    01119
    01120   mutable char    *rowsense_;
    01121
    01123   mutable double  *rhs_;
    01124
    01128   mutable double  *rowrange_;
    01129
    01132   mutable CoinWarmStartBasis* ws_;
    01135   mutable double * rowActivity_;
    01136   mutable double * columnActivity_;
    01138   ClpNodeStuff stuff_;
    01140   int numberSOS_;
    01142   CoinSet * setInfo_;
    01144   ClpSimplex * smallModel_;
    01146   ClpFactorization * factorization_;
    01149   double smallestElementInCut_;
    01153   double smallestChangeInCut_;
    01155   double largestAway_;
    01157   char * spareArrays_;
    01159   CoinWarmStartBasis basis_;
    01161   int itlimOrig_;
    01162
    01164   mutable int lastAlgorithm_;
    01165
    01167   bool notOwned_;
    01168
    01170   mutable CoinPackedMatrix *matrixByRow_;
    01171
    01173   char * integerInformation_;
    01174
    01179   int * whichRange_;
    01180
    01181   //std::map<OsiIntParam, ClpIntParam> intParamMap_;
    01182   //std::map<OsiDblParam, ClpDblParam> dblParamMap_;
    01183   //std::map<OsiStrParam, ClpStrParam> strParamMap_;
    01184
    01186   mutable ClpDataSave saveData_;
    01188   ClpSolve solveOptions_;
    01201   int cleanupScaling_;
    01221   mutable unsigned int specialOptions_;
    01223   ClpSimplex * baseModel_;
    01225   int lastNumberRows_;
    01227   ClpSimplex * continuousModel_;
    01229   CoinDoubleArrayWithLength rowScale_;
    01231   CoinDoubleArrayWithLength columnScale_;
    01233 };
    01234
    01235 class OsiClpDisasterHandler : public ClpDisasterHandler {
    01236 public:
    01240
    01241   virtual void intoSimplex();
    01243   virtual bool check() const ;
    01245   virtual void saveInfo();
    01247
    01248
    01253   OsiClpDisasterHandler(OsiClpSolverInterface * model = NULL);
    01255   virtual ~OsiClpDisasterHandler();
    01256   // Copy
    01257   OsiClpDisasterHandler(const OsiClpDisasterHandler&);
    01258   // Assignment
    01259   OsiClpDisasterHandler& operator=(const OsiClpDisasterHandler&);
    01261   virtual ClpDisasterHandler * clone() const;
    01262
    01264
    01269   void setOsiModel(OsiClpSolverInterface * model);
    01271   inline OsiClpSolverInterface * osiModel() const
    01272   { return osiModel_;}
    01274   inline void setWhereFrom(int value)
    01275   { whereFrom_=value;}
    01277   inline int whereFrom() const
    01278   { return whereFrom_;}
    01280   inline void setPhase(int value)
    01281   { phase_=value;}
    01283   inline int phase() const
    01284   { return phase_;}
    01286   inline bool inTrouble() const
    01287   { return inTrouble_;}
    01288
    01290
    01291
    01292 protected:
    01296
    01297   OsiClpSolverInterface * osiModel_;
    01305   int whereFrom_;
    01313   int phase_;
    01315   bool inTrouble_;
    01316
    01318 };
    01319
    01320 //#############################################################################
    01328 int
    01329 OsiClpSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    01330 #endif