/home/coin/SVN-release/Cbc-2.5.0/Osi/src/OsiSpx/OsiSpxSolverInterface.hpp

Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 // name:     OSI Interface for SoPlex >= 1.4.2c
00003 // authors:  Tobias Pfender
00004 //           Ambros Gleixner
00005 //           Wei Huang
00006 //           Konrad-Zuse-Zentrum Berlin (Germany)
00007 //           email: pfender@zib.de
00008 // date:     01/16/2002
00009 // license:  this file may be freely distributed under the terms of the CPL
00010 //-----------------------------------------------------------------------------
00011 // Copyright (C) 2002, Tobias Pfender, International Business Machines
00012 // Corporation and others.  All Rights Reserved.
00013 // Last edit: $Id: OsiSpxSolverInterface.hpp 1528 2010-06-13 18:13:22Z stefan $
00014 
00015 #ifndef OsiSpxSolverInterface_H
00016 #define OsiSpxSolverInterface_H
00017 
00018 #include <string>
00019 #include "soplex.h"
00020 #include "OsiSolverInterface.hpp"
00021 #include "CoinWarmStartBasis.hpp"
00022 
00028 class OsiSpxSolverInterface : virtual public OsiSolverInterface, public soplex::SoPlex {
00029   friend void OsiSpxSolverInterfaceUnitTest(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     // 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 
00097     inline CoinWarmStart *getEmptyWarmStart () const
00098     { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; }
00100     virtual CoinWarmStart* getWarmStart() const;
00103     virtual bool setWarmStart(const CoinWarmStart* warmstart);
00105 
00106   //---------------------------------------------------------------------------
00113 
00114     virtual void markHotStart();
00116     virtual void solveFromHotStart();
00118     virtual void unmarkHotStart();
00120 
00121   //---------------------------------------------------------------------------
00136 
00137       virtual int getNumCols() const;
00138   
00140       virtual int getNumRows() const;
00141   
00143       virtual int getNumElements() const;
00144   
00146       virtual const double * getColLower() const;
00147   
00149       virtual const double * getColUpper() const;
00150   
00160       virtual const char * getRowSense() const;
00161   
00170       virtual const double * getRightHandSide() const;
00171   
00180       virtual const double * getRowRange() const;
00181   
00183       virtual const double * getRowLower() const;
00184   
00186       virtual const double * getRowUpper() const;
00187   
00189       virtual const double * getObjCoefficients() const;
00190   
00192       virtual double getObjSense() const;
00193 
00195       virtual bool isContinuous(int colNumber) const;
00196 
00197 #if 0
00199       virtual bool isBinary(int columnNumber) const;
00200   
00205       virtual bool isInteger(int columnNumber) const;
00206   
00208       virtual bool isIntegerNonBinary(int columnNumber) const;
00209   
00211       virtual bool isFreeBinary(int columnNumber) const;
00212 #endif
00213   
00215       virtual const CoinPackedMatrix * getMatrixByRow() const;
00216   
00218       virtual const CoinPackedMatrix * getMatrixByCol() const;
00219   
00221       virtual double getInfinity() const;
00223     
00226 
00227       virtual const double * getColSolution() const;
00228   
00230       virtual const double * getRowPrice() const;
00231   
00233       virtual const double * getReducedCost() const;
00234   
00237       virtual const double * getRowActivity() const;
00238   
00240       virtual double getObjValue() const;
00241   
00244       virtual int getIterationCount() const;
00245   
00257       virtual std::vector<double*> getDualRays(int maxNumRays) const;
00269       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
00270   
00271 #if 0
00272 
00274       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
00275         const;
00276 #endif
00277 
00278 
00279   
00280   //---------------------------------------------------------------------------
00281 
00284     //-------------------------------------------------------------------------
00288       virtual void setObjCoeff( int elementIndex, double elementValue );
00289 
00292       virtual void setColLower( int elementIndex, double elementValue );
00293       
00296       virtual void setColUpper( int elementIndex, double elementValue );
00297       
00301       virtual void setColBounds( int elementIndex,
00302                                  double lower, double upper );
00303     
00304 #if 0 // we are using the default implementation of OsiSolverInterface
00305 
00313       virtual void setColSetBounds(const int* indexFirst,
00314                                    const int* indexLast,
00315                                    const double* boundList);
00316 #endif
00317       
00320       virtual void setRowLower( int elementIndex, double elementValue );
00321       
00324       virtual void setRowUpper( int elementIndex, double elementValue );
00325     
00329       virtual void setRowBounds( int elementIndex,
00330                                  double lower, double upper );
00331     
00333       virtual void setRowType(int index, char sense, double rightHandSide,
00334                               double range);
00335     
00336 #if 0 // we are using the default implementation of OsiSolverInterface
00337 
00344       virtual void setRowSetBounds(const int* indexFirst,
00345                                    const int* indexLast,
00346                                    const double* boundList);
00347 
00357       virtual void setRowSetTypes(const int* indexFirst,
00358                                   const int* indexLast,
00359                                   const char* senseList,
00360                                   const double* rhsList,
00361                                   const double* rangeList);
00362 #endif
00363 
00364     
00365     //-------------------------------------------------------------------------
00369       virtual void setContinuous(int index);
00371       virtual void setInteger(int index);
00372 #if 0 // we are using the default implementation of OsiSolverInterface
00373 
00375       virtual void setContinuous(const int* indices, int len);
00378       virtual void setInteger(const int* indices, int len);
00379 #endif
00380 
00381     
00382     //-------------------------------------------------------------------------
00384     virtual void setObjSense(double s);
00385     
00396     virtual void setColSolution(const double * colsol);
00397     
00408     virtual void setRowPrice(const double * rowprice);
00409     
00410     //-------------------------------------------------------------------------
00416       virtual void addCol(const CoinPackedVectorBase& vec,
00417                           const double collb, const double colub,   
00418                           const double obj);
00419 
00420 #if 0 // we are using the default implementation of OsiSolverInterface
00421 
00422       virtual void addCols(const int numcols,
00423                            const CoinPackedVectorBase * const * cols,
00424                            const double* collb, const double* colub,   
00425                            const double* obj);
00426 #endif
00427 
00429       virtual void deleteCols(const int num, const int * colIndices);
00430     
00432       virtual void addRow(const CoinPackedVectorBase& vec,
00433                           const double rowlb, const double rowub);
00435       virtual void addRow(const CoinPackedVectorBase& vec,
00436                           const char rowsen, const double rowrhs,   
00437                           const double rowrng);
00438 
00439 #if 0 // we are using the default implementation of OsiSolverInterface
00440 
00441       virtual void addRows(const int numrows,
00442                            const CoinPackedVectorBase * const * rows,
00443                            const double* rowlb, const double* rowub);
00445       virtual void addRows(const int numrows,
00446                            const CoinPackedVectorBase * const * rows,
00447                            const char* rowsen, const double* rowrhs,   
00448                            const double* rowrng);
00449 #endif
00450 
00452       virtual void deleteRows(const int num, const int * rowIndices);
00453     
00454 #if 0 // we are using the default implementation of 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 
00580 
00581   OsiSpxSolverInterface(); 
00582   
00584   virtual OsiSolverInterface * clone(bool copyData = true) const;
00585   
00587   OsiSpxSolverInterface( const OsiSpxSolverInterface& );
00588   
00590   OsiSpxSolverInterface& operator=( const OsiSpxSolverInterface& rhs );
00591   
00593   virtual ~OsiSpxSolverInterface();
00595   
00596 protected:
00597   
00600 
00601   virtual void applyRowCut( const OsiRowCut & rc );
00602   
00606   virtual void applyColCut( const OsiColCut & cc );
00608 
00611 
00612   soplex::SoPlex soplex_;
00614 
00615   
00616 private:
00619   
00621   void freeCachedColRim();
00622 
00624   void freeCachedRowRim();
00625 
00627   void freeCachedResults();
00628   
00630   void freeCachedMatrix();
00631 
00632   enum keepCachedFlag
00633   {
00635     KEEPCACHED_NONE    = 0,
00637     KEEPCACHED_COLUMN  = 1,
00639     KEEPCACHED_ROW     = 2,
00641     KEEPCACHED_MATRIX  = 4,
00643     KEEPCACHED_RESULTS = 8,
00645     KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
00647     KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
00649     FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & !KEEPCACHED_COLUMN,
00651     FREECACHED_ROW     = KEEPCACHED_PROBLEM & !KEEPCACHED_ROW,
00653     FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & !KEEPCACHED_MATRIX,
00655     FREECACHED_RESULTS = KEEPCACHED_ALL & !KEEPCACHED_RESULTS
00656   };
00657 
00659   void freeCachedData( int keepCached = KEEPCACHED_NONE );
00660 
00662   void freeAllMemory();
00663 
00665   void printBounds(); 
00667   
00668   
00671 
00672   soplex::DIdxSet   spxintvars_;
00673 
00675   soplex::SPxSolver::VarStatus *hotStartCStat_;
00676   int                       hotStartCStatSize_;
00677   soplex::SPxSolver::VarStatus *hotStartRStat_;
00678   int                       hotStartRStatSize_;
00679   int                       hotStartMaxIteration_;
00680 
00683 
00684   mutable soplex::DVector *obj_;
00685 
00687   mutable char    *rowsense_;
00688   
00690   mutable double  *rhs_;
00691   
00693   mutable double  *rowrange_;
00694   
00696   mutable soplex::DVector *colsol_;
00697   
00699   mutable soplex::DVector *rowsol_;
00700 
00702   mutable soplex::DVector *redcost_;
00703 
00705   mutable soplex::DVector *rowact_;
00706 
00708   mutable CoinPackedMatrix *matrixByRow_;  
00709   
00711   mutable CoinPackedMatrix *matrixByCol_;  
00713 
00714 };
00715 
00716 //#############################################################################
00722 void OsiSpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00723 
00724 #endif

Generated on Mon Jul 5 03:02:17 2010 by  doxygen 1.4.7