summaryrefslogtreecommitdiff
path: root/impl/MaxStrategy.hpp
diff options
context:
space:
mode:
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);