From 0c62b0ba1b307ddc626a62127d835738775bb20d Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Tue, 23 Oct 2012 15:32:35 +1100 Subject: Fix the merge. --- impl/MaxStrategy.hpp | 61 +++++++--------------------------------------------- 1 file changed, 8 insertions(+), 53 deletions(-) (limited to 'impl/MaxStrategy.hpp') diff --git a/impl/MaxStrategy.hpp b/impl/MaxStrategy.hpp index ba7cc11..3ed7972 100644 --- a/impl/MaxStrategy.hpp +++ b/impl/MaxStrategy.hpp @@ -42,38 +42,30 @@ struct DynamicMaxStrategy : public MaxStrategy { _influence(system.maxExpressionCount(), IdSet >(system.maxExpressionCount())), _var_influence(system.variableCount(), - IdSet >(system.maxExpressionCount())), - _frozen(false) + IdSet >(system.maxExpressionCount())) {} - void freeze() { - _frozen = true; - } - - void thaw() { - _frozen = false; - } - - bool is_frozen() { - return _frozen; - } - void setRho(DynamicVariableAssignment& rho) { _rho = ρ } unsigned int get(const MaxExpression& e) const { + // slightly hacky + return const_cast*>(this)->get(e); + } + + unsigned int get(const MaxExpression& e) { if (!_frozen) solve(e); return _values[e]; } - void invalidate(const Variable& v) const { + void invalidate(const Variable& v) { log::strategy << indent() << "Invalidating " << v << " - " << *_system[v] << std::endl; 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 @@ -203,46 +195,9 @@ private: IdSet > _stable; IdMap,IdSet > > _influence; IdMap,IdSet > > _var_influence; - bool _frozen; }; -template -IdMap,T> solve_for(const EquationSystem& system) { - IdMap,T> result(system.variableCount(), infinity()); - - DynamicMaxStrategy strategy(system); - DynamicVariableAssignment rho(system, strategy, -infinity()); - strategy.setRho(rho); - - bool changed; - do { - changed = false; - - // improve strategy - rho.freeze(); - strategy.thaw(); - for (unsigned int i = 0; i < system.variableCount(); ++i) { - strategy.get(*system[system.variable(i)]); - } - - // iterate fixpoint - strategy.freeze(); - rho.thaw(); - for (unsigned int i = 0; i < system.variableCount(); ++i) { - Variable& var = system.variable(i); - T val = rho[var]; - if (result[var] != val) { - result[var] = val; - changed = true; - } - } - } while(changed); - - return result; -} - - /*template std::ostream& operator<<(std::ostream& cout, const MaxStrategy& strat) { strat.print(cout); -- cgit v1.2.3