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

- File List
- File Members

# /home/coin/SVN-release/Bcps-0.91.0/Osi/src/OsiMsk/OsiMskSolverInterface.hpp

Go to the documentation of this file.

    00001 // Osi interface for Mosek ver. 3.1
    00002 // Lower versions are not supported
    00003 //-----------------------------------------------------------------------------
    00004 // name:     OSI Interface for MOSEK
    00005 // author:   Bo Jensen
    00006 //
    00007 //           email: bo.jensen@MOSEK.com
    00008 // date:     ?
    00009 //-----------------------------------------------------------------------------
    00010
    00011 #ifndef OsiMskSolverInterface_H
    00012 #define OsiMskSolverInterface_H
    00013
    00014 #include "mosek.h"
    00015 #include <string>
    00016 #include "OsiSolverInterface.hpp"
    00017 #include "CoinPackedMatrix.hpp"
    00018 #include "CoinWarmStartBasis.hpp"
    00019
    00020 /* MOSEK Solver Interface
    00021    Instantiation of OsiMskSolverInterface for MOSEK
    00022 */
    00023
    00024 class OsiMskSolverInterface :
    00025   virtual public OsiSolverInterface {
    00026   friend void OsiMskSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00027 public:
    00028
    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;
    00090
    00091   //---------------------------------------------------------------------------
    00100   inline CoinWarmStart *getEmptyWarmStart () const
    00101   { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; }
    00102
    00104
    00105     virtual CoinWarmStart* getWarmStart() const;
    00108     virtual bool setWarmStart(const CoinWarmStart* warmstart);
    00110
    00111   //---------------------------------------------------------------------------
    00118
    00119     virtual void markHotStart();
    00121     virtual void solveFromHotStart();
    00123     virtual void unmarkHotStart();
    00125
    00126   //---------------------------------------------------------------------------
    00141
    00142       virtual int getNumCols() const;
    00143
    00145       virtual int getNumRows() const;
    00146
    00148       virtual int getNumElements() const;
    00149
    00151       virtual const double * getColLower() const;
    00152
    00154       virtual const double * getColUpper() const;
    00155
    00165       virtual const char * getRowSense() const;
    00166
    00175       virtual const double * getRightHandSide() const;
    00176
    00185       virtual const double * getRowRange() const;
    00186
    00188       virtual const double * getRowLower() const;
    00189
    00191       virtual const double * getRowUpper() const;
    00192
    00194       virtual const double * getObjCoefficients() const;
    00195
    00197       virtual double getObjSense() const;
    00198
    00200       virtual bool isContinuous(int colNumber) const;
    00201
    00202 #if 0
    00204       virtual bool isBinary(int columnNumber) const;
    00205
    00210       virtual bool isInteger(int columnNumber) const;
    00211
    00213       virtual bool isIntegerNonBinary(int columnNumber) const;
    00214
    00216       virtual bool isFreeBinary(int columnNumber) const;
    00217 #endif
    00218
    00220       virtual const CoinPackedMatrix * getMatrixByRow() const;
    00221
    00223       virtual const CoinPackedMatrix * getMatrixByCol() const;
    00224
    00226       virtual double getInfinity() const;
    00228
    00231
    00232       virtual const double * getColSolution() const;
    00233
    00235       virtual const double * getRowPrice() const;
    00236
    00238       virtual const double * getReducedCost() const;
    00239
    00242       virtual const double * getRowActivity() const;
    00243
    00245       virtual double getObjValue() const;
    00246
    00249       virtual int getIterationCount() const;
    00250
    00262       virtual std::vector<double*> getDualRays(int maxNumRays) const;
    00274       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
    00275
    00276 #if 0
    00277
    00279       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
    00280         const;
    00281 #endif
    00282
    00283
    00284
    00285   //---------------------------------------------------------------------------
    00286
    00289     //-------------------------------------------------------------------------
    00293       virtual void setObjCoeff( int elementIndex, double elementValue );
    00294
    00296       virtual void setObjCoeffSet(const int* indexFirst,
    00297                                   const int* indexLast,
    00298                                   const double* coeffList);
    00299
    00302       virtual void setColLower( int elementIndex, double elementValue );
    00303
    00306       virtual void setColUpper( int elementIndex, double elementValue );
    00307
    00311       virtual void setColBounds( int elementIndex,
    00312                                  double lower, double upper );
    00313
    00321       virtual void setColSetBounds(const int* indexFirst,
    00322                                    const int* indexLast,
    00323                                    const double* boundList);
    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
    00350       virtual void setRowSetBounds(const int* indexFirst,
    00351                                    const int* indexLast,
    00352                                    const double* boundList);
    00353
    00363       virtual void setRowSetTypes(const int* indexFirst,
    00364                                   const int* indexLast,
    00365                                   const char* senseList,
    00366                                   const double* rhsList,
    00367                                   const double* rangeList);
    00369
    00370     //-------------------------------------------------------------------------
    00374       virtual void setContinuous(int index);
    00376       virtual void setInteger(int index);
    00379       virtual void setContinuous(const int* indices, int len);
    00382       virtual void setInteger(const int* indices, int len);
    00384
    00385     //-------------------------------------------------------------------------
    00387     virtual void setObjSense(double s);
    00388
    00399     virtual void setColSolution(const double * colsol);
    00400
    00411     virtual void setRowPrice(const double * rowprice);
    00412
    00413     //-------------------------------------------------------------------------
    00419       virtual void addCol(const CoinPackedVectorBase& vec,
    00420                           const double collb, const double colub,
    00421                           const double obj);
    00423       virtual void addCols(const int numcols,
    00424                            const CoinPackedVectorBase * const * cols,
    00425                            const double* collb, const double* colub,
    00426                            const double* obj);
    00428       virtual void deleteCols(const int num, const int * colIndices);
    00429
    00431       virtual void addRow(const CoinPackedVectorBase& vec,
    00432                           const double rowlb, const double rowub);
    00434       virtual void addRow(const CoinPackedVectorBase& vec,
    00435                           const char rowsen, const double rowrhs,
    00436                           const double rowrng);
    00438       virtual void addRows(const int numrows,
    00439                            const CoinPackedVectorBase * const * rows,
    00440                            const double* rowlb, const double* rowub);
    00442       virtual void addRows(const int numrows,
    00443                            const CoinPackedVectorBase * const * rows,
    00444                            const char* rowsen, const double* rowrhs,
    00445                            const double* rowrng);
    00447       virtual void deleteRows(const int num, const int * rowIndices);
    00448
    00449 #if 0
    00450   // ??? implemented in OsiSolverInterface
    00451       //-----------------------------------------------------------------------
    00473       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
    00474                                             double effectivenessLb = 0.0);
    00475 #endif
    00476
    00477
    00478
    00479   //---------------------------------------------------------------------------
    00480
    00494     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00495                              const double* collb, const double* colub,
    00496                              const double* obj,
    00497                              const double* rowlb, const double* rowub);
    00498
    00506     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00507                                double*& collb, double*& colub, double*& obj,
    00508                                double*& rowlb, double*& rowub);
    00509
    00522     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00523                              const double* collb, const double* colub,
    00524                              const double* obj,
    00525                              const char* rowsen, const double* rowrhs,
    00526                              const double* rowrng);
    00527
    00535     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00536                                double*& collb, double*& colub, double*& obj,
    00537                                char*& rowsen, double*& rowrhs,
    00538                                double*& rowrng);
    00539
    00542     virtual void loadProblem(const int numcols, const int numrows,
    00543                              const int* start, const int* index,
    00544                              const double* value,
    00545                              const double* collb, const double* colub,
    00546                              const double* obj,
    00547                              const double* rowlb, const double* rowub);
    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 char* rowsen, const double* rowrhs,
    00557                              const double* rowrng);
    00558
    00560     virtual int readMps(const char *filename,
    00561                          const char *extension = "mps");
    00562
    00567     virtual void writeMps(const char *filename,
    00568                           const char *extension = "mps",
    00569                           double objSense=0.0) const;
    00571
    00572   //---------------------------------------------------------------------------
    00573
    00579   enum keepCachedFlag
    00580   {
    00582     KEEPCACHED_NONE    = 0,
    00584     KEEPCACHED_COLUMN  = 1,
    00586     KEEPCACHED_ROW     = 2,
    00588     KEEPCACHED_MATRIX  = 4,
    00590     KEEPCACHED_RESULTS = 8,
    00592     KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
    00594     KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
    00596     FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & !KEEPCACHED_COLUMN,
    00598     FREECACHED_ROW     = KEEPCACHED_PROBLEM & !KEEPCACHED_ROW,
    00600     FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & !KEEPCACHED_MATRIX,
    00602     FREECACHED_RESULTS = KEEPCACHED_ALL & !KEEPCACHED_RESULTS
    00603   };
    00604
    00605   MSKtask_t getLpPtr( int keepCached = KEEPCACHED_NONE );
    00606
    00608
    00609   MSKenv_t getEnvironmentPtr();
    00611
    00613   const char* getCtype() const;
    00614
    00624   static void incrementInstanceCounter();
    00625
    00634   static void decrementInstanceCounter();
    00635
    00637   static unsigned int getNumInstances();
    00639
    00640
    00643
    00644   OsiMskSolverInterface();
    00645
    00647   virtual OsiSolverInterface * clone(bool copyData = true) const;
    00648
    00650   OsiMskSolverInterface( const OsiMskSolverInterface& );
    00651
    00653   OsiMskSolverInterface& operator=( const OsiMskSolverInterface& rhs );
    00654
    00656   virtual ~OsiMskSolverInterface();
    00658
    00659 protected:
    00660
    00663
    00664   virtual void applyRowCut( const OsiRowCut & rc );
    00665
    00669   virtual void applyColCut( const OsiColCut & cc );
    00671
    00672 private:
    00675
    00676   void switchToLP();
    00677
    00679   void switchToMIP();
    00680
    00682   void resizeColType( int minsize );
    00683
    00685   void freeColType();
    00686
    00687   bool definedSolution(int solution) const;
    00688
    00689   int solverUsed() const;
    00690
    00692
    00695
    00696   static MSKenv_t env_ ;
    00697
    00699   //static unsigned int numInstances_;
    00701   static unsigned int numInstances_;
    00702
    00705
    00706   int Mskerr;
    00707   int MSKsolverused_;
    00708
    00709   int InitialSolver;
    00710
    00712   public: MSKtask_t getMutableLpPtr() const;
    00713
    00715   void gutsOfCopy( const OsiMskSolverInterface & source );
    00716
    00718   void gutsOfConstructor();
    00719
    00721   void gutsOfDestructor();
    00722
    00724   void freeCachedColRim();
    00725
    00727   void freeCachedRowRim();
    00728
    00730   void freeCachedResults();
    00731
    00733   void freeCachedMatrix();
    00734
    00736   void freeCachedData( int keepCached = KEEPCACHED_NONE );
    00737
    00739   void freeAllMemory();
    00740
    00742   void printBounds();
    00745
    00746   mutable MSKtask_t task_;
    00747
    00749   int *hotStartCStat_;
    00750   int hotStartCStatSize_;
    00751   int *hotStartRStat_;
    00752   int hotStartRStatSize_;
    00753   int hotStartMaxIteration_;
    00754
    00757
    00758   mutable double  *obj_;
    00759
    00761   mutable double  *collower_;
    00762
    00764   mutable double  *colupper_;
    00765
    00767   mutable char    *rowsense_;
    00768
    00770   mutable double  *rhs_;
    00771
    00773   mutable double  *rowrange_;
    00774
    00776   mutable double  *rowlower_;
    00777
    00779   mutable double  *rowupper_;
    00780
    00782   mutable double  *colsol_;
    00783
    00785   mutable double  *rowsol_;
    00786
    00788   mutable double  *redcost_;
    00789
    00791   mutable double  *rowact_;
    00792
    00794   mutable CoinPackedMatrix *matrixByRow_;
    00795
    00797   mutable CoinPackedMatrix *matrixByCol_;
    00799
    00802
    00803   char            *coltype_;
    00804
    00806   int             coltypesize_;
    00807
    00809   mutable bool    probtypemip_;
    00810
    00812 };
    00813
    00814 //#############################################################################
    00817 void OsiMskSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
    00818
    00819 #endif