From 606087ce8588924fd56d525749fbfb9161c0548a Mon Sep 17 00:00:00 2001 From: Jan Erik Karuc Date: Thu, 20 Feb 2020 22:29:31 +0100 Subject: [PATCH] Absolute ub guessing and in-place center calculation --- .../IterativeMinMaxLinearEquationSolver.cpp | 20 +++++++------------ .../IterativeMinMaxLinearEquationSolver.h | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/storm/solver/IterativeMinMaxLinearEquationSolver.cpp b/src/storm/solver/IterativeMinMaxLinearEquationSolver.cpp index 684c20b27..18fa718c1 100644 --- a/src/storm/solver/IterativeMinMaxLinearEquationSolver.cpp +++ b/src/storm/solver/IterativeMinMaxLinearEquationSolver.cpp @@ -388,6 +388,7 @@ namespace storm { std::vector boundsDiffV(currentX->size()); ValueType precision = storm::utility::convertNumber(env.solver().minMax().getPrecision()); + ValueType two = storm::utility::convertNumber(2.0); ValueType iterationPrecision = precision; SolverStatus status = SolverStatus::InProgress; @@ -407,7 +408,7 @@ namespace storm { } else { currentVerificationIterations = 0; - currentUpperBound = guessUpperBound(env, *currentX, precision); + currentUpperBound = guessUpperBound(*currentX, precision); newUpperBound = currentUpperBound; // TODO: More efficient check for verification iterations @@ -456,14 +457,9 @@ namespace storm { // All values moved down or stayed the same and we have a maximum difference of twice the requested precision // We can safely use twice the requested precision, as we calculate the center of both vectors - if (!storm::utility::vector::hasNegativeEntry(ubDiffV) && storm::utility::vector::max_if(boundsDiffV, this->getRelevantValues()) < storm::utility::convertNumber(2.0) * precision) { + if (!storm::utility::vector::hasNegativeEntry(ubDiffV) && storm::utility::vector::max_if(boundsDiffV, this->getRelevantValues()) < two * precision) { // Calculate the center of both vectors and store it in currentX - // TODO: Do calculations in-place on currentX - // center = (1 / 2) * u + v - std::vector centerV = *currentX; - storm::utility::vector::addVectors(*currentX, currentUpperBound, centerV); - storm::utility::vector::scaleVectorInPlace(centerV, storm::utility::convertNumber(0.5)); - std::swap(centerV, *currentX); + storm::utility::vector::applyPointwise(*currentX, currentUpperBound, *currentX, [&two] (ValueType const& a, ValueType const& b) -> ValueType { return (a + b) / two; }); status = SolverStatus::Converged; } @@ -472,7 +468,7 @@ namespace storm { } } - iterationPrecision = iterationPrecision / storm::utility::convertNumber(2.0); + iterationPrecision = iterationPrecision / two; } // Swap the result into the output x. @@ -497,10 +493,8 @@ namespace storm { } template - std::vector IterativeMinMaxLinearEquationSolver::guessUpperBound(Environment const& env, std::vector const& x, ValueType const& precision) const { - std::vector ub = x; - storm::utility::vector::scaleVectorInPlace(ub, storm::utility::one() + precision); - return ub; + std::vector IterativeMinMaxLinearEquationSolver::guessUpperBound(std::vector &x, ValueType const& precision) const { + storm::utility::vector::applyPointwise(x, x, [&] (ValueType const& argument) -> ValueType { return argument + precision; }); } template diff --git a/src/storm/solver/IterativeMinMaxLinearEquationSolver.h b/src/storm/solver/IterativeMinMaxLinearEquationSolver.h index 32ba7d32e..247f7f4f9 100644 --- a/src/storm/solver/IterativeMinMaxLinearEquationSolver.h +++ b/src/storm/solver/IterativeMinMaxLinearEquationSolver.h @@ -45,7 +45,7 @@ namespace storm { bool solveEquationsSoundValueIteration(Environment const& env, OptimizationDirection dir, std::vector& x, std::vector const& b) const; bool solveEquationsViToPi(Environment const& env, OptimizationDirection dir, std::vector& x, std::vector const& b) const; - std::vector guessUpperBound(Environment const& env, std::vector const& x, ValueType const& precision) const; + std::vector guessUpperBound(std::vector &x, ValueType const& precision) const; bool solveEquationsRationalSearch(Environment const& env, OptimizationDirection dir, std::vector& x, std::vector const& b) const;