diff options
author | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-11-02 11:06:41 +1100 |
---|---|---|
committer | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-11-02 11:06:41 +1100 |
commit | ea660a9528cea35b7971dfc405e464cbddb2d1d0 (patch) | |
tree | c1989f3d1bd79ac8325326f00ba3cb321f0a3911 /impl/MaxStrategy.hpp | |
parent | a8472ef1867418b94116324531b3587e0e0e7363 (diff) | |
parent | 1c3d68659fb6341e7a72d563448380a7ffae8c2e (diff) |
Merge branch 'master' of ssh://bitbucket.org/czan/honours
Conflicts:
tex/thesis/contribution/contribution.tex
Diffstat (limited to 'impl/MaxStrategy.hpp')
-rw-r--r-- | impl/MaxStrategy.hpp | 62 |
1 files changed, 16 insertions, 46 deletions
diff --git a/impl/MaxStrategy.hpp b/impl/MaxStrategy.hpp index 5534597..6fee921 100644 --- a/impl/MaxStrategy.hpp +++ b/impl/MaxStrategy.hpp @@ -20,7 +20,7 @@ unsigned int stack_depth = 1; std::string indent() { std::string result = ""; for (unsigned int i = 0; i < stack_depth; ++i) { - result += '\t'; + result += ' '; } return result; } @@ -39,24 +39,13 @@ struct DynamicMaxStrategy : public MaxStrategy<Domain> { _values(system.maxExpressionCount(), 0), _stable(system.maxExpressionCount()), _influence(system.maxExpressionCount(), - IdSet<MaxExpression<Domain> >(system.maxExpressionCount())), - _var_influence(system.variableCount(), - IdSet<MaxExpression<Domain> >(system.maxExpressionCount())), - _changed(false) + IdSet<MaxExpression<Domain> >(system.maxExpressionCount())) {} void setRho(DynamicVariableAssignment<Domain>& rho) { _rho = ρ } - void hasChanged(bool c) { - _changed = c; - } - - bool hasChanged() const { - return _changed; - } - unsigned int get(const MaxExpression<Domain>& e) const { log::strategy << indent() << "Look up " << e << std::endl; return _values[e]; @@ -70,9 +59,8 @@ struct DynamicMaxStrategy : public MaxStrategy<Domain> { void invalidate(const Variable<Domain>& v) { log::strategy << indent() << "Invalidating " << v << " - " << *_system[v] << std::endl; - //log::debug << indent() << " var-influence sets " << _var_influence << std::endl; - IdSet<MaxExpression<Domain> > infl = _var_influence[v]; + IdSet<MaxExpression<Domain> > infl = _influence[*_system[v]]; for (typename IdSet<MaxExpression<Domain> >::iterator it = infl.begin(), end = infl.end(); @@ -102,32 +90,32 @@ struct DynamicMaxStrategy : public MaxStrategy<Domain> { private: void solve(const MaxExpression<Domain>& x) { if (!_stable.contains(x)) { + std::cerr << indent() << x.id() << std::endl; _stable.insert(x); log::strategy << indent() << "Stabilise " << x << std::endl; stack_depth++; DependencyAssignment assignment(*this, *_rho, x); DependencyStrategy depStrat(*this, x); - unsigned int val = x.bestStrategy(assignment, depStrat); + unsigned int val = x.bestStrategy(assignment, depStrat, _values[x]); stack_depth--; if (val != _values[x]) { + std::cerr << indent() << "-" << std::endl; log::strategy << x << " => " << *x.arguments()[val] << std::endl; - IdSet<MaxExpression<Domain> > oldInfluence = _influence[x]; - //_influence[x].clear(); _values[x] = val; - _changed = true; _rho->invalidate(*_system.varFromExpr(x)); //_rho->stabilise(); - _stable.filter(oldInfluence); - + IdSet<MaxExpression<Domain> > infl = _influence[x]; + _stable.filter(infl); + for (typename IdSet<MaxExpression<Domain> >::iterator - it = oldInfluence.begin(), - end = oldInfluence.end(); + it = infl.begin(), + end = infl.end(); it != end; ++it) { solve(_system.maxExpression(*it)); @@ -153,8 +141,8 @@ private: } const Domain operator[](const Variable<Domain>& var) { // solve the strategy for this variable, too + // recursive magic! _strat.solve(*_strat._system[var]); - _strat._var_influence[var].insert(_expr); _strat._influence[*_strat._system[var]].insert(_expr); return _rho[var]; } @@ -190,8 +178,6 @@ private: IdMap<MaxExpression<Domain>,unsigned int> _values; IdSet<MaxExpression<Domain> > _stable; IdMap<MaxExpression<Domain>,IdSet<MaxExpression<Domain> > > _influence; - IdMap<Variable<Domain>,IdSet<MaxExpression<Domain> > > _var_influence; - bool _changed; }; @@ -205,28 +191,12 @@ struct Solver { } Domain solve(Variable<Domain>& var) { - MaxExpression<Domain>& rhs = *_system[var]; - - // _rho automatically keeps up to date with changes made to the - // strategy, so you don't need to stabilise it - + MaxExpression<Domain>& rhs = *_system[var]; + // this will automatically work sufficiently to get the final + // strategy for this variable's RHS _strategy.get(rhs); - - /* - do { - _strategy.hasChanged(false); - - log::debug << "Stabilise assignment (toplevel)" << std::endl; - _rho.stabilise(); - - log::debug << "Improve strategy (toplevel)" << std::endl; - // improve strategy - _strategy.get(rhs); - log::debug << (_strategy.hasChanged() ? "Strategy has changed - loop again" : "Strategy has not changed - terminate") << std::endl; - } while (_strategy.hasChanged()); - */ - + // this will automatically solve for the value of the RHS, if required return _rho[var]; } private: |