Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
BeliefBasedModelChecker.cpp
Go to the documentation of this file.
2
22#include "storm/utility/graph.h"
24
25#include <sstream>
26
27namespace storm::pomdp::beliefs {
28
29void validateRewardModelSelection(PropertyInformation const& propertyInformation, std::vector<std::string> const& rewardModelNames) {
30 STORM_LOG_THROW(!rewardModelNames.empty(), storm::exceptions::IllegalArgumentException,
31 "Reward-aware belief exploration requires at least one selected reward model.");
32 for (auto const& rewardBound : propertyInformation.rewardBounds) {
33 // TODO: we can lift this if the handling of empty reward models is made consistent in storm-main
34 STORM_LOG_THROW(!rewardBound.rewardModelName.empty(), storm::exceptions::NotSupportedException,
35 "For POMDPs, reward-bounded formulae must explicitly name a reward model for each bound.");
37 !(propertyInformation.dir == storm::OptimizationDirection::Minimize && rewardBound.lowerBound.has_value() && rewardBound.upperBound.has_value()),
38 storm::exceptions::NotSupportedException,
39 "Reward-bounded probability minimisation does not support dimensions with both lower and upper reward bounds.");
40 }
41 STORM_LOG_THROW(rewardModelNames.size() >= propertyInformation.rewardBounds.size(), storm::exceptions::IllegalArgumentException,
42 "The selected reward models must include all reward-bounded dimensions first.");
43 for (std::size_t i = 0; i < propertyInformation.rewardBounds.size(); ++i) {
45 rewardModelNames[i] == propertyInformation.rewardBounds[i].rewardModelName, storm::exceptions::IllegalArgumentException,
46 "Selected reward model " << i << " must match the corresponding reward bound '" << propertyInformation.rewardBounds[i].rewardModelName << "'.");
47 }
48}
49
50template<typename PomdpModelType, typename BeliefValueType, typename BeliefMdpValueType, typename PolicyValueType>
52 : inputPomdp(pomdp) {
53 STORM_LOG_THROW(inputPomdp.isCanonic(), storm::exceptions::IllegalArgumentException, "Belief-based model checking requires a canonic POMDP.");
54}
55
57template<typename PomdpModelType, typename BeliefType, typename BeliefMdpValueType, typename InfoType>
60 switch (options.getTerminationCriterion()) {
62 return [&info, maxSize = options.maxExplorationSize.value()]() { return info.discoveredBeliefs.getNumberOfBeliefIds() > maxSize; };
64 return [&swExplore, maxDuration = options.maxExplorationTime.value()]() { return swExplore.getTimeInSeconds() > static_cast<double>(maxDuration); };
66 return [&info, &swExplore, maxSize = options.maxExplorationSize.value(), maxDuration = options.maxExplorationTime.value()]() {
67 return info.discoveredBeliefs.getNumberOfBeliefIds() > maxSize || swExplore.getTimeInSeconds() > static_cast<double>(maxDuration);
68 };
69 case NONE:
70 // Unlimited unfolding (useful for known finite belief MDPs)
71 return []() { return false; };
72 default:
73 STORM_LOG_ERROR("Unknown termination criterion for belief exploration.");
74 return []() { return false; };
75 }
76}
77
83template<typename PomdpModelType, typename BeliefType, typename BeliefMdpValueType>
87 using PomdpValueType = typename PomdpModelType::ValueType;
89 if (options.cutZeroGap) {
90 // Terminate only if the preprocessing bounds have exactly zero gap.
91 return [&propertyInformation, &valueBounds](BeliefType const& belief) -> std::optional<BeliefMdpValueType> {
92 if (propertyInformation.targetObservations.contains(belief.observation())) {
94 } else {
95 auto smallestUpper = storm::utility::infinity<PomdpValueType>();
96 for (auto const& valueList : valueBounds.upper) {
97 smallestUpper = std::min(smallestUpper, belief.template getWeightedSum<PomdpValueType>(valueList));
98 }
99 PomdpValueType largestLower = -storm::utility::infinity<PomdpValueType>();
100 for (auto const& valueList : valueBounds.lower) {
101 largestLower = storm::utility::max(largestLower, belief.template getWeightedSum<PomdpValueType>(valueList));
102 }
103 if (storm::utility::abs<PomdpValueType>(smallestUpper - largestLower) <= storm::utility::zero<PomdpValueType>()) {
104 if constexpr (std::is_same_v<PomdpValueType, BeliefMdpValueType>) {
105 return propertyInformation.dir == solver::OptimizationDirection::Maximize ? largestLower : smallestUpper;
106 } else {
108 propertyInformation.dir == solver::OptimizationDirection::Maximize ? largestLower : smallestUpper);
109 }
110 }
111 return std::nullopt;
112 }
113 };
114 } else {
115 return [&propertyInformation](BeliefType const& belief) -> std::optional<BeliefMdpValueType> {
116 if (propertyInformation.targetObservations.contains(belief.observation())) {
118 } else {
119 return std::nullopt;
120 }
121 };
122 }
124 return [](BeliefType const& belief) -> std::optional<BeliefMdpValueType> {
125 // Reward-aware exploration deliberately has no terminal beliefs. Reaching a target observation does not decide
126 // a reward-bounded property: lower bounds may require further reward accumulation, and the reward vector is
127 // encoded only on the transition. The belief MDP builder consequently receives ordinary explored/frontier edges.
128 return std::nullopt;
129 };
130 } else if (options.cutZeroGap) {
131 // Terminate only if the preprocessing bounds have exactly zero gap.
132 return [&propertyInformation, &valueBounds](BeliefType const& belief) -> std::optional<BeliefMdpValueType> {
133 if (propertyInformation.targetObservations.contains(belief.observation())) {
135 } else {
136 auto smallestUpper = storm::utility::infinity<PomdpValueType>();
137 for (auto const& valueList : valueBounds.upper) {
138 smallestUpper = std::min(smallestUpper, belief.template getWeightedSum<PomdpValueType>(valueList));
139 }
140 PomdpValueType largestLower = -storm::utility::infinity<PomdpValueType>();
141 for (auto const& valueList : valueBounds.lower) {
142 largestLower = storm::utility::max(largestLower, belief.template getWeightedSum<PomdpValueType>(valueList));
143 }
144 if (storm::utility::abs<PomdpValueType>(smallestUpper - largestLower) <= storm::utility::zero<PomdpValueType>()) {
145 if constexpr (std::is_same_v<PomdpValueType, BeliefMdpValueType>) {
146 return propertyInformation.dir == solver::OptimizationDirection::Maximize ? largestLower : smallestUpper;
147 } else {
149 propertyInformation.dir == solver::OptimizationDirection::Maximize ? largestLower : smallestUpper);
150 }
151 }
152 return std::nullopt;
153 }
154 };
155 } else {
156 return [&propertyInformation](BeliefType const& belief) -> std::optional<BeliefMdpValueType> {
157 if (propertyInformation.targetObservations.contains(belief.observation())) {
159 } else {
160 return std::nullopt;
161 }
162 };
163 }
164}
165
171template<typename PomdpModelType, typename BeliefType, typename BeliefMdpValueType, typename InfoType>
172std::pair<std::shared_ptr<models::sparse::Mdp<BeliefMdpValueType>>, std::unordered_map<uint64_t, BeliefId>> buildBeliefMdpFromInfo(
174 InfoType const& info) {
175 using PomdpValueType = typename PomdpModelType::ValueType;
176 std::function<std::unordered_map<std::string, BeliefMdpValueType>(BeliefType const&)> computeCutOffValueMap =
177 [&valueBounds, &propertyInformation](BeliefType const& belief) {
178 // Add addtional cut-off sources here
179 uint64_t const nrCutoffPolicies =
180 propertyInformation.dir == storm::OptimizationDirection::Minimize ? valueBounds.upper.size() : valueBounds.lower.size();
181 std::unordered_map<std::string, BeliefMdpValueType> result;
182 for (uint64_t i = 0; i < nrCutoffPolicies; ++i) {
183 auto val = belief.template getWeightedSum<PomdpValueType>(
184 propertyInformation.dir == storm::OptimizationDirection::Minimize ? valueBounds.upper.at(i) : valueBounds.lower.at(i));
185 if constexpr (std::is_same_v<PomdpValueType, BeliefMdpValueType>) {
186 result["__sched_" + std::to_string(i)] = val;
187 } else {
188 result["__sched_" + std::to_string(i)] = storm::utility::convertNumber<BeliefMdpValueType>(val);
189 }
190 }
191 return result;
192 };
193 return buildBeliefMdp(info, propertyInformation, computeCutOffValueMap);
194}
195
196template<typename PomdpModelType, typename BeliefType, typename BeliefMdpValueType, typename PolicyValueType, typename AbstractionType,
199 storm::Environment const& env, PomdpModelType const& pomdp, PropertyInformation const& propertyInformation,
202 BeliefBasedModelCheckerStatistics statistics;
203 std::optional<storm::pomdp::policy::ObservationBasedFiniteStateController<PolicyValueType>> generatedPolicy;
206 "Unexpected kind of property.");
207
208 if (options.generatePolicy) {
209 STORM_LOG_THROW(valueBounds.preprocessingBounds.has_value(), storm::exceptions::IllegalArgumentException,
210 "Policy generation requires preprocessing bounds with continuation schedulers.");
211 auto const& bounds = *valueBounds.preprocessingBounds;
212 auto const& cutOffBounds = storm::solver::minimize(propertyInformation.dir) ? bounds.upper : bounds.lower;
213 auto const& cutOffSchedulers = storm::solver::minimize(propertyInformation.dir) ? bounds.upperSchedulers : bounds.lowerSchedulers;
214 STORM_LOG_THROW(cutOffSchedulers.size() == cutOffBounds.size(), storm::exceptions::IllegalArgumentException,
215 "Policy generation requires one continuation scheduler per " << (storm::solver::minimize(propertyInformation.dir) ? "upper" : "lower")
216 << " cut-off bound, but received " << cutOffSchedulers.size()
217 << " schedulers for " << cutOffBounds.size() << " bounds.");
218 }
219
220 STORM_LOG_INFO("Exploring the belief space.");
221
222 // First, explore the beliefs and its successors
223 using BeliefExplorationType = BeliefExploration<BeliefMdpValueType, PomdpModelType, BeliefType>;
224 storm::utility::Stopwatch swExplore(true);
225 BeliefExplorationType exploration(pomdp);
226
227 auto info = exploration.template initializeExploration<InfoType>(pomdp.getNrObservations(), options.explorationQueueOrder);
228 info.generateChoiceLabeling = options.buildChoiceLabeling || options.generatePolicy;
229
230 // Determine terminationCallback based on options
231 typename BeliefExplorationType::TerminationCallback terminationCallback =
233
234 // Determine terminalBeliefCallback based on options
235 typename BeliefExplorationType::TerminalBeliefCallback terminalBeliefCallback =
237
238 if constexpr (std::is_same_v<InfoType, ClippingExplorationInformation<BeliefMdpValueType, BeliefType>>) {
239 STORM_LOG_ASSERT(options.useClipping, "Clipping exploration information requires clipping to be enabled.");
241 exploration.resumeClippingExploration(info, terminalBeliefCallback, terminationCallback, propertyInformation.rewardModelName.value(), abstraction);
242 } else {
243 exploration.resumeClippingExploration(info, terminalBeliefCallback, terminationCallback, storm::NullRef, abstraction);
244 }
245 STORM_LOG_TRACE("Starting clipping phase.");
246 STORM_LOG_ASSERT(options.clippingResolutions.has_value(), "Clipping requested, but no resolution vector given.");
247 std::vector<uint64_t> resolutions(options.clippingResolutions.value());
249 STORM_LOG_ASSERT(valueBounds.extremeBounds.has_value(),
250 "Clipping for expected total reachability reward requires extreme value bounds to be given.");
251 ClippingBeliefAbstraction<BeliefType> clippingAbstraction(
252 env, std::move(resolutions), std::move(valueBounds.extremeBounds->template copyValues<typename BeliefType::ValueType>()));
253 exploration.resumeClippingExploration(
254 info, terminalBeliefCallback, []() { return false; }, propertyInformation.rewardModelName.value(), storm::OptionalRef(clippingAbstraction));
255 } else {
256 ClippingBeliefAbstraction<BeliefType> clippingAbstraction(env, std::move(resolutions));
257 exploration.resumeClippingExploration(
258 info, terminalBeliefCallback, []() { return false; }, storm::NullRef, storm::OptionalRef(clippingAbstraction));
259 }
260 STORM_LOG_TRACE("Finished clipping phase.");
261 } else {
263 exploration.resumeExploration(info, terminalBeliefCallback, terminationCallback, propertyInformation.rewardModelName.value(), abstraction);
264 } else {
265 exploration.resumeExploration(info, terminalBeliefCallback, terminationCallback, storm::NullRef, abstraction);
266 }
267 }
268 swExplore.stop();
269 bool earlyExplorationStop = info.queue.hasNext();
270 statistics.completedExploration = !earlyExplorationStop;
271 statistics.discoveredBeliefs = info.discoveredBeliefs.getNumberOfBeliefIds();
272 statistics.exploredBeliefs = info.exploredBeliefs.size();
273 statistics.explorationTimeMilliseconds = swExplore.getTimeInMilliseconds();
274 if (earlyExplorationStop) {
275 STORM_LOG_INFO("Exploration stopped before all beliefs were explored. " << info.discoveredBeliefs.getNumberOfBeliefIds() << " beliefs discovered. "
276 << info.exploredBeliefs.size() << " beliefs explored.");
277 }
278
279 // Second, build the Belief MDP from the exploration information
280 STORM_LOG_INFO("Constructing the belief MDP.");
281 storm::utility::Stopwatch swBuild(true);
282 auto [beliefMdp, stateToBeliefMap] =
284 swBuild.stop();
285 {
286 std::stringstream stream;
287 beliefMdp->printModelInformationToStream(stream);
288 STORM_LOG_INFO("Constructed belief MDP:\n" << stream.str());
289 }
290 statistics.beliefMdpStates = beliefMdp->getNumberOfStates();
291 statistics.beliefMdpChoices = beliefMdp->getNumberOfChoices();
292 statistics.beliefMdpTransitions = beliefMdp->getNumberOfTransitions();
293 statistics.beliefMdpBuildTimeMilliseconds = swBuild.getTimeInMilliseconds();
294
295 // Finally, perform model checking on the belief MDP.
296 storm::utility::Stopwatch swCheck(true);
297 auto formula = createFormulaForBeliefMdp(propertyInformation);
298 storm::modelchecker::CheckTask<storm::logic::Formula, BeliefMdpValueType> task(*formula, !options.generatePolicy);
299 task.setProduceSchedulers(options.generatePolicy);
300 std::unique_ptr<storm::modelchecker::CheckResult> res(storm::api::verifyWithSparseEngine<BeliefMdpValueType>(env, beliefMdp, task));
301 swCheck.stop();
302 statistics.beliefMdpAnalysisTimeMilliseconds = swCheck.getTimeInMilliseconds();
303 STORM_LOG_INFO("Time for exploring beliefs: " << swExplore << ".");
304 STORM_LOG_INFO("Time for building the belief MDP: " << swBuild << ".");
305 STORM_LOG_INFO("Time for analyzing the belief MDP: " << swCheck << ".");
306 STORM_LOG_ASSERT(res, "Model checking of belief MDP did not return any result.");
307 STORM_LOG_ASSERT(res->isExplicitQuantitativeCheckResult(), "Model checking of belief MDP did not return result of expected type.");
308 STORM_LOG_ASSERT(beliefMdp->getInitialStates().getNumberOfSetBits() == 1, "Unexpected number of initial states for belief Mdp.");
309 auto const initState = beliefMdp->getInitialStates().getNextSetIndex(0);
310 if (options.generatePolicy) {
311 auto const& quantitativeResult = res->asExplicitQuantitativeCheckResult<BeliefMdpValueType>();
312 STORM_LOG_THROW(beliefMdp->hasChoiceLabeling(), storm::exceptions::UnexpectedException, "Policy extraction requires choice labels in the belief MDP.");
313 STORM_LOG_THROW(quantitativeResult.hasScheduler(), storm::exceptions::UnexpectedException,
314 "Model checking of the belief MDP did not produce a scheduler for policy extraction.");
315 std::unordered_map<uint64_t, uint32_t> beliefStateToObservationMap;
316 for (auto const& [state, beliefId] : stateToBeliefMap) {
317 beliefStateToObservationMap.emplace(state, info.discoveredBeliefs.getBeliefFromId(beliefId).observation());
318 }
319 std::optional<std::vector<storm::storage::Scheduler<typename PomdpModelType::ValueType>>> approximationSchedulers =
320 propertyInformation.dir == storm::OptimizationDirection::Minimize ? valueBounds.preprocessingBounds->upperSchedulers
321 : valueBounds.preprocessingBounds->lowerSchedulers;
322 policy::PolicyExtractor<PomdpModelType, typename BeliefType::ValueType, BeliefMdpValueType, PolicyValueType> extractor(
323 pomdp, *beliefMdp, beliefStateToObservationMap, quantitativeResult.getScheduler(), approximationSchedulers);
324 generatedPolicy = extractor.exportPolicyAsFiniteStateController();
325 }
326 return {res->asExplicitQuantitativeCheckResult<BeliefMdpValueType>()[initState], !earlyExplorationStop, std::move(statistics), std::move(generatedPolicy)};
327}
328
329template<typename PomdpModelType, typename BeliefType, typename BeliefMdpValueType, typename PolicyValueType>
331 storm::Environment const& env, PomdpModelType const& pomdp, PropertyInformation const& propertyInformation,
336 BeliefBasedModelCheckerStatistics statistics;
337 STORM_LOG_ASSERT(propertyInformation.kind == PropertyInformation::Kind::RewardBoundedReachabilityProbability, "Unexpected kind of property.");
338 STORM_LOG_THROW(!options.useClipping, storm::exceptions::NotSupportedException, "Grid clipping is not supported for reward-bounded POMDP properties.");
339 STORM_LOG_ASSERT(rewardSplitter.getNumberOfSetRewardModels() != 0, "rewardSplitter must have a reward model set for reward-aware belief MDP construction.");
340
341 STORM_LOG_INFO("Exploring the belief space.");
342
343 // First, explore the beliefs and its successors
344 using BeliefExplorationType = BeliefExploration<BeliefMdpValueType, PomdpModelType, BeliefType>;
345 storm::utility::Stopwatch swExplore(true);
346 BeliefExplorationType exploration(pomdp);
348 auto info = exploration.template initializeExploration<InfoType>(pomdp.getNrObservations(), options.explorationQueueOrder);
349 info.generateChoiceLabeling = options.buildChoiceLabeling;
350
351 // Determine terminationCallback based on options
352 typename BeliefExplorationType::TerminationCallback terminationCallback =
354
355 // Determine terminalBeliefCallback based on options
356 typename BeliefExplorationType::TerminalBeliefCallback terminalBeliefCallback =
358
359 exploration.resumeRewardAwareExploration(info, terminalBeliefCallback, terminationCallback, rewardSplitter, abstraction);
360 swExplore.stop();
361 bool const earlyExplorationStop = info.queue.hasNext();
362 statistics.completedExploration = !earlyExplorationStop;
363 statistics.discoveredBeliefs = info.discoveredBeliefs.getNumberOfBeliefIds();
364 statistics.exploredBeliefs = info.exploredBeliefs.size();
365 statistics.explorationTimeMilliseconds = swExplore.getTimeInMilliseconds();
366 if (earlyExplorationStop) {
367 STORM_LOG_INFO("Exploration stopped before all beliefs were explored. " << info.discoveredBeliefs.getNumberOfBeliefIds() << " beliefs discovered. "
368 << info.exploredBeliefs.size() << " beliefs explored.");
369 }
370
371 // Second, build the Belief MDP from the exploration information
372 STORM_LOG_INFO("Constructing the belief MDP.");
373 storm::utility::Stopwatch swBuild(true);
374 auto [beliefMdp, stateToBeliefMap] =
376 swBuild.stop();
377 {
378 std::stringstream stream;
379 beliefMdp->printModelInformationToStream(stream);
380 STORM_LOG_INFO("Constructed belief MDP:\n" << stream.str());
381 }
382 statistics.beliefMdpStates = beliefMdp->getNumberOfStates();
383 statistics.beliefMdpChoices = beliefMdp->getNumberOfChoices();
384 statistics.beliefMdpTransitions = beliefMdp->getNumberOfTransitions();
385 statistics.beliefMdpBuildTimeMilliseconds = swBuild.getTimeInMilliseconds();
386
387 // Finally, perform model checking on the belief MDP.
388 auto formula = createFormulaForBeliefMdp(propertyInformation);
389 STORM_LOG_INFO("Analyzing property '" << *formula << "' on the belief MDP.");
390 storm::utility::Stopwatch swCheck(true);
391 std::shared_ptr<storm::models::sparse::Mdp<BeliefMdpValueType>> processedMdp = beliefMdp;
393 std::vector<std::string> rewardModelNames;
394 for (auto const& bnd : propertyInformation.rewardBounds) {
395 rewardModelNames.push_back(bnd.rewardModelName);
396 }
397 processedMdp = storm::transformer::transformTransitionToActionRewards<BeliefMdpValueType>(processedMdp, rewardModelNames)
398 .model->template as<storm::models::sparse::Mdp<BeliefMdpValueType>>();
399 double increase = static_cast<double>(processedMdp->getNumberOfStates()) / static_cast<double>(beliefMdp->getNumberOfStates());
400 STORM_LOG_INFO("Transformation of transition rewards resulted in a model with " << processedMdp->getNumberOfStates() << " states. " << increase
401 << " times more states than the original belief MDP.");
402
403 // Cut away states that can not reach the target
404 auto targetStates = processedMdp->getStateLabeling().getStates("target");
405 storm::storage::BitVector allStates(targetStates.size(), true);
406 storm::storage::BitVector probGreaterZeroStates;
407 if (storm::solver::maximize(propertyInformation.dir)) {
408 probGreaterZeroStates = storm::utility::graph::performProbGreater0E(processedMdp->getBackwardTransitions(), allStates, targetStates);
409 } else {
410 probGreaterZeroStates =
411 storm::utility::graph::performProbGreater0A(processedMdp->getTransitionMatrix(), processedMdp->getTransitionMatrix().getRowGroupIndices(),
412 processedMdp->getBackwardTransitions(), allStates, targetStates);
413 }
414 auto mergingResult = storm::transformer::GoalStateMerger<BeliefMdpValueType>(*processedMdp)
415 .mergeTargetAndSinkStates(probGreaterZeroStates, ~probGreaterZeroStates, ~allStates, rewardModelNames);
416 processedMdp = mergingResult.model->template as<storm::models::sparse::Mdp<BeliefMdpValueType>>();
417 STORM_LOG_INFO("Merging of sink states resulted in a model with " << processedMdp->getNumberOfStates() << " states.");
418 }
419 if (processedMdp != beliefMdp) {
420 statistics.processedMdpStates = processedMdp->getNumberOfStates();
421 statistics.processedMdpChoices = processedMdp->getNumberOfChoices();
422 statistics.processedMdpTransitions = processedMdp->getNumberOfTransitions();
423 }
424 storm::modelchecker::CheckTask<storm::logic::Formula, BeliefMdpValueType> task(*formula, true);
425 std::unique_ptr<storm::modelchecker::CheckResult> res(storm::api::verifyWithSparseEngine<BeliefMdpValueType>(env, processedMdp, task));
426 swCheck.stop();
427 statistics.beliefMdpAnalysisTimeMilliseconds = swCheck.getTimeInMilliseconds();
428 STORM_LOG_INFO("Time for exploring beliefs: " << swExplore << ".");
429 STORM_LOG_INFO("Time for building the belief MDP: " << swBuild << ".");
430 STORM_LOG_INFO("Time for analyzing the belief MDP: " << swCheck << ".");
431 STORM_LOG_ASSERT(res, "Model checking of belief MDP did not return any result.");
432 STORM_LOG_ASSERT(res->isExplicitQuantitativeCheckResult(), "Model checking of belief MDP did not return result of expected type.");
433 STORM_LOG_ASSERT(processedMdp->getInitialStates().getNumberOfSetBits() == 1, "Unexpected number of initial states for (processed) belief Mdp.");
434 auto const initState = processedMdp->getInitialStates().getNextSetIndex(0);
435 return {res->asExplicitQuantitativeCheckResult<BeliefMdpValueType>()[initState], !earlyExplorationStop, std::move(statistics), std::nullopt};
436}
437
438template<typename PomdpModelType, typename BeliefValueType, typename BeliefMdpValueType, typename PolicyValueType>
441 storm::Environment const& env, PropertyInformation const& propertyInformation,
444 STORM_LOG_THROW(!options.generatePolicy || !options.cutZeroGap, storm::exceptions::NotSupportedException,
445 "Zero-gap cutting is not supported for policy generation because cut-off beliefs do not retain a continuation policy.");
446 if (options.useClipping) {
449 options, valueBounds);
450 } else {
452 env, inputPomdp, propertyInformation, options, valueBounds);
453 }
454}
455
456template<typename PomdpModelType, typename BeliefValueType, typename BeliefMdpValueType, typename PolicyValueType>
459 storm::Environment const& env, PropertyInformation const& propertyInformation,
460 storm::pomdp::beliefs::BeliefBasedModelCheckerOptions<BeliefMdpValueType> const& options, uint64_t resolution, bool useDynamic,
462 STORM_LOG_THROW(options.getTerminationCriterion() == NONE, storm::exceptions::NotSupportedException,
463 "Belief discretization does not support exploration size or time limits.");
464 STORM_LOG_THROW(!options.generatePolicy, storm::exceptions::NotSupportedException, "Policy generation is not supported for belief MDP discretization.");
467 return checkUnfoldOrDiscretize<PomdpModelType, Belief<BeliefValueType>, BeliefMdpValueType, PolicyValueType>(env, inputPomdp, propertyInformation, options,
468 valueBounds, storm::OptionalRef(abstraction));
469}
470
471template<typename PomdpModelType, typename BeliefValueType, typename BeliefMdpValueType, typename PolicyValueType>
474 storm::Environment const& env, PropertyInformation const& propertyInformation,
476 storage::BeliefExplorationBounds<typename PomdpModelType::ValueType> const& valueBounds, std::vector<std::string> const& relevantRewardModelNames) {
477 validateRewardModelSelection(propertyInformation, relevantRewardModelNames);
478 STORM_LOG_THROW(!options.generatePolicy, storm::exceptions::NotSupportedException, "Policy generation is not supported for reward-aware exploration.");
480 rewardBoundedBeliefSplitter.setRewardModels(relevantRewardModelNames);
481 return checkRewardAwareUnfoldOrDiscretize<PomdpModelType, Belief<BeliefValueType>, BeliefMdpValueType, PolicyValueType>(
482 env, inputPomdp, propertyInformation, options, valueBounds, rewardBoundedBeliefSplitter);
483}
484
485template<typename PomdpModelType, typename BeliefValueType, typename BeliefMdpValueType, typename PolicyValueType>
488 storm::Environment const& env, PropertyInformation const& propertyInformation,
489 storm::pomdp::beliefs::BeliefBasedModelCheckerOptions<BeliefMdpValueType> const& options, uint64_t resolution, bool useDynamic,
490 storage::BeliefExplorationBounds<typename PomdpModelType::ValueType> const& valueBounds, std::vector<std::string> const& relevantRewardModelNames) {
491 STORM_LOG_THROW(options.getTerminationCriterion() == NONE, storm::exceptions::NotSupportedException,
492 "Belief discretization does not support exploration size or time limits.");
493 STORM_LOG_THROW(!options.generatePolicy, storm::exceptions::NotSupportedException, "Policy generation is not supported for reward-aware exploration.");
494 validateRewardModelSelection(propertyInformation, relevantRewardModelNames);
498 rewardBoundedBeliefSplitter.setRewardModels(relevantRewardModelNames);
499 return checkRewardAwareUnfoldOrDiscretize<PomdpModelType, Belief<BeliefValueType>, BeliefMdpValueType, PolicyValueType>(
500 env, inputPomdp, propertyInformation, options, valueBounds, rewardBoundedBeliefSplitter, abstraction);
501}
502
504template class BeliefBasedModelChecker<storm::models::sparse::Pomdp<double>, storm::RationalNumber, double>;
505template class BeliefBasedModelChecker<storm::models::sparse::Pomdp<storm::RationalNumber>, storm::RationalNumber, storm::RationalNumber>;
506template class BeliefBasedModelChecker<storm::models::sparse::Pomdp<storm::RationalNumber>, storm::RationalNumber, double>;
507template class BeliefBasedModelChecker<storm::models::sparse::Pomdp<double>, double, storm::RationalNumber>;
508template class BeliefBasedModelChecker<storm::models::sparse::Pomdp<double>, double, double, storm::RationalNumber>;
509// Currently we don't consider this combination as having rational numbers in models, but floats in beliefs does not really help us
510// template class BeliefBasedModelChecker<storm::models::sparse::Pomdp<storm::RationalNumber>, double, storm::RationalNumber>;
511} // namespace storm::pomdp::beliefs
Helper class that optionally holds a reference to an object of type T.
Definition OptionalRef.h:48
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.
BeliefBasedModelCheckerResult< BeliefMdpValueType, PolicyValueType > checkRewardAwareUnfold(storm::Environment const &env, PropertyInformation const &propertyInformation, storm::pomdp::beliefs::BeliefBasedModelCheckerOptions< BeliefMdpValueType > const &options, storage::BeliefExplorationBounds< typename PomdpModelType::ValueType > const &valueBounds, std::vector< std::string > const &relevantRewardModelNames)
Explores a reward-aware belief MDP, splitting beliefs before successor generation by their reward vec...
BeliefBasedModelChecker(PomdpModelType const &pomdp)
Creates a checker for a canonic POMDP.
BeliefBasedModelCheckerResult< BeliefMdpValueType, PolicyValueType > checkRewardAwareDiscretize(storm::Environment const &env, PropertyInformation const &propertyInformation, storm::pomdp::beliefs::BeliefBasedModelCheckerOptions< BeliefMdpValueType > const &options, uint64_t resolution, bool useDynamic, storage::BeliefExplorationBounds< typename PomdpModelType::ValueType > const &valueBounds, std::vector< std::string > const &relevantRewardModelNames)
Combines reward-aware exploration with Freudenthal triangulation discretization.
BeliefBasedModelCheckerResult< BeliefMdpValueType, PolicyValueType > checkUnfold(storm::Environment const &env, PropertyInformation const &propertyInformation, BeliefBasedModelCheckerOptions< BeliefMdpValueType > const &options, storage::BeliefExplorationBounds< PomdpValueType > const &valueBounds)
Explores the belief MDP by unfolding the belief space.
std::function< std::optional< BeliefMdpValueType >(BeliefType const &)> TerminalBeliefCallback
Approximates a belief by clipping it to an observation-specific grid point.
Abstracts a belief by triangulating it using the Freudenthal triangulation.
Abstracts a given belief by splitting it into sub-beliefs based on the (state-action) reward of the P...
void setRewardModels(std::vector< std::string > const &rewardModelNames)
Selects a nonempty list of reward models used to form reward vectors.
A class that provides convenience operations to display run times.
Definition Stopwatch.h:13
SecondType getTimeInSeconds() const
Gets the measured time in seconds.
Definition Stopwatch.cpp:13
#define STORM_LOG_INFO(message)
Definition logging.h:34
#define STORM_LOG_TRACE(message)
Definition logging.h:22
#define STORM_LOG_ERROR(message)
Definition logging.h:36
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
std::unique_ptr< storm::modelchecker::CheckResult > verifyWithSparseEngine(storm::Environment const &env, std::shared_ptr< storm::models::sparse::Dtmc< ValueType > > const &dtmc, storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > const &task, bool preferEliminationChecker=false)
std::pair< std::shared_ptr< models::sparse::Mdp< BeliefMdpValueType > >, std::unordered_map< uint64_t, BeliefId > > buildBeliefMdpFromInfo(PropertyInformation const &propertyInformation, storm::pomdp::storage::PreprocessingPomdpValueBounds< typename PomdpModelType::ValueType > const &valueBounds, InfoType const &info)
Converts exploration information into a finite MDP.
void validateRewardModelSelection(PropertyInformation const &propertyInformation, std::vector< std::string > const &rewardModelNames)
BeliefBasedModelCheckerResult< BeliefMdpValueType, PolicyValueType > checkRewardAwareUnfoldOrDiscretize(storm::Environment const &env, PomdpModelType const &pomdp, PropertyInformation const &propertyInformation, storm::pomdp::beliefs::BeliefBasedModelCheckerOptions< BeliefMdpValueType > const &options, storage::BeliefExplorationBounds< typename PomdpModelType::ValueType > const &valueBounds, RewardBoundedBeliefSplitter< BeliefMdpValueType, PomdpModelType, BeliefType > &rewardSplitter, storm::OptionalRef< FreudenthalTriangulationBeliefAbstraction< BeliefType > > abstraction={})
BeliefBasedModelCheckerResult< BeliefMdpValueType, PolicyValueType > checkUnfoldOrDiscretize(storm::Environment const &env, PomdpModelType const &pomdp, PropertyInformation const &propertyInformation, storm::pomdp::beliefs::BeliefBasedModelCheckerOptions< BeliefMdpValueType > const &options, storage::BeliefExplorationBounds< typename PomdpModelType::ValueType > const &valueBounds, storm::OptionalRef< AbstractionType > abstraction={})
BeliefExploration< BeliefMdpValueType, PomdpModelType, BeliefType >::TerminationCallback getTerminationCallback(storm::pomdp::beliefs::BeliefBasedModelCheckerOptions< BeliefMdpValueType > const &options, InfoType &info, storm::utility::Stopwatch &swExplore)
Creates the callback that ends exploration and turns the queued beliefs into the frontier.
std::shared_ptr< storm::logic::Formula const > createFormulaForBeliefMdp(PropertyInformation const &propertyInformation)
ExplorationInformation< BeliefMdpValueType, BeliefType, std::optional< BeliefMdpValueType >, std::optional< BeliefMdpValueType > > ClippingExplorationInformation
Exploration information that stores optional clipping probability and reward-adjustment metadata.
ExplorationInformation< BeliefMdpValueType, BeliefType > StandardExplorationInformation
Exploration information without transition metadata.
BeliefExploration< BeliefMdpValueType, PomdpModelType, BeliefType >::TerminalBeliefCallback getTerminalBeliefCallback(PropertyInformation const &propertyInformation, storm::pomdp::beliefs::BeliefBasedModelCheckerOptions< BeliefMdpValueType > const &options, storm::pomdp::storage::PreprocessingPomdpValueBounds< typename PomdpModelType::ValueType > const &valueBounds)
Creates a callback that recognizes property targets and optional zero-gap cut-offs as terminal belief...
std::pair< std::shared_ptr< models::sparse::Mdp< BeliefMdpValueType > >, std::unordered_map< uint64_t, BeliefId > > buildBeliefMdp(ExplorationInformation< BeliefMdpValueType, BeliefType, ExtraTransitionData... > const &explorationInformation, PropertyInformation const &propertyInformation, std::function< std::unordered_map< std::string, BeliefMdpValueType >(BeliefType const &)> const &computeCutOffValueMap)
Builds a belief MDP from the given exploration information and property information.
ExplorationInformation< BeliefMdpValueType, BeliefType, std::vector< BeliefMdpValueType > > RewardAwareExplorationInformation
Exploration information that stores a reward vector on each transition.
bool constexpr maximize(OptimizationDirection d)
bool constexpr minimize(OptimizationDirection d)
TransitionToActionRewardTransformerReturnType< ValueType, RewardModelType > transformTransitionToActionRewards(std::shared_ptr< storm::models::sparse::Model< ValueType, RewardModelType > > originalModel, std::vector< std::string > const &relevantRewardModelNames)
Replaces transition branch rewards from all given reward models and replaces them by equivalent state...
storm::storage::BitVector performProbGreater0A(storm::storage::SparseMatrix< T > const &transitionMatrix, std::vector< uint_fast64_t > const &nondeterministicChoiceIndices, storm::storage::SparseMatrix< T > const &backwardTransitions, storm::storage::BitVector const &phiStates, storm::storage::BitVector const &psiStates, bool useStepBound, uint_fast64_t maximalSteps, boost::optional< storm::storage::BitVector > const &choiceConstraint)
Computes the sets of states that have probability greater 0 of satisfying phi until psi under any pos...
Definition graph.cpp:881
storm::storage::BitVector performProbGreater0E(storm::storage::SparseMatrix< T > const &backwardTransitions, storm::storage::BitVector const &phiStates, storm::storage::BitVector const &psiStates, bool useStepBound, uint_fast64_t maximalSteps)
Computes the sets of states that have probability greater 0 of satisfying phi until psi under at leas...
Definition graph.cpp:674
ValueType max(ValueType const &first, ValueType const &second)
ValueType abs(ValueType const &number)
ValueType zero()
Definition constants.cpp:26
ValueType infinity()
Definition constants.cpp:31
ValueType one()
Definition constants.cpp:21
TargetType convertNumber(SourceType const &number)
OptionalRef(T &) -> OptionalRef< T >
deduction guides
constexpr NullRefType NullRef
Definition OptionalRef.h:31
bool cutZeroGap
Cut non-target beliefs only when their preprocessing lower and upper bounds have exactly zero gap....
explorationTerminationCriterion getTerminationCriterion() const
Get the termination criterion for the exploration.
Auxiliary struct used to identify cases where no abstraction of beliefs shall be applied.
Property data consumed by the belief MDP construction.
std::set< BeliefObservationType > targetObservations
Struct for storing precomputed values bounding the actual values on the POMDP.
std::optional< ExtremePOMDPValueBound< POMDPValueType > > extremeBounds
std::optional< PreprocessingPomdpValueBounds< POMDPValueType > > preprocessingBounds
Struct for storing precomputed values bounding the actual values on the POMDP.
std::vector< std::vector< POMDPValueType > > lower
std::vector< std::vector< POMDPValueType > > upper