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

- File List
- File Members

# /home/coin/svn-release/Bcps-0.93.10/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 // This code is licensed under the terms of the Eclipse Public License (EPL).
    00010
    00011 #ifndef OsiMskSolverInterface_H
    00012 #define OsiMskSolverInterface_H
    00013
    00014 #include "OsiSolverInterface.hpp"
    00015
    00016 typedef void* MSKtask_t;
    00017 typedef void* MSKenv_t;
    00018
    00019 /* MOSEK Solver Interface
    00020    Instantiation of OsiMskSolverInterface for MOSEK
    00021 */
    00022
    00023 class OsiMskSolverInterface :
    00024   virtual public OsiSolverInterface {
    00025   friend void OsiMskSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00026 public:
    00027
    00028   //---------------------------------------------------------------------------
    00031
    00032   virtual void initialSolve();
    00033
    00035   virtual void resolve();
    00036
    00038   virtual void branchAndBound();
    00040
    00041   //---------------------------------------------------------------------------
    00057     // Set an integer parameter
    00058     bool setIntParam(OsiIntParam key, int value);
    00059     // Set an double parameter
    00060     bool setDblParam(OsiDblParam key, double value);
    00061     // Set a string parameter
    00062     bool setStrParam(OsiStrParam key, const std::string & value);
    00063     // Get an integer parameter
    00064     bool getIntParam(OsiIntParam key, int& value) const;
    00065     // Get an double parameter
    00066     bool getDblParam(OsiDblParam key, double& value) const;
    00067     // Get a string parameter
    00068     bool getStrParam(OsiStrParam key, std::string& value) const;
    00070
    00071   //---------------------------------------------------------------------------
    00073
    00074
    00075     virtual bool isAbandoned() const;
    00077     virtual bool isProvenOptimal() const;
    00079     virtual bool isProvenPrimalInfeasible() const;
    00081     virtual bool isProvenDualInfeasible() const;
    00083     virtual bool isPrimalObjectiveLimitReached() const;
    00085     virtual bool isDualObjectiveLimitReached() const;
    00087     virtual bool isIterationLimitReached() const;
    00089     virtual bool isLicenseError() const;
    00091     int getRescode() const { return Mskerr; }
    00093
    00094   //---------------------------------------------------------------------------
    00103   CoinWarmStart* getEmptyWarmStart () const;
    00104
    00106
    00107     virtual CoinWarmStart* getWarmStart() const;
    00110     virtual bool setWarmStart(const CoinWarmStart* warmstart);
    00112
    00113   //---------------------------------------------------------------------------
    00120
    00121     virtual void markHotStart();
    00123     virtual void solveFromHotStart();
    00125     virtual void unmarkHotStart();
    00127
    00128   //---------------------------------------------------------------------------
    00143
    00144       virtual int getNumCols() const;
    00145
    00147       virtual int getNumRows() const;
    00148
    00150       virtual int getNumElements() const;
    00151
    00153       virtual const double * getColLower() const;
    00154
    00156       virtual const double * getColUpper() const;
    00157
    00167       virtual const char * getRowSense() const;
    00168
    00177       virtual const double * getRightHandSide() const;
    00178
    00187       virtual const double * getRowRange() const;
    00188
    00190       virtual const double * getRowLower() const;
    00191
    00193       virtual const double * getRowUpper() const;
    00194
    00196       virtual const double * getObjCoefficients() const;
    00197
    00199       virtual double getObjSense() const;
    00200
    00202       virtual bool isContinuous(int colNumber) const;
    00203
    00204 #if 0
    00206       virtual bool isBinary(int columnNumber) const;
    00207
    00212       virtual bool isInteger(int columnNumber) const;
    00213
    00215       virtual bool isIntegerNonBinary(int columnNumber) const;
    00216
    00218       virtual bool isFreeBinary(int columnNumber) const;
    00219 #endif
    00220
    00222       virtual const CoinPackedMatrix * getMatrixByRow() const;
    00223
    00225       virtual const CoinPackedMatrix * getMatrixByCol() const;
    00226
    00228       virtual double getInfinity() const;
    00230
    00233
    00234       virtual const double * getColSolution() const;
    00235
    00237       virtual const double * getRowPrice() const;
    00238
    00240       virtual const double * getReducedCost() const;
    00241
    00244       virtual const double * getRowActivity() const;
    00245
    00247       virtual double getObjValue() const;
    00248
    00251       virtual int getIterationCount() const;
    00252
    00270       virtual std::vector<double*> getDualRays(int maxNumRays,
    00271                                                bool fullRay=false) const;
    00283       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
    00284
    00285 #if 0
    00286
    00288       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
    00289         const;
    00290 #endif
    00291
    00292
    00293
    00294   //---------------------------------------------------------------------------
    00295
    00298     //-------------------------------------------------------------------------
    00302       virtual void setObjCoeff( int elementIndex, double elementValue );
    00303
    00305       virtual void setObjCoeffSet(const int* indexFirst,
    00306                                   const int* indexLast,
    00307                                   const double* coeffList);
    00308
    00311       virtual void setColLower( int elementIndex, double elementValue );
    00312
    00315       virtual void setColUpper( int elementIndex, double elementValue );
    00316
    00320       virtual void setColBounds( int elementIndex,
    00321                                  double lower, double upper );
    00322
    00330       virtual void setColSetBounds(const int* indexFirst,
    00331                                    const int* indexLast,
    00332                                    const double* boundList);
    00333
    00336       virtual void setRowLower( int elementIndex, double elementValue );
    00337
    00340       virtual void setRowUpper( int elementIndex, double elementValue );
    00341
    00345       virtual void setRowBounds( int elementIndex,
    00346                                  double lower, double upper );
    00347
    00349       virtual void setRowType(int index, char sense, double rightHandSide,
    00350                               double range);
    00351
    00359       virtual void setRowSetBounds(const int* indexFirst,
    00360                                    const int* indexLast,
    00361                                    const double* boundList);
    00362
    00372       virtual void setRowSetTypes(const int* indexFirst,
    00373                                   const int* indexLast,
    00374                                   const char* senseList,
    00375                                   const double* rhsList,
    00376                                   const double* rangeList);
    00378
    00379     //-------------------------------------------------------------------------
    00383       virtual void setContinuous(int index);
    00385       virtual void setInteger(int index);
    00388       virtual void setContinuous(const int* indices, int len);
    00391       virtual void setInteger(const int* indices, int len);
    00393
    00394     //-------------------------------------------------------------------------
    00396     virtual void setObjSense(double s);
    00397
    00408     virtual void setColSolution(const double * colsol);
    00409
    00420     virtual void setRowPrice(const double * rowprice);
    00421
    00422     //-------------------------------------------------------------------------
    00428       virtual void addCol(const CoinPackedVectorBase& vec,
    00429                           const double collb, const double colub,
    00430                           const double obj);
    00432       virtual void addCols(const int numcols,
    00433                            const CoinPackedVectorBase * const * cols,
    00434                            const double* collb, const double* colub,
    00435                            const double* obj);
    00437       virtual void deleteCols(const int num, const int * colIndices);
    00438
    00440       virtual void addRow(const CoinPackedVectorBase& vec,
    00441                           const double rowlb, const double rowub);
    00443       virtual void addRow(const CoinPackedVectorBase& vec,
    00444                           const char rowsen, const double rowrhs,
    00445                           const double rowrng);
    00447       virtual void addRows(const int numrows,
    00448                            const CoinPackedVectorBase * const * rows,
    00449                            const double* rowlb, const double* rowub);
    00451       virtual void addRows(const int numrows,
    00452                            const CoinPackedVectorBase * const * rows,
    00453                            const char* rowsen, const double* rowrhs,
    00454                            const double* rowrng);
    00456       virtual void deleteRows(const int num, const int * rowIndices);
    00457
    00458 #if 0
    00459   // ??? implemented in OsiSolverInterface
    00460       //-----------------------------------------------------------------------
    00482       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
    00483                                             double effectivenessLb = 0.0);
    00484 #endif
    00485
    00486
    00487
    00488   //---------------------------------------------------------------------------
    00489
    00503     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00504                              const double* collb, const double* colub,
    00505                              const double* obj,
    00506                              const double* rowlb, const double* rowub);
    00507
    00515     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00516                                double*& collb, double*& colub, double*& obj,
    00517                                double*& rowlb, double*& rowub);
    00518
    00531     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00532                              const double* collb, const double* colub,
    00533                              const double* obj,
    00534                              const char* rowsen, const double* rowrhs,
    00535                              const double* rowrng);
    00536
    00544     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00545                                double*& collb, double*& colub, double*& obj,
    00546                                char*& rowsen, double*& rowrhs,
    00547                                double*& rowrng);
    00548
    00551     virtual void loadProblem(const int numcols, const int numrows,
    00552                              const int* start, const int* index,
    00553                              const double* value,
    00554                              const double* collb, const double* colub,
    00555                              const double* obj,
    00556                              const double* rowlb, const double* rowub);
    00557
    00560     virtual void loadProblem(const int numcols, const int numrows,
    00561                              const int* start, const int* index,
    00562                              const double* value,
    00563                              const double* collb, const double* colub,
    00564                              const double* obj,
    00565                              const char* rowsen, const double* rowrhs,
    00566                              const double* rowrng);
    00567
    00569     virtual int readMps(const char *filename,
    00570                          const char *extension = "mps");
    00571
    00576     virtual void writeMps(const char *filename,
    00577                           const char *extension = "mps",
    00578                           double objSense=0.0) const;
    00580
    00588     void passInMessageHandler(CoinMessageHandler * handler);
    00590
    00591   //---------------------------------------------------------------------------
    00592
    00598   enum keepCachedFlag
    00599   {
    00601     KEEPCACHED_NONE    = 0,
    00603     KEEPCACHED_COLUMN  = 1,
    00605     KEEPCACHED_ROW     = 2,
    00607     KEEPCACHED_MATRIX  = 4,
    00609     KEEPCACHED_RESULTS = 8,
    00611     KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
    00613     KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
    00615     FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & ~KEEPCACHED_COLUMN,
    00617     FREECACHED_ROW     = KEEPCACHED_PROBLEM & ~KEEPCACHED_ROW,
    00619     FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & ~KEEPCACHED_MATRIX,
    00621     FREECACHED_RESULTS = KEEPCACHED_ALL & ~KEEPCACHED_RESULTS
    00622   };
    00623
    00624   MSKtask_t getLpPtr( int keepCached = KEEPCACHED_NONE );
    00625
    00627
    00628   MSKenv_t getEnvironmentPtr();
    00630
    00632   const char* getCtype() const;
    00633
    00643   static void incrementInstanceCounter();
    00644
    00653   static void decrementInstanceCounter();
    00654
    00656   static unsigned int getNumInstances();
    00658
    00659
    00662
    00663
    00664
    00665   OsiMskSolverInterface(MSKenv_t mskenv = NULL);
    00666
    00668   virtual OsiSolverInterface * clone(bool copyData = true) const;
    00669
    00671   OsiMskSolverInterface( const OsiMskSolverInterface& );
    00672
    00674   OsiMskSolverInterface& operator=( const OsiMskSolverInterface& rhs );
    00675
    00677   virtual ~OsiMskSolverInterface();
    00679
    00680 protected:
    00681
    00684
    00685   virtual void applyRowCut( const OsiRowCut & rc );
    00686
    00690   virtual void applyColCut( const OsiColCut & cc );
    00692
    00693 private:
    00696
    00697   void switchToLP();
    00698
    00700   void switchToMIP();
    00701
    00703   void resizeColType( int minsize );
    00704
    00706   void freeColType();
    00707
    00708   bool definedSolution(int solution) const;
    00709
    00710   int solverUsed() const;
    00711
    00713
    00716
    00717   static MSKenv_t env_ ;
    00718
    00720   //static unsigned int numInstances_;
    00722   static unsigned int numInstances_;
    00723
    00726
    00727   int Mskerr;
    00728   int MSKsolverused_;
    00729   double ObjOffset_;
    00730
    00731   int InitialSolver;
    00732
    00734   public: MSKtask_t getMutableLpPtr() const;
    00735
    00737   void gutsOfCopy( const OsiMskSolverInterface & source );
    00738
    00740   void gutsOfConstructor();
    00741
    00743   void gutsOfDestructor();
    00744
    00746   void freeCachedColRim();
    00747
    00749   void freeCachedRowRim();
    00750
    00752   void freeCachedResults();
    00753
    00755   void freeCachedMatrix();
    00756
    00758   void freeCachedData( int keepCached = KEEPCACHED_NONE );
    00759
    00761   void freeAllMemory();
    00762
    00765
    00766   mutable MSKtask_t task_;
    00767
    00769   int *hotStartCStat_;
    00770   int hotStartCStatSize_;
    00771   int *hotStartRStat_;
    00772   int hotStartRStatSize_;
    00773   int hotStartMaxIteration_;
    00774
    00777
    00778   mutable double  *obj_;
    00779
    00781   mutable double  *collower_;
    00782
    00784   mutable double  *colupper_;
    00785
    00787   mutable char    *rowsense_;
    00788
    00790   mutable double  *rhs_;
    00791
    00793   mutable double  *rowrange_;
    00794
    00796   mutable double  *rowlower_;
    00797
    00799   mutable double  *rowupper_;
    00800
    00802   mutable double  *colsol_;
    00803
    00805   mutable double  *rowsol_;
    00806
    00808   mutable double  *redcost_;
    00809
    00811   mutable double  *rowact_;
    00812
    00814   mutable CoinPackedMatrix *matrixByRow_;
    00815
    00817   mutable CoinPackedMatrix *matrixByCol_;
    00819
    00822
    00823   char            *coltype_;
    00824
    00826   int             coltypesize_;
    00827
    00829   mutable bool    probtypemip_;
    00830
    00832 };
    00833
    00834 //#############################################################################
    00836 void OsiMskSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00837
    00838 #endif