/home/coin/SVN-release/Osi-0.102.2/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   
00258       virtual std::vector<double*> getDualRays(int maxNumRays) const;
00270       virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
00271   
00272 #if 0
00273 
00275       virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
00276         const;
00277 #endif
00278 
00279 
00280   
00281   //---------------------------------------------------------------------------
00282 
00285     //-------------------------------------------------------------------------
00289       virtual void setObjCoeff( int elementIndex, double elementValue );
00290 
00292       virtual void setObjCoeffSet(const int* indexFirst,
00293                                   const int* indexLast,
00294                                   const double* coeffList);
00295 
00298       virtual void setColLower( int elementIndex, double elementValue );
00299       
00302       virtual void setColUpper( int elementIndex, double elementValue );
00303       
00307       virtual void setColBounds( int elementIndex,
00308                                  double lower, double upper );
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     
00346       virtual void setRowSetBounds(const int* indexFirst,
00347                                    const int* indexLast,
00348                                    const double* boundList);
00349     
00359       virtual void setRowSetTypes(const int* indexFirst,
00360                                   const int* indexLast,
00361                                   const char* senseList,
00362                                   const double* rhsList,
00363                                   const double* rangeList);
00365     
00366     //-------------------------------------------------------------------------
00370       virtual void setContinuous(int index);
00372       virtual void setInteger(int index);
00375       virtual void setContinuous(const int* indices, int len);
00378       virtual void setInteger(const int* indices, int len);
00380     
00381     //-------------------------------------------------------------------------
00383     virtual void setObjSense(double s);
00384     
00395     virtual void setColSolution(const double * colsol);
00396     
00407     virtual void setRowPrice(const double * rowprice);
00408     
00409     //-------------------------------------------------------------------------
00415       virtual void addCol(const CoinPackedVectorBase& vec,
00416                           const double collb, const double colub,   
00417                           const double obj);
00419       virtual void addCols(const int numcols,
00420                            const CoinPackedVectorBase * const * cols,
00421                            const double* collb, const double* colub,   
00422                            const double* obj);
00424       virtual void deleteCols(const int num, const int * colIndices);
00425     
00427       virtual void addRow(const CoinPackedVectorBase& vec,
00428                           const double rowlb, const double rowub);
00430       virtual void addRow(const CoinPackedVectorBase& vec,
00431                           const char rowsen, const double rowrhs,   
00432                           const double rowrng);
00434       virtual void addRows(const int numrows,
00435                            const CoinPackedVectorBase * const * rows,
00436                            const double* rowlb, const double* rowub);
00438       virtual void addRows(const int numrows,
00439                            const CoinPackedVectorBase * const * rows,
00440                            const char* rowsen, const double* rowrhs,   
00441                            const double* rowrng);
00443       virtual void deleteRows(const int num, const int * rowIndices);
00444     
00445 #if 0
00446   // ??? implemented in OsiSolverInterface
00447       //-----------------------------------------------------------------------
00469       virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
00470                                             double effectivenessLb = 0.0);
00471 #endif
00472 
00473 
00474 
00475   //---------------------------------------------------------------------------
00476 
00490     virtual void loadProblem(const CoinPackedMatrix& matrix,
00491                              const double* collb, const double* colub,   
00492                              const double* obj,
00493                              const double* rowlb, const double* rowub);
00494                             
00502     virtual void assignProblem(CoinPackedMatrix*& matrix,
00503                                double*& collb, double*& colub, double*& obj,
00504                                double*& rowlb, double*& rowub);
00505 
00518     virtual void loadProblem(const CoinPackedMatrix& matrix,
00519                              const double* collb, const double* colub,
00520                              const double* obj,
00521                              const char* rowsen, const double* rowrhs,   
00522                              const double* rowrng);
00523 
00531     virtual void assignProblem(CoinPackedMatrix*& matrix,
00532                                double*& collb, double*& colub, double*& obj,
00533                                char*& rowsen, double*& rowrhs,
00534                                double*& rowrng);
00535 
00538     virtual void loadProblem(const int numcols, const int numrows,
00539                              const int* start, const int* index,
00540                              const double* value,
00541                              const double* collb, const double* colub,   
00542                              const double* obj,
00543                              const double* rowlb, const double* rowub);
00544 
00547     virtual void loadProblem(const int numcols, const int numrows,
00548                              const int* start, const int* index,
00549                              const double* value,
00550                              const double* collb, const double* colub,   
00551                              const double* obj,
00552                              const char* rowsen, const double* rowrhs,   
00553                              const double* rowrng);
00554 
00556     virtual int readMps(const char *filename,
00557                          const char *extension = "mps");
00558 
00563     virtual void writeMps(const char *filename,
00564                           const char *extension = "mps",
00565                           double objSense=0.0) const;
00567 
00575     void passInMessageHandler(CoinMessageHandler * handler);
00577 
00578   //---------------------------------------------------------------------------
00579 
00585   enum keepCachedFlag
00586   {
00588     KEEPCACHED_NONE    = 0,
00590     KEEPCACHED_COLUMN  = 1,
00592     KEEPCACHED_ROW     = 2,
00594     KEEPCACHED_MATRIX  = 4,
00596     KEEPCACHED_RESULTS = 8,
00598     KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
00600     KEEPCACHED_ALL     = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
00602     FREECACHED_COLUMN  = KEEPCACHED_PROBLEM & !KEEPCACHED_COLUMN,
00604     FREECACHED_ROW     = KEEPCACHED_PROBLEM & !KEEPCACHED_ROW,
00606     FREECACHED_MATRIX  = KEEPCACHED_PROBLEM & !KEEPCACHED_MATRIX,
00608     FREECACHED_RESULTS = KEEPCACHED_ALL & !KEEPCACHED_RESULTS
00609   };
00610 
00611   MSKtask_t getLpPtr( int keepCached = KEEPCACHED_NONE );
00612   
00614 
00615   MSKenv_t getEnvironmentPtr();
00617 
00619   const char* getCtype() const;
00620   
00630   static void incrementInstanceCounter(); 
00631   
00640   static void decrementInstanceCounter();
00641   
00643   static unsigned int getNumInstances();
00645 
00646   
00649 
00650 
00651 
00652   OsiMskSolverInterface(MSKenv_t mskenv = NULL); 
00653   
00655   virtual OsiSolverInterface * clone(bool copyData = true) const;
00656   
00658   OsiMskSolverInterface( const OsiMskSolverInterface& );
00659   
00661   OsiMskSolverInterface& operator=( const OsiMskSolverInterface& rhs );
00662   
00664   virtual ~OsiMskSolverInterface();
00666 
00667 protected:
00668   
00671 
00672   virtual void applyRowCut( const OsiRowCut & rc );
00673   
00677   virtual void applyColCut( const OsiColCut & cc );
00679   
00680 private:
00683 
00684   void switchToLP();
00685 
00687   void switchToMIP();
00688 
00690   void resizeColType( int minsize );
00691 
00693   void freeColType();
00694 
00695   bool definedSolution(int solution) const;
00696 
00697   int solverUsed() const;
00698 
00700 
00703 
00704   static MSKenv_t env_ ;
00705   
00707   //static unsigned int numInstances_;
00709   static unsigned int numInstances_;
00710   
00713   
00714   int Mskerr;
00715   int MSKsolverused_;
00716   double ObjOffset_;
00717 
00718   int InitialSolver;
00719 
00721   public: MSKtask_t getMutableLpPtr() const;
00722   
00724   void gutsOfCopy( const OsiMskSolverInterface & source );
00725   
00727   void gutsOfConstructor();
00728   
00730   void gutsOfDestructor();
00731 
00733   void freeCachedColRim();
00734 
00736   void freeCachedRowRim();
00737 
00739   void freeCachedResults();
00740   
00742   void freeCachedMatrix();
00743 
00745   void freeCachedData( int keepCached = KEEPCACHED_NONE );
00746 
00748   void freeAllMemory();
00749 
00751   void printBounds(); 
00754 
00755   mutable MSKtask_t task_;
00756 
00758   int *hotStartCStat_;
00759   int hotStartCStatSize_;
00760   int *hotStartRStat_;
00761   int hotStartRStatSize_;
00762   int hotStartMaxIteration_;
00763 
00766 
00767   mutable double  *obj_;
00768   
00770   mutable double  *collower_;
00771   
00773   mutable double  *colupper_;
00774   
00776   mutable char    *rowsense_;
00777   
00779   mutable double  *rhs_;
00780   
00782   mutable double  *rowrange_;
00783   
00785   mutable double  *rowlower_;
00786   
00788   mutable double  *rowupper_;
00789   
00791   mutable double  *colsol_;
00792   
00794   mutable double  *rowsol_;
00795 
00797   mutable double  *redcost_;
00798 
00800   mutable double  *rowact_;
00801 
00803   mutable CoinPackedMatrix *matrixByRow_;  
00804   
00806   mutable CoinPackedMatrix *matrixByCol_;  
00808 
00811 
00812   char            *coltype_;
00813 
00815   int             coltypesize_;
00816   
00818   mutable bool    probtypemip_;
00819 
00821 };
00822 
00823 //#############################################################################
00826 void OsiMskSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00827 
00828 #endif

Generated on Wed Apr 7 03:06:54 2010 by  doxygen 1.4.7