athos@1247: /* -*- C++ -*- alpar@1253: * src/lemon/lp_base.h - Part of LEMON, a generic C++ optimization library athos@1247: * athos@1247: * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport athos@1247: * (Egervary Combinatorial Optimization Research Group, EGRES). athos@1247: * athos@1247: * Permission to use, modify and distribute this software is granted athos@1247: * provided that this copyright notice appears in all copies. For athos@1247: * precise terms see the accompanying LICENSE file. athos@1247: * athos@1247: * This software is provided "AS IS" with no warranty of any kind, athos@1247: * express or implied, and with no claim as to its suitability for any athos@1247: * purpose. athos@1247: * athos@1247: */ athos@1247: athos@1246: #ifndef LEMON_LP_BASE_H athos@1246: #define LEMON_LP_BASE_H athos@1246: alpar@1253: #include alpar@1272: #include alpar@1256: #include alpar@1273: #include alpar@1253: alpar@1256: #include alpar@1253: #include alpar@1256: #include alpar@1253: alpar@1272: //#include"lin_expr.h" alpar@1272: athos@1246: ///\file athos@1246: ///\brief The interface of the LP solver interface. athos@1246: namespace lemon { alpar@1253: alpar@1253: ///Internal data structure to convert floating id's to fix one's alpar@1253: alpar@1253: ///\todo This might by implemented to be usable in other places. alpar@1253: class _FixId alpar@1253: { alpar@1253: std::vector index; alpar@1253: std::vector cross; alpar@1253: int first_free; alpar@1253: public: alpar@1253: _FixId() : first_free(-1) {}; alpar@1253: ///Convert a floating id to a fix one alpar@1253: alpar@1253: ///\param n is a floating id alpar@1253: ///\return the corresponding fix id alpar@1253: int fixId(int n) {return cross[n];} alpar@1253: ///Convert a fix id to a floating one alpar@1253: alpar@1253: ///\param n is a fix id alpar@1253: ///\return the corresponding floating id alpar@1253: int floatingId(int n) { return index[n];} alpar@1253: ///Add a new floating id. alpar@1253: alpar@1253: ///\param n is a floating id alpar@1253: ///\return the fix id of the new value alpar@1253: ///\todo Multiple additions should also be handled. alpar@1253: int insert(int n) alpar@1253: { alpar@1253: if(n>=int(cross.size())) { alpar@1253: cross.resize(n+1); alpar@1253: if(first_free==-1) { alpar@1253: cross[n]=index.size(); alpar@1253: index.push_back(n); alpar@1253: } alpar@1253: else { alpar@1253: cross[n]=first_free; alpar@1253: int next=index[first_free]; alpar@1253: index[first_free]=n; alpar@1253: first_free=next; alpar@1253: } alpar@1256: return cross[n]; alpar@1253: } alpar@1273: ///\todo Create an own exception type. alpar@1253: else throw LogicError(); //floatingId-s must form a continuous range; alpar@1253: } alpar@1253: ///Remove a fix id. alpar@1253: alpar@1253: ///\param n is a fix id alpar@1253: /// alpar@1253: void erase(int n) alpar@1253: { alpar@1253: int fl=index[n]; alpar@1253: index[n]=first_free; alpar@1253: first_free=n; alpar@1253: for(int i=fl+1;i Expr; alpar@1273: class Expr : public std::map alpar@1272: { alpar@1272: public: alpar@1273: typedef LpSolverBase::Col Key; alpar@1273: typedef LpSolverBase::Value Value; alpar@1272: alpar@1272: protected: alpar@1273: typedef std::map Base; alpar@1272: alpar@1273: Value const_comp; alpar@1272: public: alpar@1272: typedef True IsLinExpression; alpar@1272: ///\e alpar@1272: Expr() : Base(), const_comp(0) { } alpar@1272: ///\e alpar@1273: Expr(const Key &v) : const_comp(0) { alpar@1272: Base::insert(std::make_pair(v, 1)); alpar@1272: } alpar@1272: ///\e alpar@1273: Expr(const Value &v) : const_comp(v) {} alpar@1272: ///\e alpar@1273: void set(const Key &v,const Value &c) { alpar@1272: Base::insert(std::make_pair(v, c)); alpar@1272: } alpar@1272: ///\e alpar@1273: Value &constComp() { return const_comp; } alpar@1272: ///\e alpar@1273: const Value &constComp() const { return const_comp; } alpar@1272: alpar@1272: ///Removes the components with zero coefficient. alpar@1272: void simplify() { alpar@1272: for (Base::iterator i=Base::begin(); i!=Base::end();) { alpar@1272: Base::iterator j=i; alpar@1272: ++j; alpar@1272: if ((*i).second==0) Base::erase(i); alpar@1272: j=i; alpar@1272: } alpar@1272: } alpar@1273: alpar@1273: ///Sets all coefficients and the constant component to 0. alpar@1273: void clear() { alpar@1273: Base::clear(); alpar@1273: const_comp=0; alpar@1273: } alpar@1273: alpar@1272: ///\e alpar@1272: Expr &operator+=(const Expr &e) { alpar@1272: for (Base::const_iterator j=e.begin(); j!=e.end(); ++j) alpar@1272: (*this)[j->first]+=j->second; alpar@1272: ///\todo it might be speeded up using "hints" alpar@1272: const_comp+=e.const_comp; alpar@1272: return *this; alpar@1272: } alpar@1272: ///\e alpar@1272: Expr &operator-=(const Expr &e) { alpar@1272: for (Base::const_iterator j=e.begin(); j!=e.end(); ++j) alpar@1272: (*this)[j->first]-=j->second; alpar@1272: const_comp-=e.const_comp; alpar@1272: return *this; alpar@1272: } alpar@1272: ///\e alpar@1273: Expr &operator*=(const Value &c) { alpar@1272: for (Base::iterator j=Base::begin(); j!=Base::end(); ++j) alpar@1272: j->second*=c; alpar@1272: const_comp*=c; alpar@1272: return *this; alpar@1272: } alpar@1272: ///\e alpar@1273: Expr &operator/=(const Value &c) { alpar@1272: for (Base::iterator j=Base::begin(); j!=Base::end(); ++j) alpar@1272: j->second/=c; alpar@1272: const_comp/=c; alpar@1272: return *this; alpar@1272: } alpar@1272: }; alpar@1272: alpar@1264: ///Linear constraint alpar@1272: //typedef LinConstr Constr; alpar@1272: class Constr alpar@1272: { alpar@1272: public: alpar@1272: typedef LpSolverBase::Expr Expr; alpar@1273: typedef Expr::Key Key; alpar@1273: typedef Expr::Value Value; alpar@1272: alpar@1273: static const Value INF; alpar@1273: static const Value NaN; alpar@1273: // static const Value INF=0; alpar@1273: // static const Value NaN=1; alpar@1272: alpar@1273: protected: alpar@1273: Expr _expr; alpar@1273: Value _lb,_ub; alpar@1273: public: alpar@1273: ///\e alpar@1273: Constr() : _expr(), _lb(NaN), _ub(NaN) {} alpar@1273: ///\e alpar@1273: Constr(Value lb,const Expr &e,Value ub) : alpar@1273: _expr(e), _lb(lb), _ub(ub) {} alpar@1273: ///\e alpar@1273: Constr(const Expr &e,Value ub) : alpar@1273: _expr(e), _lb(NaN), _ub(ub) {} alpar@1273: ///\e alpar@1273: Constr(Value lb,const Expr &e) : alpar@1273: _expr(e), _lb(lb), _ub(NaN) {} alpar@1273: ///\e alpar@1272: Constr(const Expr &e) : alpar@1273: _expr(e), _lb(NaN), _ub(NaN) {} alpar@1273: ///\e alpar@1273: void clear() alpar@1273: { alpar@1273: _expr.clear(); alpar@1273: _lb=_ub=NaN; alpar@1273: } alpar@1273: ///\e alpar@1273: Expr &expr() { return _expr; } alpar@1273: ///\e alpar@1273: const Expr &expr() const { return _expr; } alpar@1273: ///\e alpar@1273: Value &lowerBound() { return _lb; } alpar@1273: ///\e alpar@1273: const Value &lowerBound() const { return _lb; } alpar@1273: ///\e alpar@1273: Value &upperBound() { return _ub; } alpar@1273: ///\e alpar@1273: const Value &upperBound() const { return _ub; } alpar@1275: ///\e alpar@1275: bool lowerBounded() const { return std::isfinite(_lb); } alpar@1275: ///\e alpar@1275: bool upperBounded() const { return std::isfinite(_ub); } alpar@1272: }; alpar@1272: alpar@1253: alpar@1253: protected: alpar@1253: _FixId rows; alpar@1253: _FixId cols; athos@1246: athos@1246: /// \e athos@1246: virtual int _addCol() = 0; athos@1246: /// \e athos@1246: virtual int _addRow() = 0; athos@1246: /// \e alpar@1253: athos@1246: /// \warning Arrays are indexed from 1 (datum at index 0 is ignored) alpar@1253: /// athos@1246: virtual void _setRowCoeffs(int i, athos@1251: int length, athos@1247: int const * indices, athos@1247: Value const * values ) = 0; athos@1246: /// \e alpar@1253: athos@1246: /// \warning Arrays are indexed from 1 (datum at index 0 is ignored) alpar@1253: /// athos@1246: virtual void _setColCoeffs(int i, athos@1251: int length, athos@1247: int const * indices, athos@1247: Value const * values ) = 0; athos@1246: athos@1247: /// \e alpar@1253: athos@1247: /// The lower bound of a variable (column) have to be given by an athos@1247: /// extended number of type Value, i.e. a finite number of type alpar@1259: /// Value or -\ref INF. athos@1247: virtual void _setColLowerBound(int i, Value value) = 0; athos@1247: /// \e alpar@1253: athos@1247: /// The upper bound of a variable (column) have to be given by an athos@1247: /// extended number of type Value, i.e. a finite number of type alpar@1259: /// Value or \ref INF. athos@1247: virtual void _setColUpperBound(int i, Value value) = 0; athos@1247: /// \e alpar@1253: athos@1247: /// The lower bound of a linear expression (row) have to be given by an athos@1247: /// extended number of type Value, i.e. a finite number of type alpar@1259: /// Value or -\ref INF. athos@1247: virtual void _setRowLowerBound(int i, Value value) = 0; athos@1247: /// \e alpar@1253: athos@1247: /// The upper bound of a linear expression (row) have to be given by an athos@1247: /// extended number of type Value, i.e. a finite number of type alpar@1259: /// Value or \ref INF. athos@1247: virtual void _setRowUpperBound(int i, Value value) = 0; athos@1247: athos@1247: /// \e athos@1247: virtual void _setObjCoeff(int i, Value obj_coef) = 0; alpar@1253: alpar@1253: ///\e alpar@1263: alpar@1263: ///\bug Wrong interface alpar@1263: /// alpar@1263: virtual SolutionType _solve() = 0; alpar@1263: alpar@1263: ///\e alpar@1263: alpar@1263: ///\bug Wrong interface alpar@1263: /// alpar@1263: virtual Value _getSolution(int i) = 0; alpar@1263: ///\e alpar@1253: alpar@1253: ///\bug unimplemented!!!! alpar@1253: void clearObj() {} alpar@1253: public: alpar@1253: alpar@1253: alpar@1253: ///\e alpar@1253: virtual ~LpSolverBase() {} alpar@1253: alpar@1263: ///\name Building up and modification of the LP alpar@1263: alpar@1263: ///@{ alpar@1263: alpar@1253: ///Add a new empty column (i.e a new variable) to the LP alpar@1253: Col addCol() { Col c; c.id=cols.insert(_addCol()); return c;} alpar@1263: alpar@1256: ///\brief Fill the elements of a container with newly created columns alpar@1256: ///(i.e a new variables) alpar@1256: /// alpar@1273: ///This magic function takes a container as its argument alpar@1256: ///and fills its elements alpar@1256: ///with new columns (i.e. variables) alpar@1273: ///\param t can be alpar@1273: ///- a standard STL compatible iterable container with alpar@1273: ///\ref Col as its \c values_type alpar@1273: ///like alpar@1273: ///\code alpar@1273: ///std::vector alpar@1273: ///std::list alpar@1273: ///\endcode alpar@1273: ///- a standard STL compatible iterable container with alpar@1273: ///\ref Col as its \c mapped_type alpar@1273: ///like alpar@1273: ///\code alpar@1273: ///std::map alpar@1273: ///\endcode alpar@1273: ///- an iterable lemon \ref concept::WriteMap "write map" like alpar@1273: ///\code alpar@1273: ///ListGraph::NodeMap alpar@1273: ///ListGraph::EdgeMap alpar@1273: ///\endcode alpar@1256: ///\return The number of the created column. alpar@1256: ///\bug Iterable nodemap hasn't been implemented yet. alpar@1256: #ifdef DOXYGEN alpar@1256: template alpar@1256: int addColSet(T &t) { return 0;} alpar@1256: #else alpar@1256: template alpar@1256: typename enable_if::type alpar@1256: addColSet(T &t,dummy<0> = 0) { alpar@1256: int s=0; alpar@1256: for(typename T::iterator i=t.begin();i!=t.end();++i) {*i=addCol();s++;} alpar@1256: return s; alpar@1256: } alpar@1256: template alpar@1256: typename enable_if::type alpar@1256: addColSet(T &t,dummy<1> = 1) { alpar@1256: int s=0; alpar@1256: for(typename T::iterator i=t.begin();i!=t.end();++i) { alpar@1256: i->second=addCol(); alpar@1256: s++; alpar@1256: } alpar@1256: return s; alpar@1256: } alpar@1272: template alpar@1272: typename enable_if::type alpar@1272: addColSet(T &t,dummy<2> = 2) { alpar@1272: ///\bug return addColSet(t.valueSet()); should also work. alpar@1272: int s=0; alpar@1272: for(typename T::ValueSet::iterator i=t.valueSet().begin(); alpar@1272: i!=t.valueSet().end(); alpar@1272: ++i) alpar@1272: { alpar@1272: *i=addCol(); alpar@1272: s++; alpar@1272: } alpar@1272: return s; alpar@1272: } alpar@1256: #endif alpar@1263: alpar@1253: ///Add a new empty row (i.e a new constaint) to the LP alpar@1258: alpar@1258: ///This function adds a new empty row (i.e a new constaint) to the LP. alpar@1258: ///\return The created row alpar@1253: Row addRow() { Row r; r.id=rows.insert(_addRow()); return r;} alpar@1253: alpar@1258: ///Set a row (i.e a constaint) of the LP alpar@1253: alpar@1258: ///\param r is the row to be modified alpar@1259: ///\param l is lower bound (-\ref INF means no bound) alpar@1258: ///\param e is a linear expression (see \ref Expr) alpar@1259: ///\param u is the upper bound (\ref INF means no bound) alpar@1253: ///\bug This is a temportary function. The interface will change to alpar@1253: ///a better one. alpar@1258: void setRow(Row r, Value l,const Expr &e, Value u) { alpar@1253: std::vector indices; alpar@1253: std::vector values; alpar@1253: indices.push_back(0); alpar@1253: values.push_back(0); alpar@1258: for(Expr::const_iterator i=e.begin(); i!=e.end(); ++i) alpar@1256: if((*i).second!=0) { ///\bug EPSILON would be necessary here!!! alpar@1256: indices.push_back(cols.floatingId((*i).first.id)); alpar@1256: values.push_back((*i).second); alpar@1256: } alpar@1253: _setRowCoeffs(rows.floatingId(r.id),indices.size()-1, alpar@1253: &indices[0],&values[0]); alpar@1256: _setRowLowerBound(rows.floatingId(r.id),l-e.constComp()); alpar@1256: _setRowUpperBound(rows.floatingId(r.id),u-e.constComp()); alpar@1258: } alpar@1258: alpar@1264: ///Set a row (i.e a constaint) of the LP alpar@1264: alpar@1264: ///\param r is the row to be modified alpar@1264: ///\param c is a linear expression (see \ref Constr) alpar@1264: void setRow(Row r, const Constr &c) { alpar@1273: setRow(r, alpar@1275: c.lowerBounded()?c.lowerBound():-INF, alpar@1273: c.expr(), alpar@1275: c.upperBounded()?c.upperBound():INF); alpar@1264: } alpar@1264: alpar@1258: ///Add a new row (i.e a new constaint) to the LP alpar@1258: alpar@1259: ///\param l is the lower bound (-\ref INF means no bound) alpar@1258: ///\param e is a linear expression (see \ref Expr) alpar@1259: ///\param u is the upper bound (\ref INF means no bound) alpar@1258: ///\return The created row. alpar@1258: ///\bug This is a temportary function. The interface will change to alpar@1258: ///a better one. alpar@1258: Row addRow(Value l,const Expr &e, Value u) { alpar@1258: Row r=addRow(); alpar@1258: setRow(r,l,e,u); alpar@1253: return r; alpar@1253: } alpar@1253: alpar@1264: ///Add a new row (i.e a new constaint) to the LP alpar@1264: alpar@1264: ///\param c is a linear expression (see \ref Constr) alpar@1264: ///\return The created row. alpar@1264: Row addRow(const Constr &c) { alpar@1264: Row r=addRow(); alpar@1264: setRow(r,c); alpar@1264: return r; alpar@1264: } alpar@1264: alpar@1253: /// Set the lower bound of a column (i.e a variable) alpar@1253: alpar@1253: /// The upper bound of a variable (column) have to be given by an alpar@1253: /// extended number of type Value, i.e. a finite number of type alpar@1259: /// Value or -\ref INF. alpar@1253: virtual void setColLowerBound(Col c, Value value) { alpar@1253: _setColLowerBound(cols.floatingId(c.id),value); alpar@1253: } alpar@1253: /// Set the upper bound of a column (i.e a variable) alpar@1253: alpar@1253: /// The upper bound of a variable (column) have to be given by an alpar@1253: /// extended number of type Value, i.e. a finite number of type alpar@1259: /// Value or \ref INF. alpar@1253: virtual void setColUpperBound(Col c, Value value) { alpar@1253: _setColUpperBound(cols.floatingId(c.id),value); alpar@1253: }; alpar@1253: /// Set the lower bound of a row (i.e a constraint) alpar@1253: alpar@1253: /// The lower bound of a linear expression (row) have to be given by an alpar@1253: /// extended number of type Value, i.e. a finite number of type alpar@1259: /// Value or -\ref INF. alpar@1253: virtual void setRowLowerBound(Row r, Value value) { alpar@1253: _setRowLowerBound(rows.floatingId(r.id),value); alpar@1253: }; alpar@1253: /// Set the upper bound of a row (i.e a constraint) alpar@1253: alpar@1253: /// The upper bound of a linear expression (row) have to be given by an alpar@1253: /// extended number of type Value, i.e. a finite number of type alpar@1259: /// Value or \ref INF. alpar@1253: virtual void setRowUpperBound(Row r, Value value) { alpar@1253: _setRowUpperBound(rows.floatingId(r.id),value); alpar@1253: }; alpar@1253: ///Set an element of the objective function alpar@1253: void setObjCoeff(Col c, Value v) {_setObjCoeff(cols.floatingId(c.id),v); }; alpar@1253: ///Set the objective function alpar@1253: alpar@1253: ///\param e is a linear expression of type \ref Expr. alpar@1253: ///\todo What to do with the constant component? alpar@1253: void setObj(Expr e) { alpar@1253: clearObj(); alpar@1253: for (Expr::iterator i=e.begin(); i!=e.end(); ++i) alpar@1253: setObjCoeff((*i).first,(*i).second); alpar@1253: } alpar@1263: alpar@1263: ///@} alpar@1263: alpar@1263: alpar@1263: ///\name Solving the LP alpar@1263: alpar@1263: ///@{ alpar@1263: alpar@1263: ///\e alpar@1263: SolutionType solve() { return _solve(); } alpar@1263: alpar@1263: ///@} alpar@1263: alpar@1263: ///\name Obtaining the solution LP alpar@1263: alpar@1263: ///@{ alpar@1263: alpar@1263: ///\e alpar@1263: Value solution(Col c) { return _getSolution(cols.floatingId(c.id)); } alpar@1263: alpar@1263: ///@} alpar@1253: athos@1248: }; athos@1246: alpar@1272: ///\e alpar@1272: alpar@1272: ///\relates LpSolverBase::Expr alpar@1272: /// alpar@1272: inline LpSolverBase::Expr operator+(const LpSolverBase::Expr &a, alpar@1272: const LpSolverBase::Expr &b) alpar@1272: { alpar@1272: LpSolverBase::Expr tmp(a); alpar@1272: tmp+=b; ///\todo Don't STL have some special 'merge' algorithm? alpar@1272: return tmp; alpar@1272: } alpar@1272: ///\e alpar@1272: alpar@1272: ///\relates LpSolverBase::Expr alpar@1272: /// alpar@1272: inline LpSolverBase::Expr operator-(const LpSolverBase::Expr &a, alpar@1272: const LpSolverBase::Expr &b) alpar@1272: { alpar@1272: LpSolverBase::Expr tmp(a); alpar@1272: tmp-=b; ///\todo Don't STL have some special 'merge' algorithm? alpar@1272: return tmp; alpar@1272: } alpar@1272: ///\e alpar@1272: alpar@1272: ///\relates LpSolverBase::Expr alpar@1272: /// alpar@1272: inline LpSolverBase::Expr operator*(const LpSolverBase::Expr &a, alpar@1273: const LpSolverBase::Value &b) alpar@1272: { alpar@1272: LpSolverBase::Expr tmp(a); alpar@1272: tmp*=b; ///\todo Don't STL have some special 'merge' algorithm? alpar@1272: return tmp; alpar@1272: } alpar@1272: alpar@1272: ///\e alpar@1272: alpar@1272: ///\relates LpSolverBase::Expr alpar@1272: /// alpar@1273: inline LpSolverBase::Expr operator*(const LpSolverBase::Value &a, alpar@1272: const LpSolverBase::Expr &b) alpar@1272: { alpar@1272: LpSolverBase::Expr tmp(b); alpar@1272: tmp*=a; ///\todo Don't STL have some special 'merge' algorithm? alpar@1272: return tmp; alpar@1272: } alpar@1272: ///\e alpar@1272: alpar@1272: ///\relates LpSolverBase::Expr alpar@1272: /// alpar@1272: inline LpSolverBase::Expr operator/(const LpSolverBase::Expr &a, alpar@1273: const LpSolverBase::Value &b) alpar@1272: { alpar@1272: LpSolverBase::Expr tmp(a); alpar@1272: tmp/=b; ///\todo Don't STL have some special 'merge' algorithm? alpar@1272: return tmp; alpar@1272: } alpar@1272: alpar@1272: ///\e alpar@1272: alpar@1272: ///\relates LpSolverBase::Constr alpar@1272: /// alpar@1272: inline LpSolverBase::Constr operator<=(const LpSolverBase::Expr &e, alpar@1272: const LpSolverBase::Expr &f) alpar@1272: { alpar@1272: return LpSolverBase::Constr(-LpSolverBase::INF,e-f,0); alpar@1272: } alpar@1272: alpar@1272: ///\e alpar@1272: alpar@1272: ///\relates LpSolverBase::Constr alpar@1272: /// alpar@1273: inline LpSolverBase::Constr operator<=(const LpSolverBase::Value &e, alpar@1272: const LpSolverBase::Expr &f) alpar@1272: { alpar@1272: return LpSolverBase::Constr(e,f); alpar@1272: } alpar@1272: alpar@1272: ///\e alpar@1272: alpar@1272: ///\relates LpSolverBase::Constr alpar@1272: /// alpar@1272: inline LpSolverBase::Constr operator<=(const LpSolverBase::Expr &e, alpar@1273: const LpSolverBase::Value &f) alpar@1272: { alpar@1272: return LpSolverBase::Constr(e,f); alpar@1272: } alpar@1272: alpar@1272: ///\e alpar@1272: alpar@1272: ///\relates LpSolverBase::Constr alpar@1272: /// alpar@1272: inline LpSolverBase::Constr operator>=(const LpSolverBase::Expr &e, alpar@1272: const LpSolverBase::Expr &f) alpar@1272: { alpar@1272: return LpSolverBase::Constr(-LpSolverBase::INF,f-e,0); alpar@1272: } alpar@1272: alpar@1272: alpar@1272: ///\e alpar@1272: alpar@1272: ///\relates LpSolverBase::Constr alpar@1272: /// alpar@1273: inline LpSolverBase::Constr operator>=(const LpSolverBase::Value &e, alpar@1272: const LpSolverBase::Expr &f) alpar@1272: { alpar@1272: return LpSolverBase::Constr(f,e); alpar@1272: } alpar@1272: alpar@1272: alpar@1272: ///\e alpar@1272: alpar@1272: ///\relates LpSolverBase::Constr alpar@1272: /// alpar@1272: inline LpSolverBase::Constr operator>=(const LpSolverBase::Expr &e, alpar@1273: const LpSolverBase::Value &f) alpar@1272: { alpar@1272: return LpSolverBase::Constr(f,e); alpar@1272: } alpar@1272: alpar@1272: ///\e alpar@1272: alpar@1272: ///\relates LpSolverBase::Constr alpar@1272: /// alpar@1272: inline LpSolverBase::Constr operator==(const LpSolverBase::Expr &e, alpar@1272: const LpSolverBase::Expr &f) alpar@1272: { alpar@1272: return LpSolverBase::Constr(0,e-f,0); alpar@1272: } alpar@1272: alpar@1272: ///\e alpar@1272: alpar@1272: ///\relates LpSolverBase::Constr alpar@1272: /// alpar@1273: inline LpSolverBase::Constr operator<=(const LpSolverBase::Value &n, alpar@1272: const LpSolverBase::Constr&c) alpar@1272: { alpar@1272: LpSolverBase::Constr tmp(c); alpar@1273: ///\todo Create an own exception type. alpar@1273: if(!isnan(tmp.lowerBound())) throw LogicError(); alpar@1273: else tmp.lowerBound()=n; alpar@1272: return tmp; alpar@1272: } alpar@1272: ///\e alpar@1272: alpar@1272: ///\relates LpSolverBase::Constr alpar@1272: /// alpar@1272: inline LpSolverBase::Constr operator<=(const LpSolverBase::Constr& c, alpar@1273: const LpSolverBase::Value &n) alpar@1272: { alpar@1272: LpSolverBase::Constr tmp(c); alpar@1273: ///\todo Create an own exception type. alpar@1273: if(!isnan(tmp.upperBound())) throw LogicError(); alpar@1273: else tmp.upperBound()=n; alpar@1272: return tmp; alpar@1272: } alpar@1272: alpar@1272: ///\e alpar@1272: alpar@1272: ///\relates LpSolverBase::Constr alpar@1272: /// alpar@1273: inline LpSolverBase::Constr operator>=(const LpSolverBase::Value &n, alpar@1272: const LpSolverBase::Constr&c) alpar@1272: { alpar@1272: LpSolverBase::Constr tmp(c); alpar@1273: ///\todo Create an own exception type. alpar@1273: if(!isnan(tmp.upperBound())) throw LogicError(); alpar@1273: else tmp.upperBound()=n; alpar@1272: return tmp; alpar@1272: } alpar@1272: ///\e alpar@1272: alpar@1272: ///\relates LpSolverBase::Constr alpar@1272: /// alpar@1272: inline LpSolverBase::Constr operator>=(const LpSolverBase::Constr& c, alpar@1273: const LpSolverBase::Value &n) alpar@1272: { alpar@1272: LpSolverBase::Constr tmp(c); alpar@1273: ///\todo Create an own exception type. alpar@1273: if(!isnan(tmp.lowerBound())) throw LogicError(); alpar@1273: else tmp.lowerBound()=n; alpar@1272: return tmp; alpar@1272: } alpar@1272: alpar@1272: athos@1246: } //namespace lemon athos@1246: athos@1246: #endif //LEMON_LP_BASE_H