Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
verification.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4
12#include "storm/logic/Formula.h"
16
17namespace storm::pomdp::api {
18namespace {
19
21template<typename PomdpValueType>
22struct BeliefVerificationInput {
23 std::shared_ptr<storm::models::sparse::Pomdp<PomdpValueType>> pomdp;
24 std::shared_ptr<storm::logic::Formula const> formula;
25 analysis::FormulaInformation formulaInformation;
26 beliefs::PropertyInformation propertyInformation;
27};
28
29template<typename PomdpValueType, typename BeliefMdpValueType>
30BeliefVerificationInput<PomdpValueType> prepareBeliefVerification(storm::models::sparse::Pomdp<PomdpValueType> const& input,
31 storm::logic::Formula const& formula,
32 beliefs::BeliefBasedModelCheckerOptions<BeliefMdpValueType>& options) {
33 auto fragment = storm::logic::reachability();
34 fragment.setRewardOperatorsAllowed(true).setReachabilityRewardFormulasAllowed(true).setQualitativeOperatorResultsAllowed(false);
35 STORM_LOG_THROW(formula.isInFragment(fragment), storm::exceptions::NotSupportedException,
36 "The one-shot belief API supports only non-nested, unbounded reachability probabilities and expected reachability rewards without "
37 "thresholds. Got '"
38 << formula << "'.");
39 auto formulaInformation = analysis::getFormulaInformation(input, formula);
40 STORM_LOG_THROW(input.getInitialStates().getNumberOfSetBits() == 1, storm::exceptions::NotSupportedException,
41 "One-shot belief verification requires exactly one initial state.");
42 if (options.useClipping) {
43 STORM_LOG_THROW(options.clippingResolutions.has_value() && options.clippingResolutions->size() == input.getNrObservations(),
44 storm::exceptions::IllegalArgumentException, "Clipping requires one resolution per input POMDP observation.");
45 STORM_LOG_THROW(std::all_of(options.clippingResolutions->begin(), options.clippingResolutions->end(), [](auto resolution) { return resolution > 0; }),
46 storm::exceptions::IllegalArgumentException, "Clipping resolutions must be positive.");
47 }
48
49 using PomdpType = storm::models::sparse::Pomdp<PomdpValueType>;
50 auto pomdp = input.isCanonic() ? std::make_shared<PomdpType>(input) : storm::transformer::MakePOMDPCanonic<PomdpValueType>(input).transform();
51 STORM_LOG_THROW(!options.buildChoiceLabeling || pomdp->hasChoiceLabeling(), storm::exceptions::IllegalArgumentException,
52 "Building belief MDP choice labels requires choice labels in the input POMDP. Otherwise, set options.buildChoiceLabeling to false.");
53 auto [targetClosedPomdp, targetObservations] =
54 storm::transformer::MakeStateSetObservationClosed<PomdpValueType>(pomdp).transform(formulaInformation.getTargetStates().states);
55 pomdp = std::move(targetClosedPomdp);
56 if (options.useClipping) {
57 // Canonicalization and target refinement preserve state IDs. Extend the caller's observation-indexed grid accordingly.
58 auto const originalResolutions = *options.clippingResolutions;
59 options.clippingResolutions->resize(pomdp->getNrObservations());
60 for (uint64_t state = 0; state < input.getNumberOfStates(); ++state) {
61 options.clippingResolutions->at(pomdp->getObservation(state)) = originalResolutions.at(input.getObservation(state));
62 }
63 }
64 // FormulaInformation defines sinks only for probability until formulas. For expected reachability rewards,
65 // preprocessing and belief-MDP verification use reachability-reward model checking, which assigns infinity
66 // to states unable to reach the target, even with zero rewards. No additional sink transformation is needed.
67 if (formulaInformation.isNonNestedReachabilityProbability() && !formulaInformation.getSinkStates().empty()) {
68 // Keep the row groups and action identities intact, including when sink states share an observation with other states.
69 pomdp->getTransitionMatrix().makeRowGroupsAbsorbing(formulaInformation.getSinkStates().states, true);
70 }
71
72 beliefs::PropertyInformation propertyInformation;
73 propertyInformation.dir = formulaInformation.getOptimizationDirection();
74 propertyInformation.targetObservations = std::move(targetObservations);
75 if (formulaInformation.isNonNestedExpectedRewardFormula()) {
77 propertyInformation.rewardModelName = formulaInformation.getRewardModelName();
78 } else {
80 }
81 // Preprocessing must see the refined observations and the absorbing failure states.
82 formulaInformation = analysis::getFormulaInformation(*pomdp, formula);
83 return {std::move(pomdp), formula.asSharedPointer(), std::move(formulaInformation), std::move(propertyInformation)};
84}
85
86template<typename PomdpValueType>
87storage::BeliefExplorationBounds<PomdpValueType> computeBeliefBounds(storm::Environment const& env, BeliefVerificationInput<PomdpValueType> const& prepared,
88 bool useClipping) {
89 modelchecker::PreprocessingPomdpValueBoundsModelChecker<storm::models::sparse::Pomdp<PomdpValueType>> checker(*prepared.pomdp);
90 storage::BeliefExplorationBounds<PomdpValueType> bounds;
91 bounds.preprocessingBounds = checker.getValueBounds(env, *prepared.formula, prepared.formulaInformation);
92 if (useClipping && prepared.propertyInformation.kind == beliefs::PropertyInformation::Kind::ExpectedTotalReachabilityReward) {
93 bounds.extremeBounds = checker.getExtremeValueBound(env, *prepared.formula, prepared.formulaInformation);
94 }
95 return bounds;
96}
97
98template<typename PomdpValueType, typename BeliefValueType, typename BeliefMdpValueType, typename PolicyValueType>
99beliefs::BeliefBasedModelCheckerResult<BeliefMdpValueType, PolicyValueType> unfoldPrepared(
100 storm::Environment const& env, BeliefVerificationInput<PomdpValueType> const& prepared,
101 beliefs::BeliefBasedModelCheckerOptions<BeliefMdpValueType> const& options) {
102 auto bounds = computeBeliefBounds(env, prepared, options.useClipping);
103 beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<PomdpValueType>, BeliefValueType, BeliefMdpValueType, PolicyValueType> checker(
104 *prepared.pomdp);
105 return checker.checkUnfold(env, prepared.propertyInformation, options, bounds);
106}
107
108} // namespace
109
110template<typename PomdpValueType, typename BeliefValueType, typename BeliefMdpValueType, typename PolicyValueType>
114 auto effectiveOptions = options;
115 auto prepared = prepareBeliefVerification(pomdp, formula, effectiveOptions);
116 return unfoldPrepared<PomdpValueType, BeliefValueType, BeliefMdpValueType, PolicyValueType>(env, prepared, effectiveOptions);
117}
118
119template<typename PomdpValueType, typename BeliefValueType, typename BeliefMdpValueType, typename PolicyValueType>
121 storm::Environment const& env, storm::models::sparse::Pomdp<PomdpValueType> const& pomdp, storm::logic::Formula const& formula, uint64_t resolution,
122 bool useDynamic, beliefs::BeliefBasedModelCheckerOptions<BeliefMdpValueType> const& options) {
123 STORM_LOG_THROW(resolution > 0, storm::exceptions::IllegalArgumentException, "The discretization resolution must be positive.");
124 STORM_LOG_THROW(options.getTerminationCriterion() == beliefs::NONE, storm::exceptions::NotSupportedException,
125 "Belief discretization does not support exploration size or time limits.");
126 STORM_LOG_THROW(!options.useClipping, storm::exceptions::NotSupportedException, "Belief discretization does not support clipping.");
127 auto effectiveOptions = options;
128 auto prepared = prepareBeliefVerification(pomdp, formula, effectiveOptions);
129 auto bounds = computeBeliefBounds(env, prepared, false);
130 beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<PomdpValueType>, BeliefValueType, BeliefMdpValueType, PolicyValueType> checker(
131 *prepared.pomdp);
132 return checker.checkDiscretize(env, prepared.propertyInformation, effectiveOptions, resolution, useDynamic, bounds);
133}
134
141
148
157
164
171
178
179} // namespace storm::pomdp::api
bool isInFragment(FragmentSpecification const &fragment) const
Definition Formula.cpp:218
std::shared_ptr< Formula const > asSharedPointer()
Definition Formula.cpp:601
virtual uint_fast64_t getNumberOfStates() const override
Returns the number of states of the model.
Definition Model.cpp:191
storm::storage::BitVector const & getInitialStates() const
Retrieves the initial states of the model.
Definition Model.cpp:206
This class represents a partially observable Markov decision process.
Definition Pomdp.h:13
uint64_t getNrObservations() const
Definition Pomdp.cpp:70
uint32_t getObservation(uint64_t state) const
Definition Pomdp.cpp:65
Builds and checks a finite belief MDP approximation of a POMDP.
BeliefBasedModelCheckerResult< BeliefMdpValueType, PolicyValueType > checkDiscretize(storm::Environment const &env, PropertyInformation const &propertyInformation, storm::pomdp::beliefs::BeliefBasedModelCheckerOptions< BeliefMdpValueType > const &options, uint64_t resolution, bool useDynamic, storage::BeliefExplorationBounds< PomdpValueType > const &valueBounds)
Explores the belief space and discretises beliefs using the Freudenthal triangualtion approximation.
uint64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
FragmentSpecification reachability()
FormulaInformation getFormulaInformation(PomdpType const &pomdp, storm::logic::ProbabilityOperatorFormula const &formula)
beliefs::BeliefBasedModelCheckerResult< BeliefMdpValueType, PolicyValueType > verifyWithBeliefUnfolding(storm::Environment const &env, storm::models::sparse::Pomdp< PomdpValueType > const &pomdp, storm::logic::Formula const &formula, beliefs::BeliefBasedModelCheckerOptions< BeliefMdpValueType > const &options)
Approximates an unbounded reachability probability or expected reachability reward by unfolding the b...
template beliefs::BeliefBasedModelCheckerResult< double, storm::RationalNumber > verifyWithBeliefUnfolding< double, double, double, storm::RationalNumber >(storm::Environment const &, storm::models::sparse::Pomdp< double > const &, storm::logic::Formula const &, beliefs::BeliefBasedModelCheckerOptions< double > const &)
template beliefs::BeliefBasedModelCheckerResult< double > verifyWithBeliefUnfolding< double, double, double >(storm::Environment const &, storm::models::sparse::Pomdp< double > const &, storm::logic::Formula const &, beliefs::BeliefBasedModelCheckerOptions< double > const &)
template beliefs::BeliefBasedModelCheckerResult< double > verifyWithBeliefDiscretization< double, storm::RationalNumber, double >(storm::Environment const &, storm::models::sparse::Pomdp< double > const &, storm::logic::Formula const &, uint64_t, bool, beliefs::BeliefBasedModelCheckerOptions< double > const &)
template beliefs::BeliefBasedModelCheckerResult< double > verifyWithBeliefUnfolding< double, storm::RationalNumber, double >(storm::Environment const &, storm::models::sparse::Pomdp< double > const &, storm::logic::Formula const &, beliefs::BeliefBasedModelCheckerOptions< double > const &)
template beliefs::BeliefBasedModelCheckerResult< storm::RationalNumber > verifyWithBeliefUnfolding< storm::RationalNumber, storm::RationalNumber, storm::RationalNumber >(storm::Environment const &, storm::models::sparse::Pomdp< storm::RationalNumber > const &, storm::logic::Formula const &, beliefs::BeliefBasedModelCheckerOptions< storm::RationalNumber > const &)
template beliefs::BeliefBasedModelCheckerResult< double > verifyWithBeliefUnfolding< storm::RationalNumber, storm::RationalNumber, double >(storm::Environment const &, storm::models::sparse::Pomdp< storm::RationalNumber > const &, storm::logic::Formula const &, beliefs::BeliefBasedModelCheckerOptions< double > const &)
template beliefs::BeliefBasedModelCheckerResult< storm::RationalNumber > verifyWithBeliefDiscretization< storm::RationalNumber, storm::RationalNumber, storm::RationalNumber >(storm::Environment const &, storm::models::sparse::Pomdp< storm::RationalNumber > const &, storm::logic::Formula const &, uint64_t, bool, beliefs::BeliefBasedModelCheckerOptions< storm::RationalNumber > const &)
template beliefs::BeliefBasedModelCheckerResult< double, storm::RationalNumber > verifyWithBeliefDiscretization< double, double, double, storm::RationalNumber >(storm::Environment const &, storm::models::sparse::Pomdp< double > const &, storm::logic::Formula const &, uint64_t, bool, beliefs::BeliefBasedModelCheckerOptions< double > const &)
template beliefs::BeliefBasedModelCheckerResult< double > verifyWithBeliefDiscretization< storm::RationalNumber, storm::RationalNumber, double >(storm::Environment const &, storm::models::sparse::Pomdp< storm::RationalNumber > const &, storm::logic::Formula const &, uint64_t, bool, beliefs::BeliefBasedModelCheckerOptions< double > const &)
beliefs::BeliefBasedModelCheckerResult< BeliefMdpValueType, PolicyValueType > verifyWithBeliefDiscretization(storm::Environment const &env, storm::models::sparse::Pomdp< PomdpValueType > const &pomdp, storm::logic::Formula const &formula, uint64_t resolution, bool useDynamic, beliefs::BeliefBasedModelCheckerOptions< BeliefMdpValueType > const &options)
Approximates an unbounded reachability probability or expected reachability reward by Freudenthal dis...
template beliefs::BeliefBasedModelCheckerResult< storm::RationalNumber > verifyWithBeliefDiscretization< double, double, storm::RationalNumber >(storm::Environment const &, storm::models::sparse::Pomdp< double > const &, storm::logic::Formula const &, uint64_t, bool, beliefs::BeliefBasedModelCheckerOptions< storm::RationalNumber > const &)
template beliefs::BeliefBasedModelCheckerResult< storm::RationalNumber > verifyWithBeliefUnfolding< double, double, storm::RationalNumber >(storm::Environment const &, storm::models::sparse::Pomdp< double > const &, storm::logic::Formula const &, beliefs::BeliefBasedModelCheckerOptions< storm::RationalNumber > const &)
template beliefs::BeliefBasedModelCheckerResult< double > verifyWithBeliefDiscretization< double, double, double >(storm::Environment const &, storm::models::sparse::Pomdp< double > const &, storm::logic::Formula const &, uint64_t, bool, beliefs::BeliefBasedModelCheckerOptions< double > const &)
explorationTerminationCriterion getTerminationCriterion() const
Get the termination criterion for the exploration.