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

- File List
- File Members

# /home/coin/SVN-release/Alps-1.2.1/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 1551 2010-07-30 18:39:03Z lou $
    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
    00263       virtual std::vector<double*> getDualRays(int maxNumRays,
    00264                                                bool fullRay=false) const;
    00276       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
    00277
    00278 #if 0
    00279
    00281       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
    00282         const;
    00283 #endif
    00284
    00285
    00286
    00287   //---------------------------------------------------------------------------
    00288
    00291     //-------------------------------------------------------------------------
    00295       virtual void setObjCoeff( int elementIndex, double elementValue );
    00296
    00299       virtual void setColLower( int elementIndex, double elementValue );
    00300
    00303       virtual void setColUpper( int elementIndex, double elementValue );
    00304
    00308       virtual void setColBounds( int elementIndex,
    00309                                  double lower, double upper );
    00310
    00311 #if 0 // we are using the default implementation of OsiSolverInterface
    00312
    00320       virtual void setColSetBounds(const int* indexFirst,
    00321                                    const int* indexLast,
    00322                                    const double* boundList);
    00323 #endif
    00324
    00327       virtual void setRowLower( int elementIndex, double elementValue );
    00328
    00331       virtual void setRowUpper( int elementIndex, double elementValue );
    00332
    00336       virtual void setRowBounds( int elementIndex,
    00337                                  double lower, double upper );
    00338
    00340       virtual void setRowType(int index, char sense, double rightHandSide,
    00341                               double range);
    00342
    00343 #if 0 // we are using the default implementation of OsiSolverInterface
    00344
    00351       virtual void setRowSetBounds(const int* indexFirst,
    00352                                    const int* indexLast,
    00353                                    const double* boundList);
    00354
    00364       virtual void setRowSetTypes(const int* indexFirst,
    00365                                   const int* indexLast,
    00366                                   const char* senseList,
    00367                                   const double* rhsList,
    00368                                   const double* rangeList);
    00369 #endif
    00370
    00371
    00372     //-------------------------------------------------------------------------
    00376       virtual void setContinuous(int index);
    00378       virtual void setInteger(int index);
    00379 #if 0 // we are using the default implementation of OsiSolverInterface
    00380
    00382       virtual void setContinuous(const int* indices, int len);
    00385       virtual void setInteger(const int* indices, int len);
    00386 #endif
    00387
    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);
    00426
    00427 #if 0 // we are using the default implementation of OsiSolverInterface
    00428
    00429       virtual void addCols(const int numcols,
    00430                            const CoinPackedVectorBase * const * cols,
    00431                            const double* collb, const double* colub,
    00432                            const double* obj);
    00433 #endif
    00434
    00436       virtual void deleteCols(const int num, const int * colIndices);
    00437
    00439       virtual void addRow(const CoinPackedVectorBase& vec,
    00440                           const double rowlb, const double rowub);
    00442       virtual void addRow(const CoinPackedVectorBase& vec,
    00443                           const char rowsen, const double rowrhs,
    00444                           const double rowrng);
    00445
    00446 #if 0 // we are using the default implementation of OsiSolverInterface
    00447
    00448       virtual void addRows(const int numrows,
    00449                            const CoinPackedVectorBase * const * rows,
    00450                            const double* rowlb, const double* rowub);
    00452       virtual void addRows(const int numrows,
    00453                            const CoinPackedVectorBase * const * rows,
    00454                            const char* rowsen, const double* rowrhs,
    00455                            const double* rowrng);
    00456 #endif
    00457
    00459       virtual void deleteRows(const int num, const int * rowIndices);
    00460
    00461 #if 0 // we are using the default implementation of OsiSolverInterface
    00462       //-----------------------------------------------------------------------
    00484       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
    00485                                             double effectivenessLb = 0.0);
    00486 #endif
    00487
    00488
    00489
    00490   //---------------------------------------------------------------------------
    00491
    00505     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00506                              const double* collb, const double* colub,
    00507                              const double* obj,
    00508                              const double* rowlb, const double* rowub);
    00509
    00517     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00518                                double*& collb, double*& colub, double*& obj,
    00519                                double*& rowlb, double*& rowub);
    00520
    00533     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00534                              const double* collb, const double* colub,
    00535                              const double* obj,
    00536                              const char* rowsen, const double* rowrhs,
    00537                              const double* rowrng);
    00538
    00546     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00547                                double*& collb, double*& colub, double*& obj,
    00548                                char*& rowsen, double*& rowrhs,
    00549                                double*& rowrng);
    00550
    00553     virtual void loadProblem(const int numcols, const int numrows,
    00554                              const int* start, const int* index,
    00555                              const double* value,
    00556                              const double* collb, const double* colub,
    00557                              const double* obj,
    00558                              const double* rowlb, const double* rowub);
    00559
    00562     virtual void loadProblem(const int numcols, const int numrows,
    00563                              const int* start, const int* index,
    00564                              const double* value,
    00565                              const double* collb, const double* colub,
    00566                              const double* obj,
    00567                              const char* rowsen, const double* rowrhs,
    00568                              const double* rowrng);
    00569
    00571     virtual int readMps(const char *filename,
    00572                          const char *extension = "mps");
    00573
    00578     virtual void writeMps(const char *filename,
    00579                           const char *extension = "mps",
    00580                           double objSense=0.0) const;
    00582
    00583   //---------------------------------------------------------------------------
    00584
    00587
    00588   OsiSpxSolverInterface();
    00589
    00591   virtual OsiSolverInterface * clone(bool copyData = true) const;
    00592
    00594   OsiSpxSolverInterface( const OsiSpxSolverInterface& );
    00595
    00597   OsiSpxSolverInterface& operator=( const OsiSpxSolverInterface& rhs );
    00598
    00600   virtual ~OsiSpxSolverInterface();
    00602
    00603 protected:
    00604
    00607
    00608   virtual void applyRowCut( const OsiRowCut & rc );
    00609
    00613   virtual void applyColCut( const OsiColCut & cc );
    00615
    00618
    00619   soplex::SoPlex soplex_;
    00621
    00622
    00623 private:
    00626
    00628   void freeCachedColRim();
    00629
    00631   void freeCachedRowRim();
    00632
    00634   void freeCachedResults();
    00635
    00637   void freeCachedMatrix();
    00638
    00639   enum keepCachedFlag
    00640   {
    00642     KEEPCACHED_NONE    = 0,
    00644     KEEPCACHED_COLUMN  = 1,
    00646     KEEPCACHED_ROW     = 2,
    00648     KEEPCACHED_MATRIX  = 4,
    00650     KEEPCACHED_RESULTS = 8,
    00652     KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
    00654     KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
    00656     FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & !KEEPCACHED_COLUMN,
    00658     FREECACHED_ROW     = KEEPCACHED_PROBLEM & !KEEPCACHED_ROW,
    00660     FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & !KEEPCACHED_MATRIX,
    00662     FREECACHED_RESULTS = KEEPCACHED_ALL & !KEEPCACHED_RESULTS
    00663   };
    00664
    00666   void freeCachedData( int keepCached = KEEPCACHED_NONE );
    00667
    00669   void freeAllMemory();
    00670
    00672   void printBounds();
    00674
    00675
    00678
    00679   soplex::DIdxSet   spxintvars_;
    00680
    00682   soplex::SPxSolver::VarStatus *hotStartCStat_;
    00683   int                       hotStartCStatSize_;
    00684   soplex::SPxSolver::VarStatus *hotStartRStat_;
    00685   int                       hotStartRStatSize_;
    00686   int                       hotStartMaxIteration_;
    00687
    00690
    00691   mutable soplex::DVector *obj_;
    00692
    00694   mutable char    *rowsense_;
    00695
    00697   mutable double  *rhs_;
    00698
    00700   mutable double  *rowrange_;
    00701
    00703   mutable soplex::DVector *colsol_;
    00704
    00706   mutable soplex::DVector *rowsol_;
    00707
    00709   mutable soplex::DVector *redcost_;
    00710
    00712   mutable soplex::DVector *rowact_;
    00713
    00715   mutable CoinPackedMatrix *matrixByRow_;
    00716
    00718   mutable CoinPackedMatrix *matrixByCol_;
    00720
    00721 };
    00722
    00723 //#############################################################################
    00729 void OsiSpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00730
    00731 #endif