From ea05c9c5fa30b8822f618e861d12a09df1f8f017 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Mon, 28 May 2012 13:00:50 +1000 Subject: Fix memory error and x = max(-inf, expr) stuff. --- impl/MaxStrategy.hpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'impl/MaxStrategy.hpp') diff --git a/impl/MaxStrategy.hpp b/impl/MaxStrategy.hpp index f4e4055..a1c50d8 100644 --- a/impl/MaxStrategy.hpp +++ b/impl/MaxStrategy.hpp @@ -23,6 +23,10 @@ struct MaxStrategy { } } + virtual ~MaxStrategy() { + delete[] _assignment; + } + MaxStrategy& operator=(const MaxStrategy& other) { if (_length != other._length) { _length = other._length; @@ -35,9 +39,6 @@ struct MaxStrategy { return *this; } - virtual ~MaxStrategy() { - delete[] _assignment; - } const unsigned int& operator[] (const MaxExpression x) const { if (x.id() >= _length) { throw "Array out of bounds"; @@ -64,11 +65,11 @@ struct MaxStrategy { MaxStrategy improve(const EquationSystem& s, const VariableAssignment& rho) const { MaxStrategy newStrategy(*this); for (unsigned int i = 0; i < _length; ++i) { - const MaxExpression* expr = s.getMax(i); - const T oldValue = (*this)(*expr, rho); - std::pair best = expr->bestStrategy(rho); + const MaxExpression& expr = *s.getMax(i); + const T oldValue = (*this)(expr, rho); + std::pair best = expr.bestStrategy(rho); if (best.first > oldValue) - newStrategy[*expr] = best.second; + newStrategy[expr] = best.second; } std::cerr << "Strat improvement: "; if (_length > 0) -- cgit v1.2.3