00001
00002
00003
00004 #ifndef OsiXprSolverInterface_H
00005 #define OsiXprSolverInterface_H
00006
00007 #include <string>
00008 #include <cstdio>
00009
00010 #include "OsiSolverInterface.hpp"
00011
00012 typedef struct xo_prob_struct* XPRSprob;
00013
00014
00015
00020 class OsiXprSolverInterface : virtual public OsiSolverInterface {
00021 friend void OsiXprSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00022 public:
00025
00026 virtual void initialSolve();
00027
00029 virtual void resolve();
00030
00032 virtual void branchAndBound();
00034
00050
00051 bool setIntParam(OsiIntParam key, int value);
00052
00053 bool setDblParam(OsiDblParam key, double value);
00054
00055 bool setStrParam(OsiStrParam key, const std::string & value);
00056
00057 bool getIntParam(OsiIntParam key, int& value) const;
00058
00059 bool getDblParam(OsiDblParam key, double& value) const;
00060
00061 bool getStrParam(OsiStrParam key, std::string& value) const;
00063
00064
00066
00067
00068 virtual bool isAbandoned() const;
00070 virtual bool isProvenOptimal() const;
00072 virtual bool isProvenPrimalInfeasible() const;
00074 virtual bool isProvenDualInfeasible() const;
00076 virtual bool isPrimalObjectiveLimitReached() const;
00078 virtual bool isDualObjectiveLimitReached() const;
00080 virtual bool isIterationLimitReached() const;
00082
00083
00086
00087 CoinWarmStart *getEmptyWarmStart () const;
00089 virtual CoinWarmStart* getWarmStart() const;
00092 virtual bool setWarmStart(const CoinWarmStart* warmstart);
00094
00095
00102
00103 virtual void markHotStart();
00105 virtual void solveFromHotStart();
00107 virtual void unmarkHotStart();
00109
00110
00125
00126 virtual int getNumCols() const;
00127
00129 virtual int getNumRows() const;
00130
00132 virtual int getNumElements() const;
00133
00135 virtual const double * getColLower() const;
00136
00138 virtual const double * getColUpper() const;
00139
00149 virtual const char * getRowSense() const;
00150
00159 virtual const double * getRightHandSide() const;
00160
00169 virtual const double * getRowRange() const;
00170
00172 virtual const double * getRowLower() const;
00173
00175 virtual const double * getRowUpper() const;
00176
00178 virtual const double * getObjCoefficients() const;
00179
00181 virtual double getObjSense() const;
00182
00184 virtual bool isContinuous(int colIndex) const;
00185
00186 #if 0
00187
00188 virtual bool isBinary(int colIndex) const;
00189
00194 virtual bool isInteger(int colIndex) const;
00195
00197 virtual bool isIntegerNonBinary(int colIndex) const;
00198
00200 virtual bool isFreeBinary(int colIndex) const;
00201 #endif
00202
00203 virtual const CoinPackedMatrix * getMatrixByRow() const;
00204
00206 virtual const CoinPackedMatrix * getMatrixByCol() const;
00207
00209 virtual double getInfinity() const;
00211
00214
00215 virtual const double * getColSolution() const;
00216
00218 virtual const double * getRowPrice() const;
00219
00221 virtual const double * getReducedCost() const;
00222
00225 virtual const double * getRowActivity() const;
00226
00228 virtual double getObjValue() const;
00229
00232 virtual int getIterationCount() const;
00233
00245 virtual std::vector<double*> getDualRays(int maxNumRays) const;
00257 virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
00258
00259 #if 0
00260
00262 virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
00263 const;
00264 #endif
00265
00266
00267
00268
00269
00272
00276 virtual void setObjCoeff( int elementIndex, double elementValue );
00277
00280 virtual void setColLower( int elementIndex, double elementValue );
00281
00284 virtual void setColUpper( int elementIndex, double elementValue );
00285
00289 virtual void setColBounds( int elementIndex,
00290 double lower, double upper );
00291
00300 virtual void setColSetBounds(const int* indexFirst,
00301 const int* indexLast,
00302 const double* boundList);
00303
00306 virtual void setRowLower( int elementIndex, double elementValue );
00307
00310 virtual void setRowUpper( int elementIndex, double elementValue );
00311
00315 virtual void setRowBounds( int elementIndex,
00316 double lower, double upper );
00317
00319 virtual void setRowType(int index, char sense, double rightHandSide,
00320 double range);
00321
00330 virtual void setRowSetBounds(const int* indexFirst,
00331 const int* indexLast,
00332 const double* boundList);
00333
00344 virtual void setRowSetTypes(const int* indexFirst,
00345 const int* indexLast,
00346 const char* senseList,
00347 const double* rhsList,
00348 const double* rangeList);
00350
00351
00355 virtual void setContinuous(int index);
00357 virtual void setInteger(int index);
00360 virtual void setContinuous(const int* indices, int len);
00363 virtual void setInteger(const int* indices, int len);
00365
00366
00368 virtual void setObjSense(double s);
00369
00380 virtual void setColSolution(const double * colsol);
00381
00392 virtual void setRowPrice(const double * rowprice);
00393
00394
00400 virtual void addCol(const CoinPackedVectorBase& vec,
00401 const double collb, const double colub,
00402 const double obj);
00404 virtual void addCols(const int numcols,
00405 const CoinPackedVectorBase * const * cols,
00406 const double* collb, const double* colub,
00407 const double* obj);
00409 virtual void deleteCols(const int num, const int * colIndices);
00410
00412 virtual void addRow(const CoinPackedVectorBase& vec,
00413 const double rowlb, const double rowub);
00415 virtual void addRow(const CoinPackedVectorBase& vec,
00416 const char rowsen, const double rowrhs,
00417 const double rowrng);
00419 virtual void addRows(const int numrows,
00420 const CoinPackedVectorBase * const * rows,
00421 const double* rowlb, const double* rowub);
00423 virtual void addRows(const int numrows,
00424 const CoinPackedVectorBase * const * rows,
00425 const char* rowsen, const double* rowrhs,
00426 const double* rowrng);
00428 virtual void deleteRows(const int num, const int * rowIndices);
00429 #if 0
00430
00452 virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
00453 double effectivenessLb = 0.0);
00455
00456 #endif
00457
00458
00472 virtual void loadProblem(const CoinPackedMatrix& matrix,
00473 const double* collb, const double* colub,
00474 const double* obj,
00475 const double* rowlb, const double* rowub);
00476
00484 virtual void assignProblem(CoinPackedMatrix*& matrix,
00485 double*& collb, double*& colub, double*& obj,
00486 double*& rowlb, double*& rowub);
00487
00500 virtual void loadProblem(const CoinPackedMatrix& matrix,
00501 const double* collb, const double* colub,
00502 const double* obj,
00503 const char* rowsen, const double* rowrhs,
00504 const double* rowrng);
00505
00513 virtual void assignProblem(CoinPackedMatrix*& matrix,
00514 double*& collb, double*& colub, double*& obj,
00515 char*& rowsen, double*& rowrhs,
00516 double*& rowrng);
00517
00520 virtual void loadProblem(const int numcols, const int numrows,
00521 const int* start, const int* index,
00522 const double* value,
00523 const double* collb, const double* colub,
00524 const double* obj,
00525 const double* rowlb, const double* rowub);
00526
00529 virtual void loadProblem(const int numcols, const int numrows,
00530 const int* start, const int* index,
00531 const double* value,
00532 const double* collb, const double* colub,
00533 const double* obj,
00534 const char* rowsen, const double* rowrhs,
00535 const double* rowrng);
00536
00537
00539 virtual int readMps(const char *filename,
00540 const char *extension = "mps");
00541
00542
00547 virtual void writeMps(const char *filename,
00548 const char *extension = "mps",
00549 double objSense=0.0) const;
00551
00559 void passInMessageHandler(CoinMessageHandler * handler);
00561
00562
00563
00577 static void incrementInstanceCounter();
00578
00587 static void decrementInstanceCounter();
00588
00591 static unsigned int getNumInstances();
00592
00594 XPRSprob getLpPtr() { return prob_; }
00596
00598 static int version();
00599
00602 static int iXprCallCount_;
00603
00604
00606 static FILE * getLogFilePtr();
00609 static void setLogFileName( const char * filename );
00611
00612
00615
00616 OsiXprSolverInterface (int newrows = 50, int newnz = 100);
00617
00619 virtual OsiSolverInterface * clone(bool copyData = true) const;
00620
00622 OsiXprSolverInterface (const OsiXprSolverInterface &);
00623
00625 OsiXprSolverInterface & operator=(const OsiXprSolverInterface& rhs);
00626
00628 virtual ~OsiXprSolverInterface ();
00630
00631 protected:
00632
00635
00636 virtual void applyRowCut( const OsiRowCut & rc );
00637
00641 virtual void applyColCut( const OsiColCut & cc );
00643
00644 private:
00645
00648
00649 static const char * logFileName_;
00650
00652 static FILE * logFilePtr_;
00653
00655 static unsigned int numInstances_;
00656
00658 static unsigned int osiSerial_;
00659
00661
00664
00665 void gutsOfCopy( const OsiXprSolverInterface & source );
00666
00668 void gutsOfConstructor();
00669
00671 void gutsOfDestructor();
00672
00674 void freeSolution();
00675
00678 void freeCachedResults();
00679
00681 int getNumIntVars() const;
00682
00685
00686 void getVarTypes() const;
00687
00691 void activateMe() const;
00692
00697 bool isDataLoaded() const;
00699
00700
00703
00706
00707 mutable XPRSprob prob_;
00708
00710 mutable std::string xprProbname_;
00712
00720 mutable CoinPackedMatrix *matrixByRow_;
00721 mutable CoinPackedMatrix *matrixByCol_;
00722
00724 mutable double *colupper_;
00725
00727 mutable double *collower_;
00728
00730 mutable double *rowupper_;
00731
00733 mutable double *rowlower_;
00734
00736 mutable char *rowsense_;
00737
00739 mutable double *rhs_;
00740
00744 mutable double *rowrange_;
00745
00747 mutable double *objcoeffs_;
00748
00750 mutable double objsense_;
00751
00753 mutable double *colsol_;
00754
00756 mutable double *rowsol_;
00757
00759 mutable double *rowact_;
00760
00762 mutable double *rowprice_;
00763
00765 mutable double *colprice_;
00766
00768 mutable int *ivarind_;
00769
00778 mutable char *ivartype_;
00779
00783 mutable char *vartype_;
00785
00786 };
00787
00788
00794 void
00795 OsiXprSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00796
00797 #endif