00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef OsiCpxSolverInterface_H
00014 #define OsiCpxSolverInterface_H
00015
00016 #include "CoinPragma.hpp"
00017 #include "CoinError.hpp"
00018 #include "CoinPackedMatrix.hpp"
00019 #include "CoinFinite.hpp"
00020 #include "CoinWarmStartBasis.hpp"
00021
00022 #include "OsiSolverInterface.hpp"
00023 #include "OsiRowCut.hpp"
00024 #include "OsiColCut.hpp"
00025
00026 #include "cplex.h"
00027
00028
00029 #if !defined(CPXERR_NO_INT_SOLN)
00030 #define CPXERR_NO_INT_SOLN CPXERR_NO_SOLN
00031 #endif
00032
00033
00034
00035 #ifdef DEBUG
00036 #define debugMessage printf
00037 #else
00038 #define debugMessage if( false ) printf
00039 #endif
00040
00041
00042 typedef struct cpxlp* CPXLPptr;
00043 typedef struct cpxenv* CPXENVptr;
00044
00050 class OsiCpxSolverInterface : virtual public OsiSolverInterface {
00051 friend void OsiCpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00052
00053 public:
00054
00055
00058
00059 virtual void initialSolve();
00060
00062 virtual void resolve();
00063
00065 virtual void branchAndBound();
00067
00068
00084
00085 bool setIntParam(OsiIntParam key, int value);
00086
00087 bool setDblParam(OsiDblParam key, double value);
00088
00089 bool setStrParam(OsiStrParam key, const std::string & value);
00090
00091 bool getIntParam(OsiIntParam key, int& value) const;
00092
00093 bool getDblParam(OsiDblParam key, double& value) const;
00094
00095 bool getStrParam(OsiStrParam key, std::string& value) const;
00096
00097 void setMipStart(bool value) { domipstart = value; }
00098
00099 bool getMipStart() const { return domipstart; }
00101
00102
00104
00105
00106 virtual bool isAbandoned() const;
00108 virtual bool isProvenOptimal() const;
00110 virtual bool isProvenPrimalInfeasible() const;
00112 virtual bool isProvenDualInfeasible() const;
00114 virtual bool isPrimalObjectiveLimitReached() const;
00116 virtual bool isDualObjectiveLimitReached() const;
00118 virtual bool isIterationLimitReached() const;
00120
00121
00124
00131 CoinWarmStart *getEmptyWarmStart () const;
00132
00134 virtual CoinWarmStart* getWarmStart() const;
00137 virtual bool setWarmStart(const CoinWarmStart* warmstart);
00139
00140
00147
00148 virtual void markHotStart();
00150 virtual void solveFromHotStart();
00152 virtual void unmarkHotStart();
00154
00155
00170
00171 virtual int getNumCols() const;
00172
00174 virtual int getNumRows() const;
00175
00177 virtual int getNumElements() const;
00178
00180 virtual const double * getColLower() const;
00181
00183 virtual const double * getColUpper() const;
00184
00194 virtual const char * getRowSense() const;
00195
00204 virtual const double * getRightHandSide() const;
00205
00214 virtual const double * getRowRange() const;
00215
00217 virtual const double * getRowLower() const;
00218
00220 virtual const double * getRowUpper() const;
00221
00223 virtual const double * getObjCoefficients() const;
00224
00226 virtual double getObjSense() const;
00227
00229 virtual bool isContinuous(int colNumber) const;
00230
00231 #if 0
00233 virtual bool isBinary(int columnNumber) const;
00234
00239 virtual bool isInteger(int columnNumber) const;
00240
00242 virtual bool isIntegerNonBinary(int columnNumber) const;
00243
00245 virtual bool isFreeBinary(int columnNumber) const;
00246 #endif
00247
00249 virtual const CoinPackedMatrix * getMatrixByRow() const;
00250
00252 virtual const CoinPackedMatrix * getMatrixByCol() const;
00253
00255 virtual double getInfinity() const;
00257
00260
00261 virtual const double * getColSolution() const;
00262
00264 virtual const double * getRowPrice() const;
00265
00267 virtual const double * getReducedCost() const;
00268
00271 virtual const double * getRowActivity() const;
00272
00274 virtual double getObjValue() const;
00275
00278 virtual int getIterationCount() const;
00279
00297 virtual std::vector<double*> getDualRays(int maxNumRays,
00298 bool fullRay = false) const;
00310 virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
00311
00312 #if 0
00313
00315 virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
00316 const;
00317 #endif
00318
00319
00320
00321
00322
00325
00329 virtual void setObjCoeff( int elementIndex, double elementValue );
00330
00332 virtual void setObjCoeffSet(const int* indexFirst,
00333 const int* indexLast,
00334 const double* coeffList);
00335
00336 using OsiSolverInterface::setColLower ;
00339 virtual void setColLower( int elementIndex, double elementValue );
00340
00341 using OsiSolverInterface::setColUpper ;
00344 virtual void setColUpper( int elementIndex, double elementValue );
00345
00349 virtual void setColBounds( int elementIndex,
00350 double lower, double upper );
00351
00359 virtual void setColSetBounds(const int* indexFirst,
00360 const int* indexLast,
00361 const double* boundList);
00362
00365 virtual void setRowLower( int elementIndex, double elementValue );
00366
00369 virtual void setRowUpper( int elementIndex, double elementValue );
00370
00374 virtual void setRowBounds( int elementIndex,
00375 double lower, double upper );
00376
00378 virtual void setRowType(int index, char sense, double rightHandSide,
00379 double range);
00380
00388 virtual void setRowSetBounds(const int* indexFirst,
00389 const int* indexLast,
00390 const double* boundList);
00391
00401 virtual void setRowSetTypes(const int* indexFirst,
00402 const int* indexLast,
00403 const char* senseList,
00404 const double* rhsList,
00405 const double* rangeList);
00407
00408
00412 virtual void setContinuous(int index);
00414 virtual void setInteger(int index);
00417 virtual void setContinuous(const int* indices, int len);
00420 virtual void setInteger(const int* indices, int len);
00422
00423
00425 virtual void setObjSense(double s);
00426
00437 virtual void setColSolution(const double * colsol);
00438
00449 virtual void setRowPrice(const double * rowprice);
00450
00451
00456 using OsiSolverInterface::addCol ;
00458 virtual void addCol(const CoinPackedVectorBase& vec,
00459 const double collb, const double colub,
00460 const double obj);
00461
00462 using OsiSolverInterface::addCols ;
00464 virtual void addCols(const int numcols,
00465 const CoinPackedVectorBase * const * cols,
00466 const double* collb, const double* colub,
00467 const double* obj);
00469 virtual void deleteCols(const int num, const int * colIndices);
00470
00471 using OsiSolverInterface::addRow ;
00473 virtual void addRow(const CoinPackedVectorBase& vec,
00474 const double rowlb, const double rowub);
00476 virtual void addRow(const CoinPackedVectorBase& vec,
00477 const char rowsen, const double rowrhs,
00478 const double rowrng);
00479
00480 using OsiSolverInterface::addRows ;
00482 virtual void addRows(const int numrows,
00483 const CoinPackedVectorBase * const * rows,
00484 const double* rowlb, const double* rowub);
00486 virtual void addRows(const int numrows,
00487 const CoinPackedVectorBase * const * rows,
00488 const char* rowsen, const double* rowrhs,
00489 const double* rowrng);
00491 virtual void deleteRows(const int num, const int * rowIndices);
00492
00493 #if 0
00494
00495
00517 virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
00518 double effectivenessLb = 0.0);
00519 #endif
00520
00521
00522
00523
00524
00538 virtual void loadProblem(const CoinPackedMatrix& matrix,
00539 const double* collb, const double* colub,
00540 const double* obj,
00541 const double* rowlb, const double* rowub);
00542
00550 virtual void assignProblem(CoinPackedMatrix*& matrix,
00551 double*& collb, double*& colub, double*& obj,
00552 double*& rowlb, double*& rowub);
00553
00566 virtual void loadProblem(const CoinPackedMatrix& matrix,
00567 const double* collb, const double* colub,
00568 const double* obj,
00569 const char* rowsen, const double* rowrhs,
00570 const double* rowrng);
00571
00579 virtual void assignProblem(CoinPackedMatrix*& matrix,
00580 double*& collb, double*& colub, double*& obj,
00581 char*& rowsen, double*& rowrhs,
00582 double*& rowrng);
00583
00586 virtual void loadProblem(const int numcols, const int numrows,
00587 const int* start, const int* index,
00588 const double* value,
00589 const double* collb, const double* colub,
00590 const double* obj,
00591 const double* rowlb, const double* rowub);
00592
00595 virtual void loadProblem(const int numcols, const int numrows,
00596 const int* start, const int* index,
00597 const double* value,
00598 const double* collb, const double* colub,
00599 const double* obj,
00600 const char* rowsen, const double* rowrhs,
00601 const double* rowrng);
00602
00603 using OsiSolverInterface::readMps ;
00605 virtual int readMps(const char *filename,
00606 const char *extension = "mps");
00607
00612 virtual void writeMps(const char *filename,
00613 const char *extension = "mps",
00614 double objSense=0.0) const;
00615
00617
00625 void passInMessageHandler(CoinMessageHandler * handler);
00627
00628
00629
00635 enum keepCachedFlag
00636 {
00638 KEEPCACHED_NONE = 0,
00640 KEEPCACHED_COLUMN = 1,
00642 KEEPCACHED_ROW = 2,
00644 KEEPCACHED_MATRIX = 4,
00646 KEEPCACHED_RESULTS = 8,
00648 KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
00650 KEEPCACHED_ALL = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
00652 FREECACHED_COLUMN = KEEPCACHED_PROBLEM & ~KEEPCACHED_COLUMN,
00654 FREECACHED_ROW = KEEPCACHED_PROBLEM & ~KEEPCACHED_ROW,
00656 FREECACHED_MATRIX = KEEPCACHED_PROBLEM & ~KEEPCACHED_MATRIX,
00658 FREECACHED_RESULTS = KEEPCACHED_ALL & ~KEEPCACHED_RESULTS
00659 };
00660 CPXLPptr getLpPtr( int keepCached = KEEPCACHED_NONE );
00661
00663
00664 CPXENVptr getEnvironmentPtr();
00666
00668 const char* getCtype() const;
00669
00672
00673 OsiCpxSolverInterface();
00674
00676 virtual OsiSolverInterface * clone(bool copyData = true) const;
00677
00679 OsiCpxSolverInterface( const OsiCpxSolverInterface& );
00680
00682 OsiCpxSolverInterface& operator=( const OsiCpxSolverInterface& rhs );
00683
00685 virtual ~OsiCpxSolverInterface();
00686
00688 virtual void reset();
00690
00691
00711
00715 virtual int canDoSimplexInterface() const;
00716
00717 using OsiSolverInterface::enableSimplexInterface ;
00721 virtual void enableSimplexInterface(int doingPrimal) {};
00722
00726 virtual void disableSimplexInterface() {};
00727
00731 virtual void enableFactorization() const {};
00732
00736 virtual void disableFactorization() const {};
00737
00739 virtual bool basisIsAvailable() const;
00740
00744 virtual void getBasisStatus(int* cstat, int* rstat) const;
00745
00747 virtual void getBInvARow(int row, double* z, double * slack=NULL) const;
00748
00750 virtual void getBInvRow(int row, double* z) const;
00751
00753 virtual void getBInvACol(int col, double* vec) const;
00754
00756 virtual void getBInvCol(int col, double* vec) const;
00757
00763 virtual void getBasics(int* index) const;
00765 void switchToLP();
00766
00768 void switchToMIP();
00769
00771
00772
00773 protected:
00774
00777
00778 virtual void applyRowCut( const OsiRowCut & rc );
00779
00783 virtual void applyColCut( const OsiColCut & cc );
00785
00786 private:
00789
00790 void resizeColType( int minsize );
00791
00793 void freeColType();
00795
00796
00799
00801 CPXLPptr getMutableLpPtr() const;
00802
00804 void gutsOfCopy( const OsiCpxSolverInterface & source );
00805
00807 void gutsOfConstructor();
00808
00810 void gutsOfDestructor();
00811
00813 void freeCachedColRim();
00814
00816 void freeCachedRowRim();
00817
00819 void freeCachedResults();
00820
00822 void freeCachedMatrix();
00823
00825 void freeCachedData( int keepCached = KEEPCACHED_NONE );
00826
00828 void freeAllMemory();
00829
00831
00832
00835
00836 mutable CPXENVptr env_;
00838 mutable CPXLPptr lp_;
00839
00841 int *hotStartCStat_;
00842 int hotStartCStatSize_;
00843 int *hotStartRStat_;
00844 int hotStartRStatSize_;
00845 int hotStartMaxIteration_;
00846
00849
00850 mutable double *obj_;
00851
00853 mutable double *collower_;
00854
00856 mutable double *colupper_;
00857
00859 mutable char *rowsense_;
00860
00862 mutable double *rhs_;
00863
00865 mutable double *rowrange_;
00866
00868 mutable double *rowlower_;
00869
00871 mutable double *rowupper_;
00872
00874 mutable double *colsol_;
00875
00877 mutable double *rowsol_;
00878
00880 mutable double *redcost_;
00881
00883 mutable double *rowact_;
00884
00886 mutable CoinPackedMatrix *matrixByRow_;
00887
00889 mutable CoinPackedMatrix *matrixByCol_;
00891
00894
00895 char *coltype_;
00896
00898 int coltypesize_;
00899
00901 mutable bool probtypemip_;
00902
00904 bool domipstart;
00905
00907 };
00908
00909
00911 void OsiCpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00912
00913 #endif