diff options
author | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-08-07 17:56:43 +1000 |
---|---|---|
committer | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-08-07 17:56:43 +1000 |
commit | 59fb7d23578c4da14f9c14cc413090b1af13328c (patch) | |
tree | 42d187c4b182a025578377f77d1c5e369751b5b3 /impl/ImprovementOperator.hpp | |
parent | c26f38114fedde81effb938ffbedfe922d77a322 (diff) |
Merge complete! Get onto the right branch.
Diffstat (limited to 'impl/ImprovementOperator.hpp')
-rw-r--r-- | impl/ImprovementOperator.hpp | 89 |
1 files changed, 88 insertions, 1 deletions
diff --git a/impl/ImprovementOperator.hpp b/impl/ImprovementOperator.hpp index a435b6e..8ebf2d1 100644 --- a/impl/ImprovementOperator.hpp +++ b/impl/ImprovementOperator.hpp @@ -39,7 +39,7 @@ struct NaiveImprovementOperator : public ImprovementOperator<Domain> { strat.set(expr, index); } } - //log::strategy << strat << std::endl; + log::strategy << strat << std::endl; return changed; } }; @@ -68,4 +68,91 @@ struct RepeatedImprovementOperator : public ImprovementOperator<Domain> { const ImprovementOperator<Domain>& _subImprovement; }; +<<<<<<< HEAD + + +#include "VariableAssignment.hpp" + +template<typename Domain> +struct DynamicMaxStrategy : public MaxStrategy<Domain> { + DynamicMaxStrategy( + const EquationSystem<Domain>& system + ) : _system(system), + _rho(NULL), + _values(system), + _stable(system.maxExpressionCount()), + _influence(system.maxExpressionCount(), + IdSet<MaxExpression<Domain>>(system.maxExpressionCount())), + _var_influence(system.variableCount(), + IdSet<MaxExpression<Domain>>(system.maxExpressionCount())) + {} + + void setRho(DynamicVariableAssignment<Domain>& rho) { + _rho = ρ + } + + unsigned int get(const MaxExpression<Domain>& e) const { + solve(e); + return _values.get(e); + } + + void invalidate(const Variable<Domain>& v) const { + log::strategy << "invalidating " << v << " - " << *_system[v] << std::endl; + log::strategy << "\t" << _var_influence[v] << std::endl; + _stable.filter(_var_influence[v]); + + for (auto it = _var_influence[v].begin(); + it != _var_influence[v].end(); + ++it) { + solve(_system.maxExpression(*it)); + } + } + + struct DependencyAssignment : public VariableAssignment<Domain>{ + DependencyAssignment(const DynamicMaxStrategy& strat, + VariableAssignment<Domain>& rho, + const MaxExpression<Domain>& expr) + : _strat(strat), + _rho(rho), + _expr(expr) { + } + const Domain& operator[](const Variable<Domain>& var) const { + _strat._var_influence[var].insert(_expr); + return _rho[var]; + } + private: + const DynamicMaxStrategy& _strat; + VariableAssignment<Domain>& _rho; + const MaxExpression<Domain>& _expr; + }; + + struct DependencyStrategy : public MaxStrategy<Domain> { + DependencyStrategy(const DynamicMaxStrategy& strat, const MaxExpression<Domain>& expr) + : _strat(strat), + _expr(expr) { + } + unsigned int get(const MaxExpression<Domain>& e) const { + _strat.solve(e); + if (&_expr != &e) { + _strat._influence[e].insert(_expr); + } + return _strat._values.get(e); + } + private: + const DynamicMaxStrategy& _strat; + const MaxExpression<Domain>& _expr; + }; + +private: + const EquationSystem<Domain>& _system; + mutable DynamicVariableAssignment<Domain>* _rho; + mutable ConcreteMaxStrategy<Domain> _values; + mutable IdSet<MaxExpression<Domain>> _stable; + mutable IdMap<MaxExpression<Domain>,IdSet<MaxExpression<Domain>>> _influence; + mutable IdMap<Variable<Domain>,IdSet<MaxExpression<Domain>>> _var_influence; +}; + + +======= +>>>>>>> bitbucket/master #endif |