diff options
Diffstat (limited to 'impl/ImprovementOperator.hpp')
-rw-r--r-- | impl/ImprovementOperator.hpp | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/impl/ImprovementOperator.hpp b/impl/ImprovementOperator.hpp index e6b2ded..716768d 100644 --- a/impl/ImprovementOperator.hpp +++ b/impl/ImprovementOperator.hpp @@ -168,39 +168,26 @@ struct SmartImprovementOperator : public ImprovementOperator<Domain> { IdMap<MaxExpression<Domain>,IdSet<MaxExpression<Domain>>>& _influence; }; - void invalidateSubexpressions(IdSet<MaxExpression<Domain>>& set, Expression<Domain>& expr) const { - MaxExpression<Domain>* maxExpr = dynamic_cast<MaxExpression<Domain>*>(&expr); - if (maxExpr != NULL && maxExpr->id() < _system.maxExpressionCount()) { - if (invalidateAll(set, *maxExpr)) { + void invalidateSubexpressions(IdSet<MaxExpression<Domain>>& set, const Expression<Domain>* expr) const { + if (!expr) return; + const MaxExpression<Domain>* maxExpr = dynamic_cast<const MaxExpression<Domain>*>(expr); + if (maxExpr != NULL) { + if (!set.contains(*maxExpr)) { + set.insert(*maxExpr); for (auto it = maxExpr->arguments().begin(), - end = maxExpr->arguments().end(); + end = maxExpr->arguments().end(); it != end; ++it) { - invalidateSubexpressions(set, **it); + if (*it) + invalidateSubexpressions(set, *it); } } } } - bool invalidateAll(IdSet<MaxExpression<Domain>>& set, MaxExpression<Domain>& expr) const { - if (!set.contains(expr)) { - set.insert(expr); - for (auto it = _influence[expr].begin(), - end = _influence[expr].end(); - it != end; - ++it) { - if (!set.contains(_system.maxExpression(*it))) { - set.insert(_system.maxExpression(*it)); - } - //invalidateSubexpressions(set, _system.maxExpression(*it)); - } - return true; - } - return false; - } - void markChanged(IdSet<Variable<Domain>>& set, MaxExpression<Domain>& expr, IdSet<MaxExpression<Domain>>& seen) const { - if (seen.contains(expr)) return; + if (seen.contains(expr)) + return; seen.insert(expr); auto var = _system.varFromExpr(expr); if (var == NULL || !set.contains(*var)) { @@ -234,7 +221,7 @@ struct SmartImprovementOperator : public ImprovementOperator<Domain> { end = changedIn.end(); it != end; ++it) { - invalidateSubexpressions(invalidSet, *_system[_system.variable(*it)]); + invalidateSubexpressions(invalidSet, _system[_system.variable(*it)]); } stableSet = invalidSet.inverse(); } |