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

- File List
- File Members

# /home/coin/SVN-release/Osi-0.98.1/Osi/src/OsiOsl/OsiOslSolverInterface.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 _OsiOslSolverInterface_hpp_
    00005 #define _OsiOslSolverInterface_hpp_
    00006
    00007 #if (defined(__MINGW32__) || defined(__CYGWIN32__)) && !defined(OSLMSDLL)
    00008 #  define OSLMSDLL
    00009 #endif
    00010
    00011 #include <string>
    00012 #include "ekk_c_api.h"
    00013
    00014 #include "OsiSolverInterface.hpp"
    00015 #include "CoinPackedMatrix.hpp"
    00016 #include "CoinWarmStartBasis.hpp"
    00017
    00018 //#############################################################################
    00019
    00025 class OsiOslSolverInterface : virtual public OsiSolverInterface {
    00026    friend void OsiOslSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00027
    00028 public:
    00029   //---------------------------------------------------------------------------
    00032
    00033     virtual void initialSolve();
    00034
    00036     virtual void resolve();
    00037
    00039     virtual void branchAndBound();
    00041
    00042   //---------------------------------------------------------------------------
    00058     // Set an integer parameter
    00059     bool setIntParam(OsiIntParam key, int value);
    00060     // Set an double parameter
    00061     bool setDblParam(OsiDblParam key, double value);
    00062     // Set a string parameter
    00063     bool setStrParam(OsiStrParam key, const std::string & 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;
    00089     //Returns true if a basis is available and optimal
    00090   virtual bool basisIsAvailable() 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
    00298 #if 0
    00299       // The default implementation is OK.
    00303       virtual void setColBounds( int elementIndex,
    00304                                  double lower, double upper ) {
    00305          setColLower(elementIndex, lower);
    00306          setColUpper(elementIndex, upper);
    00307       }
    00308 #endif
    00309
    00317       virtual void setColSetBounds(const int* indexFirst,
    00318                                    const int* indexLast,
    00319                                    const double* boundList);
    00320
    00323       virtual void setRowLower( int elementIndex, double elementValue );
    00324
    00327       virtual void setRowUpper( int elementIndex, double elementValue );
    00328
    00332       virtual void setRowBounds( int elementIndex,
    00333                                  double lower, double upper );
    00334
    00336       virtual void setRowType(int index, char sense, double rightHandSide,
    00337                               double range);
    00338
    00347       virtual void setRowSetBounds(const int* indexFirst,
    00348                                    const int* indexLast,
    00349                                    const double* boundList);
    00350
    00361       virtual void setRowSetTypes(const int* indexFirst,
    00362                                   const int* indexLast,
    00363                                   const char* senseList,
    00364                                   const double* rhsList,
    00365                                   const double* rangeList);
    00367
    00368     //-------------------------------------------------------------------------
    00372       virtual void setContinuous(int index);
    00374       virtual void setInteger(int index);
    00377       virtual void setContinuous(const int* indices, int len);
    00380       virtual void setInteger(const int* indices, int len);
    00382
    00383     //-------------------------------------------------------------------------
    00385     virtual void setObjSense(double s );
    00386
    00397     virtual void setColSolution(const double * colsol);
    00398
    00409     virtual void setRowPrice(const double * rowprice);
    00410
    00411     //-------------------------------------------------------------------------
    00417       virtual void addCol(const CoinPackedVectorBase& vec,
    00418                              const double collb, const double colub,
    00419                              const double obj);
    00421       virtual void addCols(const int numcols,
    00422                            const CoinPackedVectorBase * const * cols,
    00423                            const double* collb, const double* colub,
    00424                            const double* obj);
    00425 #if 0
    00426
    00427       virtual void addCols(const CoinPackedMatrix& matrix,
    00428                               const double* collb, const double* colub,
    00429                               const double* obj);
    00430 #endif
    00431
    00432       virtual void deleteCols(const int num, const int * colIndices);
    00433
    00435       virtual void addRow(const CoinPackedVectorBase& vec,
    00436                           const double rowlb, const double rowub);
    00438       virtual void addRow(const CoinPackedVectorBase& vec,
    00439                           const char rowsen, const double rowrhs,
    00440                           const double rowrng);
    00442       virtual void addRows(const int numrows,
    00443                            const CoinPackedVectorBase * const * rows,
    00444                            const double* rowlb, const double* rowub);
    00446       virtual void addRows(const int numrows,
    00447                            const CoinPackedVectorBase * const * rows,
    00448                            const char* rowsen, const double* rowrhs,
    00449                            const double* rowrng);
    00450 #if 0
    00451
    00452       virtual void addRows(const CoinPackedMatrix& matrix,
    00453                            const double* rowlb, const double* rowub);
    00455       virtual void addRows(const CoinPackedMatrix& matrix,
    00456                            const char* rowsen, const double* rowrhs,
    00457                            const double* rowrng);
    00458 #endif
    00459
    00460       virtual void deleteRows(const int num, const int * rowIndices);
    00461
    00462       //-----------------------------------------------------------------------
    00463 #if 0
    00464
    00485       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
    00486                                             double effectivenessLb = 0.0);
    00487 #endif
    00488
    00489
    00490
    00491   //---------------------------------------------------------------------------
    00492
    00506     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00507                              const double* collb, const double* colub,
    00508                              const double* obj,
    00509                              const double* rowlb, const double* rowub);
    00510
    00518     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00519                                double*& collb, double*& colub, double*& obj,
    00520                                double*& rowlb, double*& rowub);
    00521
    00534     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00535                              const double* collb, const double* colub,
    00536                              const double* obj,
    00537                              const char* rowsen, const double* rowrhs,
    00538                              const double* rowrng);
    00539
    00547     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00548                                double*& collb, double*& colub, double*& obj,
    00549                                char*& rowsen, double*& rowrhs,
    00550                                double*& rowrng);
    00551
    00554     virtual void loadProblem(const int numcols, const int numrows,
    00555                              const CoinBigIndex * start, const int* index,
    00556                              const double* value,
    00557                              const double* collb, const double* colub,
    00558                              const double* obj,
    00559                              const double* rowlb, const double* rowub);
    00560
    00563     virtual void loadProblem(const int numcols, const int numrows,
    00564                              const CoinBigIndex * start, const int* index,
    00565                              const double* value,
    00566                              const double* collb, const double* colub,
    00567                              const double* obj,
    00568                              const char* rowsen, const double* rowrhs,
    00569                              const double* rowrng);
    00570
    00573     virtual int readMps(const char *filename,
    00574                         const char *extension = "mps");
    00575
    00580     virtual void writeMps(const char *filename,
    00581                           const char *extension = "mps",
    00582                           double objSense=0.0) const;
    00584
    00585   //---------------------------------------------------------------------------
    00586
    00589
    00590     EKKModel * getModelPtr();
    00591
    00602       static void incrementInstanceCounter();
    00603
    00612       static void decrementInstanceCounter();
    00613
    00616       static unsigned int getNumInstances();
    00618
    00619
    00622
    00623     OsiOslSolverInterface();
    00624
    00626     virtual OsiSolverInterface * clone(bool copyData = true) const;
    00627
    00629     OsiOslSolverInterface (const OsiOslSolverInterface &);
    00630
    00632     OsiOslSolverInterface &
    00633     operator=(const OsiOslSolverInterface& rhs);
    00634
    00636     virtual ~OsiOslSolverInterface ();
    00637
    00639     virtual void reset();
    00641
    00642 protected:
    00643
    00647     virtual void applyRowCut( const OsiRowCut & rc );
    00648
    00650     virtual void applyColCut( const OsiColCut & cc );
    00652
    00653 private:
    00654
    00657
    00658     static EKKContext * getContextPtr();
    00660
    00663
    00664     static EKKContext * contextPtr_;
    00666     static unsigned int numInstances_;
    00668
    00669
    00675     EKKModel * getMutableModelPtr() const;
    00676
    00678     void gutsOfDestructor();
    00679
    00681     void freeCachedResults();
    00682
    00684     void extractSenseRhsRange() const;
    00686
    00689
    00690      mutable EKKModel * modelPtr_;
    00691
    00694
    00695       mutable char    *rowsense_;
    00696
    00698       mutable double  *rhs_;
    00699
    00703      mutable double  *rowrange_;
    00704
    00707      CoinWarmStartBasis* ws_;
    00709      int itlimOrig_;
    00710
    00712      mutable CoinPackedMatrix *matrixByRow_;
    00714      mutable CoinPackedMatrix *matrixByColumn_;
    00716
    00717
    00718 };
    00719
    00720 //#############################################################################
    00728 void
    00729 OsiOslSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00730
    00731 #endif