From 823ae23180cfc021bedc75bdc15751194605391a Mon Sep 17 00:00:00 2001 From: Matthias Volk Date: Fri, 6 Mar 2020 16:04:04 +0100 Subject: [PATCH] Use updateStatus in more cases --- .../IterativeMinMaxLinearEquationSolver.cpp | 19 ++------ .../solver/NativeLinearEquationSolver.cpp | 48 ++++--------------- 2 files changed, 12 insertions(+), 55 deletions(-) diff --git a/src/storm/solver/IterativeMinMaxLinearEquationSolver.cpp b/src/storm/solver/IterativeMinMaxLinearEquationSolver.cpp index 7684a12f3..f5b7d4c8f 100644 --- a/src/storm/solver/IterativeMinMaxLinearEquationSolver.cpp +++ b/src/storm/solver/IterativeMinMaxLinearEquationSolver.cpp @@ -736,19 +736,11 @@ namespace storm { if (this->soundValueIterationHelper->checkConvergenceUpdateBounds(dir, relevantValuesPtr)) { status = SolverStatus::Converged; } else { - // Update the status accordingly - if (this->hasCustomTerminationCondition() && this->soundValueIterationHelper->checkCustomTerminationCondition(this->getTerminationCondition())) { - status = SolverStatus::TerminatedEarly; - } else if (iterations >= env.solver().minMax().getMaximalNumberOfIterations()) { - status = SolverStatus::MaximalIterationsExceeded; - } + status = this->updateStatus(status, this->hasCustomTerminationCondition() && this->soundValueIterationHelper->checkCustomTerminationCondition(this->getTerminationCondition()), iterations, env.solver().minMax().getMaximalNumberOfIterations()); } // Potentially show progress. this->showProgressIterative(iterations); - if (storm::utility::resources::isTerminate()) { - status = SolverStatus::Aborted; - } } this->soundValueIterationHelper->setSolutionVector(); @@ -1047,9 +1039,8 @@ namespace storm { // Increase the precision. precision /= storm::utility::convertNumber(static_cast(10)); } - if (storm::utility::resources::isTerminate()) { - status = SolverStatus::Aborted; - } + + status = this->updateStatus(status, false, overallIterations, env.solver().minMax().getMaximalNumberOfIterations()); } // Swap the two vectors if the current result is not in the original x. @@ -1057,10 +1048,6 @@ namespace storm { std::swap(x, tmpX); } - if (status == SolverStatus::InProgress && overallIterations == env.solver().minMax().getMaximalNumberOfIterations()) { - status = SolverStatus::MaximalIterationsExceeded; - } - this->reportStatus(status, overallIterations); return status == SolverStatus::Converged || status == SolverStatus::TerminatedEarly; diff --git a/src/storm/solver/NativeLinearEquationSolver.cpp b/src/storm/solver/NativeLinearEquationSolver.cpp index 57f89eb48..97c988f71 100644 --- a/src/storm/solver/NativeLinearEquationSolver.cpp +++ b/src/storm/solver/NativeLinearEquationSolver.cpp @@ -75,10 +75,6 @@ namespace storm { if (storm::utility::vector::equalModuloPrecision(*this->cachedRowVector, x, precision, relative)) { status = SolverStatus::Converged; } - if (this->terminateNow(x, SolverGuarantee::None)) { - status = SolverStatus::TerminatedEarly; - } - // If we did not yet converge, we need to backup the contents of x. if (status != SolverStatus::Converged) { *this->cachedRowVector = x; @@ -90,9 +86,7 @@ namespace storm { // Increase iteration count so we can abort if convergence is too slow. ++iterations; - if (storm::utility::resources::isTerminate()) { - status = SolverStatus::Aborted; - } + status = this->updateStatus(status, x, SolverGuarantee::None, iterations, maxIter); } if (!this->isCachingEnabled()) { @@ -147,9 +141,6 @@ namespace storm { if (storm::utility::vector::equalModuloPrecision(*currentX, *nextX, precision, relative)) { status = SolverStatus::Converged; } - if (this->terminateNow(*currentX, SolverGuarantee::None)) { - status = SolverStatus::TerminatedEarly; - } // Swap the two pointers as a preparation for the next iteration. std::swap(nextX, currentX); @@ -159,9 +150,7 @@ namespace storm { // Increase iteration count so we can abort if convergence is too slow. ++iterations; - if (storm::utility::resources::isTerminate()) { - status = SolverStatus::Aborted; - } + status = this->updateStatus(status, *currentX, SolverGuarantee::None, iterations, maxIter); } // If the last iteration did not write to the original x we have to swap the contents, because the @@ -343,18 +332,11 @@ namespace storm { // Check for termination. std::swap(currentX, newX); ++iterations; - if (this->terminateNow(*currentX, guarantee)) { - status = SolverStatus::TerminatedEarly; - } + + status = this->updateStatus(status, *currentX, guarantee, iterations, maxIterations); // Potentially show progress. this->showProgressIterative(iterations); - if (storm::utility::resources::isTerminate()) { - status = SolverStatus::Aborted; - } - } - if (status == SolverStatus::InProgress && iterations == maxIterations) { - status = SolverStatus::MaximalIterationsExceeded; } return PowerIterationResult(iterations - currentIterations, status); @@ -559,15 +541,11 @@ namespace storm { status = SolverStatus::Converged; } } - if (lowerStep) { - if (this->terminateNow(*lowerX, SolverGuarantee::LessOrEqual)) { + if (lowerStep && this->terminateNow(*lowerX, SolverGuarantee::LessOrEqual)) { status = SolverStatus::TerminatedEarly; - } } - if (upperStep) { - if (this->terminateNow(*upperX, SolverGuarantee::GreaterOrEqual)) { + if (upperStep && this->terminateNow(*upperX, SolverGuarantee::GreaterOrEqual)) { status = SolverStatus::TerminatedEarly; - } } } @@ -578,9 +556,7 @@ namespace storm { // Set up next iteration. ++iterations; doConvergenceCheck = !doConvergenceCheck; - if (storm::utility::resources::isTerminate()) { - status = SolverStatus::Aborted; - } + status = this->updateStatus(status, false, iterations, maxIter); } // We take the means of the lower and upper bound so we guarantee the desired precision. @@ -639,19 +615,13 @@ namespace storm { status = SolverStatus::Converged; } - // Check whether we terminate early. - if (this->hasCustomTerminationCondition() && this->soundValueIterationHelper->checkCustomTerminationCondition(this->getTerminationCondition())) { - status = SolverStatus::TerminatedEarly; - } - // Update environment variables. ++iterations; // Potentially show progress. this->showProgressIterative(iterations); - if (storm::utility::resources::isTerminate()) { - status = SolverStatus::Aborted; - } + + status = this->updateStatus(status, this->hasCustomTerminationCondition() && this->soundValueIterationHelper->checkCustomTerminationCondition(this->getTerminationCondition()), iterations, env.solver().native().getMaximalNumberOfIterations()); } this->soundValueIterationHelper->setSolutionVector();