Browse Source

Use updateStatus in more cases

tempestpy_adaptions
Matthias Volk 5 years ago
parent
commit
823ae23180
  1. 19
      src/storm/solver/IterativeMinMaxLinearEquationSolver.cpp
  2. 48
      src/storm/solver/NativeLinearEquationSolver.cpp

19
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<ValueType>(static_cast<uint64_t>(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;

48
src/storm/solver/NativeLinearEquationSolver.cpp

@ -75,10 +75,6 @@ namespace storm {
if (storm::utility::vector::equalModuloPrecision<ValueType>(*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<ValueType>(*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();

Loading…
Cancel
Save