diff options
author | Carlo Zancanaro <carlo@carlo-laptop> | 2012-07-09 03:36:11 +1000 |
---|---|---|
committer | Carlo Zancanaro <carlo@carlo-laptop> | 2012-07-09 03:36:11 +1000 |
commit | f7d846f18354e254353bc417ed1a666c59ef3ea2 (patch) | |
tree | 7d2b94142c48712c5bdfa61551811e03518b803b /impl/FixpointAlgorithm.hpp | |
parent | b8045f2fa861959cdd87bd88dc2c6be98c115ec8 (diff) |
Better implementation: smarter strategy iteration
Also add the beginnings of some log stuff, mayhaps.
Diffstat (limited to 'impl/FixpointAlgorithm.hpp')
-rw-r--r-- | impl/FixpointAlgorithm.hpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/impl/FixpointAlgorithm.hpp b/impl/FixpointAlgorithm.hpp index 350047f..8511c43 100644 --- a/impl/FixpointAlgorithm.hpp +++ b/impl/FixpointAlgorithm.hpp @@ -5,12 +5,14 @@ #include "IdMap.hpp" #include "VariableAssignment.hpp" #include "EquationSystem.hpp" +#include "MaxStrategy.hpp" template<typename Domain> struct FixpointAlgorithm { virtual ~FixpointAlgorithm() { } virtual void maxFixpoint( const EquationSystem<Domain>& system, + const MaxStrategy<Domain>& strat, StableVariableAssignment<Domain>& rho, IdSet<Variable<Domain> >& changedIn, IdSet<Variable<Domain> >& changedOut @@ -23,16 +25,17 @@ struct NaiveFixpointAlgorithm : public FixpointAlgorithm<Domain> { : _system(system) { } virtual void maxFixpoint( const EquationSystem<Domain>& system, + const MaxStrategy<Domain>& strat, StableVariableAssignment<Domain>& rhoOut, - IdSet<Variable<Domain> >& changedIn, - IdSet<Variable<Domain> >& changedOut + IdSet<Variable<Domain> >&, + IdSet<Variable<Domain> >& ) { VariableAssignment<Domain>* rho = NULL; VariableAssignment<Domain>* result = system.assignment(infinity<Domain>()); do { if (rho) delete rho; rho = result; - result = _system.eval(*rho); + result = _system.eval(*rho, strat); } while (!_system.equalAssignments(*rho, *result)); if (rho) delete rho; @@ -55,11 +58,13 @@ struct SmartFixpointAlgorithm : public FixpointAlgorithm<Domain> { struct DynamicVariableAssignment : public VariableAssignment<Domain> { DynamicVariableAssignment( const EquationSystem<Domain>& system, + const MaxStrategy<Domain>& strat, IdMap<Variable<Domain>,IdSet<Variable<Domain> > >& influence, StableVariableAssignment<Domain>& rho, IdSet<Variable<Domain> >& stable, IdSet<Variable<Domain> >& changed ) : _system(system), + _strategy(strat), _values(rho), _stable(stable), _changed(changed), @@ -76,7 +81,7 @@ struct SmartFixpointAlgorithm : public FixpointAlgorithm<Domain> { if (!_stable.contains(x)) { _stable.insert(x); - Domain val = _system[x]->eval(DependencyAssignment(*this, x)); + Domain val = _system[x]->eval(DependencyAssignment(*this, x), _strategy); if (val != _values[x]) { IdSet<Variable<Domain> > oldInfluence = _influence[x]; @@ -110,6 +115,7 @@ struct SmartFixpointAlgorithm : public FixpointAlgorithm<Domain> { }; const EquationSystem<Domain>& _system; + const MaxStrategy<Domain>& _strategy; StableVariableAssignment<Domain>& _values; IdSet<Variable<Domain> >& _stable; IdSet<Variable<Domain> >& _changed; @@ -132,6 +138,7 @@ struct SmartFixpointAlgorithm : public FixpointAlgorithm<Domain> { virtual void maxFixpoint( const EquationSystem<Domain>& system, + const MaxStrategy<Domain>& strat, StableVariableAssignment<Domain>& rhoOut, IdSet<Variable<Domain> >& changedIn, IdSet<Variable<Domain> >& changedOut @@ -147,7 +154,7 @@ struct SmartFixpointAlgorithm : public FixpointAlgorithm<Domain> { } changedIn.invert(); - DynamicVariableAssignment rho(system, _influence, rhoOut, changedIn, changedOut); + DynamicVariableAssignment rho(system, strat, _influence, rhoOut, changedIn, changedOut); for (unsigned int i = 0, length = system.variableCount(); i < length; ++i) { rho[system.variable(i)]; } |