diff options
Diffstat (limited to 'impl/VariableAssignment.hpp')
-rw-r--r-- | impl/VariableAssignment.hpp | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/impl/VariableAssignment.hpp b/impl/VariableAssignment.hpp index a1f0b5b..cfce925 100644 --- a/impl/VariableAssignment.hpp +++ b/impl/VariableAssignment.hpp @@ -8,6 +8,9 @@ template<typename Domain> struct VariableAssignment { virtual ~VariableAssignment() { } virtual const Domain& operator[](const Variable<Domain>&) const = 0; + virtual const Domain& operator[](const Variable<Domain>& x) { + return (*const_cast<const VariableAssignment*>(this))[x]; + } }; #include "EquationSystem.hpp" @@ -19,21 +22,40 @@ template<typename Domain> struct DynamicVariableAssignment : public VariableAssignment<Domain> { DynamicVariableAssignment( const EquationSystem<Domain>& system, - const DynamicMaxStrategy<Domain>& strat + DynamicMaxStrategy<Domain>& strat, + const Domain& value=infinity<Domain>() ) : _system(system), _strategy(strat), _values(system.variableCount(), unknown(infinity<Domain>())), _stable(system.variableCount()), _influence(system.variableCount(), - IdSet<Variable<Domain> >(system.variableCount())) + IdSet<Variable<Domain> >(system.variableCount())), + _frozen(false) { } + void freeze() { + _frozen = true; + } + + void thaw() { + _frozen = false; + } + + bool is_frozen() { + return _frozen; + } + const Domain& operator[](const Variable<Domain>& var) const { - solve(var); return _values[var]; } - void invalidate(const Variable<Domain>& x) const { + const Domain& operator[](const Variable<Domain>& var) { + if (!_frozen) + solve(var); + return _values[var]; + } + + void invalidate(const Variable<Domain>& x) { log::fixpoint << indent() << "Invalidating " << x << std::endl; if (_stable.contains(x)) { _stable.remove(x); @@ -56,7 +78,7 @@ struct DynamicVariableAssignment : public VariableAssignment<Domain> { private: - void solve(const Variable<Domain>& x) const { + void solve(const Variable<Domain>& x) { if (!_stable.contains(x)) { _stable.insert(x); log::fixpoint << indent() << "Stabilise " << x << std::endl; @@ -93,7 +115,7 @@ private: } struct DependencyAssignment : public VariableAssignment<Domain> { - DependencyAssignment(const DynamicVariableAssignment& assignment, const Variable<Domain>& var) + DependencyAssignment(DynamicVariableAssignment& assignment, const Variable<Domain>& var) : _assignment(assignment), _var(var) { } const Domain& operator[](const Variable<Domain>& x) const { const Domain& result = _assignment[x]; @@ -101,7 +123,7 @@ private: return result; } private: - const DynamicVariableAssignment& _assignment; + DynamicVariableAssignment& _assignment; const Variable<Domain>& _var; }; |