00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef OsiCpxSolverInterface_H
00016 #define OsiCpxSolverInterface_H
00017
00018 #include <string>
00019 #include "cplex.h"
00020 #include "OsiSolverInterface.hpp"
00021 #include "CoinPackedMatrix.hpp"
00022 #include "CoinWarmStartBasis.hpp"
00023
00024
00025 #if !defined(CPXERR_NO_INT_SOLN)
00026 #define CPXERR_NO_INT_SOLN CPXERR_NO_SOLN
00027 #endif
00028
00029
00035 class OsiCpxSolverInterface : virtual public OsiSolverInterface {
00036 friend void OsiCpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00037
00038 public:
00039
00040
00043
00044 virtual void initialSolve();
00045
00047 virtual void resolve();
00048
00050 virtual void branchAndBound();
00052
00053
00069
00070 bool setIntParam(OsiIntParam key, int value);
00071
00072 bool setDblParam(OsiDblParam key, double value);
00073
00074 bool setStrParam(OsiStrParam key, const std::string & 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;
00082
00083
00085
00086
00087 virtual bool isAbandoned() const;
00089 virtual bool isProvenOptimal() const;
00091 virtual bool isProvenPrimalInfeasible() const;
00093 virtual bool isProvenDualInfeasible() const;
00095 virtual bool isPrimalObjectiveLimitReached() const;
00097 virtual bool isDualObjectiveLimitReached() const;
00099 virtual bool isIterationLimitReached() const;
00101
00102
00105
00112 inline CoinWarmStart *getEmptyWarmStart () const
00113 { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; }
00114
00116 virtual CoinWarmStart* getWarmStart() const;
00119 virtual bool setWarmStart(const CoinWarmStart* warmstart);
00121
00122
00129
00130 virtual void markHotStart();
00132 virtual void solveFromHotStart();
00134 virtual void unmarkHotStart();
00136
00137
00152
00153 virtual int getNumCols() const;
00154
00156 virtual int getNumRows() const;
00157
00159 virtual int getNumElements() const;
00160
00162 virtual const double * getColLower() const;
00163
00165 virtual const double * getColUpper() const;
00166
00176 virtual const char * getRowSense() const;
00177
00186 virtual const double * getRightHandSide() const;
00187
00196 virtual const double * getRowRange() const;
00197
00199 virtual const double * getRowLower() const;
00200
00202 virtual const double * getRowUpper() const;
00203
00205 virtual const double * getObjCoefficients() const;
00206
00208 virtual double getObjSense() const;
00209
00211 virtual bool isContinuous(int colNumber) const;
00212
00213 #if 0
00215 virtual bool isBinary(int columnNumber) const;
00216
00221 virtual bool isInteger(int columnNumber) const;
00222
00224 virtual bool isIntegerNonBinary(int columnNumber) const;
00225
00227 virtual bool isFreeBinary(int columnNumber) const;
00228 #endif
00229
00231 virtual const CoinPackedMatrix * getMatrixByRow() const;
00232
00234 virtual const CoinPackedMatrix * getMatrixByCol() const;
00235
00237 virtual double getInfinity() const;
00239
00242
00243 virtual const double * getColSolution() const;
00244
00246 virtual const double * getRowPrice() const;
00247
00249 virtual const double * getReducedCost() const;
00250
00253 virtual const double * getRowActivity() const;
00254
00256 virtual double getObjValue() const;
00257
00260 virtual int getIterationCount() const;
00261
00273 virtual std::vector<double*> getDualRays(int maxNumRays) 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
00307 virtual void setObjCoeffSet(const int* indexFirst,
00308 const int* indexLast,
00309 const double* coeffList);
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
00332 virtual void setColSetBounds(const int* indexFirst,
00333 const int* indexLast,
00334 const double* boundList);
00335
00338 virtual void setRowLower( int elementIndex, double elementValue );
00339
00342 virtual void setRowUpper( int elementIndex, double elementValue );
00343
00347 virtual void setRowBounds( int elementIndex,
00348 double lower, double upper );
00349
00351 virtual void setRowType(int index, char sense, double rightHandSide,
00352 double range);
00353
00361 virtual void setRowSetBounds(const int* indexFirst,
00362 const int* indexLast,
00363 const double* boundList);
00364
00374 virtual void setRowSetTypes(const int* indexFirst,
00375 const int* indexLast,
00376 const char* senseList,
00377 const double* rhsList,
00378 const double* rangeList);
00380
00381
00385 virtual void setContinuous(int index);
00387 virtual void setInteger(int index);
00390 virtual void setContinuous(const int* indices, int len);
00393 virtual void setInteger(const int* indices, int len);
00395
00396
00398 virtual void setObjSense(double s);
00399
00410 virtual void setColSolution(const double * colsol);
00411
00422 virtual void setRowPrice(const double * rowprice);
00423
00424
00430 virtual void addCol(const CoinPackedVectorBase& vec,
00431 const double collb, const double colub,
00432 const double obj);
00434 virtual void addCols(const int numcols,
00435 const CoinPackedVectorBase * const * cols,
00436 const double* collb, const double* colub,
00437 const double* obj);
00439 virtual void deleteCols(const int num, const int * colIndices);
00440
00442 virtual void addRow(const CoinPackedVectorBase& vec,
00443 const double rowlb, const double rowub);
00445 virtual void addRow(const CoinPackedVectorBase& vec,
00446 const char rowsen, const double rowrhs,
00447 const double rowrng);
00449 virtual void addRows(const int numrows,
00450 const CoinPackedVectorBase * const * rows,
00451 const double* rowlb, const double* rowub);
00453 virtual void addRows(const int numrows,
00454 const CoinPackedVectorBase * const * rows,
00455 const char* rowsen, const double* rowrhs,
00456 const double* rowrng);
00458 virtual void deleteRows(const int num, const int * rowIndices);
00459
00460 #if 0
00461
00462
00484 virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
00485 double effectivenessLb = 0.0);
00486 #endif
00487
00488
00489
00490
00491
00505 virtual void loadProblem(const CoinPackedMatrix& matrix,
00506 const double* collb, const double* colub,
00507 const double* obj,
00508 const double* rowlb, const double* rowub);
00509
00517 virtual void assignProblem(CoinPackedMatrix*& matrix,
00518 double*& collb, double*& colub, double*& obj,
00519 double*& rowlb, double*& rowub);
00520
00533 virtual void loadProblem(const CoinPackedMatrix& matrix,
00534 const double* collb, const double* colub,
00535 const double* obj,
00536 const char* rowsen, const double* rowrhs,
00537 const double* rowrng);
00538
00546 virtual void assignProblem(CoinPackedMatrix*& matrix,
00547 double*& collb, double*& colub, double*& obj,
00548 char*& rowsen, double*& rowrhs,
00549 double*& rowrng);
00550
00553 virtual void loadProblem(const int numcols, const int numrows,
00554 const int* start, const int* index,
00555 const double* value,
00556 const double* collb, const double* colub,
00557 const double* obj,
00558 const double* rowlb, const double* rowub);
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 char* rowsen, const double* rowrhs,
00568 const double* rowrng);
00569
00571 virtual int readMps(const char *filename,
00572 const char *extension = "mps");
00573
00578 virtual void writeMps(const char *filename,
00579 const char *extension = "mps",
00580 double objSense=0.0) const;
00581
00583
00584
00585
00591 enum keepCachedFlag
00592 {
00594 KEEPCACHED_NONE = 0,
00596 KEEPCACHED_COLUMN = 1,
00598 KEEPCACHED_ROW = 2,
00600 KEEPCACHED_MATRIX = 4,
00602 KEEPCACHED_RESULTS = 8,
00604 KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
00606 KEEPCACHED_ALL = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
00608 FREECACHED_COLUMN = KEEPCACHED_PROBLEM & !KEEPCACHED_COLUMN,
00610 FREECACHED_ROW = KEEPCACHED_PROBLEM & !KEEPCACHED_ROW,
00612 FREECACHED_MATRIX = KEEPCACHED_PROBLEM & !KEEPCACHED_MATRIX,
00614 FREECACHED_RESULTS = KEEPCACHED_ALL & !KEEPCACHED_RESULTS
00615 };
00616 CPXLPptr getLpPtr( int keepCached = KEEPCACHED_NONE );
00617
00619
00620 CPXENVptr getEnvironmentPtr();
00622
00624 const char* getCtype() const;
00625
00635 static void incrementInstanceCounter();
00636
00645 static void decrementInstanceCounter();
00646
00648 static unsigned int getNumInstances();
00650
00651
00654
00655 OsiCpxSolverInterface();
00656
00658 virtual OsiSolverInterface * clone(bool copyData = true) const;
00659
00661 OsiCpxSolverInterface( const OsiCpxSolverInterface& );
00662
00664 OsiCpxSolverInterface& operator=( const OsiCpxSolverInterface& rhs );
00665
00667 virtual ~OsiCpxSolverInterface();
00668
00670 virtual void reset();
00672
00673
00693
00697 virtual int canDoSimplexInterface() const;
00698
00702 virtual void enableSimplexInterface(int doingPrimal) {};
00703
00707 virtual void disableSimplexInterface() {};
00708
00712 virtual void enableFactorization() const {};
00713
00717 virtual void disableFactorization() const {};
00718
00720 virtual bool basisIsAvailable() const;
00721
00725 virtual void getBasisStatus(int* cstat, int* rstat) const;
00726
00728 virtual void getBInvARow(int row, double* z, double * slack=NULL) const;
00729
00731 virtual void getBInvRow(int row, double* z) const;
00732
00734 virtual void getBInvACol(int col, double* vec) const;
00735
00737 virtual void getBInvCol(int col, double* vec) const;
00738
00744 virtual void getBasics(int* index) const;
00746
00747
00748 protected:
00749
00752
00753 virtual void applyRowCut( const OsiRowCut & rc );
00754
00758 virtual void applyColCut( const OsiColCut & cc );
00760
00761 private:
00764
00765 void switchToLP();
00766
00768 void switchToMIP();
00769
00771 void resizeColType( int minsize );
00772
00774 void freeColType();
00776
00779
00780 static CPXENVptr env_;
00782 static int cpxVersionMajor_;
00783 static int cpxVersionMinor_;
00784 static int cpxVersionMinorMinor_;
00786 static unsigned int numInstances_;
00788
00789
00792
00794 CPXLPptr getMutableLpPtr() const;
00795
00797 void gutsOfCopy( const OsiCpxSolverInterface & source );
00798
00800 void gutsOfConstructor();
00801
00803 void gutsOfDestructor();
00804
00806 void freeCachedColRim();
00807
00809 void freeCachedRowRim();
00810
00812 void freeCachedResults();
00813
00815 void freeCachedMatrix();
00816
00818 void freeCachedData( int keepCached = KEEPCACHED_NONE );
00819
00821 void freeAllMemory();
00822
00824 void printBounds();
00826
00827
00830
00831 mutable CPXLPptr lp_;
00832
00834 int *hotStartCStat_;
00835 int hotStartCStatSize_;
00836 int *hotStartRStat_;
00837 int hotStartRStatSize_;
00838 int hotStartMaxIteration_;
00839
00842
00843 mutable double *obj_;
00844
00846 mutable double *collower_;
00847
00849 mutable double *colupper_;
00850
00852 mutable char *rowsense_;
00853
00855 mutable double *rhs_;
00856
00858 mutable double *rowrange_;
00859
00861 mutable double *rowlower_;
00862
00864 mutable double *rowupper_;
00865
00867 mutable double *colsol_;
00868
00870 mutable double *rowsol_;
00871
00873 mutable double *redcost_;
00874
00876 mutable double *rowact_;
00877
00879 mutable CoinPackedMatrix *matrixByRow_;
00880
00882 mutable CoinPackedMatrix *matrixByCol_;
00884
00887
00888 char *coltype_;
00889
00891 int coltypesize_;
00892
00894 mutable bool probtypemip_;
00895
00897 };
00898
00899
00905 void OsiCpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00906
00907 #endif
00908