00001
00002
00003
00004
00005
00006
00007
00008
00009
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
00020
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
00058 bool setIntParam(OsiIntParam key, int value);
00059
00060 bool setDblParam(OsiDblParam key, double value);
00061
00062 bool setStrParam(OsiStrParam key, const std::string & value);
00063
00064 bool getIntParam(OsiIntParam key, int& value) const;
00065
00066 bool getDblParam(OsiDblParam key, double& value) const;
00067
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
00092
00101 CoinWarmStart* getEmptyWarmStart () const;
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
00268 virtual std::vector<double*> getDualRays(int maxNumRays,
00269 bool fullRay=false) const;
00281 virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
00282
00283 #if 0
00284
00286 virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
00287 const;
00288 #endif
00289
00290
00291
00292
00293
00296
00300 virtual void setObjCoeff( int elementIndex, double elementValue );
00301
00303 virtual void setObjCoeffSet(const int* indexFirst,
00304 const int* indexLast,
00305 const double* coeffList);
00306
00309 virtual void setColLower( int elementIndex, double elementValue );
00310
00313 virtual void setColUpper( int elementIndex, double elementValue );
00314
00318 virtual void setColBounds( int elementIndex,
00319 double lower, double upper );
00320
00328 virtual void setColSetBounds(const int* indexFirst,
00329 const int* indexLast,
00330 const double* boundList);
00331
00334 virtual void setRowLower( int elementIndex, double elementValue );
00335
00338 virtual void setRowUpper( int elementIndex, double elementValue );
00339
00343 virtual void setRowBounds( int elementIndex,
00344 double lower, double upper );
00345
00347 virtual void setRowType(int index, char sense, double rightHandSide,
00348 double range);
00349
00357 virtual void setRowSetBounds(const int* indexFirst,
00358 const int* indexLast,
00359 const double* boundList);
00360
00370 virtual void setRowSetTypes(const int* indexFirst,
00371 const int* indexLast,
00372 const char* senseList,
00373 const double* rhsList,
00374 const double* rangeList);
00376
00377
00381 virtual void setContinuous(int index);
00383 virtual void setInteger(int index);
00386 virtual void setContinuous(const int* indices, int len);
00389 virtual void setInteger(const int* indices, int len);
00391
00392
00394 virtual void setObjSense(double s);
00395
00406 virtual void setColSolution(const double * colsol);
00407
00418 virtual void setRowPrice(const double * rowprice);
00419
00420
00426 virtual void addCol(const CoinPackedVectorBase& vec,
00427 const double collb, const double colub,
00428 const double obj);
00430 virtual void addCols(const int numcols,
00431 const CoinPackedVectorBase * const * cols,
00432 const double* collb, const double* colub,
00433 const double* obj);
00435 virtual void deleteCols(const int num, const int * colIndices);
00436
00438 virtual void addRow(const CoinPackedVectorBase& vec,
00439 const double rowlb, const double rowub);
00441 virtual void addRow(const CoinPackedVectorBase& vec,
00442 const char rowsen, const double rowrhs,
00443 const double rowrng);
00445 virtual void addRows(const int numrows,
00446 const CoinPackedVectorBase * const * rows,
00447 const double* rowlb, const double* rowub);
00449 virtual void addRows(const int numrows,
00450 const CoinPackedVectorBase * const * rows,
00451 const char* rowsen, const double* rowrhs,
00452 const double* rowrng);
00454 virtual void deleteRows(const int num, const int * rowIndices);
00455
00456 #if 0
00457
00458
00480 virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
00481 double effectivenessLb = 0.0);
00482 #endif
00483
00484
00485
00486
00487
00501 virtual void loadProblem(const CoinPackedMatrix& matrix,
00502 const double* collb, const double* colub,
00503 const double* obj,
00504 const double* rowlb, const double* rowub);
00505
00513 virtual void assignProblem(CoinPackedMatrix*& matrix,
00514 double*& collb, double*& colub, double*& obj,
00515 double*& rowlb, double*& rowub);
00516
00529 virtual void loadProblem(const CoinPackedMatrix& matrix,
00530 const double* collb, const double* colub,
00531 const double* obj,
00532 const char* rowsen, const double* rowrhs,
00533 const double* rowrng);
00534
00542 virtual void assignProblem(CoinPackedMatrix*& matrix,
00543 double*& collb, double*& colub, double*& obj,
00544 char*& rowsen, double*& rowrhs,
00545 double*& rowrng);
00546
00549 virtual void loadProblem(const int numcols, const int numrows,
00550 const int* start, const int* index,
00551 const double* value,
00552 const double* collb, const double* colub,
00553 const double* obj,
00554 const double* rowlb, const double* rowub);
00555
00558 virtual void loadProblem(const int numcols, const int numrows,
00559 const int* start, const int* index,
00560 const double* value,
00561 const double* collb, const double* colub,
00562 const double* obj,
00563 const char* rowsen, const double* rowrhs,
00564 const double* rowrng);
00565
00567 virtual int readMps(const char *filename,
00568 const char *extension = "mps");
00569
00574 virtual void writeMps(const char *filename,
00575 const char *extension = "mps",
00576 double objSense=0.0) const;
00578
00586 void passInMessageHandler(CoinMessageHandler * handler);
00588
00589
00590
00596 enum keepCachedFlag
00597 {
00599 KEEPCACHED_NONE = 0,
00601 KEEPCACHED_COLUMN = 1,
00603 KEEPCACHED_ROW = 2,
00605 KEEPCACHED_MATRIX = 4,
00607 KEEPCACHED_RESULTS = 8,
00609 KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
00611 KEEPCACHED_ALL = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
00613 FREECACHED_COLUMN = KEEPCACHED_PROBLEM & ~KEEPCACHED_COLUMN,
00615 FREECACHED_ROW = KEEPCACHED_PROBLEM & ~KEEPCACHED_ROW,
00617 FREECACHED_MATRIX = KEEPCACHED_PROBLEM & ~KEEPCACHED_MATRIX,
00619 FREECACHED_RESULTS = KEEPCACHED_ALL & ~KEEPCACHED_RESULTS
00620 };
00621
00622 MSKtask_t getLpPtr( int keepCached = KEEPCACHED_NONE );
00623
00625
00626 MSKenv_t getEnvironmentPtr();
00628
00630 const char* getCtype() const;
00631
00641 static void incrementInstanceCounter();
00642
00651 static void decrementInstanceCounter();
00652
00654 static unsigned int getNumInstances();
00656
00657
00660
00661
00662
00663 OsiMskSolverInterface(MSKenv_t mskenv = NULL);
00664
00666 virtual OsiSolverInterface * clone(bool copyData = true) const;
00667
00669 OsiMskSolverInterface( const OsiMskSolverInterface& );
00670
00672 OsiMskSolverInterface& operator=( const OsiMskSolverInterface& rhs );
00673
00675 virtual ~OsiMskSolverInterface();
00677
00678 protected:
00679
00682
00683 virtual void applyRowCut( const OsiRowCut & rc );
00684
00688 virtual void applyColCut( const OsiColCut & cc );
00690
00691 private:
00694
00695 void switchToLP();
00696
00698 void switchToMIP();
00699
00701 void resizeColType( int minsize );
00702
00704 void freeColType();
00705
00706 bool definedSolution(int solution) const;
00707
00708 int solverUsed() const;
00709
00711
00714
00715 static MSKenv_t env_ ;
00716
00718
00720 static unsigned int numInstances_;
00721
00724
00725 int Mskerr;
00726 int MSKsolverused_;
00727 double ObjOffset_;
00728
00729 int InitialSolver;
00730
00732 public: MSKtask_t getMutableLpPtr() const;
00733
00735 void gutsOfCopy( const OsiMskSolverInterface & source );
00736
00738 void gutsOfConstructor();
00739
00741 void gutsOfDestructor();
00742
00744 void freeCachedColRim();
00745
00747 void freeCachedRowRim();
00748
00750 void freeCachedResults();
00751
00753 void freeCachedMatrix();
00754
00756 void freeCachedData( int keepCached = KEEPCACHED_NONE );
00757
00759 void freeAllMemory();
00760
00763
00764 mutable MSKtask_t task_;
00765
00767 int *hotStartCStat_;
00768 int hotStartCStatSize_;
00769 int *hotStartRStat_;
00770 int hotStartRStatSize_;
00771 int hotStartMaxIteration_;
00772
00775
00776 mutable double *obj_;
00777
00779 mutable double *collower_;
00780
00782 mutable double *colupper_;
00783
00785 mutable char *rowsense_;
00786
00788 mutable double *rhs_;
00789
00791 mutable double *rowrange_;
00792
00794 mutable double *rowlower_;
00795
00797 mutable double *rowupper_;
00798
00800 mutable double *colsol_;
00801
00803 mutable double *rowsol_;
00804
00806 mutable double *redcost_;
00807
00809 mutable double *rowact_;
00810
00812 mutable CoinPackedMatrix *matrixByRow_;
00813
00815 mutable CoinPackedMatrix *matrixByCol_;
00817
00820
00821 char *coltype_;
00822
00824 int coltypesize_;
00825
00827 mutable bool probtypemip_;
00828
00830 };
00831
00832
00834 void OsiMskSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00835
00836 #endif