summaryrefslogtreecommitdiff
path: root/impl/MaxStrategy.hpp
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@carlo-laptop>2012-10-23 15:32:35 +1100
committerCarlo Zancanaro <carlo@carlo-laptop>2012-10-23 15:32:35 +1100
commit0c62b0ba1b307ddc626a62127d835738775bb20d (patch)
tree737af5c2fbfb27554425eeda6f18f8d71267d9db /impl/MaxStrategy.hpp
parent3002319eb5fd6b3eff0ffa764534bb571536a08c (diff)
Fix the merge.
Diffstat (limited to 'impl/MaxStrategy.hpp')
-rw-r--r--impl/MaxStrategy.hpp61
1 files changed, 8 insertions, 53 deletions
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<Domain> {
_influence(system.maxExpressionCount(),
IdSet<MaxExpression<Domain> >(system.maxExpressionCount())),
_var_influence(system.variableCount(),
- IdSet<MaxExpression<Domain> >(system.maxExpressionCount())),
- _frozen(false)
+ IdSet<MaxExpression<Domain> >(system.maxExpressionCount()))
{}
- void freeze() {
- _frozen = true;
- }
-
- void thaw() {
- _frozen = false;
- }
-
- bool is_frozen() {
- return _frozen;
- }
-
void setRho(DynamicVariableAssignment<Domain>& rho) {
_rho = &rho;
}
unsigned int get(const MaxExpression<Domain>& e) const {
+ // slightly hacky
+ return const_cast<DynamicMaxStrategy<Domain>*>(this)->get(e);
+ }
+
+ unsigned int get(const MaxExpression<Domain>& e) {
if (!_frozen)
solve(e);
return _values[e];
}
- void invalidate(const Variable<Domain>& v) const {
+ void invalidate(const Variable<Domain>& 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<MaxExpression<Domain> > infl = _var_influence[v];
_var_influence[v].clear();
for (typename IdSet<MaxExpression<Domain> >::iterator
@@ -203,46 +195,9 @@ private:
IdSet<MaxExpression<Domain> > _stable;
IdMap<MaxExpression<Domain>,IdSet<MaxExpression<Domain> > > _influence;
IdMap<Variable<Domain>,IdSet<MaxExpression<Domain> > > _var_influence;
- bool _frozen;
};
-template<typename T>
-IdMap<Variable<T>,T> solve_for(const EquationSystem<T>& system) {
- IdMap<Variable<T>,T> result(system.variableCount(), infinity<T>());
-
- DynamicMaxStrategy<T> strategy(system);
- DynamicVariableAssignment<T> rho(system, strategy, -infinity<T>());
- 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<T>& var = system.variable(i);
- T val = rho[var];
- if (result[var] != val) {
- result[var] = val;
- changed = true;
- }
- }
- } while(changed);
-
- return result;
-}
-
-
/*template<typename Domain>
std::ostream& operator<<(std::ostream& cout, const MaxStrategy<Domain>& strat) {
strat.print(cout);