From 42e729d20000eb141b2907ad83630af34f4afea3 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Mon, 6 Aug 2012 22:58:29 +1000 Subject: New variation on the equation system solver. Much simpler to understand. Basically have a variable assignment which is dynamic and updates with the strategy changes. Similarly have strategy changes easily invalidate the variable assignment. This makes them strongly inter-dependent, but simplifies the implementation considerably. Proving it should be easier like this, too. --- impl/Expression.hpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'impl/Expression.hpp') diff --git a/impl/Expression.hpp b/impl/Expression.hpp index 01921b6..63f732d 100644 --- a/impl/Expression.hpp +++ b/impl/Expression.hpp @@ -13,6 +13,12 @@ struct VariableAssignment; template struct MaxStrategy; +template +struct Variable; + +template +struct MaxExpression; + template struct Expression { virtual ~Expression() { } @@ -23,6 +29,9 @@ struct Expression { return eval(rho); } + virtual void mapTo(Variable&, IdMap, Variable*>&) const { + } + virtual void print(std::ostream&) const = 0; }; @@ -101,6 +110,14 @@ struct OperatorExpression : public Expression { return _operator; } + virtual void mapTo(Variable& v, IdMap, Variable*>& m) const { + for (unsigned int i = 0, length = _arguments.size(); + i < length; + ++i) { + _arguments[i]->mapTo(v, m); + } + } + void print(std::ostream& cout) const { cout << _operator << "("; for (unsigned int i = 0, length = _arguments.size(); @@ -144,6 +161,15 @@ struct MaxExpression : public OperatorExpression { return bestIndex; } + virtual void mapTo(Variable& v, IdMap, Variable*>& m) const { + m[*this] = &v; + for (unsigned int i = 0, length = this->_arguments.size(); + i < length; + ++i) { + this->_arguments[i]->mapTo(v, m); + } + } + unsigned int id() const { return _id; } -- cgit v1.2.3