summaryrefslogtreecommitdiff
path: root/impl/VariableAssignment.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'impl/VariableAssignment.hpp')
-rw-r--r--impl/VariableAssignment.hpp98
1 files changed, 41 insertions, 57 deletions
diff --git a/impl/VariableAssignment.hpp b/impl/VariableAssignment.hpp
index f41dab3..ead7c67 100644
--- a/impl/VariableAssignment.hpp
+++ b/impl/VariableAssignment.hpp
@@ -10,22 +10,6 @@ struct VariableAssignment {
virtual const Domain& operator[](const Variable<Domain>&) const = 0;
};
-template<typename Domain>
-struct StableVariableAssignment
-: public VariableAssignment<Domain>, public IdMap<Variable<Domain>, Domain> {
- StableVariableAssignment(unsigned int length)
- : IdMap<Variable<Domain>,Domain>(length, -infinity<Domain>()) { }
- StableVariableAssignment(unsigned int length, const Domain& value)
- : IdMap<Variable<Domain>,Domain>(length, value) { }
-
- const Domain& operator[](const Variable<Domain>& var) const {
- return IdMap<Variable<Domain>,Domain>::operator[](var);
- }
- Domain& operator[](const Variable<Domain>& var) {
- return IdMap<Variable<Domain>,Domain>::operator[](var);
- }
-};
-
#include "EquationSystem.hpp"
template<typename Domain>
@@ -50,7 +34,7 @@ struct DynamicVariableAssignment : public VariableAssignment<Domain> {
}
void invalidate(const Variable<Domain>& x) const {
- log::fixpoint << "invalidating " << x << std::endl;
+ log::fixpoint << "\tInvalidating " << x << std::endl;
_stable.remove(x);
_values[x] = infinity<Domain>();
}
@@ -58,53 +42,53 @@ struct DynamicVariableAssignment : public VariableAssignment<Domain> {
private:
void solve(const Variable<Domain>& x) const {
- if (!_stable.contains(x)) {
- _stable.insert(x);
-
- Domain val = _system[x]->eval(DependencyAssignment(*this, x),
- _strategy);
-
- if (val != _values[x]) {
- log::fixpoint << "Updating value for " << x
- << " to " << val << std::endl;
-
- auto oldInfluence = _influence[x];
- _influence[x].clear();
- _values[x] = val;
-
- _strategy.invalidate(x);
-
- _stable.filter(oldInfluence);
-
- for (auto it = oldInfluence.begin();
- it != oldInfluence.end();
- ++it) {
- solve(_system.variable(*it));
- }
- } else {
- log::fixpoint << x << " did not change" << std::endl;
+ if (!_stable.contains(x)) {
+ _stable.insert(x);
+ log::fixpoint << "\tStabilise " << x << std::endl;
+
+ Domain val = _system[x]->eval(DependencyAssignment(*this, x),
+ _strategy);
+
+ if (val != _values[x]) {
+ log::fixpoint << x << " = " << val << std::endl;
+
+ auto oldInfluence = _influence[x];
+ _influence[x].clear();
+ _values[x] = val;
+
+ _strategy.invalidate(x);
+
+ _stable.filter(oldInfluence);
+
+ for (auto it = oldInfluence.begin();
+ it != oldInfluence.end();
+ ++it) {
+ solve(_system.variable(*it));
}
} else {
- log::fixpoint << x << " is stable" << std::endl;
+ log::fixpoint << "\t" << x << " did not change" << std::endl;
}
+ } else {
+ log::fixpoint << "\t" << x << " is stable" << std::endl;
}
+ }
+
+ struct DependencyAssignment : public VariableAssignment<Domain> {
+ DependencyAssignment(const DynamicVariableAssignment& assignment, const Variable<Domain>& var)
+ : _assignment(assignment), _var(var) { }
+ const Domain& operator[](const Variable<Domain>& x) const {
+ const Domain& result = _assignment[x];
+ _assignment._influence[x].insert(_var);
+ return result;
+ }
+ private:
+ const DynamicVariableAssignment& _assignment;
+ const Variable<Domain>& _var;
+ };
- struct DependencyAssignment : public VariableAssignment<Domain> {
- DependencyAssignment(const DynamicVariableAssignment& assignment, const Variable<Domain>& var)
- : _assignment(assignment), _var(var) { }
- const Domain& operator[](const Variable<Domain>& x) const {
- const Domain& result = _assignment[x];
- _assignment._influence[x].insert(_var);
- return result;
- }
- private:
- const DynamicVariableAssignment& _assignment;
- const Variable<Domain>& _var;
- };
-
const EquationSystem<Domain>& _system;
const DynamicMaxStrategy<Domain>& _strategy;
- mutable StableVariableAssignment<Domain> _values;
+ mutable IdMap<Variable<Domain>, Domain> _values;
mutable IdSet<Variable<Domain> > _stable;
mutable IdMap<Variable<Domain>,IdSet<Variable<Domain> > > _influence;
};