00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef OsiGlpkSolverInterface_H
00011 #define OsiGlpkSolverInterface_H
00012
00013 #include <string>
00014 #include "OsiSolverInterface.hpp"
00015 #include "CoinPackedMatrix.hpp"
00016 #include "CoinWarmStartBasis.hpp"
00017
00023 #ifndef LPX
00024 #define LPX glp_prob
00025 #endif
00026
00027 #ifndef GLP_PROB_DEFINED
00028 #define GLP_PROB_DEFINED
00029 typedef struct { double _opaque_prob[100]; } glp_prob;
00030 #endif
00031
00032 class OsiGlpkSolverInterface : virtual public OsiSolverInterface {
00033 friend void OsiGlpkSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00034
00035 public:
00036
00037
00040
00041 virtual void initialSolve();
00042
00044 virtual void resolve();
00045
00047 virtual void branchAndBound();
00049
00050
00066
00067 bool setIntParam(OsiIntParam key, int value);
00068
00069 bool setDblParam(OsiDblParam key, double value);
00070
00071 bool setStrParam(OsiStrParam key, const std::string & value);
00072
00073 bool setHintParam(OsiHintParam key, bool sense = true,
00074 OsiHintStrength strength = OsiHintTry, void *info = 0) ;
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 virtual bool isTimeLimitReached() const;
00103 virtual bool isFeasible() const;
00105
00106
00115 inline CoinWarmStart *getEmptyWarmStart () const
00116 { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; }
00118 virtual CoinWarmStart* getWarmStart() const;
00121 virtual bool setWarmStart(const CoinWarmStart* warmstart);
00123
00124
00131
00132 virtual void markHotStart();
00134 virtual void solveFromHotStart();
00136 virtual void unmarkHotStart();
00138
00139
00154
00155 virtual int getNumCols() const;
00156
00158 virtual int getNumRows() const;
00159
00161 virtual int getNumElements() const;
00162
00164 virtual const double * getColLower() const;
00165
00167 virtual const double * getColUpper() const;
00168
00178 virtual const char * getRowSense() const;
00179
00188 virtual const double * getRightHandSide() const;
00189
00198 virtual const double * getRowRange() const;
00199
00201 virtual const double * getRowLower() const;
00202
00204 virtual const double * getRowUpper() const;
00205
00207 virtual const double * getObjCoefficients() const;
00208
00210 virtual double getObjSense() const;
00211
00213 virtual bool isContinuous(int colNumber) const;
00214
00215 #if 0
00217 virtual bool isBinary(int columnNumber) const;
00218
00223 virtual bool isInteger(int columnNumber) const;
00224
00226 virtual bool isIntegerNonBinary(int columnNumber) const;
00227
00229 virtual bool isFreeBinary(int columnNumber) const;
00230 #endif
00231
00233 virtual const CoinPackedMatrix * getMatrixByRow() const;
00234
00236 virtual const CoinPackedMatrix * getMatrixByCol() const;
00237
00239 virtual double getInfinity() const;
00241
00244
00245 virtual const double * getColSolution() const;
00246
00248 virtual const double * getRowPrice() const;
00249
00251 virtual const double * getReducedCost() const;
00252
00255 virtual const double * getRowActivity() const;
00256
00258 virtual double getObjValue() const;
00259
00262 virtual int getIterationCount() const;
00263
00275 virtual std::vector<double*> getDualRays(int maxNumRays,
00276 bool fullRay=false) const;
00294 virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
00295
00296 #if 0
00297
00299 virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
00300 const;
00301 #endif
00302
00303
00304
00305
00306
00309
00313 virtual void setObjCoeff( int elementIndex, double elementValue );
00314
00315 using OsiSolverInterface::setColLower ;
00318 virtual void setColLower( int elementIndex, double elementValue );
00319
00320 using OsiSolverInterface::setColUpper ;
00323 virtual void setColUpper( int elementIndex, double elementValue );
00324
00328 virtual void setColBounds( int elementIndex,
00329 double lower, double upper );
00330
00339 virtual void setColSetBounds(const int* indexFirst,
00340 const int* indexLast,
00341 const double* boundList);
00342
00345 virtual void setRowLower( int elementIndex, double elementValue );
00346
00349 virtual void setRowUpper( int elementIndex, double elementValue );
00350
00354 virtual void setRowBounds( int elementIndex,
00355 double lower, double upper );
00356
00358 virtual void setRowType(int index, char sense, double rightHandSide,
00359 double range);
00360
00369 virtual void setRowSetBounds(const int* indexFirst,
00370 const int* indexLast,
00371 const double* boundList);
00372
00383 virtual void setRowSetTypes(const int* indexFirst,
00384 const int* indexLast,
00385 const char* senseList,
00386 const double* rhsList,
00387 const double* rangeList);
00389
00390
00394 virtual void setContinuous(int index);
00396 virtual void setInteger(int index);
00399 virtual void setContinuous(const int* indices, int len);
00402 virtual void setInteger(const int* indices, int len);
00404
00405
00407 virtual void setObjSense(double s);
00408
00419 virtual void setColSolution(const double * colsol);
00420
00431 virtual void setRowPrice(const double * rowprice);
00432
00433
00438
00439 using OsiSolverInterface::addCol ;
00441 virtual void addCol(const CoinPackedVectorBase& vec,
00442 const double collb, const double colub,
00443 const double obj);
00444
00445 using OsiSolverInterface::addCols ;
00447 virtual void addCols(const int numcols,
00448 const CoinPackedVectorBase * const * cols,
00449 const double* collb, const double* colub,
00450 const double* obj);
00452 virtual void deleteCols(const int num, const int * colIndices);
00453
00454 using OsiSolverInterface::addRow ;
00456 virtual void addRow(const CoinPackedVectorBase& vec,
00457 const double rowlb, const double rowub);
00459 virtual void addRow(const CoinPackedVectorBase& vec,
00460 const char rowsen, const double rowrhs,
00461 const double rowrng);
00462
00463 using OsiSolverInterface::addRows ;
00465 virtual void addRows(const int numrows,
00466 const CoinPackedVectorBase * const * rows,
00467 const double* rowlb, const double* rowub);
00469 virtual void addRows(const int numrows,
00470 const CoinPackedVectorBase * const * rows,
00471 const char* rowsen, const double* rowrhs,
00472 const double* rowrng);
00474 virtual void deleteRows(const int num, const int * rowIndices);
00475
00476 #if 0
00477
00478
00500 virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
00501 double effectivenessLb = 0.0);
00502 #endif
00503
00504
00505
00506
00507
00521 virtual void loadProblem(const CoinPackedMatrix& matrix,
00522 const double* collb, const double* colub,
00523 const double* obj,
00524 const double* rowlb, const double* rowub);
00525
00533 virtual void assignProblem(CoinPackedMatrix*& matrix,
00534 double*& collb, double*& colub, double*& obj,
00535 double*& rowlb, double*& rowub);
00536
00549 virtual void loadProblem(const CoinPackedMatrix& matrix,
00550 const double* collb, const double* colub,
00551 const double* obj,
00552 const char* rowsen, const double* rowrhs,
00553 const double* rowrng);
00554
00562 virtual void assignProblem(CoinPackedMatrix*& matrix,
00563 double*& collb, double*& colub, double*& obj,
00564 char*& rowsen, double*& rowrhs,
00565 double*& rowrng);
00566
00569 virtual void loadProblem(const int numcols, const int numrows,
00570 const int* start, const int* index,
00571 const double* value,
00572 const double* collb, const double* colub,
00573 const double* obj,
00574 const double* rowlb, const double* rowub);
00575
00578 virtual void loadProblem(const int numcols, const int numrows,
00579 const int* start, const int* index,
00580 const double* value,
00581 const double* collb, const double* colub,
00582 const double* obj,
00583 const char* rowsen, const double* rowrhs,
00584 const double* rowrng);
00585
00586 using OsiSolverInterface::readMps ;
00588 virtual int readMps(const char *filename,
00589 const char *extension = "mps");
00590
00595 virtual void writeMps(const char *filename,
00596 const char *extension = "mps",
00597 double objSense=0.0) const;
00599
00600
00601
00608
00611 void setObjName (std::string name) ;
00612
00618 void setRowName(int ndx, std::string name) ;
00619
00625 void setColName(int ndx, std::string name) ;
00626
00628
00629
00630
00633 enum keepCachedFlag
00634 {
00636 KEEPCACHED_NONE = 0,
00638 KEEPCACHED_COLUMN = 1,
00640 KEEPCACHED_ROW = 2,
00642 KEEPCACHED_MATRIX = 4,
00644 KEEPCACHED_RESULTS = 8,
00646 KEEPCACHED_PROBLEM = KEEPCACHED_COLUMN | KEEPCACHED_ROW | KEEPCACHED_MATRIX,
00648 KEEPCACHED_ALL = KEEPCACHED_PROBLEM | KEEPCACHED_RESULTS,
00650 FREECACHED_COLUMN = KEEPCACHED_PROBLEM & ~KEEPCACHED_COLUMN,
00652 FREECACHED_ROW = KEEPCACHED_PROBLEM & ~KEEPCACHED_ROW,
00654 FREECACHED_MATRIX = KEEPCACHED_PROBLEM & ~KEEPCACHED_MATRIX,
00656 FREECACHED_RESULTS = KEEPCACHED_ALL & ~KEEPCACHED_RESULTS
00657 };
00658
00660 LPX * getModelPtr();
00661
00663
00672 static void incrementInstanceCounter() { ++numInstances_; }
00673
00681 static void decrementInstanceCounter();
00682
00684 static unsigned int getNumInstances() { return numInstances_; }
00686
00687
00690
00691 OsiGlpkSolverInterface();
00692
00694 virtual OsiSolverInterface * clone(bool copyData = true) const;
00695
00697 OsiGlpkSolverInterface( const OsiGlpkSolverInterface& );
00698
00700 OsiGlpkSolverInterface& operator=( const OsiGlpkSolverInterface& rhs );
00701
00703 virtual ~OsiGlpkSolverInterface();
00704
00706 virtual void reset();
00708
00709 protected:
00710
00713
00714 virtual void applyRowCut( const OsiRowCut & rc );
00715
00719 virtual void applyColCut( const OsiColCut & cc );
00720
00722 LPX * getMutableModelPtr() const;
00723
00725
00726 private:
00729
00731 void gutsOfCopy( const OsiGlpkSolverInterface & source );
00732
00734 void gutsOfConstructor();
00735
00737 void gutsOfDestructor();
00738
00740 void freeCachedColRim();
00741
00743 void freeCachedRowRim();
00744
00746 void freeCachedResults();
00747
00749 void freeCachedMatrix();
00750
00752 void freeCachedData( int keepCached = KEEPCACHED_NONE );
00753
00755 void freeAllMemory();
00756
00758 void printBounds();
00759
00761 void fillColBounds() const;
00763
00764
00767
00768 mutable LPX* lp_;
00769
00771 static unsigned int numInstances_;
00772
00773
00774
00775
00776 int bbWasLast_;
00777
00778
00780 int maxIteration_;
00782 int hotStartMaxIteration_;
00784 int nameDisc_;
00785
00786
00788 double dualObjectiveLimit_;
00790 double primalObjectiveLimit_;
00792 double dualTolerance_;
00794 double primalTolerance_;
00796 double objOffset_;
00797
00798
00800 std::string probName_;
00801
00803 mutable void *info_[OsiLastHintParam] ;
00804
00805
00807
00809 int hotStartCStatSize_;
00811 int *hotStartCStat_;
00813 double *hotStartCVal_;
00815 double *hotStartCDualVal_;
00816
00818 int hotStartRStatSize_;
00820 int *hotStartRStat_;
00822 double *hotStartRVal_;
00824 double *hotStartRDualVal_;
00825
00826
00828 bool isIterationLimitReached_;
00830 bool isTimeLimitReached_;
00832 bool isAbandoned_;
00838 bool isObjLowerLimitReached_;
00844 bool isObjUpperLimitReached_;
00846 bool isPrimInfeasible_;
00848 bool isDualInfeasible_;
00850 bool isFeasible_;
00851
00854
00856 mutable int iter_used_;
00857
00859 mutable double *obj_;
00860
00862 mutable double *collower_;
00863
00865 mutable double *colupper_;
00866
00868 mutable char *ctype_;
00869
00871 mutable char *rowsense_;
00872
00874 mutable double *rhs_;
00875
00877 mutable double *rowrange_;
00878
00880 mutable double *rowlower_;
00881
00883 mutable double *rowupper_;
00884
00886 mutable double *colsol_;
00887
00889 mutable double *rowsol_;
00890
00892 mutable double *redcost_;
00893
00895 mutable double *rowact_;
00896
00898 mutable CoinPackedMatrix *matrixByRow_;
00899
00901 mutable CoinPackedMatrix *matrixByCol_;
00903
00904 };
00905
00906
00908 void OsiGlpkSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
00909
00910 #endif // OsiGlpkSolverInterface_H