00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef OsiSpxSolverInterface_H
00016 #define OsiSpxSolverInterface_H
00017
00018 #include <string>
00019 #include "OsiSolverInterface.hpp"
00020 #include "CoinWarmStartBasis.hpp"
00021
00022 #ifndef _SOPLEX_H_
00023
00024
00025
00026 namespace soplex {
00027 class DIdxSet;
00028 class DVector;
00029 class SPxOut;
00030 class SoPlex;
00031 }
00032 #endif
00033
00037 class OsiSpxSolverInterface : virtual public OsiSolverInterface {
00038 friend void OsiSpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00039
00040 public:
00041
00042
00045
00046 virtual void initialSolve();
00047
00049 virtual void resolve();
00050
00052 virtual void branchAndBound();
00054
00055
00071
00072 bool setIntParam(OsiIntParam key, int value);
00073
00074 bool setDblParam(OsiDblParam key, double value);
00075
00076 bool getIntParam(OsiIntParam key, int& value) const;
00077
00078 bool getDblParam(OsiDblParam key, double& value) const;
00079
00080 bool getStrParam(OsiStrParam key, std::string& value) const;
00081
00082 void setTimeLimit(double value);
00083
00084 double getTimeLimit() const;
00086
00087
00089
00090
00091 virtual bool isAbandoned() const;
00093 virtual bool isProvenOptimal() const;
00095 virtual bool isProvenPrimalInfeasible() const;
00097 virtual bool isProvenDualInfeasible() const;
00098
00100 virtual bool isDualObjectiveLimitReached() const;
00102 virtual bool isIterationLimitReached() const;
00104 virtual bool isTimeLimitReached() const;
00106
00107
00110
00111 inline CoinWarmStart *getEmptyWarmStart () const
00112 { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; }
00114 virtual CoinWarmStart* getWarmStart() const;
00117 virtual bool setWarmStart(const CoinWarmStart* warmstart);
00119
00120
00127
00128 virtual void markHotStart();
00130 virtual void solveFromHotStart();
00132 virtual void unmarkHotStart();
00134
00135
00150
00151 virtual int getNumCols() const;
00152
00154 virtual int getNumRows() const;
00155
00157 virtual int getNumElements() const;
00158
00160 virtual const double * getColLower() const;
00161
00163 virtual const double * getColUpper() const;
00164
00174 virtual const char * getRowSense() const;
00175
00184 virtual const double * getRightHandSide() const;
00185
00194 virtual const double * getRowRange() const;
00195
00197 virtual const double * getRowLower() const;
00198
00200 virtual const double * getRowUpper() const;
00201
00203 virtual const double * getObjCoefficients() const;
00204
00206 virtual double getObjSense() const;
00207
00209 virtual bool isContinuous(int colNumber) const;
00210
00211 #if 0
00213 virtual bool isBinary(int columnNumber) const;
00214
00219 virtual bool isInteger(int columnNumber) const;
00220
00222 virtual bool isIntegerNonBinary(int columnNumber) const;
00223
00225 virtual bool isFreeBinary(int columnNumber) const;
00226 #endif
00227
00229 virtual const CoinPackedMatrix * getMatrixByRow() const;
00230
00232 virtual const CoinPackedMatrix * getMatrixByCol() const;
00233
00235 virtual double getInfinity() const;
00237
00240
00241 virtual const double * getColSolution() const;
00242
00244 virtual const double * getRowPrice() const;
00245
00247 virtual const double * getReducedCost() const;
00248
00251 virtual const double * getRowActivity() const;
00252
00254 virtual double getObjValue() const;
00255
00258 virtual int getIterationCount() const;
00259
00277 virtual std::vector<double*> getDualRays(int maxNumRays,
00278 bool fullRay=false) const;
00290 virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
00291
00292 #if 0
00293
00295 virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
00296 const;
00297 #endif
00298
00299
00300
00301
00302
00305
00309 virtual void setObjCoeff( int elementIndex, double elementValue );
00310
00313 virtual void setColLower( int elementIndex, double elementValue );
00314
00317 virtual void setColUpper( int elementIndex, double elementValue );
00318
00322 virtual void setColBounds( int elementIndex,
00323 double lower, double upper );
00324
00325 #if 0 // we are using the default implementation of OsiSolverInterface
00326
00334 virtual void setColSetBounds(const int* indexFirst,
00335 const int* indexLast,
00336 const double* boundList);
00337 #endif
00338
00341 virtual void setRowLower( int elementIndex, double elementValue );
00342
00345 virtual void setRowUpper( int elementIndex, double elementValue );
00346
00350 virtual void setRowBounds( int elementIndex,
00351 double lower, double upper );
00352
00354 virtual void setRowType(int index, char sense, double rightHandSide,
00355 double range);
00356
00357 #if 0 // we are using the default implementation of OsiSolverInterface
00358
00365 virtual void setRowSetBounds(const int* indexFirst,
00366 const int* indexLast,
00367 const double* boundList);
00368
00378 virtual void setRowSetTypes(const int* indexFirst,
00379 const int* indexLast,
00380 const char* senseList,
00381 const double* rhsList,
00382 const double* rangeList);
00383 #endif
00384
00385
00386
00390 virtual void setContinuous(int index);
00392 virtual void setInteger(int index);
00393 #if 0 // we are using the default implementation of OsiSolverInterface
00394
00396 virtual void setContinuous(const int* indices, int len);
00399 virtual void setInteger(const int* indices, int len);
00400 #endif
00401
00402
00403
00405 virtual void setObjSense(double s);
00406
00417 virtual void setColSolution(const double * colsol);
00418
00429 virtual void setRowPrice(const double * rowprice);
00430
00431
00437 virtual void addCol(const CoinPackedVectorBase& vec,
00438 const double collb, const double colub,
00439 const double obj);
00440
00441 #if 0 // we are using the default implementation of OsiSolverInterface
00442
00443 virtual void addCols(const int numcols,
00444 const CoinPackedVectorBase * const * cols,
00445 const double* collb, const double* colub,
00446 const double* obj);
00447 #endif
00448
00450 virtual void deleteCols(const int num, const int * colIndices);
00451
00453 virtual void addRow(const CoinPackedVectorBase& vec,
00454 const double rowlb, const double rowub);
00456 virtual void addRow(const CoinPackedVectorBase& vec,
00457 const char rowsen, const double rowrhs,
00458 const double rowrng);
00459
00460 #if 0 // we are using the default implementation of OsiSolverInterface
00461
00462 virtual void addRows(const int numrows,
00463 const CoinPackedVectorBase * const * rows,
00464 const double* rowlb, const double* rowub);
00466 virtual void addRows(const int numrows,
00467 const CoinPackedVectorBase * const * rows,
00468 const char* rowsen, const double* rowrhs,
00469 const double* rowrng);
00470 #endif
00471
00473 virtual void deleteRows(const int num, const int * rowIndices);
00474
00475 #if 0 // we are using the default implementation of OsiSolverInterface
00476
00498 virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
00499 double effectivenessLb = 0.0);
00500 #endif
00501
00502
00503
00504
00505
00519 virtual void loadProblem(const CoinPackedMatrix& matrix,
00520 const double* collb, const double* colub,
00521 const double* obj,
00522 const double* rowlb, const double* rowub);
00523
00531 virtual void assignProblem(CoinPackedMatrix*& matrix,
00532 double*& collb, double*& colub, double*& obj,
00533 double*& rowlb, double*& rowub);
00534
00547 virtual void loadProblem(const CoinPackedMatrix& matrix,
00548 const double* collb, const double* colub,
00549 const double* obj,
00550 const char* rowsen, const double* rowrhs,
00551 const double* rowrng);
00552
00560 virtual void assignProblem(CoinPackedMatrix*& matrix,
00561 double*& collb, double*& colub, double*& obj,
00562 char*& rowsen, double*& rowrhs,
00563 double*& rowrng);
00564
00567 virtual void loadProblem(const int numcols, const int numrows,
00568 const int* start, const int* index,
00569 const double* value,
00570 const double* collb, const double* colub,
00571 const double* obj,
00572 const double* rowlb, const double* rowub);
00573
00576 virtual void loadProblem(const int numcols, const int numrows,
00577 const int* start, const int* index,
00578 const double* value,
00579 const double* collb, const double* colub,
00580 const double* obj,
00581 const char* rowsen, const double* rowrhs,
00582 const double* rowrng);
00583
00585 virtual int readMps(const char *filename,
00586 const char *extension = "mps");
00587
00592 virtual void writeMps(const char *filename,
00593 const char *extension = "mps",
00594 double objSense=0.0) const;
00596
00597
00598
00601
00602 OsiSpxSolverInterface();
00603
00605 virtual OsiSolverInterface * clone(bool copyData = true) const;
00606
00608 OsiSpxSolverInterface( const OsiSpxSolverInterface& );
00609
00611 OsiSpxSolverInterface& operator=( const OsiSpxSolverInterface& rhs );
00612
00614 virtual ~OsiSpxSolverInterface();
00616
00617
00618 enum keepCachedFlag
00619 {
00621 KEEPCACHED_NONE = 0,
00623 KEEPCACHED_COLUMN = 1,
00625 KEEPCACHED_ROW = 2,
00627 KEEPCACHED_MATRIX = 4,
00629 KEEPCACHED_RESULTS = 8,
00631 KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
00633 KEEPCACHED_ALL = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
00635 FREECACHED_COLUMN = KEEPCACHED_PROBLEM & ~KEEPCACHED_COLUMN,
00637 FREECACHED_ROW = KEEPCACHED_PROBLEM & ~KEEPCACHED_ROW,
00639 FREECACHED_MATRIX = KEEPCACHED_PROBLEM & ~KEEPCACHED_MATRIX,
00641 FREECACHED_RESULTS = KEEPCACHED_ALL & ~KEEPCACHED_RESULTS
00642 };
00643 soplex::SoPlex* getLpPtr( int keepCached = KEEPCACHED_NONE );
00644
00645 soplex::SPxOut* getSPxOut() { return spxout_; }
00646
00647 protected:
00648
00651
00652 virtual void applyRowCut( const OsiRowCut & rc );
00653
00657 virtual void applyColCut( const OsiColCut & cc );
00659
00662
00663 soplex::SPxOut *spxout_;
00665 soplex::SoPlex *soplex_;
00667
00668
00669 private:
00672
00674 void freeCachedColRim();
00675
00677 void freeCachedRowRim();
00678
00680 void freeCachedResults();
00681
00683 void freeCachedMatrix();
00684
00686 void freeCachedData( int keepCached = KEEPCACHED_NONE );
00687
00689 void freeAllMemory();
00691
00692
00695
00696 soplex::DIdxSet *spxintvars_;
00697
00699 void* hotStartCStat_;
00700 int hotStartCStatSize_;
00701 void* hotStartRStat_;
00702 int hotStartRStatSize_;
00703 int hotStartMaxIteration_;
00704
00707
00708 mutable soplex::DVector *obj_;
00709
00711 mutable char *rowsense_;
00712
00714 mutable double *rhs_;
00715
00717 mutable double *rowrange_;
00718
00720 mutable soplex::DVector *colsol_;
00721
00723 mutable soplex::DVector *rowsol_;
00724
00726 mutable soplex::DVector *redcost_;
00727
00729 mutable soplex::DVector *rowact_;
00730
00732 mutable CoinPackedMatrix *matrixByRow_;
00733
00735 mutable CoinPackedMatrix *matrixByCol_;
00737
00738 };
00739
00740
00742 void OsiSpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00743
00744 #endif