OsiMskSolverInterface.hpp
Go to the documentation of this file.
1 // Osi interface for Mosek ver. 5.0
2 // Lower versions are not supported
3 //-----------------------------------------------------------------------------
4 // name: OSI Interface for MOSEK
5 // author: Bo Jensen
6 // email: support@MOSEK.com
7 //-----------------------------------------------------------------------------
8 
9 #ifndef OsiMskSolverInterface_H
10 #define OsiMskSolverInterface_H
11 
12 #include "OsiSolverInterface.hpp"
13 
14 typedef void* MSKtask_t;
15 typedef void* MSKenv_t;
16 
17 /* MOSEK Solver Interface
18  Instantiation of OsiMskSolverInterface for MOSEK
19 */
20 
22  virtual public OsiSolverInterface {
23  friend void OsiMskSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
24 public:
25 
26  //---------------------------------------------------------------------------
29 
30  virtual void initialSolve();
31 
33  virtual void resolve();
34 
36  virtual void branchAndBound();
38 
39  //---------------------------------------------------------------------------
55  // Set an integer parameter
56  bool setIntParam(OsiIntParam key, int value);
57  // Set an double parameter
58  bool setDblParam(OsiDblParam key, double value);
59  // Set a string parameter
60  bool setStrParam(OsiStrParam key, const std::string & value);
61  // Get an integer parameter
62  bool getIntParam(OsiIntParam key, int& value) const;
63  // Get an double parameter
64  bool getDblParam(OsiDblParam key, double& value) const;
65  // Get a string parameter
66  bool getStrParam(OsiStrParam key, std::string& value) const;
68 
69  //---------------------------------------------------------------------------
71 
72 
73  virtual bool isAbandoned() const;
75  virtual bool isProvenOptimal() const;
77  virtual bool isProvenPrimalInfeasible() const;
79  virtual bool isProvenDualInfeasible() const;
81  virtual bool isPrimalObjectiveLimitReached() const;
83  virtual bool isDualObjectiveLimitReached() const;
85  virtual bool isIterationLimitReached() const;
87 
88  //---------------------------------------------------------------------------
97  CoinWarmStart* getEmptyWarmStart () const;
98 
100 
101  virtual CoinWarmStart* getWarmStart() const;
104  virtual bool setWarmStart(const CoinWarmStart* warmstart);
106 
107  //---------------------------------------------------------------------------
114 
115  virtual void markHotStart();
117  virtual void solveFromHotStart();
119  virtual void unmarkHotStart();
121 
122  //---------------------------------------------------------------------------
137 
138  virtual int getNumCols() const;
139 
141  virtual int getNumRows() const;
142 
144  virtual int getNumElements() const;
145 
147  virtual const double * getColLower() const;
148 
150  virtual const double * getColUpper() const;
151 
161  virtual const char * getRowSense() const;
162 
171  virtual const double * getRightHandSide() const;
172 
181  virtual const double * getRowRange() const;
182 
184  virtual const double * getRowLower() const;
185 
187  virtual const double * getRowUpper() const;
188 
190  virtual const double * getObjCoefficients() const;
191 
193  virtual double getObjSense() const;
194 
196  virtual bool isContinuous(int colNumber) const;
197 
198 #if 0
199 
200  virtual bool isBinary(int columnNumber) const;
201 
206  virtual bool isInteger(int columnNumber) const;
207 
209  virtual bool isIntegerNonBinary(int columnNumber) const;
210 
212  virtual bool isFreeBinary(int columnNumber) const;
213 #endif
214 
216  virtual const CoinPackedMatrix * getMatrixByRow() const;
217 
219  virtual const CoinPackedMatrix * getMatrixByCol() const;
220 
222  virtual double getInfinity() const;
224 
227 
228  virtual const double * getColSolution() const;
229 
231  virtual const double * getRowPrice() const;
232 
234  virtual const double * getReducedCost() const;
235 
238  virtual const double * getRowActivity() const;
239 
241  virtual double getObjValue() const;
242 
245  virtual int getIterationCount() const;
246 
258  virtual std::vector<double*> getDualRays(int maxNumRays) const;
270  virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
271 
272 #if 0
273 
275  virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
276  const;
277 #endif
278 
279 
280 
281  //---------------------------------------------------------------------------
282 
285  //-------------------------------------------------------------------------
289  virtual void setObjCoeff( int elementIndex, double elementValue );
290 
292  virtual void setObjCoeffSet(const int* indexFirst,
293  const int* indexLast,
294  const double* coeffList);
295 
298  virtual void setColLower( int elementIndex, double elementValue );
299 
302  virtual void setColUpper( int elementIndex, double elementValue );
303 
307  virtual void setColBounds( int elementIndex,
308  double lower, double upper );
309 
317  virtual void setColSetBounds(const int* indexFirst,
318  const int* indexLast,
319  const double* boundList);
320 
323  virtual void setRowLower( int elementIndex, double elementValue );
324 
327  virtual void setRowUpper( int elementIndex, double elementValue );
328 
332  virtual void setRowBounds( int elementIndex,
333  double lower, double upper );
334 
336  virtual void setRowType(int index, char sense, double rightHandSide,
337  double range);
338 
346  virtual void setRowSetBounds(const int* indexFirst,
347  const int* indexLast,
348  const double* boundList);
349 
359  virtual void setRowSetTypes(const int* indexFirst,
360  const int* indexLast,
361  const char* senseList,
362  const double* rhsList,
363  const double* rangeList);
365 
366  //-------------------------------------------------------------------------
370  virtual void setContinuous(int index);
372  virtual void setInteger(int index);
375  virtual void setContinuous(const int* indices, int len);
378  virtual void setInteger(const int* indices, int len);
380 
381  //-------------------------------------------------------------------------
383  virtual void setObjSense(double s);
384 
395  virtual void setColSolution(const double * colsol);
396 
407  virtual void setRowPrice(const double * rowprice);
408 
409  //-------------------------------------------------------------------------
415  virtual void addCol(const CoinPackedVectorBase& vec,
416  const double collb, const double colub,
417  const double obj);
419  virtual void addCols(const int numcols,
420  const CoinPackedVectorBase * const * cols,
421  const double* collb, const double* colub,
422  const double* obj);
424  virtual void deleteCols(const int num, const int * colIndices);
425 
427  virtual void addRow(const CoinPackedVectorBase& vec,
428  const double rowlb, const double rowub);
430  virtual void addRow(const CoinPackedVectorBase& vec,
431  const char rowsen, const double rowrhs,
432  const double rowrng);
434  virtual void addRows(const int numrows,
435  const CoinPackedVectorBase * const * rows,
436  const double* rowlb, const double* rowub);
438  virtual void addRows(const int numrows,
439  const CoinPackedVectorBase * const * rows,
440  const char* rowsen, const double* rowrhs,
441  const double* rowrng);
443  virtual void deleteRows(const int num, const int * rowIndices);
444 
445 #if 0
446  // ??? implemented in OsiSolverInterface
447  //-----------------------------------------------------------------------
469  virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
470  double effectivenessLb = 0.0);
471 #endif
472 
473 
474 
475  //---------------------------------------------------------------------------
476 
490  virtual void loadProblem(const CoinPackedMatrix& matrix,
491  const double* collb, const double* colub,
492  const double* obj,
493  const double* rowlb, const double* rowub);
494 
502  virtual void assignProblem(CoinPackedMatrix*& matrix,
503  double*& collb, double*& colub, double*& obj,
504  double*& rowlb, double*& rowub);
505 
518  virtual void loadProblem(const CoinPackedMatrix& matrix,
519  const double* collb, const double* colub,
520  const double* obj,
521  const char* rowsen, const double* rowrhs,
522  const double* rowrng);
523 
531  virtual void assignProblem(CoinPackedMatrix*& matrix,
532  double*& collb, double*& colub, double*& obj,
533  char*& rowsen, double*& rowrhs,
534  double*& rowrng);
535 
538  virtual void loadProblem(const int numcols, const int numrows,
539  const int* start, const int* index,
540  const double* value,
541  const double* collb, const double* colub,
542  const double* obj,
543  const double* rowlb, const double* rowub);
544 
547  virtual void loadProblem(const int numcols, const int numrows,
548  const int* start, const int* index,
549  const double* value,
550  const double* collb, const double* colub,
551  const double* obj,
552  const char* rowsen, const double* rowrhs,
553  const double* rowrng);
554 
556  virtual int readMps(const char *filename,
557  const char *extension = "mps");
558 
563  virtual void writeMps(const char *filename,
564  const char *extension = "mps",
565  double objSense=0.0) const;
567 
575  void passInMessageHandler(CoinMessageHandler * handler);
577 
578  //---------------------------------------------------------------------------
579 
586  {
609  };
610 
611  MSKtask_t getLpPtr( int keepCached = KEEPCACHED_NONE );
612 
614 
617 
619  const char* getCtype() const;
620 
630  static void incrementInstanceCounter();
631 
640  static void decrementInstanceCounter();
641 
643  static unsigned int getNumInstances();
645 
646 
649 
650 
651 
652  OsiMskSolverInterface(MSKenv_t mskenv = NULL);
653 
655  virtual OsiSolverInterface * clone(bool copyData = true) const;
656 
659 
662 
664  virtual ~OsiMskSolverInterface();
666 
667 protected:
668 
671 
672  virtual void applyRowCut( const OsiRowCut & rc );
673 
677  virtual void applyColCut( const OsiColCut & cc );
679 
680 private:
683 
684  void switchToLP();
685 
687  void switchToMIP();
688 
690  void resizeColType( int minsize );
691 
693  void freeColType();
694 
695  bool definedSolution(int solution) const;
696 
697  int solverUsed() const;
698 
700 
703 
704  static MSKenv_t env_ ;
705 
707  //static unsigned int numInstances_;
709  static unsigned int numInstances_;
710 
713 
714  int Mskerr;
716  double ObjOffset_;
717 
719 
721  public: MSKtask_t getMutableLpPtr() const;
722 
724  void gutsOfCopy( const OsiMskSolverInterface & source );
725 
727  void gutsOfConstructor();
728 
730  void gutsOfDestructor();
731 
733  void freeCachedColRim();
734 
736  void freeCachedRowRim();
737 
739  void freeCachedResults();
740 
742  void freeCachedMatrix();
743 
745  void freeCachedData( int keepCached = KEEPCACHED_NONE );
746 
748  void freeAllMemory();
749 
751  void printBounds();
754 
755  mutable MSKtask_t task_;
756 
763 
766 
767  mutable double *obj_;
768 
770  mutable double *collower_;
771 
773  mutable double *colupper_;
774 
776  mutable char *rowsense_;
777 
779  mutable double *rhs_;
780 
782  mutable double *rowrange_;
783 
785  mutable double *rowlower_;
786 
788  mutable double *rowupper_;
789 
791  mutable double *colsol_;
792 
794  mutable double *rowsol_;
795 
797  mutable double *redcost_;
798 
800  mutable double *rowact_;
801 
803  mutable CoinPackedMatrix *matrixByRow_;
804 
806  mutable CoinPackedMatrix *matrixByCol_;
808 
811 
812  char *coltype_;
813 
816 
818  mutable bool probtypemip_;
819 
821 };
822 
823 //#############################################################################
826 void OsiMskSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
827 
828 #endif