summaryrefslogtreecommitdiff
path: root/impl/MaxStrategy.hpp
diff options
context:
space:
mode:
authorZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-11-01 18:06:13 +1100
committerZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-11-01 18:06:13 +1100
commitb7eaa99578037789a337c5061c0ea8ee3150b63c (patch)
treee63a023a85ef167760f55229c1d96fbcaaa1c64e /impl/MaxStrategy.hpp
parente207a8fec1bae01068bdb3a27a2090a4af5f8cb2 (diff)
A bunch of fixes to the solver, and moving it in to clang.
Also some contribution writing stuff. Basically: lots of work.
Diffstat (limited to 'impl/MaxStrategy.hpp')
-rw-r--r--impl/MaxStrategy.hpp55
1 files changed, 15 insertions, 40 deletions
diff --git a/impl/MaxStrategy.hpp b/impl/MaxStrategy.hpp
index 71ea4f4..6fee921 100644
--- a/impl/MaxStrategy.hpp
+++ b/impl/MaxStrategy.hpp
@@ -20,7 +20,7 @@ unsigned int stack_depth = 1;
std::string indent() {
std::string result = "";
for (unsigned int i = 0; i < stack_depth; ++i) {
- result += '\t';
+ result += ' ';
}
return result;
}
@@ -39,22 +39,13 @@ struct DynamicMaxStrategy : public MaxStrategy<Domain> {
_values(system.maxExpressionCount(), 0),
_stable(system.maxExpressionCount()),
_influence(system.maxExpressionCount(),
- IdSet<MaxExpression<Domain> >(system.maxExpressionCount())),
- _changed(false)
+ IdSet<MaxExpression<Domain> >(system.maxExpressionCount()))
{}
void setRho(DynamicVariableAssignment<Domain>& rho) {
_rho = &rho;
}
- void hasChanged(bool c) {
- _changed = c;
- }
-
- bool hasChanged() const {
- return _changed;
- }
-
unsigned int get(const MaxExpression<Domain>& e) const {
log::strategy << indent() << "Look up " << e << std::endl;
return _values[e];
@@ -99,32 +90,32 @@ struct DynamicMaxStrategy : public MaxStrategy<Domain> {
private:
void solve(const MaxExpression<Domain>& x) {
if (!_stable.contains(x)) {
+ std::cerr << indent() << x.id() << std::endl;
_stable.insert(x);
log::strategy << indent() << "Stabilise " << x << std::endl;
stack_depth++;
DependencyAssignment assignment(*this, *_rho, x);
DependencyStrategy depStrat(*this, x);
- unsigned int val = x.bestStrategy(assignment, depStrat);
+ unsigned int val = x.bestStrategy(assignment, depStrat, _values[x]);
stack_depth--;
if (val != _values[x]) {
+ std::cerr << indent() << "-" << std::endl;
log::strategy << x << " => " << *x.arguments()[val] << std::endl;
- IdSet<MaxExpression<Domain> > oldInfluence = _influence[x];
- //_influence[x].clear();
_values[x] = val;
- _changed = true;
_rho->invalidate(*_system.varFromExpr(x));
//_rho->stabilise();
- _stable.filter(oldInfluence);
-
+ IdSet<MaxExpression<Domain> > infl = _influence[x];
+ _stable.filter(infl);
+
for (typename IdSet<MaxExpression<Domain> >::iterator
- it = oldInfluence.begin(),
- end = oldInfluence.end();
+ it = infl.begin(),
+ end = infl.end();
it != end;
++it) {
solve(_system.maxExpression(*it));
@@ -150,6 +141,7 @@ private:
}
const Domain operator[](const Variable<Domain>& var) {
// solve the strategy for this variable, too
+ // recursive magic!
_strat.solve(*_strat._system[var]);
_strat._influence[*_strat._system[var]].insert(_expr);
return _rho[var];
@@ -186,7 +178,6 @@ private:
IdMap<MaxExpression<Domain>,unsigned int> _values;
IdSet<MaxExpression<Domain> > _stable;
IdMap<MaxExpression<Domain>,IdSet<MaxExpression<Domain> > > _influence;
- bool _changed;
};
@@ -200,28 +191,12 @@ struct Solver {
}
Domain solve(Variable<Domain>& var) {
- MaxExpression<Domain>& rhs = *_system[var];
-
- // _rho automatically keeps up to date with changes made to the
- // strategy, so you don't need to stabilise it
-
+ MaxExpression<Domain>& rhs = *_system[var];
+ // this will automatically work sufficiently to get the final
+ // strategy for this variable's RHS
_strategy.get(rhs);
-
- /*
- do {
- _strategy.hasChanged(false);
-
- log::debug << "Stabilise assignment (toplevel)" << std::endl;
- _rho.stabilise();
-
- log::debug << "Improve strategy (toplevel)" << std::endl;
- // improve strategy
- _strategy.get(rhs);
- log::debug << (_strategy.hasChanged() ? "Strategy has changed - loop again" : "Strategy has not changed - terminate") << std::endl;
- } while (_strategy.hasChanged());
- */
-
+ // this will automatically solve for the value of the RHS, if required
return _rho[var];
}
private: