Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
BeliefBasedModelCheckerTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
16#include "storm/api/storm.h"
23#include "storm/utility/graph.h"
24
25namespace {
26enum class PreprocessingType { None, SelfloopReduction, QualitativeReduction, All };
27
28class DefaultDoubleVIEnvironment {
29 public:
30 typedef double POMDPValueType;
31 typedef double BeliefValueType;
32 typedef double BeliefMDPValueType;
33
34 static storm::Environment createEnvironment() {
35 storm::Environment env;
36 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
38 return env;
39 }
40 static bool const isExactModelChecking = false;
41 static POMDPValueType precision() {
43 } // there actually aren't any precision guarantees, but we still want to detect if results are weird.
44 static PreprocessingType const preprocessingType = PreprocessingType::None;
45 static uint64_t overApproxResolution() {
46 return 2;
47 }
48};
49
50class SelfloopReductionDefaultDoubleVIEnvironment {
51 public:
52 typedef double POMDPValueType;
53 typedef double BeliefValueType;
54 typedef double BeliefMDPValueType;
55 static storm::Environment createEnvironment() {
56 storm::Environment env;
57 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
59 return env;
60 }
61 static bool const isExactModelChecking = false;
62 static POMDPValueType precision() {
64 } // there actually aren't any precision guarantees, but we still want to detect if results are weird.
65 static PreprocessingType const preprocessingType = PreprocessingType::SelfloopReduction;
66 static uint64_t overApproxResolution() {
67 return 2;
68 }
69};
70
71class QualitativeReductionDefaultDoubleVIEnvironment {
72 public:
73 typedef double POMDPValueType;
74 typedef double BeliefValueType;
75 typedef double BeliefMDPValueType;
76 static storm::Environment createEnvironment() {
77 storm::Environment env;
78 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
80 return env;
81 }
82 static bool const isExactModelChecking = false;
83 static POMDPValueType precision() {
85 } // there actually aren't any precision guarantees, but we still want to detect if results are weird.
86 static PreprocessingType const preprocessingType = PreprocessingType::QualitativeReduction;
87 static uint64_t overApproxResolution() {
88 return 2;
89 }
90};
91
92class PreprocessedDefaultDoubleVIEnvironment {
93 public:
94 typedef double POMDPValueType;
95 typedef double BeliefValueType;
96 typedef double BeliefMDPValueType;
97 static storm::Environment createEnvironment() {
98 storm::Environment env;
99 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
101 return env;
102 }
103 static bool const isExactModelChecking = false;
104 static POMDPValueType precision() {
106 } // there actually aren't any precision guarantees, but we still want to detect if results are weird.
107 static PreprocessingType const preprocessingType = PreprocessingType::All;
108 static uint64_t overApproxResolution() {
109 return 2;
110 }
111};
112
113class FineDoubleVIEnvironment {
114 public:
115 typedef double POMDPValueType;
116 typedef double BeliefValueType;
117 typedef double BeliefMDPValueType;
118 static storm::Environment createEnvironment() {
119 storm::Environment env;
120 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
122 return env;
123 }
124 static bool const isExactModelChecking = false;
125 static POMDPValueType precision() {
127 } // there actually aren't any precision guarantees, but we still want to detect if results are weird.
128 static PreprocessingType const preprocessingType = PreprocessingType::None;
129 static uint64_t overApproxResolution() {
130 return 24;
131 }
132};
133
134class DefaultDoubleOVIEnvironment {
135 public:
136 typedef double POMDPValueType;
137 typedef double BeliefValueType;
138 typedef double BeliefMDPValueType;
139 static storm::Environment createEnvironment() {
140 storm::Environment env;
141 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::OptimisticValueIteration);
143 env.solver().setForceSoundness(true);
144 return env;
145 }
146 static bool const isExactModelChecking = false;
147 static POMDPValueType precision() {
149 } // there actually aren't any precision guarantees, but we still want to detect if results are weird.
150 static PreprocessingType const preprocessingType = PreprocessingType::None;
151 static uint64_t overApproxResolution() {
152 return 2;
153 }
154};
155
156class DefaultDoubleSVIEnvironment {
157 public:
158 typedef double POMDPValueType;
159 typedef double BeliefValueType;
160 typedef double BeliefMDPValueType;
161 static storm::Environment createEnvironment() {
162 storm::Environment env;
163 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::SoundValueIteration);
165 env.solver().setForceSoundness(true);
166 return env;
167 }
168 static bool const isExactModelChecking = false;
169 static POMDPValueType precision() {
171 } // there actually aren't any precision guarantees, but we still want to detect if results are weird.
172 static PreprocessingType const preprocessingType = PreprocessingType::None;
173 static uint64_t overApproxResolution() {
174 return 2;
175 }
176};
177
178class DefaultRationalPIEnvironment {
179 public:
180 typedef storm::RationalNumber POMDPValueType;
181 typedef storm::RationalNumber BeliefValueType;
182 typedef storm::RationalNumber BeliefMDPValueType;
183
184 static storm::Environment createEnvironment() {
185 storm::Environment env;
186 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::PolicyIteration);
187 env.solver().setForceExact(true);
188 return env;
189 }
190 static bool const isExactModelChecking = true;
191 static POMDPValueType precision() {
193 } // there actually aren't any precision guarantees, but we still want to detect if results are weird.
194 static PreprocessingType const preprocessingType = PreprocessingType::None;
195 static uint64_t overApproxResolution() {
196 return 2;
197 }
198};
199
200class PreprocessedDefaultRationalPIEnvironment {
201 public:
202 typedef storm::RationalNumber POMDPValueType;
203 typedef storm::RationalNumber BeliefValueType;
204 typedef storm::RationalNumber BeliefMDPValueType;
205
206 static storm::Environment createEnvironment() {
207 storm::Environment env;
208 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::PolicyIteration);
209 env.solver().setForceExact(true);
210 return env;
211 }
212 static bool const isExactModelChecking = true;
213 static POMDPValueType precision() {
215 } // there actually aren't any precision guarantees, but we still want to detect if results are weird.
216 static PreprocessingType const preprocessingType = PreprocessingType::All;
217 static uint64_t overApproxResolution() {
218 return 2;
219 }
220};
221
222template<typename TestType>
223class BeliefBasedModelCheckerTest : public ::testing::Test {
224 public:
225 typedef typename TestType::POMDPValueType POMDPValueType;
226 typedef typename TestType::BeliefValueType BeliefValueType;
227 typedef typename TestType::BeliefMDPValueType BeliefMDPValueType;
228 typedef storm::utility::ExtendedValueType<BeliefMDPValueType> ExtendedBeliefMDPValueType;
229
230 BeliefBasedModelCheckerTest() : _environment(TestType::createEnvironment()) {}
231
232 void SetUp() override {
233#ifndef STORM_HAVE_Z3
234 GTEST_SKIP() << "Z3 not available.";
235#endif
236 }
237
238 storm::Environment const& env() const {
239 return _environment;
240 }
241
242 template<typename ValueType>
243 ValueType parseNumber(std::string const& str) {
245 }
246 struct Input {
247 std::shared_ptr<storm::models::sparse::Pomdp<POMDPValueType>> model;
248 std::shared_ptr<storm::logic::Formula const> formula;
249 std::shared_ptr<storm::pomdp::beliefs::PropertyInformation> propertyInfo = std::make_shared<storm::pomdp::beliefs::PropertyInformation>();
250 };
251 Input buildPrism(std::string const& programFile, std::string const& formulaAsString, std::string const& constantsAsString = "") const {
252 // Parse and build input
253 storm::prism::Program program = storm::api::parseProgram(programFile);
254 program = program.preprocess(constantsAsString);
255 Input input;
256 input.formula = storm::api::parsePropertiesForPrismProgram(formulaAsString, program).front().getRawFormula();
257 input.model = storm::api::buildSparseModel<POMDPValueType>(program, {input.formula})->template as<storm::models::sparse::Pomdp<POMDPValueType>>();
258 bool const isBoundedProbability =
259 input.formula->isProbabilityOperatorFormula() && input.formula->asProbabilityOperatorFormula().getSubformula().isBoundedUntilFormula();
260
261 // Preprocess
262 storm::transformer::MakePOMDPCanonic<POMDPValueType> makeCanonic(*input.model);
263 input.model = makeCanonic.transform();
264 EXPECT_TRUE(input.model->isCanonic());
265 if (!isBoundedProbability &&
266 (TestType::preprocessingType == PreprocessingType::SelfloopReduction || TestType::preprocessingType == PreprocessingType::All)) {
267 storm::transformer::GlobalPOMDPSelfLoopEliminator<POMDPValueType> selfLoopEliminator(*input.model);
268 if (selfLoopEliminator.preservesFormula(*input.formula)) {
269 input.model = selfLoopEliminator.transform();
270 } else {
271 EXPECT_TRUE(input.formula->isOperatorFormula());
272 EXPECT_TRUE(input.formula->asOperatorFormula().hasOptimalityType());
273 bool maximizing = storm::solver::maximize(input.formula->asOperatorFormula().getOptimalityType());
274 // Valid reasons for unpreserved formulas:
275 EXPECT_TRUE(maximizing || input.formula->isProbabilityOperatorFormula());
276 EXPECT_TRUE(!maximizing || input.formula->isRewardOperatorFormula());
277 }
278 }
279 if (!isBoundedProbability &&
280 (TestType::preprocessingType == PreprocessingType::QualitativeReduction || TestType::preprocessingType == PreprocessingType::All)) {
281 EXPECT_TRUE(input.formula->isOperatorFormula());
282 EXPECT_TRUE(input.formula->asOperatorFormula().hasOptimalityType());
283 if (input.formula->isProbabilityOperatorFormula() && storm::solver::maximize(input.formula->asOperatorFormula().getOptimalityType())) {
284 storm::analysis::QualitativeAnalysisOnGraphs<POMDPValueType> qualitativeAnalysis(*input.model);
285 storm::storage::BitVector prob0States = qualitativeAnalysis.analyseProb0(input.formula->asProbabilityOperatorFormula());
286 storm::storage::BitVector prob1States = qualitativeAnalysis.analyseProb1(input.formula->asProbabilityOperatorFormula());
287 storm::pomdp::transformer::KnownProbabilityTransformer<POMDPValueType> kpt;
288 input.model = kpt.transform(*input.model, prob0States, prob1States);
289 }
290 }
291 EXPECT_TRUE(input.model->isCanonic());
292 auto formulaInfo = storm::pomdp::analysis::getFormulaInformation(*input.model, *input.formula);
293 std::optional<std::string> rewardModelName;
294 std::set<uint32_t> targetObservations;
295 EXPECT_TRUE(formulaInfo.isNonNestedReachabilityProbability() || formulaInfo.isNonNestedExpectedRewardFormula());
296 if (formulaInfo.getTargetStates().observationClosed) {
297 targetObservations = formulaInfo.getTargetStates().observations;
298 } else {
299 storm::transformer::MakeStateSetObservationClosed<POMDPValueType> obsCloser(input.model);
300 std::tie(input.model, targetObservations) = obsCloser.transform(formulaInfo.getTargetStates().states);
301 }
302 if (formulaInfo.isNonNestedReachabilityProbability()) {
303 if (!formulaInfo.getSinkStates().empty()) {
304 storm::storage::sparse::ModelComponents<POMDPValueType> components;
305 components.stateLabeling = input.model->getStateLabeling();
306 components.rewardModels = input.model->getRewardModels();
307 auto matrix = input.model->getTransitionMatrix();
308 matrix.makeRowGroupsAbsorbing(formulaInfo.getSinkStates().states);
309 components.transitionMatrix = matrix;
310 components.observabilityClasses = input.model->getObservations();
311 if (input.model->hasChoiceLabeling()) {
312 components.choiceLabeling = input.model->getChoiceLabeling();
313 }
314 if (input.model->hasObservationValuations()) {
315 components.observationValuations = input.model->getObservationValuations();
316 }
317 input.model = std::make_shared<storm::models::sparse::Pomdp<POMDPValueType>>(std::move(components), true);
318 auto reachableFromSinkStates =
319 storm::utility::graph::getReachableStates(input.model->getTransitionMatrix(), formulaInfo.getSinkStates().states,
320 formulaInfo.getSinkStates().states, ~formulaInfo.getSinkStates().states);
321 reachableFromSinkStates &= ~formulaInfo.getSinkStates().states;
322 STORM_LOG_THROW(reachableFromSinkStates.empty(), storm::exceptions::NotSupportedException,
323 "There are sink states that can reach non-sink states. This is currently not supported");
324 }
325 } else {
326 // Expected reward formula!
327 rewardModelName = formulaInfo.getRewardModelName();
328 }
329
330 if (rewardModelName) {
332 input.propertyInfo->rewardModelName = rewardModelName;
333 } else if (formulaInfo.isBounded()) {
335 auto const& boundedFormula = input.formula->asProbabilityOperatorFormula().getSubformula().asBoundedUntilFormula();
336 for (uint64_t i = 0; i < boundedFormula.getDimension(); ++i) {
337 auto const& reference = boundedFormula.getTimeBoundReference(i);
338 input.propertyInfo->rewardBounds.push_back({.rewardModelName = reference.getOptionalRewardModelName().get_value_or(""),
339 .lowerBound = boundedFormula.getLowerBoundAsOptionalTimeBound(i),
340 .upperBound = boundedFormula.getUpperBoundAsOptionalTimeBound(i)});
341 }
342 } else {
344 }
345 input.propertyInfo->dir = formulaInfo.getOptimizationDirection();
346 input.propertyInfo->targetObservations = targetObservations;
347
348 return input;
349 }
350 POMDPValueType precision() const {
351 return TestType::precision();
352 }
353 uint64_t overApproxResolution() const {
354 return TestType::overApproxResolution();
355 }
356 template<typename ValueType>
357 ValueType modelcheckingPrecision() const {
358 if (TestType::isExactModelChecking) {
360 } else {
362 }
363 }
364 bool isExact() const {
365 return TestType::isExactModelChecking;
366 }
367
368 private:
369 storm::Environment _environment;
370};
371
372typedef ::testing::Types<DefaultDoubleVIEnvironment, SelfloopReductionDefaultDoubleVIEnvironment, QualitativeReductionDefaultDoubleVIEnvironment,
373 PreprocessedDefaultDoubleVIEnvironment, FineDoubleVIEnvironment, DefaultDoubleOVIEnvironment, DefaultDoubleSVIEnvironment,
374 DefaultRationalPIEnvironment, PreprocessedDefaultRationalPIEnvironment>
376
377TYPED_TEST_SUITE(BeliefBasedModelCheckerTest, TestingTypes, );
378
379TYPED_TEST(BeliefBasedModelCheckerTest, cut_zero_gap) {
380 using POMDPValueType = typename TestFixture::POMDPValueType;
381 using BeliefValueType = typename TestFixture::BeliefValueType;
382 using BeliefMDPValueType = typename TestFixture::BeliefMDPValueType;
384
385 auto check = [&](std::string const& formula, std::string const& expectedValue) {
386 SCOPED_TRACE(formula);
387 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", formula, "slippery=0");
388 ASSERT_EQ(data.model->getInitialStates().getNumberOfSetBits(), 1ul);
389 auto const initialState = data.model->getInitialStates().getNextSetIndex(0);
390 auto const expected = this->template parseNumber<BeliefMDPValueType>(expectedValue);
391 auto const initialValue = this->template parseNumber<POMDPValueType>(expectedValue);
392 auto const delta = this->template parseNumber<POMDPValueType>("1/100000000");
396 bounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
397 auto setInitialBounds = [&](POMDPValueType const& lower, POMDPValueType const& upper) {
398 for (auto& values : bounds.preprocessingBounds->lower) {
399 values[initialState] = lower;
400 }
401 for (auto& values : bounds.preprocessingBounds->upper) {
402 values[initialState] = upper;
403 }
404 };
405
407 EXPECT_FALSE(options.cutZeroGap);
408 options.buildChoiceLabeling = false;
410 auto propertyInfo = *data.propertyInfo;
411 // Zero-gap cutoffs do not retain executable continuation policies, including when clipping is enabled.
412 options.cutZeroGap = true;
413 options.generatePolicy = true;
414 for (bool const useClipping : {false, true}) {
415 SCOPED_TRACE(useClipping);
416 options.useClipping = useClipping;
417 STORM_SILENT_EXPECT_THROW(checker.checkUnfold(this->env(), propertyInfo, options, bounds), storm::exceptions::NotSupportedException);
418 }
419 options.generatePolicy = false;
420 options.useClipping = false;
421 for (int const mode : {0, 1, 2}) {
422 SCOPED_TRACE(mode); // Unfolding, static discretization, dynamic discretization.
423 auto run = [&]() {
424 return mode == 0 ? checker.checkUnfold(this->env(), propertyInfo, options, bounds)
425 : checker.checkDiscretize(this->env(), propertyInfo, options, this->overApproxResolution(), mode == 2, bounds);
426 };
427
428 setInitialBounds(initialValue, initialValue);
429 options.cutZeroGap = true;
430 auto const cut = run();
431 EXPECT_TRUE(cut.completedExploration);
432 EXPECT_EQ(cut.statistics.discoveredBeliefs, 1ul);
433 EXPECT_EQ(cut.statistics.exploredBeliefs, 0ul);
434 EXPECT_LE(storm::utility::abs(cut.value - expected), this->template modelcheckingPrecision<BeliefMDPValueType>());
435
436 options.cutZeroGap = false;
437 auto const uncut = run();
438 EXPECT_TRUE(uncut.completedExploration);
439 EXPECT_GT(uncut.statistics.discoveredBeliefs, 1ul);
440 EXPECT_GT(uncut.statistics.exploredBeliefs, 0ul);
441
442 // A positive gap below the floating-point solver precision must still be explored.
443 setInitialBounds(initialValue - delta, initialValue + delta);
444 options.cutZeroGap = true;
445 auto const positiveGap = run();
446 EXPECT_TRUE(positiveGap.completedExploration);
447 EXPECT_GT(positiveGap.statistics.discoveredBeliefs, 1ul);
448 EXPECT_GT(positiveGap.statistics.exploredBeliefs, 0ul);
449 }
450 };
451
452 check("Pmax=? [F \"goal\" ]", "7/10");
453 check("Pmin=? [F \"goal\" ]", "3/10");
454 check("Rmax=? [F s>4 ]", "29/50");
455 check("Rmin=? [F s>4 ]", "19/50");
456}
457
458TYPED_TEST(BeliefBasedModelCheckerTest, policy_requires_matching_cutoff_schedulers) {
459 using POMDPValueType = typename TestFixture::POMDPValueType;
460 using BeliefValueType = typename TestFixture::BeliefValueType;
461 using BeliefMDPValueType = typename TestFixture::BeliefMDPValueType;
463
464 for (std::string const formula : {"Pmax=? [F \"goal\"]", "Pmin=? [F \"goal\"]"}) {
465 SCOPED_TRACE(formula);
466 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", formula, "slippery=0");
471 options.generatePolicy = true;
472 options.maxExplorationSize = 0;
473 options.clippingResolutions = std::vector<uint64_t>(data.model->getNrObservations(), 2);
474 STORM_SILENT_EXPECT_THROW(checker.checkUnfold(this->env(), *data.propertyInfo, options, bounds), storm::exceptions::IllegalArgumentException);
475
476 ASSERT_NO_THROW(bounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula));
477 bool const minimize = storm::solver::minimize(data.propertyInfo->dir);
478 auto& schedulers = minimize ? bounds.preprocessingBounds->upperSchedulers : bounds.preprocessingBounds->lowerSchedulers;
479 auto const originalSchedulers = schedulers;
480 ASSERT_FALSE(originalSchedulers.empty());
481 // Only the schedulers for the selected cut-off direction are required.
482 (minimize ? bounds.preprocessingBounds->lowerSchedulers : bounds.preprocessingBounds->upperSchedulers).clear();
483 for (bool const useClipping : {false, true}) {
484 SCOPED_TRACE(useClipping);
485 options.useClipping = useClipping;
486 for (auto const schedulerCount : {0ul, originalSchedulers.size() + 1}) {
487 SCOPED_TRACE(schedulerCount);
488 schedulers = originalSchedulers;
489 schedulers.resize(schedulerCount, originalSchedulers.front());
490 STORM_SILENT_EXPECT_THROW(checker.checkUnfold(this->env(), *data.propertyInfo, options, bounds), storm::exceptions::IllegalArgumentException);
491 }
492 }
493 options.useClipping = false;
494 schedulers = originalSchedulers;
495 auto const result = checker.checkUnfold(this->env(), *data.propertyInfo, options, bounds);
496 EXPECT_TRUE(result.policy.has_value());
497 // Numerical checking still accepts value bounds without continuation schedulers.
498 options.generatePolicy = false;
499 schedulers.clear();
500 EXPECT_NO_THROW(checker.checkUnfold(this->env(), *data.propertyInfo, options, bounds));
501 }
502}
503
504TYPED_TEST(BeliefBasedModelCheckerTest, generated_policy_preserves_truncated_frontier_bound) {
505 using POMDPValueType = typename TestFixture::POMDPValueType;
506 using BeliefValueType = typename TestFixture::BeliefValueType;
507 using BeliefMDPValueType = typename TestFixture::BeliefMDPValueType;
509
510 for (std::string const formula : {"Pmax=? [F \"goal\"]", "Pmin=? [F \"goal\"]"}) {
511 SCOPED_TRACE(formula);
512 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", formula, "slippery=0");
516 bounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
517
519 options.generatePolicy = true;
520 options.buildChoiceLabeling = false;
522 // Explore the initial belief and its successor, leaving the mixed belief over s=3 and s=4 as the frontier.
523 // Its continuation must choose between alpha and beta, whose probabilities of reaching the goal differ.
524 options.maxExplorationSize = 2;
525 auto const result = checker.checkUnfold(this->env(), *data.propertyInfo, options, bounds);
526 ASSERT_FALSE(result.completedExploration);
527 ASSERT_EQ(result.statistics.exploredBeliefs, 2ul);
528 ASSERT_GT(result.statistics.discoveredBeliefs, result.statistics.exploredBeliefs);
529 ASSERT_TRUE(result.policy.has_value());
530 ASSERT_TRUE(storm::utility::isFinite(result.value));
531 EXPECT_GT(result.value, storm::utility::zero<BeliefMDPValueType>());
532 EXPECT_LT(result.value, storm::utility::one<BeliefMDPValueType>());
533
534 // Apply the exported controller without filling in unspecified actions: the cut-off policy must provide its continuation.
535 auto const inducedDtmc = storm::pomdp::policy::applyObservationBasedFSCToPomdp(*data.model, *result.policy);
537 auto const dtmcResult = dtmcChecker.check(this->env(), *data.formula);
538 ASSERT_TRUE(dtmcResult);
539 ASSERT_TRUE(dtmcResult->isExplicitQuantitativeCheckResult());
540 auto const initialState = inducedDtmc.getInitialStates().getNextSetIndex(0);
541 auto const policyValue = dtmcResult->template asExplicitQuantitativeCheckResult<POMDPValueType>()[initialState];
543 POMDPValueType const tolerance = 2 * this->template modelcheckingPrecision<POMDPValueType>();
544 if (storm::solver::maximize(data.propertyInfo->dir)) {
545 EXPECT_GE(policyValue + tolerance, bound);
546 } else {
547 EXPECT_LE(policyValue, bound + tolerance);
548 }
549 // Without clipping, the exported continuation should realize the belief-MDP value up to numerical solver error.
550 EXPECT_LE(storm::utility::abs(policyValue - bound), tolerance);
551 }
552}
553
554TYPED_TEST(BeliefBasedModelCheckerTest, terminal_initial_policy) {
555 using POMDPValueType = typename TestFixture::POMDPValueType;
556 using BeliefValueType = typename TestFixture::BeliefValueType;
557 using BeliefMDPValueType = typename TestFixture::BeliefMDPValueType;
559
560 for (std::string const formula : {"Pmax=? [F s=0]", "Rmin=? [F s=0]"}) {
561 SCOPED_TRACE(formula);
562 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", formula, "slippery=0");
566 bounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
568 bounds.extremeBounds = preprocessChecker.getExtremeValueBound(this->env(), *data.formula);
569 }
570
572 options.generatePolicy = true;
573 options.buildChoiceLabeling = false;
574 options.clippingResolutions = std::vector<uint64_t>(data.model->getNrObservations(), 2);
575 for (bool const useClipping : {false, true}) {
576 SCOPED_TRACE(useClipping);
577 options.useClipping = useClipping;
578 auto const result = checker.checkUnfold(this->env(), *data.propertyInfo, options, bounds);
579 EXPECT_EQ(result.value, this->template parseNumber<BeliefMDPValueType>(formula.front() == 'P' ? "1" : "0"));
580 EXPECT_TRUE(result.completedExploration);
581 EXPECT_EQ(result.statistics.exploredBeliefs, 0ul);
582 ASSERT_TRUE(result.policy.has_value());
583 auto const initialObservation = data.model->getObservation(data.model->getInitialStates().getNextSetIndex(0));
584 EXPECT_TRUE(result.policy->hasOutputForObservationInNode(result.policy->getInitialNodeId(), initialObservation));
585 std::stringstream policyJson;
586 EXPECT_NO_THROW(result.policy->writeJsonToStream(policyJson));
587 EXPECT_FALSE(policyJson.str().empty());
588 }
589 }
590}
591
592TYPED_TEST(BeliefBasedModelCheckerTest, simple_Pmax) {
594 typedef typename TestFixture::POMDPValueType POMDPValueType;
595 typedef typename TestFixture::BeliefValueType BeliefValueType;
596 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
597
598 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Pmax=? [F \"goal\" ]", "slippery=0");
601
603 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
604
606 options.buildChoiceLabeling = false;
608
609 typename TestFixture::ExtendedBeliefMDPValueType overResultValue;
610 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
611
612 auto expected = this->template parseNumber<BeliefMDPValueType>("7/10");
613 auto overCheckResult = checker.checkDiscretize(this->env(), *data.propertyInfo, options, this->overApproxResolution(), true, precomputedBeliefBounds);
614 overResultValue = overCheckResult.value;
615 EXPECT_GT(overCheckResult.statistics.discoveredBeliefs, 0ul);
616 EXPECT_GT(overCheckResult.statistics.exploredBeliefs, 0ul);
617 EXPECT_GT(overCheckResult.statistics.beliefMdpStates, 0ul);
618 EXPECT_GT(overCheckResult.statistics.beliefMdpChoices, 0ul);
619 EXPECT_GT(overCheckResult.statistics.beliefMdpTransitions, 0ul);
620 EXPECT_GE(overResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
621
622 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
623 underResultValue = underCheckResult.value;
624 EXPECT_LE(underResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
625 EXPECT_LE(storm::utility::abs(overResultValue - underResultValue), this->precision())
626 << "Result [" << underResultValue << ", " << overResultValue
627 << "] is not precise enough. If (only) this fails, the result bounds are still correct, but they might be unexpectedly imprecise.\n";
628}
629
630TYPED_TEST(BeliefBasedModelCheckerTest, simple_Pmin) {
632 typedef typename TestFixture::POMDPValueType POMDPValueType;
633 typedef typename TestFixture::BeliefValueType BeliefValueType;
634 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
635
636 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Pmin=? [F \"goal\" ]", "slippery=0");
637 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
639
641 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
642
644 options.buildChoiceLabeling = false;
646
647 typename TestFixture::ExtendedBeliefMDPValueType overResultValue;
648 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
649
650 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("3/10");
651 auto overCheckResult = checker.checkDiscretize(this->env(), *data.propertyInfo, options, this->overApproxResolution(), true, precomputedBeliefBounds);
652 overResultValue = overCheckResult.value;
653 EXPECT_LE(overResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
654
655 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
656 underResultValue = underCheckResult.value;
657 EXPECT_GE(underResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
658 EXPECT_LE(storm::utility::abs(overResultValue - underResultValue), this->precision())
659 << "Result [" << overResultValue << ", " << underResultValue
660 << "] is not precise enough. If (only) this fails, the result bounds are still correct, but they might be unexpectedly imprecise.\n";
661}
662
663TYPED_TEST(BeliefBasedModelCheckerTest, discretization_rejects_exploration_limits) {
664 using POMDPValueType = typename TestFixture::POMDPValueType;
665 using BeliefValueType = typename TestFixture::BeliefValueType;
666 using BeliefMDPValueType = typename TestFixture::BeliefMDPValueType;
668
669 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Pmin=? [F \"goal\" ]", "slippery=0");
672 bounds.preprocessingBounds.emplace();
673 bounds.preprocessingBounds->lower.emplace_back(data.model->getNumberOfStates(), storm::utility::zero<POMDPValueType>());
674 bounds.preprocessingBounds->upper.emplace_back(data.model->getNumberOfStates(), storm::utility::one<POMDPValueType>());
675
677 options.maxExplorationSize = 1;
679
680 STORM_SILENT_EXPECT_THROW(checker.checkDiscretize(this->env(), *data.propertyInfo, options, 10, false, bounds), storm::exceptions::NotSupportedException);
681
682 auto const unfolded = checker.checkUnfold(this->env(), *data.propertyInfo, options, bounds);
683 EXPECT_FALSE(unfolded.completedExploration);
684
685 options.maxExplorationSize.reset();
686 auto const discretized = checker.checkDiscretize(this->env(), *data.propertyInfo, options, 10, false, bounds);
687 EXPECT_TRUE(discretized.completedExploration);
688 EXPECT_GT(discretized.statistics.exploredBeliefs, 1);
689}
690
691TYPED_TEST(BeliefBasedModelCheckerTest, simple_slippery_Pmax) {
693 typedef typename TestFixture::POMDPValueType POMDPValueType;
694 typedef typename TestFixture::BeliefValueType BeliefValueType;
695 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
696
697 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Pmax=? [F \"goal\" ]", "slippery=0.4");
698 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
700
702 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
703
705 options.buildChoiceLabeling = false;
707 typename TestFixture::ExtendedBeliefMDPValueType overResultValue;
708 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
709
710 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("7/10");
711 auto overCheckResult = checker.checkDiscretize(this->env(), *data.propertyInfo, options, this->overApproxResolution(), true, precomputedBeliefBounds);
712 overResultValue = overCheckResult.value;
713 EXPECT_GE(overResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
714 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
715
716 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
717 underResultValue = underCheckResult.value;
718 EXPECT_LE(underResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
719 EXPECT_LE(storm::utility::abs(overResultValue - underResultValue), this->precision())
720 << "Result [" << underResultValue << ", " << overResultValue
721 << "] is not precise enough. If (only) this fails, the result bounds are still correct, but they might be unexpectedly imprecise.\n";
722}
723
724TYPED_TEST(BeliefBasedModelCheckerTest, simple_slippery_Pmin) {
726 typedef typename TestFixture::POMDPValueType POMDPValueType;
727 typedef typename TestFixture::BeliefValueType BeliefValueType;
728 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
729
730 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Pmin=? [F \"goal\" ]", "slippery=0.4");
731 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
733
735 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
737 options.buildChoiceLabeling = false;
739 typename TestFixture::ExtendedBeliefMDPValueType overResultValue;
740 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
741
742 POMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("3/10");
743 auto overCheckResult = checker.checkDiscretize(this->env(), *data.propertyInfo, options, this->overApproxResolution(), true, precomputedBeliefBounds);
744 overResultValue = overCheckResult.value;
745
746 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
747 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
748 underResultValue = underCheckResult.value;
749 if (this->isExact()) {
750 // This model's value can only be approximated arbitrarily close but never reached
751 // Exact arithmetics will thus not reach the value with absoulute precision either.
752 POMDPValueType approxPrecision = storm::utility::convertNumber<POMDPValueType>(1e-5);
753 EXPECT_GE(underResultValue, expected - approxPrecision);
754 EXPECT_LE(overResultValue, expected + approxPrecision);
755 } else {
756 EXPECT_GE(underResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
757 EXPECT_LE(overResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
758 }
759 EXPECT_LE(storm::utility::abs(overResultValue - underResultValue), this->precision())
760 << "Result [" << underResultValue << ", " << overResultValue
761 << "] is not precise enough. If (only) this fails, the result bounds are still correct, but they might be unexpectedly imprecise.\n";
762}
763
764TYPED_TEST(BeliefBasedModelCheckerTest, simple_Rmax) {
766 typedef typename TestFixture::POMDPValueType POMDPValueType;
767 typedef typename TestFixture::BeliefValueType BeliefValueType;
768 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
769
770 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Rmax=? [F s>4 ]", "slippery=0");
771 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
773
775 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
777 options.buildChoiceLabeling = false;
779
780 typename TestFixture::ExtendedBeliefMDPValueType overResultValue;
781 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
782
783 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("29/50");
784 auto overCheckResult = checker.checkDiscretize(this->env(), *data.propertyInfo, options, this->overApproxResolution(), true, precomputedBeliefBounds);
785 overResultValue = overCheckResult.value;
786 EXPECT_GE(overResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
787
788 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
789 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
790 underResultValue = underCheckResult.value;
791 EXPECT_LE(underResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
792 EXPECT_LE(storm::utility::abs(overResultValue - underResultValue), this->precision())
793 << "Result [" << underResultValue << ", " << overResultValue
794 << "] is not precise enough. If (only) this fails, the result bounds are still correct, but they might be unexpectedly imprecise.\n";
795}
796
797TYPED_TEST(BeliefBasedModelCheckerTest, simple_Rmin) {
799 typedef typename TestFixture::POMDPValueType POMDPValueType;
800 typedef typename TestFixture::BeliefValueType BeliefValueType;
801 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
802
803 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Rmin=? [F s>4 ]", "slippery=0");
804 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
806
808 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
810 options.buildChoiceLabeling = false;
812
813 typename TestFixture::ExtendedBeliefMDPValueType overResultValue;
814 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
815
816 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("19/50");
817 auto overCheckResult = checker.checkDiscretize(this->env(), *data.propertyInfo, options, this->overApproxResolution(), true, precomputedBeliefBounds);
818 overResultValue = overCheckResult.value;
819 EXPECT_LE(overResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
820
821 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
822 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
823 underResultValue = underCheckResult.value;
824 EXPECT_GE(underResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
825 EXPECT_LE(storm::utility::abs(overResultValue - underResultValue), this->precision())
826 << "Result [" << overResultValue << ", " << underResultValue
827 << "] is not precise enough. If (only) this fails, the result bounds are still correct, but they might be unexpectedly imprecise.\n";
828}
829
830TYPED_TEST(BeliefBasedModelCheckerTest, simple_slippery_Rmax) {
832 typedef typename TestFixture::POMDPValueType POMDPValueType;
833 typedef typename TestFixture::BeliefValueType BeliefValueType;
834 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
835
836 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Rmax=? [F s>4 ]", "slippery=0.4");
837 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
840 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
842 options.buildChoiceLabeling = false;
844
845 typename TestFixture::ExtendedBeliefMDPValueType overResultValue;
846 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
847
848 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("29/30");
849 auto overCheckResult = checker.checkDiscretize(this->env(), *data.propertyInfo, options, this->overApproxResolution(), true, precomputedBeliefBounds);
850 overResultValue = overCheckResult.value;
851 EXPECT_GE(overResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
852
853 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
854 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
855 underResultValue = underCheckResult.value;
856 EXPECT_LE(underResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
857 EXPECT_LE(storm::utility::abs(overResultValue - underResultValue), this->precision())
858 << "Result [" << underResultValue << ", " << overResultValue
859 << "] is not precise enough. If (only) this fails, the result bounds are still correct, but they might be unexpectedly imprecise.\n";
860}
861
862TYPED_TEST(BeliefBasedModelCheckerTest, simple_slippery_Rmin) {
864 typedef typename TestFixture::POMDPValueType POMDPValueType;
865 typedef typename TestFixture::BeliefValueType BeliefValueType;
866 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
867
868 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Rmin=? [F s>4 ]", "slippery=0.4");
869 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
871
873 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
875 options.buildChoiceLabeling = false;
877
878 typename TestFixture::ExtendedBeliefMDPValueType overResultValue;
879 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
880
881 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("19/30");
882 auto overCheckResult = checker.checkDiscretize(this->env(), *data.propertyInfo, options, this->overApproxResolution(), true, precomputedBeliefBounds);
883 overResultValue = overCheckResult.value;
884 EXPECT_LE(overResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
885
886 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
887 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
888 underResultValue = underCheckResult.value;
889 EXPECT_GE(underResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
890 EXPECT_LE(storm::utility::abs(overResultValue - underResultValue), this->precision())
891 << "Result [" << overResultValue << ", " << underResultValue
892 << "] is not precise enough. If (only) this fails, the result bounds are still correct, but they might be unexpectedly imprecise.\n";
893}
894
895TYPED_TEST(BeliefBasedModelCheckerTest, maze2_Rmin) {
897 typedef typename TestFixture::POMDPValueType POMDPValueType;
898 typedef typename TestFixture::BeliefValueType BeliefValueType;
899 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
900
901 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/maze2.prism", "Rmin=? [F \"goal\"]", "sl=0");
902 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
904
906 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
908 options.buildChoiceLabeling = false;
910
911 typename TestFixture::ExtendedBeliefMDPValueType overResultValue;
912 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
913
914 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("74/91");
915 auto overCheckResult = checker.checkDiscretize(this->env(), *data.propertyInfo, options, this->overApproxResolution(), true, precomputedBeliefBounds);
916 overResultValue = overCheckResult.value;
917 EXPECT_LE(overResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
918
919 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
920 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
921 underResultValue = underCheckResult.value;
922 EXPECT_GE(underResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
923 EXPECT_LE(storm::utility::abs(overResultValue - underResultValue), this->precision())
924 << "Result [" << overResultValue << ", " << underResultValue
925 << "] is not precise enough. If (only) this fails, the result bounds are still correct, but they might be unexpectedly imprecise.\n";
926}
927
928TYPED_TEST(BeliefBasedModelCheckerTest, maze2_Rmax) {
930 typedef typename TestFixture::POMDPValueType POMDPValueType;
931 typedef typename TestFixture::BeliefValueType BeliefValueType;
932 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
933
934 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/maze2.prism", "Rmax=? [F \"goal\"]", "sl=0");
935 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
937
939 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
941 options.buildChoiceLabeling = false;
943
944 typename TestFixture::ExtendedBeliefMDPValueType overResultValue;
945 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
946
947 auto overCheckResult = checker.checkDiscretize(this->env(), *data.propertyInfo, options, this->overApproxResolution(), true, precomputedBeliefBounds);
948 overResultValue = overCheckResult.value;
949 EXPECT_EQ(storm::utility::positiveInfinity<BeliefMDPValueType>(), overResultValue);
950
951 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
952 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
953 underResultValue = underCheckResult.value;
954 EXPECT_EQ(storm::utility::positiveInfinity<BeliefMDPValueType>(), underResultValue);
955}
956
957TYPED_TEST(BeliefBasedModelCheckerTest, maze2_slippery_Rmin) {
959 typedef typename TestFixture::POMDPValueType POMDPValueType;
960 typedef typename TestFixture::BeliefValueType BeliefValueType;
961 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
962
963 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/maze2.prism", "Rmin=? [F \"goal\"]", "sl=0.075");
964 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
966
968 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
970 options.buildChoiceLabeling = false;
972
973 typename TestFixture::ExtendedBeliefMDPValueType overResultValue;
974 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
975
976 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("80/91");
977 auto overCheckResult = checker.checkDiscretize(this->env(), *data.propertyInfo, options, this->overApproxResolution(), true, precomputedBeliefBounds);
978 overResultValue = overCheckResult.value;
979 EXPECT_LE(overResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
980
981 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
982 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
983 underResultValue = underCheckResult.value;
984 EXPECT_GE(underResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
985 EXPECT_LE(storm::utility::abs(overResultValue - underResultValue), this->precision())
986 << "Result [" << overResultValue << ", " << underResultValue
987 << "] is not precise enough. If (only) this fails, the result bounds are still correct, but they might be unexpectedly imprecise.\n";
988}
989
990TYPED_TEST(BeliefBasedModelCheckerTest, maze2_slippery_Rmax) {
992 typedef typename TestFixture::POMDPValueType POMDPValueType;
993 typedef typename TestFixture::BeliefValueType BeliefValueType;
994 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
995
996 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/maze2.prism", "Rmax=? [F \"goal\"]", "sl=0.075");
997 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
999
1001 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
1003 options.buildChoiceLabeling = false;
1005
1006 typename TestFixture::ExtendedBeliefMDPValueType overResultValue;
1007 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
1008
1009 auto overCheckResult = checker.checkDiscretize(this->env(), *data.propertyInfo, options, this->overApproxResolution(), true, precomputedBeliefBounds);
1010 overResultValue = overCheckResult.value;
1011 EXPECT_EQ(storm::utility::positiveInfinity<BeliefMDPValueType>(), overResultValue);
1012
1013 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
1014 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
1015 underResultValue = underCheckResult.value;
1016 EXPECT_EQ(storm::utility::positiveInfinity<BeliefMDPValueType>(), underResultValue);
1017}
1018
1019TYPED_TEST(BeliefBasedModelCheckerTest, refuel_Pmax) {
1021 typedef typename TestFixture::POMDPValueType POMDPValueType;
1022 typedef typename TestFixture::BeliefValueType BeliefValueType;
1023 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1024
1025 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/refuel.prism", "Pmax=?[\"notbad\" U \"goal\"]", "N=4");
1026 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
1028
1030 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
1032 options.buildChoiceLabeling = false;
1034
1035 typename TestFixture::ExtendedBeliefMDPValueType overResultValue;
1036 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
1037
1038 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("38/155");
1039 auto overCheckResult = checker.checkDiscretize(this->env(), *data.propertyInfo, options, this->overApproxResolution(), true, precomputedBeliefBounds);
1040 overResultValue = overCheckResult.value;
1041 EXPECT_GE(overResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
1042
1043 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
1044 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
1045 underResultValue = underCheckResult.value;
1046 EXPECT_LE(underResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
1047 EXPECT_LE(storm::utility::abs(overResultValue - underResultValue), this->precision())
1048 << "Result [" << underResultValue << ", " << overResultValue
1049 << "] is not precise enough. If (only) this fails, the result bounds are still correct, but they might be unexpectedly imprecise.\n";
1050}
1051
1052TYPED_TEST(BeliefBasedModelCheckerTest, refuel_Pmin) {
1054 typedef typename TestFixture::POMDPValueType POMDPValueType;
1055 typedef typename TestFixture::BeliefValueType BeliefValueType;
1056 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1057
1058 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/refuel.prism", "Pmin=?[\"notbad\" U \"goal\"]", "N=4");
1059 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
1061
1063 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
1065 options.buildChoiceLabeling = false;
1067
1068 typename TestFixture::ExtendedBeliefMDPValueType overResultValue;
1069 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
1070
1071 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("0");
1072 auto overCheckResult = checker.checkDiscretize(this->env(), *data.propertyInfo, options, this->overApproxResolution(), true, precomputedBeliefBounds);
1073 overResultValue = overCheckResult.value;
1074 EXPECT_LE(overResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
1075
1076 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
1077 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
1078 underResultValue = underCheckResult.value;
1079 EXPECT_GE(underResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
1080 EXPECT_LE(storm::utility::abs(overResultValue - underResultValue), this->precision())
1081 << "Result [" << overResultValue << ", " << underResultValue
1082 << "] is not precise enough. If (only) this fails, the result bounds are still correct, but they might be unexpectedly imprecise.\n";
1083}
1084
1085TYPED_TEST(BeliefBasedModelCheckerTest, reward_bounded_simple_min_max) {
1087 typedef typename TestFixture::POMDPValueType POMDPValueType;
1088 typedef typename TestFixture::BeliefValueType BeliefValueType;
1089 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1090
1091 auto check = [this](std::string const& formula, std::string const& expectedValue) {
1092 SCOPED_TRACE(formula);
1093 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple_unit_rewards.prism", formula, "slippery=0");
1096 precomputedBeliefBounds.preprocessingBounds.emplace();
1097 precomputedBeliefBounds.preprocessingBounds->lower.emplace_back(data.model->getNumberOfStates(), storm::utility::zero<POMDPValueType>());
1098 precomputedBeliefBounds.preprocessingBounds->upper.emplace_back(data.model->getNumberOfStates(), storm::utility::one<POMDPValueType>());
1099
1101 options.buildChoiceLabeling = false;
1103 std::vector<std::string> rewardModelNames;
1104 for (auto const& rewardBound : data.propertyInfo->rewardBounds) {
1105 rewardModelNames.push_back(rewardBound.rewardModelName);
1106 }
1107 auto const expected = this->template parseNumber<BeliefMDPValueType>(expectedValue);
1108 for (bool const discretize : {false, true}) {
1109 SCOPED_TRACE(discretize ? "discretize" : "unfold");
1110 // Resolution 10 represents the model's (0.7, 0.3) beliefs exactly.
1111 auto const result =
1112 discretize ? checker.checkRewardAwareDiscretize(this->env(), *data.propertyInfo, options, 10, false, precomputedBeliefBounds, rewardModelNames)
1113 : checker.checkRewardAwareUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds, rewardModelNames);
1114 EXPECT_TRUE(result.completedExploration);
1115 EXPECT_LE(storm::utility::abs(result.value - expected), this->template modelcheckingPrecision<BeliefMDPValueType>());
1116 }
1117 };
1118
1119 // The goal is first reachable after three unit rewards; the scheduler chooses between success probabilities 0.3 and 0.7.
1120 check("Pmax=? [ true Urew{\"rew\"}<=3 \"goal\" ]", "7/10");
1121 check("Pmin=? [ true Urew{\"rew\"}<=3 \"goal\" ]", "3/10");
1122 check("Pmax=? [ true Urew{\"rew\"}<=2 \"goal\" ]", "0");
1123 check("Pmin=? [ true Urew{\"rew\"}<=2 \"goal\" ]", "0");
1124 // Target beliefs must remain explorable: their rewarded self-loop can satisfy a lower bound after the first visit.
1125 check("Pmax=? [ true Urew{\"rew\"}>=4 \"goal\" ]", "7/10");
1126 check("Pmin=? [ true Urew{\"rew\"}>=4 \"goal\" ]", "3/10");
1127}
1128
1129TYPED_TEST(BeliefBasedModelCheckerTest, reused_explorer_clears_reward_model) {
1132 using BeliefMDPValueType = typename TestFixture::BeliefMDPValueType;
1138
1139 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Rmax=? [F s>4 ]", "slippery=0");
1140 Explorer explorer(*data.model);
1141 std::string const rewardModelName;
1142 auto const selectRewardModel = [&]() {
1143 auto info = explorer.template initializeExploration<StandardInfo>(data.model->getNrObservations());
1144 explorer.resumeExploration(info, {}, {}, rewardModelName, storm::OptionalRef<NoAbstraction>{});
1145 EXPECT_GT(info.matrix.rows(), 0ul);
1146 EXPECT_EQ(info.actionRewards.size(), info.matrix.rows());
1147 };
1148
1149 selectRewardModel();
1150 auto ordinary = explorer.template initializeExploration<StandardInfo>(data.model->getNrObservations());
1151 explorer.resumeExploration(ordinary, {}, {}, storm::NullRef, storm::OptionalRef<NoAbstraction>{});
1152 EXPECT_GT(ordinary.matrix.rows(), 0ul);
1153 EXPECT_TRUE(ordinary.actionRewards.empty());
1154
1155 selectRewardModel();
1156 auto clipping = explorer.template initializeExploration<ClippingInfo>(data.model->getNrObservations());
1157 explorer.resumeClippingExploration(clipping, {}, {}, storm::NullRef, storm::OptionalRef<NoAbstraction>{});
1158 EXPECT_GT(clipping.matrix.rows(), 0ul);
1159 EXPECT_TRUE(clipping.actionRewards.empty());
1160
1161 selectRewardModel();
1163 splitter.setRewardModel();
1164 auto rewardAware = explorer.template initializeExploration<RewardAwareInfo>(data.model->getNrObservations());
1165 explorer.resumeRewardAwareExploration(rewardAware, {}, {}, splitter, storm::OptionalRef<NoAbstraction>{});
1166 EXPECT_GT(rewardAware.matrix.rows(), 0ul);
1167 EXPECT_TRUE(rewardAware.actionRewards.empty());
1168 ASSERT_FALSE(rewardAware.matrix.transitions.empty());
1169 for (auto const& transition : rewardAware.matrix.transitions) {
1170 EXPECT_EQ(transition.data.size(), 1ul);
1171 }
1172}
1173
1174TYPED_TEST(BeliefBasedModelCheckerTest, reward_aware_resume_preserves_observation_indices) {
1177 using BeliefMDPValueType = typename TestFixture::BeliefMDPValueType;
1182
1183 // Different state/action rewards ensure that new reward vectors are encountered after resuming.
1184 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Rmax=? [F s>4 ]", "slippery=0");
1185 Explorer explorer(*data.model);
1186 Splitter uninterruptedSplitter(*data.model);
1187 uninterruptedSplitter.setRewardModel();
1188 auto uninterrupted = explorer.template initializeExploration<Info>(data.model->getNrObservations(), storm::pomdp::beliefs::ExplorationQueueOrder::FIFO);
1189 explorer.resumeRewardAwareExploration(uninterrupted, {}, {}, uninterruptedSplitter, storm::OptionalRef<NoAbstraction>{});
1190
1191 Splitter resumedSplitter(*data.model);
1192 resumedSplitter.setRewardModel();
1193 auto resumed = explorer.template initializeExploration<Info>(data.model->getNrObservations(), storm::pomdp::beliefs::ExplorationQueueOrder::FIFO);
1194 for (uint64_t steps = 0; resumed.queue.hasNext() && steps < 100; ++steps) {
1195 auto const limit = resumed.exploredBeliefs.size() + 1;
1196 explorer.resumeRewardAwareExploration(
1197 resumed, {}, [&]() { return resumed.exploredBeliefs.size() >= limit; }, resumedSplitter, storm::OptionalRef<NoAbstraction>{});
1198 }
1199 ASSERT_FALSE(resumed.queue.hasNext());
1200 ASSERT_EQ(resumed.discoveredBeliefs.getNumberOfBeliefIds(), uninterrupted.discoveredBeliefs.getNumberOfBeliefIds());
1201 for (uint64_t id = 0; id < uninterrupted.discoveredBeliefs.getNumberOfBeliefIds(); ++id) {
1202 EXPECT_TRUE(resumed.discoveredBeliefs.containsBelief(uninterrupted.discoveredBeliefs.getBeliefFromId(id)));
1203 }
1204 ASSERT_EQ(resumed.matrix.transitions.size(), uninterrupted.matrix.transitions.size());
1205 for (uint64_t i = 0; i < uninterrupted.matrix.transitions.size(); ++i) {
1206 auto const& expected = uninterrupted.matrix.transitions[i];
1207 auto const& actual = resumed.matrix.transitions[i];
1208 EXPECT_EQ(actual.probability, expected.probability);
1209 EXPECT_EQ(actual.data, expected.data);
1210 EXPECT_EQ(resumed.discoveredBeliefs.getBeliefFromId(actual.targetBelief), uninterrupted.discoveredBeliefs.getBeliefFromId(expected.targetBelief));
1211 }
1212}
1213
1214TYPED_TEST(BeliefBasedModelCheckerTest, reward_bounded_requires_explicit_reward_model_name) {
1215 auto const programFile = STORM_TEST_RESOURCES_DIR "/pomdp/simple_unit_rewards.prism";
1216 auto data = this->buildPrism(programFile, "Pmax=? [ true Urew{\"rew\"}<=3 \"goal\" ]", "slippery=0");
1217 auto program = storm::api::parseProgram(programFile).preprocess("slippery=0");
1218 auto unnamedFormula = storm::api::parsePropertiesForPrismProgram("Pmax=? [ true Urew<=3 \"goal\" ]", program).front().getRawFormula();
1219
1220 STORM_SILENT_EXPECT_THROW(storm::pomdp::analysis::getFormulaInformation(*data.model, *unnamedFormula), storm::exceptions::NotSupportedException);
1221
1222 auto unnamedProperty = *data.propertyInfo;
1223 unnamedProperty.rewardBounds.front().rewardModelName.clear();
1225 typename TestFixture::BeliefMDPValueType>
1226 checker(*data.model);
1229 STORM_SILENT_EXPECT_THROW(checker.checkRewardAwareUnfold(this->env(), unnamedProperty, options, bounds, {"rew"}), storm::exceptions::NotSupportedException);
1230}
1231
1232TYPED_TEST(BeliefBasedModelCheckerTest, reward_bounded_requires_matching_reward_model_selection) {
1235 using BeliefMDPValueType = typename TestFixture::BeliefMDPValueType;
1236 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple_unit_rewards.prism", "Pmax=? [ true Urew{\"rew\"}<=3 \"goal\" ]", "slippery=0");
1240
1241 STORM_SILENT_EXPECT_THROW(checker.checkRewardAwareUnfold(this->env(), *data.propertyInfo, options, bounds, {}),
1242 storm::exceptions::IllegalArgumentException);
1243 STORM_SILENT_EXPECT_THROW(checker.checkRewardAwareDiscretize(this->env(), *data.propertyInfo, options, 10, false, bounds, {}),
1244 storm::exceptions::IllegalArgumentException);
1245 STORM_SILENT_EXPECT_THROW(checker.checkRewardAwareUnfold(this->env(), *data.propertyInfo, options, bounds, {"other"}),
1246 storm::exceptions::IllegalArgumentException);
1247 STORM_SILENT_EXPECT_THROW(checker.checkRewardAwareDiscretize(this->env(), *data.propertyInfo, options, 10, false, bounds, {"other", "rew"}),
1248 storm::exceptions::IllegalArgumentException);
1249
1251 STORM_SILENT_EXPECT_THROW(splitter.setRewardModels({}), storm::exceptions::IllegalArgumentException);
1252}
1253
1254TYPED_TEST(BeliefBasedModelCheckerTest, reward_bounded_allows_additional_observed_reward_model) {
1255 using POMDPValueType = typename TestFixture::POMDPValueType;
1256 using BeliefMDPValueType = typename TestFixture::BeliefMDPValueType;
1258 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple_unit_rewards.prism", "Pmax=? [ true Urew{\"rew\"}<=3 \"goal\" ]", "slippery=0");
1259 auto extraRewardModel = data.model->getRewardModel("rew");
1260 data.model->addRewardModel("extra", extraRewardModel);
1261
1263 bounds.preprocessingBounds.emplace();
1264 bounds.preprocessingBounds->lower.emplace_back(data.model->getNumberOfStates(), storm::utility::zero<POMDPValueType>());
1265 bounds.preprocessingBounds->upper.emplace_back(data.model->getNumberOfStates(), storm::utility::one<POMDPValueType>());
1268
1269 auto const expected = this->template parseNumber<BeliefMDPValueType>("7/10");
1270 for (bool const discretize : {false, true}) {
1271 auto const result = discretize ? checker.checkRewardAwareDiscretize(this->env(), *data.propertyInfo, options, 10, false, bounds, {"rew", "extra"})
1272 : checker.checkRewardAwareUnfold(this->env(), *data.propertyInfo, options, bounds, {"rew", "extra"});
1273 EXPECT_TRUE(result.completedExploration);
1274 EXPECT_LE(storm::utility::abs(result.value - expected), this->template modelcheckingPrecision<BeliefMDPValueType>());
1275 }
1276}
1277
1278TYPED_TEST(BeliefBasedModelCheckerTest, reward_bounded_simple_early_frontier_uses_cutoff) {
1280 typedef typename TestFixture::POMDPValueType POMDPValueType;
1281 typedef typename TestFixture::BeliefValueType BeliefValueType;
1282 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1283
1284 auto check = [this](std::string const& formula, std::string const& frontierValue, std::string const& completeValue) {
1285 SCOPED_TRACE(formula);
1286 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple_unit_rewards.prism", formula, "slippery=0");
1289 precomputedBeliefBounds.preprocessingBounds.emplace();
1290 precomputedBeliefBounds.preprocessingBounds->lower.emplace_back(data.model->getNumberOfStates(), storm::utility::zero<POMDPValueType>());
1291 precomputedBeliefBounds.preprocessingBounds->upper.emplace_back(data.model->getNumberOfStates(), storm::utility::one<POMDPValueType>());
1292
1294 options.buildChoiceLabeling = false;
1296 options.maxExplorationSize = 1;
1297
1298 std::vector<std::string> rewardModelNames;
1299 for (auto const& rewardBound : data.propertyInfo->rewardBounds) {
1300 rewardModelNames.push_back(rewardBound.rewardModelName);
1301 }
1302 for (bool const discretize : {false, true}) {
1303 SCOPED_TRACE(discretize ? "discretize" : "unfold");
1304 if (discretize) {
1306 checker.checkRewardAwareDiscretize(this->env(), *data.propertyInfo, options, 10, false, precomputedBeliefBounds, rewardModelNames),
1307 storm::exceptions::NotSupportedException);
1308 options.maxExplorationSize.reset();
1309 }
1310 auto const result =
1311 discretize ? checker.checkRewardAwareDiscretize(this->env(), *data.propertyInfo, options, 10, false, precomputedBeliefBounds, rewardModelNames)
1312 : checker.checkRewardAwareUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds, rewardModelNames);
1313 EXPECT_EQ(result.completedExploration, discretize);
1314 if (discretize) {
1315 EXPECT_GT(result.statistics.exploredBeliefs, 1);
1316 } else {
1317 EXPECT_EQ(result.statistics.exploredBeliefs, 1);
1318 EXPECT_GT(result.statistics.discoveredBeliefs, result.statistics.exploredBeliefs);
1319 }
1320 auto const expected = this->template parseNumber<BeliefMDPValueType>(discretize ? completeValue : frontierValue);
1321 EXPECT_LE(storm::utility::abs(result.value - expected), this->template modelcheckingPrecision<BeliefMDPValueType>());
1322 }
1323 };
1324
1325 // With only the initial belief explored, minimization uses the upper cut-off and maximization the lower cut-off.
1326 check("Pmin=? [ true Urew{\"rew\"}<=3 \"goal\" ]", "1", "3/10");
1327 check("Pmax=? [ true Urew{\"rew\"}<=3 \"goal\" ]", "0", "7/10");
1328 // The first transition still costs one reward: even the upper cut-off must fail a zero reward budget.
1329 check("Pmin=? [ true Urew{\"rew\"}<=0 \"goal\" ]", "0", "0");
1330 check("Pmax=? [ true Urew{\"rew\"}<=0 \"goal\" ]", "0", "0");
1331}
1332
1333TYPED_TEST(BeliefBasedModelCheckerTest, reward_bounded_hidden_transition_costs) {
1334 using POMDPValueType = typename TestFixture::POMDPValueType;
1335 using BeliefValueType = typename TestFixture::BeliefValueType;
1336 using BeliefMDPValueType = typename TestFixture::BeliefMDPValueType;
1338
1339 auto check = [this](std::string const& formula, std::string const& expectedValue, bool stopAtTargetFrontier, std::string const& completedValue = "") {
1340 SCOPED_TRACE(formula);
1341 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/hidden_transition_rewards.prism", formula);
1344 bounds.preprocessingBounds.emplace();
1345 bounds.preprocessingBounds->lower.emplace_back(data.model->getNumberOfStates(), storm::utility::zero<POMDPValueType>());
1346 bounds.preprocessingBounds->upper.emplace_back(data.model->getNumberOfStates(), storm::utility::one<POMDPValueType>());
1347
1350 if (stopAtTargetFrontier) {
1351 // Explore the draw and finish actions, leaving the target beliefs on the frontier.
1352 options.maxExplorationSize = 2;
1353 }
1354
1355 for (bool const discretize : {false, true}) {
1356 SCOPED_TRACE(discretize ? "discretize" : "unfold");
1357 if (stopAtTargetFrontier && discretize) {
1358 STORM_SILENT_EXPECT_THROW(checker.checkRewardAwareDiscretize(this->env(), *data.propertyInfo, options, 2, false, bounds, {"cost"}),
1359 storm::exceptions::NotSupportedException);
1360 options.maxExplorationSize.reset();
1361 }
1362 auto const result = discretize ? checker.checkRewardAwareDiscretize(this->env(), *data.propertyInfo, options, 2, false, bounds, {"cost"})
1363 : checker.checkRewardAwareUnfold(this->env(), *data.propertyInfo, options, bounds, {"cost"});
1364 EXPECT_EQ(result.completedExploration, discretize || !stopAtTargetFrontier);
1365 if (stopAtTargetFrontier && !discretize) {
1366 EXPECT_EQ(result.statistics.exploredBeliefs, 2);
1367 EXPECT_GT(result.statistics.discoveredBeliefs, result.statistics.exploredBeliefs);
1368 }
1369 auto const expected = this->template parseNumber<BeliefMDPValueType>(discretize && !completedValue.empty() ? completedValue : expectedValue);
1370 EXPECT_LE(storm::utility::abs(result.value - expected), this->template modelcheckingPrecision<BeliefMDPValueType>())
1371 << "actual: " << result.value << ", expected: " << expected;
1372 }
1373 };
1374
1375 // The hidden states have the same observation, but finishing costs one or two rewards respectively.
1376 check("Pmin=? [ true Urew{\"cost\"}<=1 \"goal\" ]", "1/2", false);
1377 check("Pmax=? [ true Urew{\"cost\"}<=1 \"goal\" ]", "1/2", false);
1378 check("Pmin=? [ true Urew{\"cost\"}<=2 \"goal\" ]", "1", false);
1379 check("Pmax=? [ true Urew{\"cost\"}<=2 \"goal\" ]", "1", false);
1380 // A target reached at cost one may keep accumulating reward before satisfying a lower bound.
1381 check("Pmin=? [ true Urew{\"cost\"}>=2 \"goal\" ]", "1", false);
1382 check("Pmax=? [ true Urew{\"cost\"}>=2 \"goal\" ]", "1", false);
1383 // Target beliefs on the frontier still count as targets; the incoming edge cost decides which half succeeds.
1384 check("Pmin=? [ true Urew{\"cost\"}<=1 \"goal\" ]", "1/2", true);
1385 check("Pmax=? [ true Urew{\"cost\"}<=1 \"goal\" ]", "1/2", true);
1386 // The optimistic Pmin sink collects missing reward; Pmax only counts reward already accumulated at the frontier.
1387 check("Pmin=? [ true Urew{\"cost\"}>=2 \"goal\" ]", "1", true);
1388 check("Pmax=? [ true Urew{\"cost\"}>=2 \"goal\" ]", "1/2", true, "1");
1389}
1390
1391TYPED_TEST(BeliefBasedModelCheckerTest, reward_bounded_min_lower_bound_frontier_collects_reward) {
1392 using POMDPValueType = typename TestFixture::POMDPValueType;
1393 using BeliefMDPValueType = typename TestFixture::BeliefMDPValueType;
1395
1396 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/hidden_transition_rewards.prism", "Pmin=? [ true Urew{\"cost\"}>=2 \"goal\" ]");
1397 auto extraRewardModel = data.model->getRewardModel("cost");
1398 data.model->addRewardModel("extra", extraRewardModel);
1401 bounds.preprocessingBounds.emplace();
1402 bounds.preprocessingBounds->lower.emplace_back(data.model->getNumberOfStates(), storm::utility::zero<POMDPValueType>());
1403 bounds.preprocessingBounds->upper.emplace_back(data.model->getNumberOfStates(), storm::utility::one<POMDPValueType>());
1404
1405 std::vector<storm::pomdp::beliefs::PropertyInformation> properties{*data.propertyInfo};
1406 auto strictProperty = *data.propertyInfo;
1407 strictProperty.rewardBounds.front().lowerBound = storm::logic::TimeBound(true, data.propertyInfo->rewardBounds.front().lowerBound->getBound());
1408 properties.push_back(strictProperty);
1409 auto zeroBoundData = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/hidden_transition_rewards.prism", "Pmin=? [ true Urew{\"cost\"}>=0 \"goal\" ]");
1410 properties.push_back(*zeroBoundData.propertyInfo);
1411 auto multidimensionalProperty = *data.propertyInfo;
1412 auto extraLowerBound = strictProperty.rewardBounds.front();
1413 extraLowerBound.rewardModelName = "extra";
1414 multidimensionalProperty.rewardBounds.push_back(extraLowerBound);
1415 properties.push_back(multidimensionalProperty);
1416
1419 for (uint64_t const sizeLimit : {1, 2}) {
1420 SCOPED_TRACE(sizeLimit);
1421 // Size one leaves non-target beliefs; size two leaves target beliefs whose cost-one branch still needs reward.
1422 options.maxExplorationSize = sizeLimit;
1423 for (std::size_t i = 0; i < properties.size(); ++i) {
1424 SCOPED_TRACE(i);
1425 std::vector<std::string> rewardModelNames;
1426 for (auto const& rewardBound : properties[i].rewardBounds) {
1427 rewardModelNames.push_back(rewardBound.rewardModelName);
1428 }
1429 auto const result = checker.checkRewardAwareUnfold(this->env(), properties[i], options, bounds, rewardModelNames);
1430 EXPECT_FALSE(result.completedExploration);
1431 EXPECT_EQ(result.statistics.exploredBeliefs, sizeLimit);
1433 this->template modelcheckingPrecision<BeliefMDPValueType>());
1434 }
1435 }
1436
1437 // The first dimension has only an upper bound and must earn no reward in the synthetic sink.
1438 auto upperBoundData = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/hidden_transition_rewards.prism", "Pmin=? [ true Urew{\"cost\"}<=1 \"goal\" ]");
1439 auto upperOnlyBound = upperBoundData.propertyInfo->rewardBounds.front();
1440 upperOnlyBound.rewardModelName = "extra";
1441 auto mixedProperty = strictProperty;
1442 mixedProperty.rewardBounds.insert(mixedProperty.rewardBounds.begin(), upperOnlyBound);
1443 options.maxExplorationSize = 2;
1444 auto const mixedResult = checker.checkRewardAwareUnfold(this->env(), mixedProperty, options, bounds, {"extra", "cost"});
1445 EXPECT_FALSE(mixedResult.completedExploration);
1446 auto const mixedExpected = this->template parseNumber<BeliefMDPValueType>("1/2");
1447 EXPECT_LE(storm::utility::abs(mixedResult.value - mixedExpected), this->template modelcheckingPrecision<BeliefMDPValueType>());
1448
1449 // Limits that leave no frontier must still allow the exact value, rather than rejecting the options themselves.
1450 for (auto const criterion :
1452 SCOPED_TRACE(criterion);
1453 options.maxExplorationSize.reset();
1454 options.maxExplorationTime.reset();
1456 options.maxExplorationSize = 1000;
1457 }
1459 options.maxExplorationTime = 3600;
1460 }
1461 auto const result = checker.checkRewardAwareUnfold(this->env(), *data.propertyInfo, options, bounds, {"cost"});
1462 EXPECT_TRUE(result.completedExploration);
1463 EXPECT_LE(storm::utility::abs(result.value - storm::utility::one<BeliefMDPValueType>()), this->template modelcheckingPrecision<BeliefMDPValueType>());
1464 }
1465}
1466
1467TYPED_TEST(BeliefBasedModelCheckerTest, reward_bounded_min_rejects_two_sided_dimensions) {
1468 using POMDPValueType = typename TestFixture::POMDPValueType;
1469 using BeliefMDPValueType = typename TestFixture::BeliefMDPValueType;
1471
1472 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/hidden_transition_rewards.prism", "Pmin=? [ true Urew{\"cost\"}>=2 \"goal\" ]");
1473 auto extraRewardModel = data.model->getRewardModel("cost");
1474 data.model->addRewardModel("extra", extraRewardModel);
1476
1477 auto intervalProperty = *data.propertyInfo;
1478 intervalProperty.rewardBounds.front().upperBound = intervalProperty.rewardBounds.front().lowerBound;
1479 auto zeroBoundData = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/hidden_transition_rewards.prism", "Pmin=? [ true Urew{\"cost\"}>=0 \"goal\" ]");
1480 auto zeroIntervalProperty = intervalProperty;
1481 zeroIntervalProperty.rewardBounds.front().lowerBound = zeroBoundData.propertyInfo->rewardBounds.front().lowerBound;
1482 auto multidimensionalProperty = *data.propertyInfo;
1483 auto extraIntervalBound = intervalProperty.rewardBounds.front();
1484 extraIntervalBound.rewardModelName = "extra";
1485 multidimensionalProperty.rewardBounds.push_back(extraIntervalBound);
1486
1487 // No preprocessing bounds: validation must reject the property before exploration accesses them.
1490 for (auto const& property : {intervalProperty, zeroIntervalProperty, multidimensionalProperty}) {
1491 std::vector<std::string> rewardModelNames;
1492 for (auto const& rewardBound : property.rewardBounds) {
1493 rewardModelNames.push_back(rewardBound.rewardModelName);
1494 }
1495 for (bool const limited : {false, true}) {
1496 SCOPED_TRACE(limited);
1497 options.maxExplorationSize = limited ? std::make_optional<uint64_t>(2) : std::nullopt;
1498 STORM_SILENT_EXPECT_THROW(checker.checkRewardAwareUnfold(this->env(), property, options, bounds, rewardModelNames),
1499 storm::exceptions::NotSupportedException);
1500 STORM_SILENT_EXPECT_THROW(checker.checkRewardAwareDiscretize(this->env(), property, options, 2, false, bounds, rewardModelNames),
1501 storm::exceptions::NotSupportedException);
1502 }
1503 }
1504
1505 // Pmax still reaches the underlying engine, whose existing interval restriction is unchanged.
1506 intervalProperty.dir = storm::OptimizationDirection::Maximize;
1507 options.maxExplorationSize.reset();
1508 bounds.preprocessingBounds.emplace();
1509 bounds.preprocessingBounds->lower.emplace_back(data.model->getNumberOfStates(), storm::utility::zero<POMDPValueType>());
1510 bounds.preprocessingBounds->upper.emplace_back(data.model->getNumberOfStates(), storm::utility::one<POMDPValueType>());
1511 for (bool const discretize : {false, true}) {
1512 SCOPED_TRACE(discretize);
1513 auto check = [&]() {
1514 try {
1515 if (discretize) {
1516 checker.checkRewardAwareDiscretize(this->env(), intervalProperty, options, 2, false, bounds, {"cost"});
1517 } else {
1518 checker.checkRewardAwareUnfold(this->env(), intervalProperty, options, bounds, {"cost"});
1519 }
1520 } catch (storm::exceptions::NotSupportedException const& exception) {
1521 EXPECT_NE(std::string(exception.what()).find("Bounded until formulas are only supported by this method"), std::string::npos);
1522 throw;
1523 }
1524 };
1525 STORM_SILENT_EXPECT_THROW(check(), storm::exceptions::NotSupportedException);
1526 }
1527}
1528
1529#if defined STORM_HAVE_LP_SOLVER
1530TYPED_TEST(BeliefBasedModelCheckerTest, clip_simple_Pmax) {
1532 typedef typename TestFixture::POMDPValueType POMDPValueType;
1533 typedef typename TestFixture::BeliefValueType BeliefValueType;
1534 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1535
1536 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Pmax=? [F \"goal\" ]", "slippery=0");
1539
1541 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
1542
1544 options.buildChoiceLabeling = false;
1546 options.useClipping = true;
1547 options.clippingResolutions = std::vector<uint64_t>(data.model->getNrObservations(), 2);
1548
1549 typename TestFixture::ExtendedBeliefMDPValueType overResultValue;
1550 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
1551
1552 auto expected = this->template parseNumber<BeliefMDPValueType>("7/10");
1553
1554 auto overCheckResult = checker.checkDiscretize(this->env(), *data.propertyInfo, options, this->overApproxResolution(), true, precomputedBeliefBounds);
1555 overResultValue = overCheckResult.value;
1556 EXPECT_LE(overResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
1557
1558 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
1559 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
1560 underResultValue = underCheckResult.value;
1561 EXPECT_LE(underResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
1562 EXPECT_LE(storm::utility::abs(overResultValue - underResultValue), this->precision())
1563 << "Result [" << underResultValue << ", " << overResultValue
1564 << "] is not precise enough. If (only) this fails, the result bounds are still correct, but they might be unexpectedly imprecise.\n";
1565}
1566
1567TYPED_TEST(BeliefBasedModelCheckerTest, clip_simple_Pmin) {
1569 typedef typename TestFixture::POMDPValueType POMDPValueType;
1570 typedef typename TestFixture::BeliefValueType BeliefValueType;
1571 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1572
1573 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Pmin=? [F \"goal\" ]", "slippery=0");
1574 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
1576
1578 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
1579
1581 options.buildChoiceLabeling = false;
1583 options.useClipping = true;
1584 options.clippingResolutions = std::vector<uint64_t>(data.model->getNrObservations(), 2);
1585
1586 typename TestFixture::ExtendedBeliefMDPValueType overResultValue;
1587 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
1588
1589 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("3/10");
1590
1591 auto overCheckResult = checker.checkDiscretize(this->env(), *data.propertyInfo, options, this->overApproxResolution(), true, precomputedBeliefBounds);
1592 overResultValue = overCheckResult.value;
1593 EXPECT_GE(overResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
1594
1595 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
1596 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
1597 underResultValue = underCheckResult.value;
1598 EXPECT_GE(underResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
1599 EXPECT_LE(storm::utility::abs(overResultValue - underResultValue), this->precision())
1600 << "Result [" << overResultValue << ", " << underResultValue
1601 << "] is not precise enough. If (only) this fails, the result bounds are still correct, but they might be unexpectedly imprecise.\n";
1602}
1603
1604TYPED_TEST(BeliefBasedModelCheckerTest, clip_simple_Pmin_early_clipping_is_sound) {
1606 typedef typename TestFixture::POMDPValueType POMDPValueType;
1607 typedef typename TestFixture::BeliefValueType BeliefValueType;
1608 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1609
1610 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Pmin=? [F \"goal\" ]", "slippery=0");
1613
1615 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
1616
1619 options.maxExplorationSize = 1;
1620 options.useClipping = true;
1621 options.clippingResolutions = std::vector<uint64_t>(data.model->getNrObservations(), 2);
1622
1623 auto underResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
1624 auto expected = this->template parseNumber<BeliefMDPValueType>("3/10");
1625 EXPECT_GE(underResult.value, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
1626}
1627
1628TYPED_TEST(BeliefBasedModelCheckerTest, clip_simple_slippery_Pmax) {
1630 typedef typename TestFixture::POMDPValueType POMDPValueType;
1631 typedef typename TestFixture::BeliefValueType BeliefValueType;
1632 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1633
1634 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Pmax=? [F \"goal\" ]", "slippery=0.4");
1635 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
1637
1639 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
1640
1642 options.buildChoiceLabeling = false;
1644 options.useClipping = true;
1645 options.clippingResolutions = std::vector<uint64_t>(data.model->getNrObservations(), 2);
1646
1647 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
1648
1649 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("7/10");
1650
1651 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
1652
1653 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
1654 underResultValue = underCheckResult.value;
1655 EXPECT_LE(underResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
1656}
1657
1658TYPED_TEST(BeliefBasedModelCheckerTest, clip_simple_slippery_Pmin) {
1660 typedef typename TestFixture::POMDPValueType POMDPValueType;
1661 typedef typename TestFixture::BeliefValueType BeliefValueType;
1662 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1663
1664 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Pmin=? [F \"goal\" ]", "slippery=0.4");
1665 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
1667
1669 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
1671 options.buildChoiceLabeling = false;
1673 options.useClipping = true;
1674 options.clippingResolutions = std::vector<uint64_t>(data.model->getNrObservations(), 2);
1675
1676 typename TestFixture::ExtendedBeliefMDPValueType overResultValue;
1677 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
1678
1679 POMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("3/10");
1680 auto overCheckResult = checker.checkDiscretize(this->env(), *data.propertyInfo, options, this->overApproxResolution(), true, precomputedBeliefBounds);
1681 overResultValue = overCheckResult.value;
1682
1683 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
1684 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
1685 underResultValue = underCheckResult.value;
1686 if (this->isExact()) {
1687 // This model's value can only be approximated arbitrarily close but never reached
1688 // Exact arithmetics will thus not reach the value with absoulute precision either.
1689 POMDPValueType approxPrecision = storm::utility::convertNumber<POMDPValueType>(1e-5);
1690 EXPECT_GE(underResultValue, expected - approxPrecision);
1691 EXPECT_LE(overResultValue, expected + approxPrecision);
1692 } else {
1693 EXPECT_GE(underResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
1694 EXPECT_LE(overResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
1695 }
1696 EXPECT_LE(storm::utility::abs(overResultValue - underResultValue), this->precision())
1697 << "Result [" << underResultValue << ", " << overResultValue
1698 << "] is not precise enough. If (only) this fails, the result bounds are still correct, but they might be unexpectedly imprecise.\n";
1699}
1700
1701TYPED_TEST(BeliefBasedModelCheckerTest, clip_simple_Rmax) {
1703 typedef typename TestFixture::POMDPValueType POMDPValueType;
1704 typedef typename TestFixture::BeliefValueType BeliefValueType;
1705 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1706
1707 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Rmax=? [F s>4 ]", "slippery=0");
1708 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
1710
1712 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
1713 precomputedBeliefBounds.extremeBounds = preprocessChecker.getExtremeValueBound(this->env(), *data.formula);
1714
1716 options.buildChoiceLabeling = false;
1718 options.useClipping = true;
1719 options.clippingResolutions = std::vector<uint64_t>(data.model->getNrObservations(), 2);
1720
1721 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
1722
1723 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("29/50");
1724
1725 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
1726 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
1727 underResultValue = underCheckResult.value;
1728 EXPECT_LE(underResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
1729}
1730
1731TYPED_TEST(BeliefBasedModelCheckerTest, clip_simple_Rmin) {
1733 typedef typename TestFixture::POMDPValueType POMDPValueType;
1734 typedef typename TestFixture::BeliefValueType BeliefValueType;
1735 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1736
1737 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Rmin=? [F s>4 ]", "slippery=0");
1738 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
1740
1742 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
1743 precomputedBeliefBounds.extremeBounds = preprocessChecker.getExtremeValueBound(this->env(), *data.formula);
1744
1746 options.buildChoiceLabeling = false;
1748 options.useClipping = true;
1749 options.clippingResolutions = std::vector<uint64_t>(data.model->getNrObservations(), 2);
1750
1751 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
1752
1753 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("19/50");
1754
1755 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
1756 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
1757 underResultValue = underCheckResult.value;
1758 EXPECT_GE(underResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
1759}
1760
1761TYPED_TEST(BeliefBasedModelCheckerTest, clip_simple_slippery_Rmax) {
1763 typedef typename TestFixture::POMDPValueType POMDPValueType;
1764 typedef typename TestFixture::BeliefValueType BeliefValueType;
1765 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1766
1767 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Rmax=? [F s>4 ]", "slippery=0.4");
1768 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
1770
1772 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
1773 precomputedBeliefBounds.extremeBounds = preprocessChecker.getExtremeValueBound(this->env(), *data.formula);
1774
1776 options.buildChoiceLabeling = false;
1778 options.useClipping = true;
1779 options.clippingResolutions = std::vector<uint64_t>(data.model->getNrObservations(), 2);
1780
1781 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
1782
1783 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("29/30");
1784
1785 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
1786 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
1787 underResultValue = underCheckResult.value;
1788 EXPECT_LE(underResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
1789}
1790
1791TYPED_TEST(BeliefBasedModelCheckerTest, clip_simple_slippery_Rmin) {
1793 typedef typename TestFixture::POMDPValueType POMDPValueType;
1794 typedef typename TestFixture::BeliefValueType BeliefValueType;
1795 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1796
1797 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/simple.prism", "Rmin=? [F s>4 ]", "slippery=0.4");
1798 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
1800
1802 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
1803 precomputedBeliefBounds.extremeBounds = preprocessChecker.getExtremeValueBound(this->env(), *data.formula);
1804
1806 options.buildChoiceLabeling = false;
1808 options.useClipping = true;
1809 options.clippingResolutions = std::vector<uint64_t>(data.model->getNrObservations(), 2);
1810
1811 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
1812
1813 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("19/30");
1814
1815 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
1816 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
1817 underResultValue = underCheckResult.value;
1818 EXPECT_GE(underResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
1819}
1820
1821TYPED_TEST(BeliefBasedModelCheckerTest, clip_maze2_Rmin) {
1823 typedef typename TestFixture::POMDPValueType POMDPValueType;
1824 typedef typename TestFixture::BeliefValueType BeliefValueType;
1825 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1826
1827 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/maze2.prism", "Rmin=? [F \"goal\"]", "sl=0");
1828 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
1830
1832 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
1833 precomputedBeliefBounds.extremeBounds = preprocessChecker.getExtremeValueBound(this->env(), *data.formula);
1834
1836 options.buildChoiceLabeling = false;
1838 options.useClipping = true;
1839 options.clippingResolutions = std::vector<uint64_t>(data.model->getNrObservations(), 2);
1840
1841 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
1842
1843 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("74/91");
1844 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
1845 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
1846 underResultValue = underCheckResult.value;
1847 EXPECT_GE(underResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
1848}
1849
1850TYPED_TEST(BeliefBasedModelCheckerTest, clip_maze2_Rmax) {
1852 typedef typename TestFixture::POMDPValueType POMDPValueType;
1853 typedef typename TestFixture::BeliefValueType BeliefValueType;
1854 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1855
1856 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/maze2.prism", "Rmax=? [F \"goal\"]", "sl=0");
1857 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
1859
1861 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
1862 precomputedBeliefBounds.extremeBounds = preprocessChecker.getExtremeValueBound(this->env(), *data.formula);
1863
1865 options.buildChoiceLabeling = false;
1867 options.useClipping = true;
1868 options.clippingResolutions = std::vector<uint64_t>(data.model->getNrObservations(), 2);
1869
1870 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
1871
1872 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
1873 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
1874 underResultValue = underCheckResult.value;
1875 EXPECT_EQ(storm::utility::positiveInfinity<BeliefMDPValueType>(), underResultValue);
1876}
1877
1878TYPED_TEST(BeliefBasedModelCheckerTest, clip_maze2_slippery_Rmin) {
1880 typedef typename TestFixture::POMDPValueType POMDPValueType;
1881 typedef typename TestFixture::BeliefValueType BeliefValueType;
1882 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1883
1884 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/maze2.prism", "Rmin=? [F \"goal\"]", "sl=0.075");
1885 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
1887
1889 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
1890 precomputedBeliefBounds.extremeBounds = preprocessChecker.getExtremeValueBound(this->env(), *data.formula);
1891
1893 options.buildChoiceLabeling = false;
1895 options.useClipping = true;
1896 options.clippingResolutions = std::vector<uint64_t>(data.model->getNrObservations(), 2);
1897
1898 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
1899
1900 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("80/91");
1901
1902 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
1903 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
1904 underResultValue = underCheckResult.value;
1905 EXPECT_GE(underResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
1906}
1907
1908TYPED_TEST(BeliefBasedModelCheckerTest, clip_maze2_slippery_Rmax) {
1910 typedef typename TestFixture::POMDPValueType POMDPValueType;
1911 typedef typename TestFixture::BeliefValueType BeliefValueType;
1912 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1913
1914 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/maze2.prism", "Rmax=? [F \"goal\"]", "sl=0.075");
1915 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
1917
1919 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
1920 precomputedBeliefBounds.extremeBounds = preprocessChecker.getExtremeValueBound(this->env(), *data.formula);
1921
1923 options.buildChoiceLabeling = false;
1925 options.useClipping = true;
1926 options.clippingResolutions = std::vector<uint64_t>(data.model->getNrObservations(), 2);
1927
1928 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
1929
1930 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
1931 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
1932 underResultValue = underCheckResult.value;
1933 EXPECT_EQ(storm::utility::positiveInfinity<BeliefMDPValueType>(), underResultValue);
1934}
1935
1936TYPED_TEST(BeliefBasedModelCheckerTest, clip_refuel_Pmax) {
1938 typedef typename TestFixture::POMDPValueType POMDPValueType;
1939 typedef typename TestFixture::BeliefValueType BeliefValueType;
1940 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1941
1942 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/refuel.prism", "Pmax=?[\"notbad\" U \"goal\"]", "N=4");
1943 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
1945
1947 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
1948
1950 options.buildChoiceLabeling = false;
1952 options.useClipping = true;
1953 options.clippingResolutions = std::vector<uint64_t>(data.model->getNrObservations(), 2);
1954
1955 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
1956
1957 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("38/155");
1958
1959 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
1960 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
1961 underResultValue = underCheckResult.value;
1962 EXPECT_LE(underResultValue, expected + this->template modelcheckingPrecision<BeliefMDPValueType>());
1963}
1964
1965TYPED_TEST(BeliefBasedModelCheckerTest, clip_refuel_Pmin) {
1967 typedef typename TestFixture::POMDPValueType POMDPValueType;
1968 typedef typename TestFixture::BeliefValueType BeliefValueType;
1969 typedef typename TestFixture::BeliefMDPValueType BeliefMDPValueType;
1970
1971 auto data = this->buildPrism(STORM_TEST_RESOURCES_DIR "/pomdp/refuel.prism", "Pmin=?[\"notbad\" U \"goal\"]", "N=4");
1972 storm::pomdp::beliefs::BeliefBasedModelChecker<storm::models::sparse::Pomdp<POMDPValueType>, BeliefValueType, BeliefMDPValueType> checker(*data.model);
1974
1976 precomputedBeliefBounds.preprocessingBounds = preprocessChecker.getValueBounds(this->env(), *data.formula);
1977
1979 options.buildChoiceLabeling = false;
1981 options.useClipping = true;
1982 options.clippingResolutions = std::vector<uint64_t>(data.model->getNrObservations(), 2);
1983
1984 typename TestFixture::ExtendedBeliefMDPValueType underResultValue;
1985
1986 BeliefMDPValueType expected = this->template parseNumber<BeliefMDPValueType>("0");
1987
1988 options.maxExplorationSize = data.model->getNumberOfStates() * data.model->getMaxNrStatesWithSameObservation();
1989 auto underCheckResult = checker.checkUnfold(this->env(), *data.propertyInfo, options, precomputedBeliefBounds);
1990 underResultValue = underCheckResult.value;
1991 EXPECT_GE(underResultValue, expected - this->template modelcheckingPrecision<BeliefMDPValueType>());
1992}
1993
1994#endif // defined STORM_HAVE_LP_SOLVER
1995
1996} // namespace
SolverEnvironment & solver()
void setPrecision(storm::RationalNumber value)
void setMethod(storm::solver::MinMaxMethod value, bool isSetFromDefault=false)
Helper class that optionally holds a reference to an object of type T.
Definition OptionalRef.h:48
MinMaxSolverEnvironment & minMax()
This class represents a partially observable Markov decision process.
Definition Pomdp.h:13
Builds and checks a finite belief MDP approximation of a POMDP.
Class to perform belief exploration.
Represents a belief of a Pomdp, i.e.
Definition Belief.h:21
Abstracts a given belief by splitting it into sub-beliefs based on the (state-action) reward of the P...
std::shared_ptr< storm::models::sparse::Pomdp< ValueType > > transform(storm::models::sparse::Pomdp< ValueType > const &pomdp, storm::storage::BitVector &prob0States, storm::storage::BitVector &prob1States)
Program preprocess(std::map< storm::expressions::Variable, storm::expressions::Expression > const &constantDefinitions) const
Preprocesses the program by defining the given constant definitions, substituting constants and formu...
Definition Program.cpp:1170
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
std::vector< storm::jani::Property > parsePropertiesForPrismProgram(std::string const &inputString, storm::prism::Program const &program, boost::optional< std::set< std::string > > const &propertyFilter)
storm::prism::Program parseProgram(std::string const &filename, bool prismCompatibility, bool simplify)
std::shared_ptr< storm::models::sparse::Model< ValueType > > buildSparseModel(storm::languages::SymbolicModelDescription const &model, storm::builder::BuilderOptions const &options, typename storm::builder::ExplicitModelBuilder< ValueType >::Options const &explorationOptions=typename storm::builder::ExplicitModelBuilder< ValueType >::Options())
Definition builder.h:118
SFTBDDChecker::ValueType ValueType
helper::MDPSparseModelCheckingHelperReturnType< ValueType > check(Environment const &env, SparseModelType const &model, CheckTask< storm::logic::MultiObjectiveFormula, ValueType > const &checkTask, CheckFormulaCallback const &formulaChecker)
check a lexicographic LTL-formula
NumberType parseNumber(std::string const &value)
Parse number from string.
FormulaInformation getFormulaInformation(PomdpType const &pomdp, storm::logic::ProbabilityOperatorFormula const &formula)
constexpr NoAbstractionType NoAbstraction
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.
ExplorationInformation< BeliefMdpValueType, BeliefType, std::vector< BeliefMdpValueType > > RewardAwareExplorationInformation
Exploration information that stores a reward vector on each transition.
storm::models::sparse::Dtmc< PomdpValueType > applyObservationBasedFSCToPomdp(storm::models::sparse::Pomdp< PomdpValueType > const &pomdp, storm::pomdp::policy::ObservationBasedFiniteStateController< FscValueType > const &fsc, bool treatUnspecifiedChoiceAsDontCare)
Applies an observation-based finite-state controller to a POMDP and constructs the induced DTMC.
bool constexpr maximize(OptimizationDirection d)
bool constexpr minimize(OptimizationDirection d)
storm::storage::BitVector getReachableStates(storm::storage::SparseMatrix< T > const &transitionMatrix, storm::storage::BitVector const &initialStates, storm::storage::BitVector const &constraintStates, storm::storage::BitVector const &targetStates, bool useStepBound, uint_fast64_t maximalSteps, boost::optional< storm::storage::BitVector > const &choiceFilter)
Performs a forward depth-first search through the underlying graph structure to identify the states t...
Definition graph.cpp:42
ExtendedValueType< ValueType > positiveInfinity()
bool isFinite(ExtendedNumber< ValueType > const &value)
ValueType abs(ValueType const &number)
ValueType zero()
Definition constants.cpp:26
std::conditional_t< storm::NumberTraits< ValueType >::HasInfinity, ValueType, ExtendedNumber< ValueType > > ExtendedValueType
The type to use for values that may be infinite.
ValueType one()
Definition constants.cpp:21
ValueType const & getFinite(ExtendedNumber< ValueType > const &value)
TargetType convertNumber(SourceType const &number)
constexpr NullRefType NullRef
Definition OptionalRef.h:31
TYPED_TEST(GraphTestAR, SymbolicProb01StochasticGameDieSmall)
Definition GraphTest.cpp:64
TYPED_TEST_SUITE(GraphTestAR, TestingTypes,)
::testing::Types< Cudd, Sylvan > TestingTypes
Definition GraphTest.cpp:61
#define STORM_SILENT_EXPECT_THROW(statement, expected_exception)
Definition storm_gtest.h:21
bool cutZeroGap
Cut non-target beliefs only when their preprocessing lower and upper bounds have exactly zero gap....
Auxiliary struct used to identify cases where no abstraction of beliefs shall be applied.
Struct for storing precomputed values bounding the actual values on the POMDP.
std::optional< ExtremePOMDPValueBound< POMDPValueType > > extremeBounds
std::optional< PreprocessingPomdpValueBounds< POMDPValueType > > preprocessingBounds
std::unordered_map< std::string, RewardModelType > rewardModels
storm::storage::SparseMatrix< ValueType > transitionMatrix
std::optional< storm::storage::sparse::Valuations > observationValuations
std::optional< storm::models::sparse::ChoiceLabeling > choiceLabeling
storm::models::sparse::StateLabeling stateLabeling
std::optional< std::vector< uint32_t > > observabilityClasses