From a1b28d756fe52a53d9d4da4d23853969fd529115 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Tue, 23 Oct 2012 14:40:38 +1100 Subject: Make the recursive solver work properly. If you ignore the intermediate results for the strategy iteration phase then you're in the clear! I think! --- impl/MaxStrategy.hpp | 66 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 13 deletions(-) (limited to 'impl/MaxStrategy.hpp') diff --git a/impl/MaxStrategy.hpp b/impl/MaxStrategy.hpp index 96aeef4..96d0492 100644 --- a/impl/MaxStrategy.hpp +++ b/impl/MaxStrategy.hpp @@ -31,7 +31,8 @@ template struct DynamicMaxStrategy : public MaxStrategy { DynamicMaxStrategy( const EquationSystem& system - ) : _system(system), + ) : _frozen(false), + _system(system), _rho(NULL), _values(system.maxExpressionCount(), 0), _stable(system.maxExpressionCount()), @@ -46,23 +47,26 @@ struct DynamicMaxStrategy : public MaxStrategy { } unsigned int get(const MaxExpression& e) const { - solve(e); + if (!_frozen) + solve(e); return _values[e]; } void invalidate(const Variable& v) const { log::strategy << indent() << "Invalidating " << v << " - " << *_system[v] << std::endl; - _stable.filter(_var_influence[v]); - - IdSet > infl = _var_influence[v]; - _var_influence[v].clear(); - - for (typename IdSet >::iterator - it = infl.begin(), - end = infl.end(); - it != end; - ++it) { - solve(_system.maxExpression(*it)); + if (_system[v] && _stable.contains(*_system[v])) { + _stable.remove(*_system[v]); + _stable.filter(_var_influence[v]); + + IdSet > infl = _var_influence[v]; + _var_influence[v].clear(); + for (typename IdSet >::iterator + it = infl.begin(), + end = infl.end(); + it != end; + ++it) { + solve(_system.maxExpression(*it)); + } } } @@ -78,6 +82,7 @@ private: stack_depth--; if (val != _values[x]) { + log::strategy << x << " => " << *x.arguments()[val] << std::endl; IdSet > oldInfluence = _influence[x]; @@ -105,6 +110,16 @@ private: } } + const DynamicMaxStrategy& freeze() const { + _frozen = true; + return *this; + } + + const DynamicMaxStrategy& thaw() const { + _frozen = false; + return *this; + } + struct DependencyAssignment : public VariableAssignment{ DependencyAssignment(const DynamicMaxStrategy& strat, VariableAssignment& rho, @@ -123,6 +138,30 @@ private: const MaxExpression& _expr; }; + struct InvalidatingAssignment : public VariableAssignment{ + InvalidatingAssignment(DynamicVariableAssignment& rho) + : _rho(rho) { + } + ~InvalidatingAssignment() { + for (typename std::set*>::iterator + it = seen.begin(), + ei = seen.end(); + it != ei; + ++it) { + if (!_old_stable.contains(**it)) + _rho.invalidate(**it); + } + } + const Domain& operator[](const Variable& var) const { + seen.insert(&var); + return _rho[var]; + } + private: + DynamicVariableAssignment& _rho; + IdSet > _old_stable; + mutable std::set*> seen; + }; + struct DependencyStrategy : public MaxStrategy { DependencyStrategy(const DynamicMaxStrategy& strat, const MaxExpression& expr) : _strat(strat), @@ -141,6 +180,7 @@ private: }; private: + mutable bool _frozen; const EquationSystem& _system; mutable DynamicVariableAssignment* _rho; mutable IdMap,unsigned int> _values; -- cgit v1.2.3