From b7eaa99578037789a337c5061c0ea8ee3150b63c Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Thu, 1 Nov 2012 18:06:13 +1100 Subject: A bunch of fixes to the solver, and moving it in to clang. Also some contribution writing stuff. Basically: lots of work. --- impl/MaxStrategy.hpp | 55 ++++++++++++++-------------------------------------- 1 file changed, 15 insertions(+), 40 deletions(-) (limited to 'impl/MaxStrategy.hpp') diff --git a/impl/MaxStrategy.hpp b/impl/MaxStrategy.hpp index 71ea4f4..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,22 +39,13 @@ struct DynamicMaxStrategy : public MaxStrategy { _values(system.maxExpressionCount(), 0), _stable(system.maxExpressionCount()), _influence(system.maxExpressionCount(), - IdSet >(system.maxExpressionCount())), - _changed(false) + IdSet >(system.maxExpressionCount())) {} void setRho(DynamicVariableAssignment& rho) { _rho = ρ } - void hasChanged(bool c) { - _changed = c; - } - - bool hasChanged() const { - return _changed; - } - unsigned int get(const MaxExpression& e) const { log::strategy << indent() << "Look up " << e << std::endl; return _values[e]; @@ -99,32 +90,32 @@ struct DynamicMaxStrategy : public MaxStrategy { private: void solve(const MaxExpression& 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 > oldInfluence = _influence[x]; - //_influence[x].clear(); _values[x] = val; - _changed = true; _rho->invalidate(*_system.varFromExpr(x)); //_rho->stabilise(); - _stable.filter(oldInfluence); - + IdSet > infl = _influence[x]; + _stable.filter(infl); + for (typename IdSet >::iterator - it = oldInfluence.begin(), - end = oldInfluence.end(); + it = infl.begin(), + end = infl.end(); it != end; ++it) { solve(_system.maxExpression(*it)); @@ -150,6 +141,7 @@ private: } const Domain operator[](const Variable& var) { // solve the strategy for this variable, too + // recursive magic! _strat.solve(*_strat._system[var]); _strat._influence[*_strat._system[var]].insert(_expr); return _rho[var]; @@ -186,7 +178,6 @@ private: IdMap,unsigned int> _values; IdSet > _stable; IdMap,IdSet > > _influence; - bool _changed; }; @@ -200,28 +191,12 @@ struct Solver { } Domain solve(Variable& var) { - MaxExpression& rhs = *_system[var]; - - // _rho automatically keeps up to date with changes made to the - // strategy, so you don't need to stabilise it - + MaxExpression& 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: -- cgit v1.2.3