summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--impl/MaxStrategy.hpp61
-rw-r--r--impl/VariableAssignment.hpp19
-rw-r--r--impl/main.cpp15
3 files changed, 17 insertions, 78 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);
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<typename Domain>
struct DynamicVariableAssignment : public VariableAssignment<Domain> {
DynamicVariableAssignment(
const EquationSystem<Domain>& system,
- DynamicMaxStrategy<Domain>& strat,
- const Domain& value=infinity<Domain>()
+ DynamicMaxStrategy<Domain>& strat
) : _system(system),
_strategy(strat),
_values(system.variableCount(), unknown(infinity<Domain>())),
@@ -46,7 +45,8 @@ struct DynamicVariableAssignment : public VariableAssignment<Domain> {
}
const Domain& operator[](const Variable<Domain>& var) const {
- return _values[var];
+ // slightly hacky
+ return const_cast<DynamicVariableAssignment<Domain>&>(*this)[var];
}
const Domain& operator[](const Variable<Domain>& var) {
@@ -60,7 +60,7 @@ struct DynamicVariableAssignment : public VariableAssignment<Domain> {
if (_stable.contains(x)) {
_stable.remove(x);
_values[x] = unknown(infinity<Domain>());
-
+
solve(x);
/*
IdSet<Variable<Domain> > infl = _influence[x];
@@ -128,12 +128,11 @@ private:
};
const EquationSystem<Domain>& _system;
- const DynamicMaxStrategy<Domain>& _strategy;
- mutable IdMap<Variable<Domain>, Domain> _values;
-public:
- mutable IdSet<Variable<Domain> > _stable;
-private:
- mutable IdMap<Variable<Domain>,IdSet<Variable<Domain> > > _influence;
+ DynamicMaxStrategy<Domain>& _strategy;
+ IdMap<Variable<Domain>, Domain> _values;
+ IdSet<Variable<Domain> > _stable;
+ IdMap<Variable<Domain>,IdSet<Variable<Domain> > > _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<Variable<ZBar>,ZBar> result = solve_for(system);
- if (variables.size() > 0) {
- for (unsigned int i = 0, size = system.variableCount(); i < size; ++i) {
- Variable<ZBar>& 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<ZBar>& var = system.variable(i);
- cout << var.name() << " = " << result[var] << endl;
- }
- }
- /*
DynamicMaxStrategy<ZBar> strategy(system);
DynamicVariableAssignment<ZBar> 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);