00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef OsiCpxSolverInterface_H
00014 #define OsiCpxSolverInterface_H
00015
00016 #include "OsiSolverInterface.hpp"
00017
00018 typedef struct cpxlp* CPXLPptr;
00019 typedef struct cpxenv* CPXENVptr;
00020
00026 class OsiCpxSolverInterface : virtual public OsiSolverInterface {
00027 friend void OsiCpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00028
00029 public:
00030
00031
00034
00035 virtual void initialSolve();
00036
00038 virtual void resolve();
00039
00041 virtual void branchAndBound();
00043
00044
00060
00061 bool setIntParam(OsiIntParam key, int value);
00062
00063 bool setDblParam(OsiDblParam key, double value);
00064
00065 bool setStrParam(OsiStrParam key, const std::string & value);
00066
00067 bool getIntParam(OsiIntParam key, int& value) const;
00068
00069 bool getDblParam(OsiDblParam key, double& value) const;
00070
00071 bool getStrParam(OsiStrParam key, std::string& value) const;
00072
00073 void setMipStart(bool value) { domipstart = value; }
00074
00075 bool getMipStart() const { return domipstart; }
00077
00078
00080
00081
00082 virtual bool isAbandoned() const;
00084 virtual bool isProvenOptimal() const;
00086 virtual bool isProvenPrimalInfeasible() const;
00088 virtual bool isProvenDualInfeasible() const;
00090 virtual bool isPrimalObjectiveLimitReached() const;
00092 virtual bool isDualObjectiveLimitReached() const;
00094 virtual bool isIterationLimitReached() const;
00096
00097
00100
00107 CoinWarmStart *getEmptyWarmStart () const;
00108
00110 virtual CoinWarmStart* getWarmStart() const;
00113 virtual bool setWarmStart(const CoinWarmStart* warmstart);
00115
00116
00123
00124 virtual void markHotStart();
00126 virtual void solveFromHotStart();
00128 virtual void unmarkHotStart();
00130
00131
00146
00147 virtual int getNumCols() const;
00148
00150 virtual int getNumRows() const;
00151
00153 virtual int getNumElements() const;
00154
00156 virtual const double * getColLower() const;
00157
00159 virtual const double * getColUpper() const;
00160
00170 virtual const char * getRowSense() const;
00171
00180 virtual const double * getRightHandSide() const;
00181
00190 virtual const double * getRowRange() const;
00191
00193 virtual const double * getRowLower() const;
00194
00196 virtual const double * getRowUpper() const;
00197
00199 virtual const double * getObjCoefficients() const;
00200
00202 virtual double getObjSense() const;
00203
00205 virtual bool isContinuous(int colNumber) const;
00206
00207 #if 0
00209 virtual bool isBinary(int columnNumber) const;
00210
00215 virtual bool isInteger(int columnNumber) const;
00216
00218 virtual bool isIntegerNonBinary(int columnNumber) const;
00219
00221 virtual bool isFreeBinary(int columnNumber) const;
00222 #endif
00223
00225 virtual const CoinPackedMatrix * getMatrixByRow() const;
00226
00228 virtual const CoinPackedMatrix * getMatrixByCol() const;
00229
00231 virtual double getInfinity() const;
00233
00236
00237 virtual const double * getColSolution() const;
00238
00240 virtual const double * getRowPrice() const;
00241
00243 virtual const double * getReducedCost() const;
00244
00247 virtual const double * getRowActivity() const;
00248
00250 virtual double getObjValue() const;
00251
00254 virtual int getIterationCount() const;
00255
00273 virtual std::vector<double*> getDualRays(int maxNumRays,
00274 bool fullRay = false) const;
00286 virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
00287
00288 #if 0
00289
00291 virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
00292 const;
00293 #endif
00294
00295
00296
00297
00298
00301
00305 virtual void setObjCoeff( int elementIndex, double elementValue );
00306
00308 virtual void setObjCoeffSet(const int* indexFirst,
00309 const int* indexLast,
00310 const double* coeffList);
00311
00312 using OsiSolverInterface::setColLower ;
00315 virtual void setColLower( int elementIndex, double elementValue );
00316
00317 using OsiSolverInterface::setColUpper ;
00320 virtual void setColUpper( int elementIndex, double elementValue );
00321
00325 virtual void setColBounds( int elementIndex,
00326 double lower, double upper );
00327
00335 virtual void setColSetBounds(const int* indexFirst,
00336 const int* indexLast,
00337 const double* boundList);
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
00364 virtual void setRowSetBounds(const int* indexFirst,
00365 const int* indexLast,
00366 const double* boundList);
00367
00377 virtual void setRowSetTypes(const int* indexFirst,
00378 const int* indexLast,
00379 const char* senseList,
00380 const double* rhsList,
00381 const double* rangeList);
00383
00384
00388 virtual void setContinuous(int index);
00390 virtual void setInteger(int index);
00393 virtual void setContinuous(const int* indices, int len);
00396 virtual void setInteger(const int* indices, int len);
00398
00399
00401 virtual void setObjSense(double s);
00402
00413 virtual void setColSolution(const double * colsol);
00414
00425 virtual void setRowPrice(const double * rowprice);
00426
00427
00432 using OsiSolverInterface::addCol ;
00434 virtual void addCol(const CoinPackedVectorBase& vec,
00435 const double collb, const double colub,
00436 const double obj);
00437
00438 using OsiSolverInterface::addCols ;
00440 virtual void addCols(const int numcols,
00441 const CoinPackedVectorBase * const * cols,
00442 const double* collb, const double* colub,
00443 const double* obj);
00445 virtual void deleteCols(const int num, const int * colIndices);
00446
00447 using OsiSolverInterface::addRow ;
00449 virtual void addRow(const CoinPackedVectorBase& vec,
00450 const double rowlb, const double rowub);
00452 virtual void addRow(const CoinPackedVectorBase& vec,
00453 const char rowsen, const double rowrhs,
00454 const double rowrng);
00455
00456 using OsiSolverInterface::addRows ;
00458 virtual void addRows(const int numrows,
00459 const CoinPackedVectorBase * const * rows,
00460 const double* rowlb, const double* rowub);
00462 virtual void addRows(const int numrows,
00463 const CoinPackedVectorBase * const * rows,
00464 const char* rowsen, const double* rowrhs,
00465 const double* rowrng);
00467 virtual void deleteRows(const int num, const int * rowIndices);
00468
00469 #if 0
00470
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
00579 using OsiSolverInterface::readMps ;
00581 virtual int readMps(const char *filename,
00582 const char *extension = "mps");
00583
00588 virtual void writeMps(const char *filename,
00589 const char *extension = "mps",
00590 double objSense=0.0) const;
00591
00593
00601 void passInMessageHandler(CoinMessageHandler * handler);
00603
00604
00605
00611 enum keepCachedFlag
00612 {
00614 KEEPCACHED_NONE = 0,
00616 KEEPCACHED_COLUMN = 1,
00618 KEEPCACHED_ROW = 2,
00620 KEEPCACHED_MATRIX = 4,
00622 KEEPCACHED_RESULTS = 8,
00624 KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
00626 KEEPCACHED_ALL = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
00628 FREECACHED_COLUMN = KEEPCACHED_PROBLEM & ~KEEPCACHED_COLUMN,
00630 FREECACHED_ROW = KEEPCACHED_PROBLEM & ~KEEPCACHED_ROW,
00632 FREECACHED_MATRIX = KEEPCACHED_PROBLEM & ~KEEPCACHED_MATRIX,
00634 FREECACHED_RESULTS = KEEPCACHED_ALL & ~KEEPCACHED_RESULTS
00635 };
00636 CPXLPptr getLpPtr( int keepCached = KEEPCACHED_NONE );
00637
00639
00640 CPXENVptr getEnvironmentPtr();
00642
00644 const char* getCtype() const;
00645
00648
00649 OsiCpxSolverInterface();
00650
00652 virtual OsiSolverInterface * clone(bool copyData = true) const;
00653
00655 OsiCpxSolverInterface( const OsiCpxSolverInterface& );
00656
00658 OsiCpxSolverInterface& operator=( const OsiCpxSolverInterface& rhs );
00659
00661 virtual ~OsiCpxSolverInterface();
00662
00664 virtual void reset();
00666
00667
00687
00691 virtual int canDoSimplexInterface() const;
00692
00693 using OsiSolverInterface::enableSimplexInterface ;
00697 virtual void enableSimplexInterface(int doingPrimal) {};
00698
00702 virtual void disableSimplexInterface() {};
00703
00707 virtual void enableFactorization() const {};
00708
00712 virtual void disableFactorization() const {};
00713
00715 virtual bool basisIsAvailable() const;
00716
00720 virtual void getBasisStatus(int* cstat, int* rstat) const;
00721
00723 virtual void getBInvARow(int row, double* z, double * slack=NULL) const;
00724
00726 virtual void getBInvRow(int row, double* z) const;
00727
00729 virtual void getBInvACol(int col, double* vec) const;
00730
00732 virtual void getBInvCol(int col, double* vec) const;
00733
00739 virtual void getBasics(int* index) const;
00741 void switchToLP();
00742
00744 void switchToMIP();
00745
00747
00748
00749 protected:
00750
00753
00754 virtual void applyRowCut( const OsiRowCut & rc );
00755
00759 virtual void applyColCut( const OsiColCut & cc );
00761
00762 private:
00765
00766 void resizeColType( int minsize );
00767
00769 void freeColType();
00771
00772
00775
00777 CPXLPptr getMutableLpPtr() const;
00778
00780 void gutsOfCopy( const OsiCpxSolverInterface & source );
00781
00783 void gutsOfConstructor();
00784
00786 void gutsOfDestructor();
00787
00789 void freeCachedColRim();
00790
00792 void freeCachedRowRim();
00793
00795 void freeCachedResults();
00796
00798 void freeCachedMatrix();
00799
00801 void freeCachedData( int keepCached = KEEPCACHED_NONE );
00802
00804 void freeAllMemory();
00805
00807
00808
00811
00812 mutable CPXENVptr env_;
00814 mutable CPXLPptr lp_;
00815
00817 int *hotStartCStat_;
00818 int hotStartCStatSize_;
00819 int *hotStartRStat_;
00820 int hotStartRStatSize_;
00821 int hotStartMaxIteration_;
00822
00825
00826 mutable double *obj_;
00827
00829 mutable double *collower_;
00830
00832 mutable double *colupper_;
00833
00835 mutable char *rowsense_;
00836
00838 mutable double *rhs_;
00839
00841 mutable double *rowrange_;
00842
00844 mutable double *rowlower_;
00845
00847 mutable double *rowupper_;
00848
00850 mutable double *colsol_;
00851
00853 mutable double *rowsol_;
00854
00856 mutable double *redcost_;
00857
00859 mutable double *rowact_;
00860
00862 mutable CoinPackedMatrix *matrixByRow_;
00863
00865 mutable CoinPackedMatrix *matrixByCol_;
00867
00870
00871 char *coltype_;
00872
00874 int coltypesize_;
00875
00877 mutable bool probtypemip_;
00878
00880 bool domipstart;
00881
00883 };
00884
00885
00887 void OsiCpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00888
00889 #endif