From 0c62b0ba1b307ddc626a62127d835738775bb20d Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Tue, 23 Oct 2012 15:32:35 +1100 Subject: Fix the merge. --- impl/MaxStrategy.hpp | 61 ++++++--------------------------------------- impl/VariableAssignment.hpp | 19 +++++++------- impl/main.cpp | 15 ----------- 3 files changed, 17 insertions(+), 78 deletions(-) (limited to 'impl') 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 { _influence(system.maxExpressionCount(), IdSet >(system.maxExpressionCount())), _var_influence(system.variableCount(), - IdSet >(system.maxExpressionCount())), - _frozen(false) + IdSet >(system.maxExpressionCount())) {} - void freeze() { - _frozen = true; - } - - void thaw() { - _frozen = false; - } - - bool is_frozen() { - return _frozen; - } - void setRho(DynamicVariableAssignment& rho) { _rho = ρ } unsigned int get(const MaxExpression& e) const { + // slightly hacky + return const_cast*>(this)->get(e); + } + + unsigned int get(const MaxExpression& e) { if (!_frozen) solve(e); return _values[e]; } - void invalidate(const Variable& v) const { + void invalidate(const Variable& 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 > infl = _var_influence[v]; _var_influence[v].clear(); for (typename IdSet >::iterator @@ -203,46 +195,9 @@ private: IdSet > _stable; IdMap,IdSet > > _influence; IdMap,IdSet > > _var_influence; - bool _frozen; }; -template -IdMap,T> solve_for(const EquationSystem& system) { - IdMap,T> result(system.variableCount(), infinity()); - - DynamicMaxStrategy strategy(system); - DynamicVariableAssignment rho(system, strategy, -infinity()); - 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& var = system.variable(i); - T val = rho[var]; - if (result[var] != val) { - result[var] = val; - changed = true; - } - } - } while(changed); - - return result; -} - - /*template std::ostream& operator<<(std::ostream& cout, const MaxStrategy& strat) { strat.print(cout); diff --git a/impl/VariableAssignment.hpp b/impl/VariableAssignment.hpp index cfce925..3f4ff70 100644 --- a/impl/VariableAssignment.hpp +++ b/impl/VariableAssignment.hpp @@ -22,8 +22,7 @@ template struct DynamicVariableAssignment : public VariableAssignment { DynamicVariableAssignment( const EquationSystem& system, - DynamicMaxStrategy& strat, - const Domain& value=infinity() + DynamicMaxStrategy& strat ) : _system(system), _strategy(strat), _values(system.variableCount(), unknown(infinity())), @@ -46,7 +45,8 @@ struct DynamicVariableAssignment : public VariableAssignment { } const Domain& operator[](const Variable& var) const { - return _values[var]; + // slightly hacky + return const_cast&>(*this)[var]; } const Domain& operator[](const Variable& var) { @@ -60,7 +60,7 @@ struct DynamicVariableAssignment : public VariableAssignment { if (_stable.contains(x)) { _stable.remove(x); _values[x] = unknown(infinity()); - + solve(x); /* IdSet > infl = _influence[x]; @@ -128,12 +128,11 @@ private: }; const EquationSystem& _system; - const DynamicMaxStrategy& _strategy; - mutable IdMap, Domain> _values; -public: - mutable IdSet > _stable; -private: - mutable IdMap,IdSet > > _influence; + DynamicMaxStrategy& _strategy; + IdMap, Domain> _values; + IdSet > _stable; + IdMap,IdSet > > _influence; + bool _frozen; }; #endif diff --git a/impl/main.cpp b/impl/main.cpp index 02faca5..b547c48 100644 --- a/impl/main.cpp +++ b/impl/main.cpp @@ -140,20 +140,6 @@ int main (int argc, char* argv[]) { log::debug << system << endl; system.indexMaxExpressions(); // make reverse-lookup O(1) instead of O(n) - IdMap,ZBar> result = solve_for(system); - if (variables.size() > 0) { - for (unsigned int i = 0, size = system.variableCount(); i < size; ++i) { - Variable& var = system.variable(i); - if (variables.find(var.name()) != variables.end()) - cout << var.name() << " = " << result[var] << endl; - } - } else { - for (unsigned int i = 0, size = system.variableCount(); i < size; ++i) { - Variable& var = system.variable(i); - cout << var.name() << " = " << result[var] << endl; - } - } - /* DynamicMaxStrategy strategy(system); DynamicVariableAssignment rho(system, strategy); strategy.setRho(rho); @@ -171,7 +157,6 @@ int main (int argc, char* argv[]) { cout << var.name() << " = " << rho[var].asKnown() << endl; } } - */ parser -> free(parser); tokens -> free(tokens); -- cgit v1.2.3