From e2cfa54d5b9f101e1b091e693d67c427e17f465b Mon Sep 17 00:00:00 2001 From: TimQu Date: Wed, 28 Jun 2017 18:37:36 +0200 Subject: [PATCH] Fixed an issue when computing expected rewards of Markov Automata --- .../helper/SparseMarkovAutomatonCslHelper.cpp | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/storm/modelchecker/csl/helper/SparseMarkovAutomatonCslHelper.cpp b/src/storm/modelchecker/csl/helper/SparseMarkovAutomatonCslHelper.cpp index c555fd0e8..78f38109a 100644 --- a/src/storm/modelchecker/csl/helper/SparseMarkovAutomatonCslHelper.cpp +++ b/src/storm/modelchecker/csl/helper/SparseMarkovAutomatonCslHelper.cpp @@ -200,7 +200,7 @@ namespace storm { template std::vector SparseMarkovAutomatonCslHelper::computeReachabilityRewards(OptimizationDirection dir, storm::storage::SparseMatrix const& transitionMatrix, storm::storage::SparseMatrix const& backwardTransitions, std::vector const& exitRateVector, storm::storage::BitVector const& markovianStates, RewardModelType const& rewardModel, storm::storage::BitVector const& psiStates, storm::solver::MinMaxLinearEquationSolverFactory const& minMaxLinearEquationSolverFactory) { - std::vector stateRewardWeights(transitionMatrix.getRowGroupCount()); + std::vector stateRewardWeights(transitionMatrix.getRowGroupCount(), storm::utility::zero()); for (auto const markovianState : markovianStates) { stateRewardWeights[markovianState] = storm::utility::one() / exitRateVector[markovianState]; } @@ -382,10 +382,10 @@ namespace storm { uint_fast64_t numberOfStates = transitionMatrix.getRowGroupCount(); - // First, we need to check which states have infinite expected time (by definition). + // First, we need to check which states have infinite expected reward (by definition). storm::storage::BitVector infinityStates; if (dir == OptimizationDirection::Minimize) { - // If we need to compute the minimum expected times, we have to set the values of those states to infinity that, under all schedulers, + // If we need to compute the minimum expected rewards, we have to set the values of those states to infinity that, under all schedulers, // reach a bottom SCC without a goal state. // So we start by computing all bottom SCCs without goal states. @@ -406,8 +406,7 @@ namespace storm { infinityStates = storm::utility::graph::performProbGreater0A(transitionMatrix, transitionMatrix.getRowGroupIndices(), backwardTransitions, - storm::storage::BitVector( - numberOfStates, true), + ~goalStates, unionOfNonGoalBSccs); } else { // Otherwise, we have no infinity states. @@ -432,8 +431,7 @@ namespace storm { if (!unionOfNonGoalMaximalEndComponents.empty()) { // Now we need to check for which states there exists a scheduler that reaches one of the previously computed states. infinityStates = storm::utility::graph::performProbGreater0E(backwardTransitions, - storm::storage::BitVector( - numberOfStates, true), + ~goalStates, unionOfNonGoalMaximalEndComponents); } else { // Otherwise, we have no infinity states. @@ -447,17 +445,27 @@ namespace storm { std::vector result(numberOfStates); if (!maybeStates.empty()) { + // Then, we can eliminate the rows and columns for all states whose values are already known. - std::vector x(maybeStates.getNumberOfSetBits()); - storm::storage::SparseMatrix submatrix = transitionMatrix.getSubmatrix(true, maybeStates, - maybeStates); - - // Finally, prepare the actual right-hand side. - std::vector b(submatrix.getRowCount()); - storm::utility::vector::selectVectorValues(b, maybeStates, + storm::storage::SparseMatrix submatrix; + std::vector b; + if (infinityStates.empty()) { + submatrix = transitionMatrix.getSubmatrix(true, maybeStates, maybeStates); + b.resize(submatrix.getRowCount()); + storm::utility::vector::selectVectorValues(b, maybeStates, transitionMatrix.getRowGroupIndices(), stateActionRewardVector); + } else { + // If there are infinity states, we also have to eliminate the choices that lead from a maybe state to an infinity state + storm::storage::BitVector selectedChoices = transitionMatrix.getRowFilter(maybeStates, ~infinityStates); + submatrix = transitionMatrix.getSubmatrix(false, selectedChoices, maybeStates); + b.resize(submatrix.getRowCount()); + storm::utility::vector::selectVectorValues(b, selectedChoices, stateActionRewardVector); + } + // Initialize the solution vector + std::vector x(maybeStates.getNumberOfSetBits()); + // Solve the corresponding system of equations. std::unique_ptr> solver = minMaxLinearEquationSolverFactory.create( submatrix);