00001
00002
00003
00004 #ifndef OsiXprSolverInterface_H
00005 #define OsiXprSolverInterface_H
00006
00007 #include <string>
00008 #include <cstdio>
00009
00010 #include "xprs.h"
00011 #include "OsiSolverInterface.hpp"
00012
00013 #include "CoinWarmStartBasis.hpp"
00014
00015
00016
00017
00022 class OsiXprSolverInterface : virtual public OsiSolverInterface {
00023 friend void OsiXprSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00024 public:
00027
00028 virtual void initialSolve();
00029
00031 virtual void resolve();
00032
00034 virtual void branchAndBound();
00036
00052
00053 bool setIntParam(OsiIntParam key, int value);
00054
00055 bool setDblParam(OsiDblParam key, double value);
00056
00057 bool setStrParam(OsiStrParam key, const std::string & value);
00058
00059 bool getIntParam(OsiIntParam key, int& value) const;
00060
00061 bool getDblParam(OsiDblParam key, double& value) const;
00062
00063 bool getStrParam(OsiStrParam key, std::string& value) const;
00065
00066
00068
00069
00070 virtual bool isAbandoned() const;
00072 virtual bool isProvenOptimal() const;
00074 virtual bool isProvenPrimalInfeasible() const;
00076 virtual bool isProvenDualInfeasible() const;
00078 virtual bool isPrimalObjectiveLimitReached() const;
00080 virtual bool isDualObjectiveLimitReached() const;
00082 virtual bool isIterationLimitReached() const;
00084
00085
00088
00089 inline CoinWarmStart *getEmptyWarmStart () const
00090 { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; }
00092 virtual CoinWarmStart* getWarmStart() const;
00095 virtual bool setWarmStart(const CoinWarmStart* warmstart);
00097
00098
00105
00106 virtual void markHotStart();
00108 virtual void solveFromHotStart();
00110 virtual void unmarkHotStart();
00112
00113
00128
00129 virtual int getNumCols() const;
00130
00132 virtual int getNumRows() const;
00133
00135 virtual int getNumElements() const;
00136
00138 virtual const double * getColLower() const;
00139
00141 virtual const double * getColUpper() const;
00142
00152 virtual const char * getRowSense() const;
00153
00162 virtual const double * getRightHandSide() const;
00163
00172 virtual const double * getRowRange() const;
00173
00175 virtual const double * getRowLower() const;
00176
00178 virtual const double * getRowUpper() const;
00179
00181 virtual const double * getObjCoefficients() const;
00182
00184 virtual double getObjSense() const;
00185
00187 virtual bool isContinuous(int colIndex) const;
00188
00189 #if 0
00191 virtual bool isBinary(int colIndex) const;
00192
00197 virtual bool isInteger(int colIndex) const;
00198
00200 virtual bool isIntegerNonBinary(int colIndex) const;
00201
00203 virtual bool isFreeBinary(int colIndex) const;
00204 #endif
00206 virtual const CoinPackedMatrix * getMatrixByRow() const;
00207
00209 virtual const CoinPackedMatrix * getMatrixByCol() const;
00210
00212 virtual double getInfinity() const;
00214
00217
00218 virtual const double * getColSolution() const;
00219
00221 virtual const double * getRowPrice() const;
00222
00224 virtual const double * getReducedCost() const;
00225
00228 virtual const double * getRowActivity() const;
00229
00231 virtual double getObjValue() const;
00232
00235 virtual int getIterationCount() const;
00236
00248 virtual std::vector<double*> getDualRays(int maxNumRays) const;
00260 virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
00261
00262 #if 0
00263
00265 virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
00266 const;
00267 #endif
00268
00269
00270
00271
00272
00275
00279 virtual void setObjCoeff( int elementIndex, double elementValue );
00280
00283 virtual void setColLower( int elementIndex, double elementValue );
00284
00287 virtual void setColUpper( int elementIndex, double elementValue );
00288
00292 virtual void setColBounds( int elementIndex,
00293 double lower, double upper );
00294
00303 virtual void setColSetBounds(const int* indexFirst,
00304 const int* indexLast,
00305 const double* boundList);
00306
00309 virtual void setRowLower( int elementIndex, double elementValue );
00310
00313 virtual void setRowUpper( int elementIndex, double elementValue );
00314
00318 virtual void setRowBounds( int elementIndex,
00319 double lower, double upper );
00320
00322 virtual void setRowType(int index, char sense, double rightHandSide,
00323 double range);
00324
00333 virtual void setRowSetBounds(const int* indexFirst,
00334 const int* indexLast,
00335 const double* boundList);
00336
00347 virtual void setRowSetTypes(const int* indexFirst,
00348 const int* indexLast,
00349 const char* senseList,
00350 const double* rhsList,
00351 const double* rangeList);
00353
00354
00358 virtual void setContinuous(int index);
00360 virtual void setInteger(int index);
00363 virtual void setContinuous(const int* indices, int len);
00366 virtual void setInteger(const int* indices, int len);
00368
00369
00371 virtual void setObjSense(double s);
00372
00383 virtual void setColSolution(const double * colsol);
00384
00395 virtual void setRowPrice(const double * rowprice);
00396
00397
00403 virtual void addCol(const CoinPackedVectorBase& vec,
00404 const double collb, const double colub,
00405 const double obj);
00407 virtual void addCols(const int numcols,
00408 const CoinPackedVectorBase * const * cols,
00409 const double* collb, const double* colub,
00410 const double* obj);
00412 virtual void deleteCols(const int num, const int * colIndices);
00413
00415 virtual void addRow(const CoinPackedVectorBase& vec,
00416 const double rowlb, const double rowub);
00418 virtual void addRow(const CoinPackedVectorBase& vec,
00419 const char rowsen, const double rowrhs,
00420 const double rowrng);
00422 virtual void addRows(const int numrows,
00423 const CoinPackedVectorBase * const * rows,
00424 const double* rowlb, const double* rowub);
00426 virtual void addRows(const int numrows,
00427 const CoinPackedVectorBase * const * rows,
00428 const char* rowsen, const double* rowrhs,
00429 const double* rowrng);
00431 virtual void deleteRows(const int num, const int * rowIndices);
00432 #if 0
00433
00455 virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
00456 double effectivenessLb = 0.0);
00458
00459 #endif
00460
00461
00475 virtual void loadProblem(const CoinPackedMatrix& matrix,
00476 const double* collb, const double* colub,
00477 const double* obj,
00478 const double* rowlb, const double* rowub);
00479
00487 virtual void assignProblem(CoinPackedMatrix*& matrix,
00488 double*& collb, double*& colub, double*& obj,
00489 double*& rowlb, double*& rowub);
00490
00503 virtual void loadProblem(const CoinPackedMatrix& matrix,
00504 const double* collb, const double* colub,
00505 const double* obj,
00506 const char* rowsen, const double* rowrhs,
00507 const double* rowrng);
00508
00516 virtual void assignProblem(CoinPackedMatrix*& matrix,
00517 double*& collb, double*& colub, double*& obj,
00518 char*& rowsen, double*& rowrhs,
00519 double*& rowrng);
00520
00523 virtual void loadProblem(const int numcols, const int numrows,
00524 const int* start, const int* index,
00525 const double* value,
00526 const double* collb, const double* colub,
00527 const double* obj,
00528 const double* rowlb, const double* rowub);
00529
00532 virtual void loadProblem(const int numcols, const int numrows,
00533 const int* start, const int* index,
00534 const double* value,
00535 const double* collb, const double* colub,
00536 const double* obj,
00537 const char* rowsen, const double* rowrhs,
00538 const double* rowrng);
00539
00540
00542 virtual int readMps(const char *filename,
00543 const char *extension = "mps");
00544
00545
00550 virtual void writeMps(const char *filename,
00551 const char *extension = "mps",
00552 double objSense=0.0) const;
00554
00555
00556
00570 static void incrementInstanceCounter();
00571
00580 static void decrementInstanceCounter();
00581
00584 static unsigned int getNumInstances();
00586
00588 static int version();
00589
00592 static int iXprCallCount_;
00593
00594
00596 static FILE * getLogFilePtr();
00599 static void setLogFileName( const char * filename );
00601
00602
00605
00606 OsiXprSolverInterface (int newrows = 50, int newnz = 100);
00607
00609 virtual OsiSolverInterface * clone(bool copyData = true) const;
00610
00612 OsiXprSolverInterface (const OsiXprSolverInterface &);
00613
00615 OsiXprSolverInterface & operator=(const OsiXprSolverInterface& rhs);
00616
00618 virtual ~OsiXprSolverInterface ();
00620
00621 protected:
00622
00625
00626 virtual void applyRowCut( const OsiRowCut & rc );
00627
00631 virtual void applyColCut( const OsiColCut & cc );
00633
00634 private:
00635
00638
00639 static const char * logFileName_;
00640
00642 static FILE * logFilePtr_;
00643
00645 static unsigned int numInstances_;
00646
00648 static unsigned int osiSerial_;
00649
00651
00654
00655 void gutsOfCopy( const OsiXprSolverInterface & source );
00656
00658 void gutsOfConstructor();
00659
00661 void gutsOfDestructor();
00662
00664 void freeSolution();
00665
00668 void freeCachedResults();
00669
00671 int getNumIntVars() const;
00672
00675
00676 void getVarTypes() const;
00677
00681 void activateMe() const;
00682
00687 bool isDataLoaded() const;
00689
00690
00693
00696
00697 mutable XPRSprob prob_;
00698
00700 mutable std::string xprProbname_;
00702
00710 mutable CoinPackedMatrix *matrixByRow_;
00711 mutable CoinPackedMatrix *matrixByCol_;
00712
00714 mutable double *colupper_;
00715
00717 mutable double *collower_;
00718
00720 mutable double *rowupper_;
00721
00723 mutable double *rowlower_;
00724
00726 mutable char *rowsense_;
00727
00729 mutable double *rhs_;
00730
00734 mutable double *rowrange_;
00735
00737 mutable double *objcoeffs_;
00738
00740 mutable double objsense_;
00741
00743 mutable double *colsol_;
00744
00746 mutable double *rowsol_;
00747
00749 mutable double *rowact_;
00750
00752 mutable double *rowprice_;
00753
00755 mutable double *colprice_;
00756
00758 mutable int *ivarind_;
00759
00768 mutable char *ivartype_;
00769
00773 mutable char *vartype_;
00775
00776 };
00777
00778
00784 void
00785 OsiXprSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00786
00787 #endif