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

- File List
- File Members

# /home/coin/SVN-release/Alps-1.2.1/Osi/src/OsiMsk/OsiMskSolverInterface.hpp

Go to the documentation of this file.

    00001 // Osi interface for Mosek ver. 5.0
    00002 // Lower versions are not supported
    00003 //-----------------------------------------------------------------------------
    00004 // name:     OSI Interface for MOSEK
    00005 // author:   Bo Jensen
    00006 // email:    support@MOSEK.com
    00007 //-----------------------------------------------------------------------------
    00008
    00009 #ifndef OsiMskSolverInterface_H
    00010 #define OsiMskSolverInterface_H
    00011
    00012 #include "OsiSolverInterface.hpp"
    00013
    00014 typedef void* MSKtask_t;
    00015 typedef void* MSKenv_t;
    00016
    00017 /* MOSEK Solver Interface
    00018    Instantiation of OsiMskSolverInterface for MOSEK
    00019 */
    00020
    00021 class OsiMskSolverInterface :
    00022   virtual public OsiSolverInterface {
    00023   friend void OsiMskSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00024 public:
    00025
    00026   //---------------------------------------------------------------------------
    00029
    00030   virtual void initialSolve();
    00031
    00033   virtual void resolve();
    00034
    00036   virtual void branchAndBound();
    00038
    00039   //---------------------------------------------------------------------------
    00055     // Set an integer parameter
    00056     bool setIntParam(OsiIntParam key, int value);
    00057     // Set an double parameter
    00058     bool setDblParam(OsiDblParam key, double value);
    00059     // Set a string parameter
    00060     bool setStrParam(OsiStrParam key, const std::string & value);
    00061     // Get an integer parameter
    00062     bool getIntParam(OsiIntParam key, int& value) const;
    00063     // Get an double parameter
    00064     bool getDblParam(OsiDblParam key, double& value) const;
    00065     // Get a string parameter
    00066     bool getStrParam(OsiStrParam key, std::string& value) const;
    00068
    00069   //---------------------------------------------------------------------------
    00071
    00072
    00073     virtual bool isAbandoned() const;
    00075     virtual bool isProvenOptimal() const;
    00077     virtual bool isProvenPrimalInfeasible() const;
    00079     virtual bool isProvenDualInfeasible() const;
    00081     virtual bool isPrimalObjectiveLimitReached() const;
    00083     virtual bool isDualObjectiveLimitReached() const;
    00085     virtual bool isIterationLimitReached() const;
    00087
    00088   //---------------------------------------------------------------------------
    00097   CoinWarmStart* getEmptyWarmStart () const;
    00098
    00100
    00101     virtual CoinWarmStart* getWarmStart() const;
    00104     virtual bool setWarmStart(const CoinWarmStart* warmstart);
    00106
    00107   //---------------------------------------------------------------------------
    00114
    00115     virtual void markHotStart();
    00117     virtual void solveFromHotStart();
    00119     virtual void unmarkHotStart();
    00121
    00122   //---------------------------------------------------------------------------
    00137
    00138       virtual int getNumCols() const;
    00139
    00141       virtual int getNumRows() const;
    00142
    00144       virtual int getNumElements() const;
    00145
    00147       virtual const double * getColLower() const;
    00148
    00150       virtual const double * getColUpper() const;
    00151
    00161       virtual const char * getRowSense() const;
    00162
    00171       virtual const double * getRightHandSide() const;
    00172
    00181       virtual const double * getRowRange() const;
    00182
    00184       virtual const double * getRowLower() const;
    00185
    00187       virtual const double * getRowUpper() const;
    00188
    00190       virtual const double * getObjCoefficients() const;
    00191
    00193       virtual double getObjSense() const;
    00194
    00196       virtual bool isContinuous(int colNumber) const;
    00197
    00198 #if 0
    00200       virtual bool isBinary(int columnNumber) const;
    00201
    00206       virtual bool isInteger(int columnNumber) const;
    00207
    00209       virtual bool isIntegerNonBinary(int columnNumber) const;
    00210
    00212       virtual bool isFreeBinary(int columnNumber) const;
    00213 #endif
    00214
    00216       virtual const CoinPackedMatrix * getMatrixByRow() const;
    00217
    00219       virtual const CoinPackedMatrix * getMatrixByCol() const;
    00220
    00222       virtual double getInfinity() const;
    00224
    00227
    00228       virtual const double * getColSolution() const;
    00229
    00231       virtual const double * getRowPrice() const;
    00232
    00234       virtual const double * getReducedCost() const;
    00235
    00238       virtual const double * getRowActivity() const;
    00239
    00241       virtual double getObjValue() const;
    00242
    00245       virtual int getIterationCount() const;
    00246
    00264       virtual std::vector<double*> getDualRays(int maxNumRays,
    00265                                                bool fullRay=false) const;
    00277       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
    00278
    00279 #if 0
    00280
    00282       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
    00283         const;
    00284 #endif
    00285
    00286
    00287
    00288   //---------------------------------------------------------------------------
    00289
    00292     //-------------------------------------------------------------------------
    00296       virtual void setObjCoeff( int elementIndex, double elementValue );
    00297
    00299       virtual void setObjCoeffSet(const int* indexFirst,
    00300                                   const int* indexLast,
    00301                                   const double* coeffList);
    00302
    00305       virtual void setColLower( int elementIndex, double elementValue );
    00306
    00309       virtual void setColUpper( int elementIndex, double elementValue );
    00310
    00314       virtual void setColBounds( int elementIndex,
    00315                                  double lower, double upper );
    00316
    00324       virtual void setColSetBounds(const int* indexFirst,
    00325                                    const int* indexLast,
    00326                                    const double* boundList);
    00327
    00330       virtual void setRowLower( int elementIndex, double elementValue );
    00331
    00334       virtual void setRowUpper( int elementIndex, double elementValue );
    00335
    00339       virtual void setRowBounds( int elementIndex,
    00340                                  double lower, double upper );
    00341
    00343       virtual void setRowType(int index, char sense, double rightHandSide,
    00344                               double range);
    00345
    00353       virtual void setRowSetBounds(const int* indexFirst,
    00354                                    const int* indexLast,
    00355                                    const double* boundList);
    00356
    00366       virtual void setRowSetTypes(const int* indexFirst,
    00367                                   const int* indexLast,
    00368                                   const char* senseList,
    00369                                   const double* rhsList,
    00370                                   const double* rangeList);
    00372
    00373     //-------------------------------------------------------------------------
    00377       virtual void setContinuous(int index);
    00379       virtual void setInteger(int index);
    00382       virtual void setContinuous(const int* indices, int len);
    00385       virtual void setInteger(const int* indices, int len);
    00387
    00388     //-------------------------------------------------------------------------
    00390     virtual void setObjSense(double s);
    00391
    00402     virtual void setColSolution(const double * colsol);
    00403
    00414     virtual void setRowPrice(const double * rowprice);
    00415
    00416     //-------------------------------------------------------------------------
    00422       virtual void addCol(const CoinPackedVectorBase& vec,
    00423                           const double collb, const double colub,
    00424                           const double obj);
    00426       virtual void addCols(const int numcols,
    00427                            const CoinPackedVectorBase * const * cols,
    00428                            const double* collb, const double* colub,
    00429                            const double* obj);
    00431       virtual void deleteCols(const int num, const int * colIndices);
    00432
    00434       virtual void addRow(const CoinPackedVectorBase& vec,
    00435                           const double rowlb, const double rowub);
    00437       virtual void addRow(const CoinPackedVectorBase& vec,
    00438                           const char rowsen, const double rowrhs,
    00439                           const double rowrng);
    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);
    00450       virtual void deleteRows(const int num, const int * rowIndices);
    00451
    00452 #if 0
    00453   // ??? implemented in OsiSolverInterface
    00454       //-----------------------------------------------------------------------
    00476       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
    00477                                             double effectivenessLb = 0.0);
    00478 #endif
    00479
    00480
    00481
    00482   //---------------------------------------------------------------------------
    00483
    00497     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00498                              const double* collb, const double* colub,
    00499                              const double* obj,
    00500                              const double* rowlb, const double* rowub);
    00501
    00509     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00510                                double*& collb, double*& colub, double*& obj,
    00511                                double*& rowlb, double*& rowub);
    00512
    00525     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00526                              const double* collb, const double* colub,
    00527                              const double* obj,
    00528                              const char* rowsen, const double* rowrhs,
    00529                              const double* rowrng);
    00530
    00538     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00539                                double*& collb, double*& colub, double*& obj,
    00540                                char*& rowsen, double*& rowrhs,
    00541                                double*& rowrng);
    00542
    00545     virtual void loadProblem(const int numcols, const int numrows,
    00546                              const int* start, const int* index,
    00547                              const double* value,
    00548                              const double* collb, const double* colub,
    00549                              const double* obj,
    00550                              const double* rowlb, const double* rowub);
    00551
    00554     virtual void loadProblem(const int numcols, const int numrows,
    00555                              const int* start, const int* index,
    00556                              const double* value,
    00557                              const double* collb, const double* colub,
    00558                              const double* obj,
    00559                              const char* rowsen, const double* rowrhs,
    00560                              const double* rowrng);
    00561
    00563     virtual int readMps(const char *filename,
    00564                          const char *extension = "mps");
    00565
    00570     virtual void writeMps(const char *filename,
    00571                           const char *extension = "mps",
    00572                           double objSense=0.0) const;
    00574
    00582     void passInMessageHandler(CoinMessageHandler * handler);
    00584
    00585   //---------------------------------------------------------------------------
    00586
    00592   enum keepCachedFlag
    00593   {
    00595     KEEPCACHED_NONE    = 0,
    00597     KEEPCACHED_COLUMN  = 1,
    00599     KEEPCACHED_ROW     = 2,
    00601     KEEPCACHED_MATRIX  = 4,
    00603     KEEPCACHED_RESULTS = 8,
    00605     KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
    00607     KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
    00609     FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & !KEEPCACHED_COLUMN,
    00611     FREECACHED_ROW     = KEEPCACHED_PROBLEM & !KEEPCACHED_ROW,
    00613     FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & !KEEPCACHED_MATRIX,
    00615     FREECACHED_RESULTS = KEEPCACHED_ALL & !KEEPCACHED_RESULTS
    00616   };
    00617
    00618   MSKtask_t getLpPtr( int keepCached = KEEPCACHED_NONE );
    00619
    00621
    00622   MSKenv_t getEnvironmentPtr();
    00624
    00626   const char* getCtype() const;
    00627
    00637   static void incrementInstanceCounter();
    00638
    00647   static void decrementInstanceCounter();
    00648
    00650   static unsigned int getNumInstances();
    00652
    00653
    00656
    00657
    00658
    00659   OsiMskSolverInterface(MSKenv_t mskenv = NULL);
    00660
    00662   virtual OsiSolverInterface * clone(bool copyData = true) const;
    00663
    00665   OsiMskSolverInterface( const OsiMskSolverInterface& );
    00666
    00668   OsiMskSolverInterface& operator=( const OsiMskSolverInterface& rhs );
    00669
    00671   virtual ~OsiMskSolverInterface();
    00673
    00674 protected:
    00675
    00678
    00679   virtual void applyRowCut( const OsiRowCut & rc );
    00680
    00684   virtual void applyColCut( const OsiColCut & cc );
    00686
    00687 private:
    00690
    00691   void switchToLP();
    00692
    00694   void switchToMIP();
    00695
    00697   void resizeColType( int minsize );
    00698
    00700   void freeColType();
    00701
    00702   bool definedSolution(int solution) const;
    00703
    00704   int solverUsed() const;
    00705
    00707
    00710
    00711   static MSKenv_t env_ ;
    00712
    00714   //static unsigned int numInstances_;
    00716   static unsigned int numInstances_;
    00717
    00720
    00721   int Mskerr;
    00722   int MSKsolverused_;
    00723   double ObjOffset_;
    00724
    00725   int InitialSolver;
    00726
    00728   public: MSKtask_t getMutableLpPtr() const;
    00729
    00731   void gutsOfCopy( const OsiMskSolverInterface & source );
    00732
    00734   void gutsOfConstructor();
    00735
    00737   void gutsOfDestructor();
    00738
    00740   void freeCachedColRim();
    00741
    00743   void freeCachedRowRim();
    00744
    00746   void freeCachedResults();
    00747
    00749   void freeCachedMatrix();
    00750
    00752   void freeCachedData( int keepCached = KEEPCACHED_NONE );
    00753
    00755   void freeAllMemory();
    00756
    00758   void printBounds();
    00761
    00762   mutable MSKtask_t task_;
    00763
    00765   int *hotStartCStat_;
    00766   int hotStartCStatSize_;
    00767   int *hotStartRStat_;
    00768   int hotStartRStatSize_;
    00769   int hotStartMaxIteration_;
    00770
    00773
    00774   mutable double  *obj_;
    00775
    00777   mutable double  *collower_;
    00778
    00780   mutable double  *colupper_;
    00781
    00783   mutable char    *rowsense_;
    00784
    00786   mutable double  *rhs_;
    00787
    00789   mutable double  *rowrange_;
    00790
    00792   mutable double  *rowlower_;
    00793
    00795   mutable double  *rowupper_;
    00796
    00798   mutable double  *colsol_;
    00799
    00801   mutable double  *rowsol_;
    00802
    00804   mutable double  *redcost_;
    00805
    00807   mutable double  *rowact_;
    00808
    00810   mutable CoinPackedMatrix *matrixByRow_;
    00811
    00813   mutable CoinPackedMatrix *matrixByCol_;
    00815
    00818
    00819   char            *coltype_;
    00820
    00822   int             coltypesize_;
    00823
    00825   mutable bool    probtypemip_;
    00826
    00828 };
    00829
    00830 //#############################################################################
    00833 void OsiMskSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00834
    00835 #endif