# HG changeset patch # User athos # Date 1165250893 0 # Node ID 18fc834761d9407d35b0eb604cb5d0cd453ece92 # Parent 8b18b6fed090d47f5e09f5484aef211873b3810a Some query functions got implemented, but only for GLPK. diff -r 8b18b6fed090 -r 18fc834761d9 lemon/lp_base.h --- a/lemon/lp_base.h Mon Dec 04 15:00:24 2006 +0000 +++ b/lemon/lp_base.h Mon Dec 04 16:48:13 2006 +0000 @@ -703,12 +703,15 @@ virtual void _setRowCoeffs(int i, LpRowIterator b, LpRowIterator e) = 0; virtual void _setColCoeffs(int i, LpColIterator b, LpColIterator e) = 0; virtual void _setCoeff(int row, int col, Value value) = 0; + virtual Value _getCoeff(int row, int col) = 0; + virtual void _setColLowerBound(int i, Value value) = 0; virtual void _setColUpperBound(int i, Value value) = 0; // virtual void _setRowLowerBound(int i, Value value) = 0; // virtual void _setRowUpperBound(int i, Value value) = 0; virtual void _setRowBounds(int i, Value lower, Value upper) = 0; virtual void _setObjCoeff(int i, Value obj_coef) = 0; + virtual Value _getObjCoeff(int i) = 0; virtual void _clearObj()=0; virtual SolveExitStatus _solve() = 0; @@ -725,6 +728,9 @@ virtual void _setMax() = 0; virtual void _setMin() = 0; + + virtual bool _isMax() = 0; + //Own protected stuff //Constant component of the objective function @@ -1000,6 +1006,16 @@ _setCoeff(_lpId(r),_lpId(c), val); } + /// Get an element of the coefficient matrix of the LP + + ///\param r is the row of the element in question + ///\param c is the coloumn of the element in question + ///\return the corresponding coefficient + + Value coeff(Row r, Col c){ + return _getCoeff(_lpId(r),_lpId(c)); + } + /// Set the lower bound of a column (i.e a variable) /// The lower bound of a variable (column) has to be given by an @@ -1171,8 +1187,12 @@ ///Set an element of the objective function void objCoeff(Col c, Value v) {_setObjCoeff(_lpId(c),v); }; + + ///Get an element of the objective function + Value objCoeff(Col c) {return _getObjCoeff(_lpId(c)); }; + ///Set the objective function - + ///\param e is a linear expression of type \ref Expr. ///\bug Is should be called obj() void setObj(Expr e) { @@ -1187,6 +1207,11 @@ ///Minimize void min() { _setMin(); } + ///Query function: is this a maximization problem? + bool is_max() {return _isMax(); } + + ///Query function: is this a minimization problem? + bool is_min() {return !is_max(); } ///@} diff -r 8b18b6fed090 -r 18fc834761d9 lemon/lp_glpk.cc --- a/lemon/lp_glpk.cc Mon Dec 04 15:00:24 2006 +0000 +++ b/lemon/lp_glpk.cc Mon Dec 04 16:48:13 2006 +0000 @@ -213,6 +213,13 @@ } } + LpGlpk::Value LpGlpk::_getCoeff(int row, int col) + { + ///\todo This is not yet implemented!!! + return 0; + } + + void LpGlpk::_setColLowerBound(int i, Value lo) { if (lo==INF) { @@ -424,6 +431,11 @@ lpx_set_obj_coef(lp, i, obj_coef); } + LpGlpk::Value LpGlpk::_getObjCoeff(int i){ + //i=0 means the constant term (shift) + return lpx_get_obj_coef(lp, i); + } + void LpGlpk::_clearObj() { for (int i=0;i<=lpx_get_num_cols(lp);++i){ @@ -551,7 +563,13 @@ lpx_set_obj_dir(lp, LPX_MIN); } + bool LpGlpk::_isMax() + { + return (lpx_get_obj_dir(lp)==LPX_MAX); + } + + void LpGlpk::messageLevel(int m) { lpx_set_int_parm(lp, LPX_K_MSGLEV, m); diff -r 8b18b6fed090 -r 18fc834761d9 lemon/lp_glpk.h --- a/lemon/lp_glpk.h Mon Dec 04 15:00:24 2006 +0000 +++ b/lemon/lp_glpk.h Mon Dec 04 16:48:13 2006 +0000 @@ -60,12 +60,15 @@ virtual void _setRowCoeffs(int i, LpRowIterator b, LpRowIterator e); virtual void _setColCoeffs(int i, LpColIterator b, LpColIterator e); virtual void _setCoeff(int row, int col, Value value); + virtual Value _getCoeff(int row, int col); + virtual void _setColLowerBound(int i, Value value); virtual void _setColUpperBound(int i, Value value); // virtual void _setRowLowerBound(int i, Value value); // virtual void _setRowUpperBound(int i, Value value); virtual void _setRowBounds(int i, Value lower, Value upper); virtual void _setObjCoeff(int i, Value obj_coef); + virtual Value _getObjCoeff(int i); virtual void _clearObj(); // virtual void _setObj(int length, // int const * indices, @@ -91,6 +94,8 @@ virtual void _setMax(); virtual void _setMin(); + virtual bool _isMax(); + public: ///Set the verbosity of the messages diff -r 8b18b6fed090 -r 18fc834761d9 lemon/lp_skeleton.cc --- a/lemon/lp_skeleton.cc Mon Dec 04 15:00:24 2006 +0000 +++ b/lemon/lp_skeleton.cc Mon Dec 04 16:48:13 2006 +0000 @@ -68,6 +68,11 @@ { } + LpSkeleton::Value LpSkeleton::_getCoeff(int, int) + { + return 0; + } + void LpSkeleton::_setColLowerBound(int, Value) { @@ -93,6 +98,10 @@ { } + LpSkeleton::Value LpSkeleton::_getObjCoeff(int i){ + return 0; + } + void LpSkeleton::_setMax() { } @@ -101,6 +110,12 @@ { } + bool LpSkeleton::_isMax() + { + return true; + } + + void LpSkeleton::_clearObj() { } diff -r 8b18b6fed090 -r 18fc834761d9 lemon/lp_skeleton.h --- a/lemon/lp_skeleton.h Mon Dec 04 15:00:24 2006 +0000 +++ b/lemon/lp_skeleton.h Mon Dec 04 16:48:13 2006 +0000 @@ -55,6 +55,9 @@ /// Set one element of the coefficient matrix virtual void _setCoeff(int row, int col, Value value); + /// Get one element of the coefficient matrix + virtual Value _getCoeff(int row, int col); + /// The lower bound of a variable (column) have to be given by an /// extended number of type Value, i.e. a finite number of type /// Value or -\ref INF. @@ -91,6 +94,9 @@ /// \e virtual void _setObjCoeff(int i, Value obj_coef); + /// \e + virtual Value _getObjCoeff(int i); + ///\e ///\bug Wrong interface @@ -134,6 +140,11 @@ virtual void _setMin(); ///\e + virtual bool _isMax(); + + + + ///\e virtual bool _isBasicCol(int i); diff -r 8b18b6fed090 -r 18fc834761d9 test/lp_test.cc --- a/test/lp_test.cc Mon Dec 04 15:00:24 2006 +0000 +++ b/test/lp_test.cc Mon Dec 04 16:48:13 2006 +0000 @@ -293,6 +293,13 @@ lp.max(); + + //Testing the problem retrieving routines + check(lp.objCoeff(x1)==1,"First term should be 1 in the obj function!"); + check(lp.is_max(),"This is a maximization!"); + check(lp.coeff(upright,x1)==1,"The coefficient in question is 1!"); + + //Maximization of x1+x2 //over the triangle with vertices (0,0) (0,1) (1,0) double expected_opt=1;