Osi
trunk
|
00001 //----------------------------------------------------------------------------- 00002 // name: OSI Interface for SoPlex >= 1.4.2c 00003 // authors: Tobias Pfender 00004 // Ambros Gleixner 00005 // Wei Huang 00006 // Konrad-Zuse-Zentrum Berlin (Germany) 00007 // email: pfender@zib.de 00008 // date: 01/16/2002 00009 // license: this file may be freely distributed under the terms of the EPL 00010 //----------------------------------------------------------------------------- 00011 // Copyright (C) 2002, Tobias Pfender, International Business Machines 00012 // Corporation and others. All Rights Reserved. 00013 // Last edit: $Id$ 00014 00015 #ifndef OsiSpxSolverInterface_H 00016 #define OsiSpxSolverInterface_H 00017 00018 #include <string> 00019 #include "OsiSolverInterface.hpp" 00020 #include "CoinWarmStartBasis.hpp" 00021 00022 /* forward declarations so the header can be compiled without having to include soplex.h */ 00023 namespace soplex { 00024 class DIdxSet; 00025 class DVector; 00026 class SoPlex; 00027 } 00028 00032 class OsiSpxSolverInterface : virtual public OsiSolverInterface { 00033 friend void OsiSpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir); 00034 00035 public: 00036 00037 //--------------------------------------------------------------------------- 00040 00041 virtual void initialSolve(); 00042 00044 virtual void resolve(); 00045 00047 virtual void branchAndBound(); 00049 00050 //--------------------------------------------------------------------------- 00066 // Set an integer parameter 00067 bool setIntParam(OsiIntParam key, int value); 00068 // Set an double parameter 00069 bool setDblParam(OsiDblParam key, double value); 00070 // Get an integer parameter 00071 bool getIntParam(OsiIntParam key, int& value) const; 00072 // Get an double parameter 00073 bool getDblParam(OsiDblParam key, double& value) const; 00074 // Get a string parameter 00075 bool getStrParam(OsiStrParam key, std::string& value) const; 00076 // Set timelimit 00077 void setTimeLimit(double value); 00078 // Get timelimit 00079 double getTimeLimit() const; 00081 00082 //--------------------------------------------------------------------------- 00084 00085 00086 virtual bool isAbandoned() const; 00088 virtual bool isProvenOptimal() const; 00090 virtual bool isProvenPrimalInfeasible() const; 00092 virtual bool isProvenDualInfeasible() const; 00093 // Is the given primal objective limit reached? - use implementation from OsiSolverInterface 00095 virtual bool isDualObjectiveLimitReached() const; 00097 virtual bool isIterationLimitReached() const; 00099 virtual bool isTimeLimitReached() const; 00101 00102 //--------------------------------------------------------------------------- 00105 00106 inline CoinWarmStart *getEmptyWarmStart () const 00107 { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; } 00109 virtual CoinWarmStart* getWarmStart() const; 00112 virtual bool setWarmStart(const CoinWarmStart* warmstart); 00114 00115 //--------------------------------------------------------------------------- 00122 00123 virtual void markHotStart(); 00125 virtual void solveFromHotStart(); 00127 virtual void unmarkHotStart(); 00129 00130 //--------------------------------------------------------------------------- 00145 00146 virtual int getNumCols() const; 00147 00149 virtual int getNumRows() const; 00150 00152 virtual int getNumElements() const; 00153 00155 virtual const double * getColLower() const; 00156 00158 virtual const double * getColUpper() const; 00159 00169 virtual const char * getRowSense() const; 00170 00179 virtual const double * getRightHandSide() const; 00180 00189 virtual const double * getRowRange() const; 00190 00192 virtual const double * getRowLower() const; 00193 00195 virtual const double * getRowUpper() const; 00196 00198 virtual const double * getObjCoefficients() const; 00199 00201 virtual double getObjSense() const; 00202 00204 virtual bool isContinuous(int colNumber) const; 00205 00206 #if 0 00207 00208 virtual bool isBinary(int columnNumber) const; 00209 00214 virtual bool isInteger(int columnNumber) const; 00215 00217 virtual bool isIntegerNonBinary(int columnNumber) const; 00218 00220 virtual bool isFreeBinary(int columnNumber) const; 00221 #endif 00222 00224 virtual const CoinPackedMatrix * getMatrixByRow() const; 00225 00227 virtual const CoinPackedMatrix * getMatrixByCol() const; 00228 00230 virtual double getInfinity() const; 00232 00235 00236 virtual const double * getColSolution() const; 00237 00239 virtual const double * getRowPrice() const; 00240 00242 virtual const double * getReducedCost() const; 00243 00246 virtual const double * getRowActivity() const; 00247 00249 virtual double getObjValue() const; 00250 00253 virtual int getIterationCount() const; 00254 00272 virtual std::vector<double*> getDualRays(int maxNumRays, 00273 bool fullRay=false) const; 00285 virtual std::vector<double*> getPrimalRays(int maxNumRays) const; 00286 00287 #if 0 00288 00290 virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05) 00291 const; 00292 #endif 00293 00294 00295 00296 //--------------------------------------------------------------------------- 00297 00300 //------------------------------------------------------------------------- 00304 virtual void setObjCoeff( int elementIndex, double elementValue ); 00305 00308 virtual void setColLower( int elementIndex, double elementValue ); 00309 00312 virtual void setColUpper( int elementIndex, double elementValue ); 00313 00317 virtual void setColBounds( int elementIndex, 00318 double lower, double upper ); 00319 00320 #if 0 // we are using the default implementation of OsiSolverInterface 00321 00329 virtual void setColSetBounds(const int* indexFirst, 00330 const int* indexLast, 00331 const double* boundList); 00332 #endif 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 00352 #if 0 // we are using the default implementation of OsiSolverInterface 00353 00360 virtual void setRowSetBounds(const int* indexFirst, 00361 const int* indexLast, 00362 const double* boundList); 00363 00373 virtual void setRowSetTypes(const int* indexFirst, 00374 const int* indexLast, 00375 const char* senseList, 00376 const double* rhsList, 00377 const double* rangeList); 00378 #endif 00379 00380 00381 //------------------------------------------------------------------------- 00385 virtual void setContinuous(int index); 00387 virtual void setInteger(int index); 00388 #if 0 // we are using the default implementation of OsiSolverInterface 00389 00391 virtual void setContinuous(const int* indices, int len); 00394 virtual void setInteger(const int* indices, int len); 00395 #endif 00396 00397 00398 //------------------------------------------------------------------------- 00400 virtual void setObjSense(double s); 00401 00412 virtual void setColSolution(const double * colsol); 00413 00424 virtual void setRowPrice(const double * rowprice); 00425 00426 //------------------------------------------------------------------------- 00432 virtual void addCol(const CoinPackedVectorBase& vec, 00433 const double collb, const double colub, 00434 const double obj); 00435 00436 #if 0 // we are using the default implementation of OsiSolverInterface 00437 00438 virtual void addCols(const int numcols, 00439 const CoinPackedVectorBase * const * cols, 00440 const double* collb, const double* colub, 00441 const double* obj); 00442 #endif 00443 00445 virtual void deleteCols(const int num, const int * colIndices); 00446 00448 virtual void addRow(const CoinPackedVectorBase& vec, 00449 const double rowlb, const double rowub); 00451 virtual void addRow(const CoinPackedVectorBase& vec, 00452 const char rowsen, const double rowrhs, 00453 const double rowrng); 00454 00455 #if 0 // we are using the default implementation of OsiSolverInterface 00456 00457 virtual void addRows(const int numrows, 00458 const CoinPackedVectorBase * const * rows, 00459 const double* rowlb, const double* rowub); 00461 virtual void addRows(const int numrows, 00462 const CoinPackedVectorBase * const * rows, 00463 const char* rowsen, const double* rowrhs, 00464 const double* rowrng); 00465 #endif 00466 00468 virtual void deleteRows(const int num, const int * rowIndices); 00469 00470 #if 0 // we are using the default implementation of OsiSolverInterface 00471 //----------------------------------------------------------------------- 00493 virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs, 00494 double effectivenessLb = 0.0); 00495 #endif 00496 00497 00498 00499 //--------------------------------------------------------------------------- 00500 00514 virtual void loadProblem(const CoinPackedMatrix& matrix, 00515 const double* collb, const double* colub, 00516 const double* obj, 00517 const double* rowlb, const double* rowub); 00518 00526 virtual void assignProblem(CoinPackedMatrix*& matrix, 00527 double*& collb, double*& colub, double*& obj, 00528 double*& rowlb, double*& rowub); 00529 00542 virtual void loadProblem(const CoinPackedMatrix& matrix, 00543 const double* collb, const double* colub, 00544 const double* obj, 00545 const char* rowsen, const double* rowrhs, 00546 const double* rowrng); 00547 00555 virtual void assignProblem(CoinPackedMatrix*& matrix, 00556 double*& collb, double*& colub, double*& obj, 00557 char*& rowsen, double*& rowrhs, 00558 double*& rowrng); 00559 00562 virtual void loadProblem(const int numcols, const int numrows, 00563 const int* start, const int* index, 00564 const double* value, 00565 const double* collb, const double* colub, 00566 const double* obj, 00567 const double* rowlb, const double* rowub); 00568 00571 virtual void loadProblem(const int numcols, const int numrows, 00572 const int* start, const int* index, 00573 const double* value, 00574 const double* collb, const double* colub, 00575 const double* obj, 00576 const char* rowsen, const double* rowrhs, 00577 const double* rowrng); 00578 00580 virtual int readMps(const char *filename, 00581 const char *extension = "mps"); 00582 00587 virtual void writeMps(const char *filename, 00588 const char *extension = "mps", 00589 double objSense=0.0) const; 00591 00592 //--------------------------------------------------------------------------- 00593 00596 00597 OsiSpxSolverInterface(); 00598 00600 virtual OsiSolverInterface * clone(bool copyData = true) const; 00601 00603 OsiSpxSolverInterface( const OsiSpxSolverInterface& ); 00604 00606 OsiSpxSolverInterface& operator=( const OsiSpxSolverInterface& rhs ); 00607 00609 virtual ~OsiSpxSolverInterface(); 00611 00612 protected: 00613 00616 00617 virtual void applyRowCut( const OsiRowCut & rc ); 00618 00622 virtual void applyColCut( const OsiColCut & cc ); 00624 00627 00628 soplex::SoPlex* soplex_; 00630 00631 00632 private: 00635 00637 void freeCachedColRim(); 00638 00640 void freeCachedRowRim(); 00641 00643 void freeCachedResults(); 00644 00646 void freeCachedMatrix(); 00647 00648 enum keepCachedFlag 00649 { 00651 KEEPCACHED_NONE = 0, 00653 KEEPCACHED_COLUMN = 1, 00655 KEEPCACHED_ROW = 2, 00657 KEEPCACHED_MATRIX = 4, 00659 KEEPCACHED_RESULTS = 8, 00661 KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX, 00663 KEEPCACHED_ALL = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS, 00665 FREECACHED_COLUMN = KEEPCACHED_PROBLEM & ~KEEPCACHED_COLUMN, 00667 FREECACHED_ROW = KEEPCACHED_PROBLEM & ~KEEPCACHED_ROW, 00669 FREECACHED_MATRIX = KEEPCACHED_PROBLEM & ~KEEPCACHED_MATRIX, 00671 FREECACHED_RESULTS = KEEPCACHED_ALL & ~KEEPCACHED_RESULTS 00672 }; 00673 00675 void freeCachedData( int keepCached = KEEPCACHED_NONE ); 00676 00678 void freeAllMemory(); 00680 00681 00684 00685 soplex::DIdxSet* spxintvars_; 00686 00688 void* hotStartCStat_; 00689 int hotStartCStatSize_; 00690 void* hotStartRStat_; 00691 int hotStartRStatSize_; 00692 int hotStartMaxIteration_; 00693 00696 00697 mutable soplex::DVector *obj_; 00698 00700 mutable char *rowsense_; 00701 00703 mutable double *rhs_; 00704 00706 mutable double *rowrange_; 00707 00709 mutable soplex::DVector *colsol_; 00710 00712 mutable soplex::DVector *rowsol_; 00713 00715 mutable soplex::DVector *redcost_; 00716 00718 mutable soplex::DVector *rowact_; 00719 00721 mutable CoinPackedMatrix *matrixByRow_; 00722 00724 mutable CoinPackedMatrix *matrixByCol_; 00726 00727 }; 00728 00729 //############################################################################# 00731 void OsiSpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir); 00732 00733 #endif