diff options
Diffstat (limited to 'impl/EquationSystem.hpp')
-rw-r--r-- | impl/EquationSystem.hpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/impl/EquationSystem.hpp b/impl/EquationSystem.hpp index adc608b..00916d0 100644 --- a/impl/EquationSystem.hpp +++ b/impl/EquationSystem.hpp @@ -11,6 +11,9 @@ struct EquationSystem { for (int i = 0, size = _vars.size(); i < size; ++i) { delete _vars[i]; } + for (int i = 0, size = _expressions.size(); i < size; ++i) { + delete _expressions[i]; + } } Variable<T>* newVariable(const std::string&) { _vars.push_back(new Variable<T>(_vars.size())); @@ -20,10 +23,17 @@ struct EquationSystem { return _vars.size(); } + Expression<T>* newExpression(Operator<T>* op, const std::vector<Expression<T>*>& args) { + Expression<T>* expr = new Expression<T>(op, args); + _expressions.push_back(expr); + return expr; + } + MaxExpression<T>* newMaxExpression(const std::vector<Expression<T>*>& args) { MaxExpression<T>* expr = new MaxExpression<T>(args); expr->id(_max_expressions.size()); _max_expressions.push_back(expr); + _expressions.push_back(expr); return expr; } unsigned int maxCount() const { @@ -42,23 +52,23 @@ struct EquationSystem { } Expression<T>*& operator[] (const Variable<T>& v) { - if (_expressions.size() <= v.id()) { - _expressions.resize(v.id()+1); + if (_right_expressions.size() <= v.id()) { + _right_expressions.resize(v.id()+1); } - return _expressions[v.id()]; + return _right_expressions[v.id()]; } const Expression<T>*& operator[] (const Variable<T>& v) const { - if (_expressions.size() <= v.id()) { + if (_right_expressions.size() <= v.id()) { throw "Out of range"; } - return _expressions[v.id()]; + return _right_expressions[v.id()]; } template<typename F> VariableAssignment<T> foreach(F op, const VariableAssignment<T>& rho) const { VariableAssignment<T> result(_vars.size()); for (unsigned int i = 0, size = _vars.size(); i < size; ++i) { - result[*_vars[i]] = op(*_expressions[i], rho); + result[*_vars[i]] = op(*_right_expressions[i], rho); } return result; } @@ -66,7 +76,7 @@ struct EquationSystem { VariableAssignment<T> operator() (const VariableAssignment<T>& rho) const { VariableAssignment<T> result(_vars.size()); for (unsigned int i = 0, size = _vars.size(); i < size; ++i) { - result[*_vars[i]] = (*_expressions[i])(rho); + result[*_vars[i]] = (*_right_expressions[i])(rho); } return result; } @@ -112,6 +122,7 @@ struct EquationSystem { std::vector<Variable<T>*> _vars; std::vector<MaxExpression<T>*> _max_expressions; std::vector<Expression<T>*> _expressions; + std::vector<Expression<T>*> _right_expressions; }; #include "MaxStrategy.hpp" |