# HG changeset patch # User alpar # Date 1113764242 0 # Node ID ee5959aa4410c3a32e25ae9a4d3a31849b615777 # Parent a32f990b73d9888c46c28607ac4a79ff1bfc175d - compile failure fixed - newLp(), copyLp() added - more doc. diff -r a32f990b73d9 -r ee5959aa4410 src/lemon/lp_base.cc --- a/src/lemon/lp_base.cc Fri Apr 15 22:12:51 2005 +0000 +++ b/src/lemon/lp_base.cc Sun Apr 17 18:57:22 2005 +0000 @@ -25,9 +25,9 @@ const LpSolverBase::Value LpSolverBase::NaN = std::numeric_limits::quiet_NaN(); - const LpSolverBase::Constr::Value - LpSolverBase::Constr::INF = std::numeric_limits::infinity(); - const LpSolverBase::Constr::Value - LpSolverBase::Constr::NaN = std::numeric_limits::quiet_NaN(); +// const LpSolverBase::Constr::Value +// LpSolverBase::Constr::INF = std::numeric_limits::infinity(); +// const LpSolverBase::Constr::Value +// LpSolverBase::Constr::NaN = std::numeric_limits::quiet_NaN(); } //namespace lemon diff -r a32f990b73d9 -r ee5959aa4410 src/lemon/lp_base.h --- a/src/lemon/lp_base.h Fri Apr 15 22:12:51 2005 +0000 +++ b/src/lemon/lp_base.h Sun Apr 17 18:57:22 2005 +0000 @@ -198,7 +198,7 @@ ///There are several ways to access and modify the contents of this ///container. ///- Its it fully compatible with \c std::map, so for expamle - ///if \c e is an Expr and \c v and \c w are of type \ref Col then you can + ///if \c e is an Expr and \c v and \c w are of type \ref Col, then you can ///read and modify the coefficients like ///these. ///\code @@ -318,8 +318,29 @@ ///Linear constraint - ///\todo document please - /// + ///This data stucture represents a linear constraint in the LP. + ///Basically it is a linear expression with a lower or an upper bound + ///(or both). These parts of the constraint can be obtained by the member + ///functions \ref expr(), \ref lowerBound() and \ref upperBound(), + ///respectively. + ///There are two ways to construct a constraint. + ///- You can set the linear expression and the bounds directly + /// by the functions above. + ///- The operators \<=, == and \>= + /// are defined between expressions, or even between constraints whenever + /// it makes sense. Therefore if \c e and \c f are linear expressions and + /// \c s and \c t are numbers, then the followings are valid expressions + /// and thus they can be used directly e.g. in \ref addRow() whenever + /// it makes sense. + /// \code + /// e<=s + /// e<=f + /// s<=e<=t + /// e>=t + /// \endcode + ///\warning The validity of a constraint is checked only at run time, so + ///e.g. \ref addRow(x[1]\<=x[2]<=5) will compile, but will throw a + ///\ref LogicError exception. class Constr { public: @@ -327,11 +348,9 @@ typedef Expr::Key Key; typedef Expr::Value Value; - static const Value INF; - static const Value NaN; - // static const Value INF=0; - // static const Value NaN=1; - +// static const Value INF; +// static const Value NaN; + protected: Expr _expr; Value _lb,_ub; @@ -356,24 +375,35 @@ _expr.clear(); _lb=_ub=NaN; } - ///\e + + ///Reference to the linear expression Expr &expr() { return _expr; } - ///\e + ///Cont reference to the linear expression const Expr &expr() const { return _expr; } - ///\e + ///Reference to the lower bound. + + ///\return + ///- -\ref INF: the constraint is lower unbounded. + ///- -\ref NaN: lower bound has not been set. + ///- finite number: the lower bound Value &lowerBound() { return _lb; } - ///\e + ///The const version of \ref lowerBound() const Value &lowerBound() const { return _lb; } - ///\e + ///Reference to the upper bound. + + ///\return + ///- -\ref INF: the constraint is upper unbounded. + ///- -\ref NaN: upper bound has not been set. + ///- finite number: the upper bound Value &upperBound() { return _ub; } - ///\e + ///The const version of \ref upperBound() const Value &upperBound() const { return _ub; } - ///\e + ///Is the constraint lower bounded? bool lowerBounded() const { using namespace std; return isfinite(_lb); } - ///\e + ///Is the constraint upper bounded? bool upperBounded() const { using namespace std; return isfinite(_ub); @@ -386,6 +416,9 @@ _FixId cols; //Abstract virtual functions + virtual LpSolverBase &_newLp() = 0; + virtual LpSolverBase &_copyLp() = 0; + virtual int _addCol() = 0; virtual int _addRow() = 0; virtual void _setRowCoeffs(int i, @@ -426,6 +459,11 @@ ///\e virtual ~LpSolverBase() {} + ///Creates a new LP problem + LpSolverBase &newLp() {return _newLp();} + ///Make a copy of the LP problem + LpSolverBase ©Lp() {return _copyLp();} + ///\name Build up and modify of the LP ///@{ @@ -451,7 +489,7 @@ ///\ref Col as its \c mapped_type ///like ///\code - ///std::map + ///std::map ///\endcode ///- an iterable lemon \ref concept::WriteMap "write map" like ///\code @@ -459,7 +497,6 @@ ///ListGraph::EdgeMap ///\endcode ///\return The number of the created column. - ///\bug Iterable nodemap hasn't been implemented yet. #ifdef DOXYGEN template int addColSet(T &t) { return 0;} @@ -668,7 +705,7 @@ ///\return ///- \ref INF or -\ref INF means either infeasibility or unboundedness /// of the primal problem, depending on whether we minimize or maximize. - ///- \ref NAN if no primal solution is found. + ///- \ref NaN if no primal solution is found. ///- The (finite) objective value if an optimal solution is found. Value primalValue() { return _getPrimalValue()+obj_const_comp;} ///@} @@ -683,7 +720,7 @@ const LpSolverBase::Expr &b) { LpSolverBase::Expr tmp(a); - tmp+=b; ///\todo Don't STL have some special 'merge' algorithm? + tmp+=b; ///\todo Doesn't STL have some special 'merge' algorithm? return tmp; } ///\e @@ -694,7 +731,7 @@ const LpSolverBase::Expr &b) { LpSolverBase::Expr tmp(a); - tmp-=b; ///\todo Don't STL have some special 'merge' algorithm? + tmp-=b; ///\todo Doesn't STL have some special 'merge' algorithm? return tmp; } ///\e @@ -705,7 +742,7 @@ const LpSolverBase::Value &b) { LpSolverBase::Expr tmp(a); - tmp*=b; ///\todo Don't STL have some special 'merge' algorithm? + tmp*=b; ///\todo Doesn't STL have some special 'merge' algorithm? return tmp; } @@ -717,7 +754,7 @@ const LpSolverBase::Expr &b) { LpSolverBase::Expr tmp(b); - tmp*=a; ///\todo Don't STL have some special 'merge' algorithm? + tmp*=a; ///\todo Doesn't STL have some special 'merge' algorithm? return tmp; } ///\e @@ -728,7 +765,7 @@ const LpSolverBase::Value &b) { LpSolverBase::Expr tmp(a); - tmp/=b; ///\todo Don't STL have some special 'merge' algorithm? + tmp/=b; ///\todo Doesn't STL have some special 'merge' algorithm? return tmp; } diff -r a32f990b73d9 -r ee5959aa4410 src/lemon/lp_glpk.cc --- a/src/lemon/lp_glpk.cc Fri Apr 15 22:12:51 2005 +0000 +++ b/src/lemon/lp_glpk.cc Sun Apr 17 18:57:22 2005 +0000 @@ -24,6 +24,24 @@ namespace lemon { + ///\e + + ///\bug Unimplemented! + /// + LpSolverBase &LpGlpk::_newLp() + { + return *((LpSolverBase *)0); + } + + ///\e + + ///\bug Unimplemented! + /// + LpSolverBase &LpGlpk::_copyLp() + { + return *((LpSolverBase *)0); + } + LpGlpk::LpGlpk() : Parent(), lp(lpx_create_prob()) { ///\todo constrol function for this: diff -r a32f990b73d9 -r ee5959aa4410 src/lemon/lp_glpk.h --- a/src/lemon/lp_glpk.h Fri Apr 15 22:12:51 2005 +0000 +++ b/src/lemon/lp_glpk.h Sun Apr 17 18:57:22 2005 +0000 @@ -31,7 +31,7 @@ /// \brief Wrapper for GLPK solver /// - /// This class implements a lemon wrapper for GLPK. + /// This class implements an interface for GLPK. ///\ingroup gen_opt_group class LpGlpk : public LpSolverBase { protected: @@ -45,6 +45,9 @@ ~LpGlpk(); protected: + virtual LpSolverBase &_newLp(); + virtual LpSolverBase &_copyLp(); + virtual int _addCol(); virtual int _addRow(); virtual void _setRowCoeffs(int i, diff -r a32f990b73d9 -r ee5959aa4410 src/lemon/lp_skeleton.cc --- a/src/lemon/lp_skeleton.cc Fri Apr 15 22:12:51 2005 +0000 +++ b/src/lemon/lp_skeleton.cc Sun Apr 17 18:57:22 2005 +0000 @@ -21,6 +21,16 @@ ///\brief A skeleton file to implement LP solver interfaces namespace lemon { + LpSolverBase &LpSkeleton::_newLp() + { + return *((LpSolverBase *)0); + } + + LpSolverBase &LpSkeleton::_copyLp() + { + return *((LpSolverBase *)0); + } + int LpSkeleton::_addCol() { return ++col_num; diff -r a32f990b73d9 -r ee5959aa4410 src/lemon/lp_skeleton.h --- a/src/lemon/lp_skeleton.h Fri Apr 15 22:12:51 2005 +0000 +++ b/src/lemon/lp_skeleton.h Sun Apr 17 18:57:22 2005 +0000 @@ -29,6 +29,10 @@ int col_num,row_num; protected: + ///\e + virtual LpSolverBase &_newLp(); + ///\e + virtual LpSolverBase &_copyLp(); /// \e virtual int _addCol(); /// \e