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

- File List
- File Members

# /home/coin/SVN-release/DyLP-1.5.0/Osi/src/OsiSpx/OsiSpxSolverInterface.hpp

Go to the documentation of this file.

    00001 //  LAST EDIT: Fri Aug 31 13:54:15 2001 by Tobias Pfender (opt14!bzfpfend)
    00002 //-----------------------------------------------------------------------------
    00003 // name:     OSI Interface for SOPLEX
    00004 // author:   Tobias Pfender
    00005 //           Konrad-Zuse-Zentrum Berlin (Germany)
    00006 //           email: pfender@zib.de
    00007 // date:     01/16/2002
    00008 // license:  this file may be freely distributed under the terms of the CPL
    00009 //-----------------------------------------------------------------------------
    00010 // Copyright (C) 2002, Tobias Pfender, International Business Machines
    00011 // Corporation and others.  All Rights Reserved.
    00012
    00013 #ifndef OsiSpxSolverInterface_H
    00014 #define OsiSpxSolverInterface_H
    00015
    00016 #include <string>
    00017 #include "spxsolver.h"
    00018 #include "OsiSolverInterface.hpp"
    00019 #include "CoinWarmStartBasis.hpp"
    00020
    00026 class OsiSpxSolverInterface : virtual public OsiSolverInterface {
    00027   friend void OsiSpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00028
    00029 public:
    00030
    00031   //---------------------------------------------------------------------------
    00034
    00035   virtual void initialSolve();
    00036
    00038   virtual void resolve();
    00039
    00041   virtual void branchAndBound();
    00043
    00044   //---------------------------------------------------------------------------
    00060     // Set an integer parameter
    00061     bool setIntParam(OsiIntParam key, int value);
    00062     // Set an double parameter
    00063     bool setDblParam(OsiDblParam key, double value);
    00064     // Get an integer parameter
    00065     bool getIntParam(OsiIntParam key, int& value) const;
    00066     // Get an double parameter
    00067     bool getDblParam(OsiDblParam key, double& value) const;
    00068     // Get a string parameter
    00069     bool getStrParam(OsiStrParam key, std::string& value) const;
    00071
    00072   //---------------------------------------------------------------------------
    00074
    00075
    00076     virtual bool isAbandoned() const;
    00078     virtual bool isProvenOptimal() const;
    00080     virtual bool isProvenPrimalInfeasible() const;
    00082     virtual bool isProvenDualInfeasible() const;
    00084     virtual bool isPrimalObjectiveLimitReached() const;
    00086     virtual bool isDualObjectiveLimitReached() const;
    00088     virtual bool isIterationLimitReached() const;
    00090
    00091   //---------------------------------------------------------------------------
    00094
    00095     inline CoinWarmStart *getEmptyWarmStart () const
    00096     { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; }
    00098     virtual CoinWarmStart* getWarmStart() const;
    00101     virtual bool setWarmStart(const CoinWarmStart* warmstart);
    00103
    00104   //---------------------------------------------------------------------------
    00111
    00112     virtual void markHotStart();
    00114     virtual void solveFromHotStart();
    00116     virtual void unmarkHotStart();
    00118
    00119   //---------------------------------------------------------------------------
    00134
    00135       virtual int getNumCols() const;
    00136
    00138       virtual int getNumRows() const;
    00139
    00141       virtual int getNumElements() const;
    00142
    00144       virtual const double * getColLower() const;
    00145
    00147       virtual const double * getColUpper() const;
    00148
    00158       virtual const char * getRowSense() const;
    00159
    00168       virtual const double * getRightHandSide() const;
    00169
    00178       virtual const double * getRowRange() const;
    00179
    00181       virtual const double * getRowLower() const;
    00182
    00184       virtual const double * getRowUpper() const;
    00185
    00187       virtual const double * getObjCoefficients() const;
    00188
    00190       virtual double getObjSense() const;
    00191
    00193       virtual bool isContinuous(int colNumber) const;
    00194
    00195 #if 0
    00197       virtual bool isBinary(int columnNumber) const;
    00198
    00203       virtual bool isInteger(int columnNumber) const;
    00204
    00206       virtual bool isIntegerNonBinary(int columnNumber) const;
    00207
    00209       virtual bool isFreeBinary(int columnNumber) const;
    00210 #endif
    00211
    00213       virtual const CoinPackedMatrix * getMatrixByRow() const;
    00214
    00216       virtual const CoinPackedMatrix * getMatrixByCol() const;
    00217
    00219       virtual double getInfinity() const;
    00221
    00224
    00225       virtual const double * getColSolution() const;
    00226
    00228       virtual const double * getRowPrice() const;
    00229
    00231       virtual const double * getReducedCost() const;
    00232
    00235       virtual const double * getRowActivity() const;
    00236
    00238       virtual double getObjValue() const;
    00239
    00242       virtual int getIterationCount() const;
    00243
    00255       virtual std::vector<double*> getDualRays(int maxNumRays) const;
    00267       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
    00268
    00269 #if 0
    00270
    00272       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
    00273         const;
    00274 #endif
    00275
    00276
    00277
    00278   //---------------------------------------------------------------------------
    00279
    00282     //-------------------------------------------------------------------------
    00286       virtual void setObjCoeff( int elementIndex, double elementValue );
    00287
    00290       virtual void setColLower( int elementIndex, double elementValue );
    00291
    00294       virtual void setColUpper( int elementIndex, double elementValue );
    00295
    00299       virtual void setColBounds( int elementIndex,
    00300                                  double lower, double upper );
    00301
    00302 #if 0 // we are using the default implementation of OsiSolverInterface
    00303
    00311       virtual void setColSetBounds(const int* indexFirst,
    00312                                    const int* indexLast,
    00313                                    const double* boundList);
    00314 #endif
    00315
    00318       virtual void setRowLower( int elementIndex, double elementValue );
    00319
    00322       virtual void setRowUpper( int elementIndex, double elementValue );
    00323
    00327       virtual void setRowBounds( int elementIndex,
    00328                                  double lower, double upper );
    00329
    00331       virtual void setRowType(int index, char sense, double rightHandSide,
    00332                               double range);
    00333
    00334 #if 0 // we are using the default implementation of OsiSolverInterface
    00335
    00342       virtual void setRowSetBounds(const int* indexFirst,
    00343                                    const int* indexLast,
    00344                                    const double* boundList);
    00345
    00355       virtual void setRowSetTypes(const int* indexFirst,
    00356                                   const int* indexLast,
    00357                                   const char* senseList,
    00358                                   const double* rhsList,
    00359                                   const double* rangeList);
    00360 #endif
    00361
    00362
    00363     //-------------------------------------------------------------------------
    00367       virtual void setContinuous(int index);
    00369       virtual void setInteger(int index);
    00370 #if 0 // we are using the default implementation of OsiSolverInterface
    00371
    00373       virtual void setContinuous(const int* indices, int len);
    00376       virtual void setInteger(const int* indices, int len);
    00377 #endif
    00378
    00379
    00380     //-------------------------------------------------------------------------
    00382     virtual void setObjSense(double s);
    00383
    00394     virtual void setColSolution(const double * colsol);
    00395
    00406     virtual void setRowPrice(const double * rowprice);
    00407
    00408     //-------------------------------------------------------------------------
    00414       virtual void addCol(const CoinPackedVectorBase& vec,
    00415                           const double collb, const double colub,
    00416                           const double obj);
    00417
    00418 #if 0 // we are using the default implementation of OsiSolverInterface
    00419
    00420       virtual void addCols(const int numcols,
    00421                            const CoinPackedVectorBase * const * cols,
    00422                            const double* collb, const double* colub,
    00423                            const double* obj);
    00424 #endif
    00425
    00427       virtual void deleteCols(const int num, const int * colIndices);
    00428
    00430       virtual void addRow(const CoinPackedVectorBase& vec,
    00431                           const double rowlb, const double rowub);
    00433       virtual void addRow(const CoinPackedVectorBase& vec,
    00434                           const char rowsen, const double rowrhs,
    00435                           const double rowrng);
    00436
    00437 #if 0 // we are using the default implementation of OsiSolverInterface
    00438
    00439       virtual void addRows(const int numrows,
    00440                            const CoinPackedVectorBase * const * rows,
    00441                            const double* rowlb, const double* rowub);
    00443       virtual void addRows(const int numrows,
    00444                            const CoinPackedVectorBase * const * rows,
    00445                            const char* rowsen, const double* rowrhs,
    00446                            const double* rowrng);
    00447 #endif
    00448
    00450       virtual void deleteRows(const int num, const int * rowIndices);
    00451
    00452 #if 0 // we are using the default implementation of OsiSolverInterface
    00453       //-----------------------------------------------------------------------
    00475       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
    00476                                             double effectivenessLb = 0.0);
    00477 #endif
    00478
    00479
    00480
    00481   //---------------------------------------------------------------------------
    00482
    00496     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00497                              const double* collb, const double* colub,
    00498                              const double* obj,
    00499                              const double* rowlb, const double* rowub);
    00500
    00508     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00509                                double*& collb, double*& colub, double*& obj,
    00510                                double*& rowlb, double*& rowub);
    00511
    00524     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00525                              const double* collb, const double* colub,
    00526                              const double* obj,
    00527                              const char* rowsen, const double* rowrhs,
    00528                              const double* rowrng);
    00529
    00537     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00538                                double*& collb, double*& colub, double*& obj,
    00539                                char*& rowsen, double*& rowrhs,
    00540                                double*& rowrng);
    00541
    00544     virtual void loadProblem(const int numcols, const int numrows,
    00545                              const int* start, const int* index,
    00546                              const double* value,
    00547                              const double* collb, const double* colub,
    00548                              const double* obj,
    00549                              const double* rowlb, const double* rowub);
    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 char* rowsen, const double* rowrhs,
    00559                              const double* rowrng);
    00560
    00562     virtual int readMps(const char *filename,
    00563                          const char *extension = "mps");
    00564
    00569     virtual void writeMps(const char *filename,
    00570                           const char *extension = "mps",
    00571                           double objSense=0.0) const;
    00573
    00574   //---------------------------------------------------------------------------
    00575
    00578
    00579   OsiSpxSolverInterface();
    00580
    00582   virtual OsiSolverInterface * clone(bool copyData = true) const;
    00583
    00585   OsiSpxSolverInterface( const OsiSpxSolverInterface& );
    00586
    00588   OsiSpxSolverInterface& operator=( const OsiSpxSolverInterface& rhs );
    00589
    00591   virtual ~OsiSpxSolverInterface();
    00593
    00594 protected:
    00595
    00598
    00599   virtual void applyRowCut( const OsiRowCut & rc );
    00600
    00604   virtual void applyColCut( const OsiColCut & cc );
    00606
    00609
    00610   soplex::SPxSolver spxsolver_;
    00612
    00613
    00614 private:
    00617
    00619   void freeCachedColRim();
    00620
    00622   void freeCachedRowRim();
    00623
    00625   void freeCachedResults();
    00626
    00628   void freeCachedMatrix();
    00629
    00630   enum keepCachedFlag
    00631   {
    00633     KEEPCACHED_NONE    = 0,
    00635     KEEPCACHED_COLUMN  = 1,
    00637     KEEPCACHED_ROW     = 2,
    00639     KEEPCACHED_MATRIX  = 4,
    00641     KEEPCACHED_RESULTS = 8,
    00643     KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
    00645     KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
    00647     FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & !KEEPCACHED_COLUMN,
    00649     FREECACHED_ROW     = KEEPCACHED_PROBLEM & !KEEPCACHED_ROW,
    00651     FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & !KEEPCACHED_MATRIX,
    00653     FREECACHED_RESULTS = KEEPCACHED_ALL & !KEEPCACHED_RESULTS
    00654   };
    00655
    00657   void freeCachedData( int keepCached = KEEPCACHED_NONE );
    00658
    00660   void freeAllMemory();
    00661
    00663   void printBounds();
    00665
    00666
    00669
    00670   soplex::DIdxSet   spxintvars_;
    00671
    00673   soplex::SoPlex::VarStatus *hotStartCStat_;
    00674   int                       hotStartCStatSize_;
    00675   soplex::SoPlex::VarStatus *hotStartRStat_;
    00676   int                       hotStartRStatSize_;
    00677   int                       hotStartMaxIteration_;
    00678
    00681
    00682   mutable soplex::DVector *obj_;
    00683
    00685   mutable char    *rowsense_;
    00686
    00688   mutable double  *rhs_;
    00689
    00691   mutable double  *rowrange_;
    00692
    00694   mutable soplex::DVector *colsol_;
    00695
    00697   mutable soplex::DVector *rowsol_;
    00698
    00700   mutable soplex::DVector *redcost_;
    00701
    00703   mutable soplex::DVector *rowact_;
    00704
    00706   mutable CoinPackedMatrix *matrixByRow_;
    00707
    00709   mutable CoinPackedMatrix *matrixByCol_;
    00711
    00712 };
    00713
    00714 //#############################################################################
    00720 void OsiSpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00721
    00722 #endif