2 #ifndef LEMON_EXPRESSION_H
3 #define LEMON_EXPRESSION_H
10 /*! \brief Linear expression
12 \c Expr<_Col,_Value> implements a class of linear expressions with the
13 operations of addition and multiplication with scalar.
17 template <typename _Col, typename _Value>
20 template <typename _Col, typename _Value>
24 typename std::map<_Col, _Value> Data;
29 data.insert(std::make_pair(_col, 1));
31 Expr& operator*=(_Value _value) {
32 for (typename Data::iterator i=data.begin();
34 (*i).second *= _value;
38 Expr& operator+=(const Expr<_Col, _Value>& expr) {
39 for (typename Data::const_iterator j=expr.data.begin();
40 j!=expr.data.end(); ++j) {
41 typename Data::iterator i=data.find((*j).first);
43 data.insert(std::make_pair((*j).first, (*j).second));
45 (*i).second+=(*j).second;
50 template <typename _C, typename _V>
51 friend std::ostream& operator<<(std::ostream& os,
52 const Expr<_C, _V>& expr);
55 template <typename _Col, typename _Value>
56 Expr<_Col, _Value> operator*(_Value _value, _Col _col) {
57 Expr<_Col, _Value> tmp(_col);
62 template <typename _Col, typename _Value>
63 Expr<_Col, _Value> operator*(_Value _value,
64 const Expr<_Col, _Value>& expr) {
65 Expr<_Col, _Value> tmp(expr);
70 template <typename _Col, typename _Value>
71 Expr<_Col, _Value> operator+(const Expr<_Col, _Value>& expr1,
72 const Expr<_Col, _Value>& expr2) {
73 Expr<_Col, _Value> tmp(expr1);
78 template <typename _Col, typename _Value>
79 std::ostream& operator<<(std::ostream& os,
80 const Expr<_Col, _Value>& expr) {
81 for (typename Expr<_Col, _Value>::Data::const_iterator i=
83 i!=expr.data.end(); ++i) {
84 os << (*i).second << "*" << (*i).first << " ";
91 #endif //LEMON_EXPRESSION_H