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

- File List
- File Members

# /home/coin/svn-release/Alps-1.5.2/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 EPL
    00010 //-----------------------------------------------------------------------------
    00011 // Copyright (C) 2002, Tobias Pfender, International Business Machines
    00012 // Corporation and others.  All Rights Reserved.
    00013 // Last edit: $Id: OsiSpxSolverInterface.hpp 1967 2014-06-12 16:02:12Z stefan $
    00014
    00015 #ifndef OsiSpxSolverInterface_H
    00016 #define OsiSpxSolverInterface_H
    00017
    00018 #include <string>
    00019 #include "OsiSolverInterface.hpp"
    00020 #include "CoinWarmStartBasis.hpp"
    00021
    00022 #ifndef _SOPLEX_H_
    00023 /* forward declarations so the header can be compiled without having to include soplex.h
    00024  * however, these declaration work only for SoPlex < 2.0, so we do them only if soplex.h hasn't been included already
    00025  */
    00026 namespace soplex {
    00027   class DIdxSet;
    00028   class DVector;
    00029   class SoPlex;
    00030 }
    00031 #endif
    00032
    00036 class OsiSpxSolverInterface : virtual public OsiSolverInterface {
    00037   friend void OsiSpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00038
    00039 public:
    00040
    00041   //---------------------------------------------------------------------------
    00044
    00045   virtual void initialSolve();
    00046
    00048   virtual void resolve();
    00049
    00051   virtual void branchAndBound();
    00053
    00054   //---------------------------------------------------------------------------
    00070     // Set an integer parameter
    00071     bool setIntParam(OsiIntParam key, int value);
    00072     // Set an double parameter
    00073     bool setDblParam(OsiDblParam key, double value);
    00074     // Get an integer parameter
    00075     bool getIntParam(OsiIntParam key, int& value) const;
    00076     // Get an double parameter
    00077     bool getDblParam(OsiDblParam key, double& value) const;
    00078     // Get a string parameter
    00079     bool getStrParam(OsiStrParam key, std::string& value) const;
    00080     // Set timelimit
    00081     void setTimeLimit(double value);
    00082     // Get timelimit
    00083     double getTimeLimit() const;
    00085
    00086   //---------------------------------------------------------------------------
    00088
    00089
    00090     virtual bool isAbandoned() const;
    00092     virtual bool isProvenOptimal() const;
    00094     virtual bool isProvenPrimalInfeasible() const;
    00096     virtual bool isProvenDualInfeasible() const;
    00097     // Is the given primal objective limit reached? - use implementation from OsiSolverInterface
    00099     virtual bool isDualObjectiveLimitReached() const;
    00101     virtual bool isIterationLimitReached() const;
    00103     virtual bool isTimeLimitReached() const;
    00105
    00106   //---------------------------------------------------------------------------
    00109
    00110     inline CoinWarmStart *getEmptyWarmStart () const
    00111     { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; }
    00113     virtual CoinWarmStart* getWarmStart() const;
    00116     virtual bool setWarmStart(const CoinWarmStart* warmstart);
    00118
    00119   //---------------------------------------------------------------------------
    00126
    00127     virtual void markHotStart();
    00129     virtual void solveFromHotStart();
    00131     virtual void unmarkHotStart();
    00133
    00134   //---------------------------------------------------------------------------
    00149
    00150       virtual int getNumCols() const;
    00151
    00153       virtual int getNumRows() const;
    00154
    00156       virtual int getNumElements() const;
    00157
    00159       virtual const double * getColLower() const;
    00160
    00162       virtual const double * getColUpper() const;
    00163
    00173       virtual const char * getRowSense() const;
    00174
    00183       virtual const double * getRightHandSide() const;
    00184
    00193       virtual const double * getRowRange() const;
    00194
    00196       virtual const double * getRowLower() const;
    00197
    00199       virtual const double * getRowUpper() const;
    00200
    00202       virtual const double * getObjCoefficients() const;
    00203
    00205       virtual double getObjSense() const;
    00206
    00208       virtual bool isContinuous(int colNumber) const;
    00209
    00210 #if 0
    00212       virtual bool isBinary(int columnNumber) const;
    00213
    00218       virtual bool isInteger(int columnNumber) const;
    00219
    00221       virtual bool isIntegerNonBinary(int columnNumber) const;
    00222
    00224       virtual bool isFreeBinary(int columnNumber) const;
    00225 #endif
    00226
    00228       virtual const CoinPackedMatrix * getMatrixByRow() const;
    00229
    00231       virtual const CoinPackedMatrix * getMatrixByCol() const;
    00232
    00234       virtual double getInfinity() const;
    00236
    00239
    00240       virtual const double * getColSolution() const;
    00241
    00243       virtual const double * getRowPrice() const;
    00244
    00246       virtual const double * getReducedCost() const;
    00247
    00250       virtual const double * getRowActivity() const;
    00251
    00253       virtual double getObjValue() const;
    00254
    00257       virtual int getIterationCount() const;
    00258
    00276       virtual std::vector<double*> getDualRays(int maxNumRays,
    00277                                                bool fullRay=false) const;
    00289       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
    00290
    00291 #if 0
    00292
    00294       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
    00295         const;
    00296 #endif
    00297
    00298
    00299
    00300   //---------------------------------------------------------------------------
    00301
    00304     //-------------------------------------------------------------------------
    00308       virtual void setObjCoeff( int elementIndex, double elementValue );
    00309
    00312       virtual void setColLower( int elementIndex, double elementValue );
    00313
    00316       virtual void setColUpper( int elementIndex, double elementValue );
    00317
    00321       virtual void setColBounds( int elementIndex,
    00322                                  double lower, double upper );
    00323
    00324 #if 0 // we are using the default implementation of OsiSolverInterface
    00325
    00333       virtual void setColSetBounds(const int* indexFirst,
    00334                                    const int* indexLast,
    00335                                    const double* boundList);
    00336 #endif
    00337
    00340       virtual void setRowLower( int elementIndex, double elementValue );
    00341
    00344       virtual void setRowUpper( int elementIndex, double elementValue );
    00345
    00349       virtual void setRowBounds( int elementIndex,
    00350                                  double lower, double upper );
    00351
    00353       virtual void setRowType(int index, char sense, double rightHandSide,
    00354                               double range);
    00355
    00356 #if 0 // we are using the default implementation of OsiSolverInterface
    00357
    00364       virtual void setRowSetBounds(const int* indexFirst,
    00365                                    const int* indexLast,
    00366                                    const double* boundList);
    00367
    00377       virtual void setRowSetTypes(const int* indexFirst,
    00378                                   const int* indexLast,
    00379                                   const char* senseList,
    00380                                   const double* rhsList,
    00381                                   const double* rangeList);
    00382 #endif
    00383
    00384
    00385     //-------------------------------------------------------------------------
    00389       virtual void setContinuous(int index);
    00391       virtual void setInteger(int index);
    00392 #if 0 // we are using the default implementation of OsiSolverInterface
    00393
    00395       virtual void setContinuous(const int* indices, int len);
    00398       virtual void setInteger(const int* indices, int len);
    00399 #endif
    00400
    00401
    00402     //-------------------------------------------------------------------------
    00404     virtual void setObjSense(double s);
    00405
    00416     virtual void setColSolution(const double * colsol);
    00417
    00428     virtual void setRowPrice(const double * rowprice);
    00429
    00430     //-------------------------------------------------------------------------
    00436       virtual void addCol(const CoinPackedVectorBase& vec,
    00437                           const double collb, const double colub,
    00438                           const double obj);
    00439
    00440 #if 0 // we are using the default implementation of OsiSolverInterface
    00441
    00442       virtual void addCols(const int numcols,
    00443                            const CoinPackedVectorBase * const * cols,
    00444                            const double* collb, const double* colub,
    00445                            const double* obj);
    00446 #endif
    00447
    00449       virtual void deleteCols(const int num, const int * colIndices);
    00450
    00452       virtual void addRow(const CoinPackedVectorBase& vec,
    00453                           const double rowlb, const double rowub);
    00455       virtual void addRow(const CoinPackedVectorBase& vec,
    00456                           const char rowsen, const double rowrhs,
    00457                           const double rowrng);
    00458
    00459 #if 0 // we are using the default implementation of OsiSolverInterface
    00460
    00461       virtual void addRows(const int numrows,
    00462                            const CoinPackedVectorBase * const * rows,
    00463                            const double* rowlb, const double* rowub);
    00465       virtual void addRows(const int numrows,
    00466                            const CoinPackedVectorBase * const * rows,
    00467                            const char* rowsen, const double* rowrhs,
    00468                            const double* rowrng);
    00469 #endif
    00470
    00472       virtual void deleteRows(const int num, const int * rowIndices);
    00473
    00474 #if 0 // we are using the default implementation of OsiSolverInterface
    00475       //-----------------------------------------------------------------------
    00497       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
    00498                                             double effectivenessLb = 0.0);
    00499 #endif
    00500
    00501
    00502
    00503   //---------------------------------------------------------------------------
    00504
    00518     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00519                              const double* collb, const double* colub,
    00520                              const double* obj,
    00521                              const double* rowlb, const double* rowub);
    00522
    00530     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00531                                double*& collb, double*& colub, double*& obj,
    00532                                double*& rowlb, double*& rowub);
    00533
    00546     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00547                              const double* collb, const double* colub,
    00548                              const double* obj,
    00549                              const char* rowsen, const double* rowrhs,
    00550                              const double* rowrng);
    00551
    00559     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00560                                double*& collb, double*& colub, double*& obj,
    00561                                char*& rowsen, double*& rowrhs,
    00562                                double*& rowrng);
    00563
    00566     virtual void loadProblem(const int numcols, const int numrows,
    00567                              const int* start, const int* index,
    00568                              const double* value,
    00569                              const double* collb, const double* colub,
    00570                              const double* obj,
    00571                              const double* rowlb, const double* rowub);
    00572
    00575     virtual void loadProblem(const int numcols, const int numrows,
    00576                              const int* start, const int* index,
    00577                              const double* value,
    00578                              const double* collb, const double* colub,
    00579                              const double* obj,
    00580                              const char* rowsen, const double* rowrhs,
    00581                              const double* rowrng);
    00582
    00584     virtual int readMps(const char *filename,
    00585                          const char *extension = "mps");
    00586
    00591     virtual void writeMps(const char *filename,
    00592                           const char *extension = "mps",
    00593                           double objSense=0.0) const;
    00595
    00596   //---------------------------------------------------------------------------
    00597
    00600
    00601   OsiSpxSolverInterface();
    00602
    00604   virtual OsiSolverInterface * clone(bool copyData = true) const;
    00605
    00607   OsiSpxSolverInterface( const OsiSpxSolverInterface& );
    00608
    00610   OsiSpxSolverInterface& operator=( const OsiSpxSolverInterface& rhs );
    00611
    00613   virtual ~OsiSpxSolverInterface();
    00615
    00616 protected:
    00617
    00620
    00621   virtual void applyRowCut( const OsiRowCut & rc );
    00622
    00626   virtual void applyColCut( const OsiColCut & cc );
    00628
    00631
    00632   soplex::SoPlex *soplex_;
    00634
    00635
    00636 private:
    00639
    00641   void freeCachedColRim();
    00642
    00644   void freeCachedRowRim();
    00645
    00647   void freeCachedResults();
    00648
    00650   void freeCachedMatrix();
    00651
    00652   enum keepCachedFlag
    00653   {
    00655     KEEPCACHED_NONE    = 0,
    00657     KEEPCACHED_COLUMN  = 1,
    00659     KEEPCACHED_ROW     = 2,
    00661     KEEPCACHED_MATRIX  = 4,
    00663     KEEPCACHED_RESULTS = 8,
    00665     KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
    00667     KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
    00669     FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & ~KEEPCACHED_COLUMN,
    00671     FREECACHED_ROW     = KEEPCACHED_PROBLEM & ~KEEPCACHED_ROW,
    00673     FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & ~KEEPCACHED_MATRIX,
    00675     FREECACHED_RESULTS = KEEPCACHED_ALL & ~KEEPCACHED_RESULTS
    00676   };
    00677
    00679   void freeCachedData( int keepCached = KEEPCACHED_NONE );
    00680
    00682   void freeAllMemory();
    00684
    00685
    00688
    00689   soplex::DIdxSet   *spxintvars_;
    00690
    00692   void* hotStartCStat_;
    00693   int   hotStartCStatSize_;
    00694   void* hotStartRStat_;
    00695   int   hotStartRStatSize_;
    00696   int   hotStartMaxIteration_;
    00697
    00700
    00701   mutable soplex::DVector *obj_;
    00702
    00704   mutable char    *rowsense_;
    00705
    00707   mutable double  *rhs_;
    00708
    00710   mutable double  *rowrange_;
    00711
    00713   mutable soplex::DVector *colsol_;
    00714
    00716   mutable soplex::DVector *rowsol_;
    00717
    00719   mutable soplex::DVector *redcost_;
    00720
    00722   mutable soplex::DVector *rowact_;
    00723
    00725   mutable CoinPackedMatrix *matrixByRow_;
    00726
    00728   mutable CoinPackedMatrix *matrixByCol_;
    00730
    00731 };
    00732
    00733 //#############################################################################
    00735 void OsiSpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00736
    00737 #endif