Changeset 1099:91a8ee9d088d in lemon0.x for src/work/marci/lp/expression.h
 Timestamp:
 01/27/05 18:44:04 (16 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@1498
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/work/marci/lp/expression.h
r1097 r1099 20 20 template <typename _Col, typename _Value> 21 21 class Expr { 22 protected: 22 // protected: 23 public: 23 24 typedef 24 25 typename std::map<_Col, _Value> Data; 25 26 Data data; 26 27 public: 28 void simplify() { 29 for (typename Data::iterator i=data.begin(); 30 i!=data.end(); ++i) { 31 if ((*i).second==0) data.erase(i); 32 } 33 } 27 34 Expr() { } 28 35 Expr(_Col _col) { … … 34 41 (*i).second *= _value; 35 42 } 43 simplify(); 36 44 return *this; 37 45 } … … 46 54 } 47 55 } 56 simplify(); 57 return *this; 58 } 59 Expr& operator=(const Expr<_Col, _Value>& expr) { 60 for (typename Data::const_iterator j=expr.data.begin(); 61 j!=expr.data.end(); ++j) { 62 typename Data::iterator i=data.find((*j).first); 63 if (i==data.end()) { 64 data.insert(std::make_pair((*j).first, (*j).second)); 65 } else { 66 (*i).second+=(*j).second; 67 } 68 } 69 simplify(); 48 70 return *this; 49 71 } … … 57 79 Expr<_Col, _Value> tmp(_col); 58 80 tmp*=_value; 81 tmp.simplify(); 59 82 return tmp; 60 83 } … … 65 88 Expr<_Col, _Value> tmp(expr); 66 89 tmp*=_value; 90 tmp.simplify(); 67 91 return tmp; 68 92 } … … 73 97 Expr<_Col, _Value> tmp(expr1); 74 98 tmp+=expr2; 99 tmp.simplify(); 100 return tmp; 101 } 102 103 template <typename _Col, typename _Value> 104 Expr<_Col, _Value> operator(const Expr<_Col, _Value>& expr1, 105 const Expr<_Col, _Value>& expr2) { 106 Expr<_Col, _Value> tmp(expr1); 107 tmp=expr2; 108 tmp.simplify(); 75 109 return tmp; 76 110 }
Note: See TracChangeset
for help on using the changeset viewer.