Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/examples/testfiles/dtmc/test_conditional.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ rewards
s=2 : 1;
endrewards

label "unreachable" = false;
label "condition" = s=2;
label "target" = s=3;
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "storm/environment/modelchecker/ConditionalModelCheckerEnvironment.h"
#include "storm/environment/modelchecker/ModelCheckerEnvironment.h"
#include "storm/environment/solver/MinMaxSolverEnvironment.h"
#include "storm/exceptions/InvalidPropertyException.h"
#include "storm/exceptions/NotImplementedException.h"
#include "storm/exceptions/NotSupportedException.h"
#include "storm/modelchecker/prctl/helper/SparseMdpPrctlHelper.h"
Expand Down Expand Up @@ -1252,7 +1253,7 @@ std::optional<SolutionType> handleTrivialCases(uint64_t const initialState, Norm
if (normalForm.conditionStates.get(initialState)) {
return normalForm.getTargetValue(initialState); // The value is already known, nothing to do.
} else {
STORM_LOG_THROW(!normalForm.universalObservationFailureStates.get(initialState), storm::exceptions::NotSupportedException,
STORM_LOG_THROW(!normalForm.universalObservationFailureStates.get(initialState), storm::exceptions::InvalidPropertyException,
"Trying to compute undefined conditional probability: the condition has probability 0 under all policies.");
// The last case for a terminal initial state is that it is already target and the condition is reachable with non-zero probability.
// In this case, all schedulers induce a conditional probability of 1 (or do not reach the condition, i.e., have undefined value)
Expand Down
97 changes: 49 additions & 48 deletions src/storm/modelchecker/prctl/helper/SparseDtmcPrctlHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,33 +860,33 @@ std::vector<SolutionType> SparseDtmcPrctlHelper<ValueType, RewardModelType, Solu
} else {
// Prepare result vector.
std::vector<ValueType> result(transitionMatrix.getRowCount(), storm::utility::infinity<ValueType>());

if (!conditionStates.empty()) {
BaierTransformedModel transformedModel =
computeBaierTransformation(env, transitionMatrix, backwardTransitions, targetStates, conditionStates, boost::none);

if (transformedModel.noTargetStates) {
storm::utility::vector::setVectorValues(result, transformedModel.beforeStates, storm::utility::zero<ValueType>());
STORM_LOG_THROW(!conditionStates.empty(), storm::exceptions::InvalidPropertyException,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to check that conditionStates are reachable from all relevant (i.e. initial) states?

Something like

auto const conditionGreaterZeroStates = storm::utility::graph::performProbGreater0(backwardTransitions, allStates, conditionStates);
STORM_LOG_THROW(goal.hasRelevantStates && goal.getRelevantStates().isSubsetOf(conditionGreaterZeroStates), ...);

"The condition set has probability 0, so the conditional probability is not defined.");

BaierTransformedModel transformedModel =
computeBaierTransformation(env, transitionMatrix, backwardTransitions, targetStates, conditionStates, boost::none);

if (transformedModel.noTargetStates) {
storm::utility::vector::setVectorValues(result, transformedModel.beforeStates, storm::utility::zero<ValueType>());
} else {
// At this point, we do not need to check whether there are 'before' states, since the condition
// states were non-empty so there is at least one state with a positive probability of satisfying
// the condition.

// Now compute reachability probabilities in the transformed model.
storm::storage::SparseMatrix<ValueType> const& newTransitionMatrix = transformedModel.transitionMatrix.get();
storm::storage::BitVector newRelevantValues;
if (goal.hasRelevantValues()) {
newRelevantValues = transformedModel.getNewRelevantStates(goal.relevantValues());
} else {
// At this point, we do not need to check whether there are 'before' states, since the condition
// states were non-empty so there is at least one state with a positive probability of satisfying
// the condition.

// Now compute reachability probabilities in the transformed model.
storm::storage::SparseMatrix<ValueType> const& newTransitionMatrix = transformedModel.transitionMatrix.get();
storm::storage::BitVector newRelevantValues;
if (goal.hasRelevantValues()) {
newRelevantValues = transformedModel.getNewRelevantStates(goal.relevantValues());
} else {
newRelevantValues = transformedModel.getNewRelevantStates();
}
goal.setRelevantValues(std::move(newRelevantValues));
std::vector<ValueType> conditionalProbabilities = computeUntilProbabilities(
env, std::move(goal), newTransitionMatrix, newTransitionMatrix.transpose(),
storm::storage::BitVector(newTransitionMatrix.getRowCount(), true), transformedModel.targetStates.get(), qualitative);

storm::utility::vector::setVectorValues(result, transformedModel.beforeStates, conditionalProbabilities);
newRelevantValues = transformedModel.getNewRelevantStates();
}
goal.setRelevantValues(std::move(newRelevantValues));
std::vector<ValueType> conditionalProbabilities =
computeUntilProbabilities(env, std::move(goal), newTransitionMatrix, newTransitionMatrix.transpose(),
storm::storage::BitVector(newTransitionMatrix.getRowCount(), true), transformedModel.targetStates.get(), qualitative);

storm::utility::vector::setVectorValues(result, transformedModel.beforeStates, conditionalProbabilities);
}

return result;
Expand All @@ -901,34 +901,35 @@ std::vector<SolutionType> SparseDtmcPrctlHelper<ValueType, RewardModelType, Solu
if constexpr (storm::IsIntervalType<ValueType>) {
STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "We do not support computing conditional rewards with interval models.");
} else {
STORM_LOG_THROW(!conditionStates.empty(), storm::exceptions::InvalidPropertyException,
"The condition set has probability 0, so the conditional probability is not defined.");

// Prepare result vector.
std::vector<ValueType> result(transitionMatrix.getRowCount(), storm::utility::infinity<ValueType>());

if (!conditionStates.empty()) {
BaierTransformedModel transformedModel = computeBaierTransformation(env, transitionMatrix, backwardTransitions, targetStates, conditionStates,
rewardModel.getTotalRewardVector(transitionMatrix));

if (transformedModel.noTargetStates) {
storm::utility::vector::setVectorValues(result, transformedModel.beforeStates, storm::utility::zero<ValueType>());
BaierTransformedModel transformedModel = computeBaierTransformation(env, transitionMatrix, backwardTransitions, targetStates, conditionStates,
rewardModel.getTotalRewardVector(transitionMatrix));

if (transformedModel.noTargetStates) {
storm::utility::vector::setVectorValues(result, transformedModel.beforeStates, storm::utility::zero<ValueType>());
} else {
// At this point, we do not need to check whether there are 'before' states, since the condition
// states were non-empty so there is at least one state with a positive probability of satisfying
// the condition.

// Now compute reachability probabilities in the transformed model.
storm::storage::SparseMatrix<ValueType> const& newTransitionMatrix = transformedModel.transitionMatrix.get();
storm::storage::BitVector newRelevantValues;
if (goal.hasRelevantValues()) {
newRelevantValues = transformedModel.getNewRelevantStates(goal.relevantValues());
} else {
// At this point, we do not need to check whether there are 'before' states, since the condition
// states were non-empty so there is at least one state with a positive probability of satisfying
// the condition.

// Now compute reachability probabilities in the transformed model.
storm::storage::SparseMatrix<ValueType> const& newTransitionMatrix = transformedModel.transitionMatrix.get();
storm::storage::BitVector newRelevantValues;
if (goal.hasRelevantValues()) {
newRelevantValues = transformedModel.getNewRelevantStates(goal.relevantValues());
} else {
newRelevantValues = transformedModel.getNewRelevantStates();
}
goal.setRelevantValues(std::move(newRelevantValues));
std::vector<ValueType> conditionalRewards =
computeReachabilityRewards(env, std::move(goal), newTransitionMatrix, newTransitionMatrix.transpose(), transformedModel.stateRewards.get(),
transformedModel.targetStates.get(), qualitative);
storm::utility::vector::setVectorValues(result, transformedModel.beforeStates, conditionalRewards);
newRelevantValues = transformedModel.getNewRelevantStates();
}
goal.setRelevantValues(std::move(newRelevantValues));
std::vector<ValueType> conditionalRewards =
computeReachabilityRewards(env, std::move(goal), newTransitionMatrix, newTransitionMatrix.transpose(), transformedModel.stateRewards.get(),
transformedModel.targetStates.get(), qualitative);
storm::utility::vector::setVectorValues(result, transformedModel.beforeStates, conditionalRewards);
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "storm/environment/solver/EigenSolverEnvironment.h"
#include "storm/environment/solver/GmmxxSolverEnvironment.h"
#include "storm/environment/solver/NativeSolverEnvironment.h"
#include "storm/exceptions/InvalidPropertyException.h"
#include "storm/logic/Formulas.h"
#include "storm/modelchecker/prctl/SparseDtmcPrctlModelChecker.h"
#include "storm/modelchecker/results/ExplicitQuantitativeCheckResult.h"
Expand Down Expand Up @@ -165,6 +166,10 @@ TYPED_TEST(ConditionalDtmcPrctlModelCheckerTest, Conditional) {
storm::modelchecker::ExplicitQuantitativeCheckResult<ValueType>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<ValueType>();
EXPECT_NEAR(storm::utility::one<ValueType>(), quantitativeResult2[0], this->precision());

formula = formulaParser.parseSingleFormulaFromString("P=? [F \"target\" || F \"unreachable\"]");

STORM_SILENT_EXPECT_THROW(checker.check(this->env(), *formula), storm::exceptions::InvalidPropertyException);

formula = formulaParser.parseSingleFormulaFromString("R=? [F \"target\"]");

result = checker.check(this->env(), *formula);
Expand All @@ -176,5 +181,9 @@ TYPED_TEST(ConditionalDtmcPrctlModelCheckerTest, Conditional) {
result = checker.check(this->env(), *formula);
storm::modelchecker::ExplicitQuantitativeCheckResult<ValueType>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<ValueType>();
EXPECT_NEAR(storm::utility::one<ValueType>(), quantitativeResult4[0], this->precision());

formula = formulaParser.parseSingleFormulaFromString("R=? [F \"target\" || F \"unreachable\"]");

STORM_SILENT_EXPECT_THROW(checker.check(this->env(), *formula), storm::exceptions::InvalidPropertyException);
}
} // namespace
Loading