diff options
author | Carlo Zancanaro <carlo@carlo-laptop> | 2012-08-06 22:58:29 +1000 |
---|---|---|
committer | Carlo Zancanaro <carlo@carlo-laptop> | 2012-08-06 22:58:29 +1000 |
commit | 42e729d20000eb141b2907ad83630af34f4afea3 (patch) | |
tree | e231556126d538d6b61fe099c6245176aeb3df15 /impl/Expression.hpp | |
parent | 77d26a8f2832791587b19351ee1fde207fdda608 (diff) |
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.
Diffstat (limited to 'impl/Expression.hpp')
-rw-r--r-- | impl/Expression.hpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/impl/Expression.hpp b/impl/Expression.hpp index 01921b6..63f732d 100644 --- a/impl/Expression.hpp +++ b/impl/Expression.hpp @@ -14,6 +14,12 @@ template<typename Domain> struct MaxStrategy; template<typename Domain> +struct Variable; + +template<typename Domain> +struct MaxExpression; + +template<typename Domain> struct Expression { virtual ~Expression() { } @@ -23,6 +29,9 @@ struct Expression { return eval(rho); } + virtual void mapTo(Variable<Domain>&, IdMap<MaxExpression<Domain>, Variable<Domain>*>&) const { + } + virtual void print(std::ostream&) const = 0; }; @@ -101,6 +110,14 @@ struct OperatorExpression : public Expression<Domain> { return _operator; } + virtual void mapTo(Variable<Domain>& v, IdMap<MaxExpression<Domain>, Variable<Domain>*>& 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<Domain> { return bestIndex; } + virtual void mapTo(Variable<Domain>& v, IdMap<MaxExpression<Domain>, Variable<Domain>*>& 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; } |