Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
MdpPrctlModelCheckerTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
7#include "storm/api/builder.h"
29
30namespace {
31
32enum class MdpEngine { PrismSparse, JaniSparse, Hybrid, PrismDd, JaniDd };
33
34class SparseDoubleValueIterationViOpGaussSeidelMultEnvironment {
35 public:
36 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // Unused for sparse models
37 static const MdpEngine engine = MdpEngine::PrismSparse;
38 static const bool isExact = false;
39 typedef double ValueType;
40 typedef storm::models::sparse::Mdp<ValueType> ModelType;
41 static storm::Environment createEnvironment() {
42 storm::Environment env;
43 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
46 env.solver().multiplier().setType(storm::solver::MultiplierType::ViOperator);
47 return env;
48 }
49};
50
51class SparseDoubleValueIterationViOpRegularMultEnvironment {
52 public:
53 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // Unused for sparse models
54 static const MdpEngine engine = MdpEngine::PrismSparse;
55 static const bool isExact = false;
56 typedef double ValueType;
57 typedef storm::models::sparse::Mdp<ValueType> ModelType;
58 static storm::Environment createEnvironment() {
59 storm::Environment env;
60 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
63 env.solver().multiplier().setType(storm::solver::MultiplierType::ViOperator);
64 return env;
65 }
66};
67
68class SparseDoubleValueIterationNativeGaussSeidelMultEnvironment {
69 public:
70 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // Unused for sparse models
71 static const MdpEngine engine = MdpEngine::PrismSparse;
72 static const bool isExact = false;
73 typedef double ValueType;
74 typedef storm::models::sparse::Mdp<ValueType> ModelType;
75 static storm::Environment createEnvironment() {
76 storm::Environment env;
77 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
80 env.solver().multiplier().setType(storm::solver::MultiplierType::Native);
81 return env;
82 }
83};
84
85class SparseDoubleValueIterationNativeRegularMultEnvironment {
86 public:
87 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // Unused for sparse models
88 static const MdpEngine engine = MdpEngine::PrismSparse;
89 static const bool isExact = false;
90 typedef double ValueType;
91 typedef storm::models::sparse::Mdp<ValueType> ModelType;
92 static storm::Environment createEnvironment() {
93 storm::Environment env;
94 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
97 env.solver().multiplier().setType(storm::solver::MultiplierType::Native);
98 return env;
99 }
100};
101
102class JaniSparseDoubleValueIterationEnvironment {
103 public:
104 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // Unused for sparse models
105 static const MdpEngine engine = MdpEngine::JaniSparse;
106 static const bool isExact = false;
107 typedef double ValueType;
108 typedef storm::models::sparse::Mdp<ValueType> ModelType;
109 static storm::Environment createEnvironment() {
110 storm::Environment env;
111 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
113 return env;
114 }
115};
116
117class SparseDoubleIntervalIterationEnvironment {
118 public:
119 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // Unused for sparse models
120 static const MdpEngine engine = MdpEngine::PrismSparse;
121 static const bool isExact = false;
122 typedef double ValueType;
123 typedef storm::models::sparse::Mdp<ValueType> ModelType;
124 static storm::Environment createEnvironment() {
125 storm::Environment env;
126 env.solver().setForceSoundness(true);
127 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::IntervalIteration);
130 return env;
131 }
132};
133
134class SparseDoubleSoundValueIterationEnvironment {
135 public:
136 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // Unused for sparse models
137 static const MdpEngine engine = MdpEngine::PrismSparse;
138 static const bool isExact = false;
139 typedef double ValueType;
140 typedef storm::models::sparse::Mdp<ValueType> ModelType;
141 static storm::Environment createEnvironment() {
142 storm::Environment env;
143 env.solver().setForceSoundness(true);
144 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::SoundValueIteration);
147 return env;
148 }
149};
150
151class SparseDoubleOptimisticValueIterationEnvironment {
152 public:
153 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // Unused for sparse models
154 static const MdpEngine engine = MdpEngine::PrismSparse;
155 static const bool isExact = false;
156 typedef double ValueType;
157 typedef storm::models::sparse::Mdp<ValueType> ModelType;
158 static storm::Environment createEnvironment() {
159 storm::Environment env;
160 env.solver().setForceSoundness(true);
161 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::OptimisticValueIteration);
164 return env;
165 }
166};
167
168class SparseDoubleGuessingValueIterationEnvironment {
169 public:
170 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // Unused for sparse models
171 static const MdpEngine engine = MdpEngine::PrismSparse;
172 static const bool isExact = false;
173 typedef double ValueType;
174 typedef storm::models::sparse::Mdp<ValueType> ModelType;
175 static storm::Environment createEnvironment() {
176 storm::Environment env;
177 env.solver().setForceSoundness(true);
178 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::GuessingValueIteration);
181 return env;
182 }
183};
184
185class SparseDoubleTopologicalValueIterationEnvironment {
186 public:
187 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // Unused for sparse models
188 static const MdpEngine engine = MdpEngine::PrismSparse;
189 static const bool isExact = false;
190 typedef double ValueType;
191 typedef storm::models::sparse::Mdp<ValueType> ModelType;
192 static storm::Environment createEnvironment() {
193 storm::Environment env;
194 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::Topological);
195 env.solver().topological().setUnderlyingMinMaxMethod(storm::solver::MinMaxMethod::ValueIteration);
198 return env;
199 }
200};
201
202class SparseDoubleTopologicalSoundValueIterationEnvironment {
203 public:
204 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // Unused for sparse models
205 static const MdpEngine engine = MdpEngine::PrismSparse;
206 static const bool isExact = false;
207 typedef double ValueType;
208 typedef storm::models::sparse::Mdp<ValueType> ModelType;
209 static storm::Environment createEnvironment() {
210 storm::Environment env;
211 env.solver().setForceSoundness(true);
212 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::Topological);
213 env.solver().topological().setUnderlyingMinMaxMethod(storm::solver::MinMaxMethod::SoundValueIteration);
216 return env;
217 }
218};
219
220class SparseDoubleTopologicalGuessingValueIterationEnvironment {
221 public:
222 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // Unused for sparse models
223 static const MdpEngine engine = MdpEngine::PrismSparse;
224 static const bool isExact = false;
225 typedef double ValueType;
226 typedef storm::models::sparse::Mdp<ValueType> ModelType;
227 static storm::Environment createEnvironment() {
228 storm::Environment env;
229 env.solver().setForceSoundness(true);
230 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::Topological);
231 env.solver().topological().setUnderlyingMinMaxMethod(storm::solver::MinMaxMethod::GuessingValueIteration);
234 return env;
235 }
236};
237
238class SparseDoubleLPEnvironment {
239 public:
240 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // Unused for sparse models
241 static const MdpEngine engine = MdpEngine::PrismSparse;
242 static const bool isExact = false;
243 typedef double ValueType;
244 typedef storm::models::sparse::Mdp<ValueType> ModelType;
245 static storm::Environment createEnvironment() {
246 storm::Environment env;
247 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::LinearProgramming);
249 return env;
250 }
251};
252
253class SparseDoubleViToLPEnvironment {
254 public:
255 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // Unused for sparse models
256 static const MdpEngine engine = MdpEngine::PrismSparse;
257 static const bool isExact = false;
258 typedef double ValueType;
259 typedef storm::models::sparse::Mdp<ValueType> ModelType;
260 static storm::Environment createEnvironment() {
261 storm::Environment env;
262 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ViToLp);
264 return env;
265 }
266};
267
268class SparseRationalPolicyIterationEnvironment {
269 public:
270 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // Unused for sparse models
271 static const MdpEngine engine = MdpEngine::PrismSparse;
272 static const bool isExact = true;
273 typedef storm::RationalNumber ValueType;
274 typedef storm::models::sparse::Mdp<ValueType> ModelType;
275 static storm::Environment createEnvironment() {
276 storm::Environment env;
277 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::PolicyIteration);
278 return env;
279 }
280};
281
282class SparseRationalViToPiEnvironment {
283 public:
284 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // Unused for sparse models
285 static const MdpEngine engine = MdpEngine::PrismSparse;
286 static const bool isExact = true;
287 typedef storm::RationalNumber ValueType;
288 typedef storm::models::sparse::Mdp<ValueType> ModelType;
289 static storm::Environment createEnvironment() {
290 storm::Environment env;
291 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ViToPi);
292 return env;
293 }
294};
295
296class SparseRationalRationalSearchEnvironment {
297 public:
298 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // Unused for sparse models
299 static const MdpEngine engine = MdpEngine::PrismSparse;
300 static const bool isExact = true;
301 typedef storm::RationalNumber ValueType;
302 typedef storm::models::sparse::Mdp<ValueType> ModelType;
303 static storm::Environment createEnvironment() {
304 storm::Environment env;
305 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::RationalSearch);
306 return env;
307 }
308};
309class HybridCuddDoubleValueIterationEnvironment {
310 public:
311 static const storm::dd::DdType ddType = storm::dd::DdType::CUDD;
312 static const MdpEngine engine = MdpEngine::Hybrid;
313 static const bool isExact = false;
314 typedef double ValueType;
315 typedef storm::models::symbolic::Mdp<ddType, ValueType> ModelType;
316
317 static void checkLibraryAvailable() {
318#ifndef STORM_HAVE_CUDD
319 GTEST_SKIP() << "Library CUDD not available.";
320#endif
321 }
322
323 static storm::Environment createEnvironment() {
324 storm::Environment env;
325 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
327 return env;
328 }
329};
330class HybridSylvanDoubleValueIterationEnvironment {
331 public:
332 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan;
333 static const MdpEngine engine = MdpEngine::Hybrid;
334 static const bool isExact = false;
335 typedef double ValueType;
336 typedef storm::models::symbolic::Mdp<ddType, ValueType> ModelType;
337
338 static void checkLibraryAvailable() {
339#ifndef STORM_HAVE_SYLVAN
340 GTEST_SKIP() << "Library Sylvan not available.";
341#endif
342 }
343
344 static storm::Environment createEnvironment() {
345 storm::Environment env;
346 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
348 return env;
349 }
350};
351class HybridCuddDoubleSoundValueIterationEnvironment {
352 public:
353 static const storm::dd::DdType ddType = storm::dd::DdType::CUDD;
354 static const MdpEngine engine = MdpEngine::Hybrid;
355 static const bool isExact = false;
356 typedef double ValueType;
357 typedef storm::models::symbolic::Mdp<ddType, ValueType> ModelType;
358
359 static void checkLibraryAvailable() {
360#ifndef STORM_HAVE_CUDD
361 GTEST_SKIP() << "Library CUDD not available.";
362#endif
363 }
364
365 static storm::Environment createEnvironment() {
366 storm::Environment env;
367 env.solver().setForceSoundness(true);
368 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::SoundValueIteration);
371 return env;
372 }
373};
374class HybridCuddDoubleOptimisticValueIterationEnvironment {
375 public:
376 static const storm::dd::DdType ddType = storm::dd::DdType::CUDD;
377 static const MdpEngine engine = MdpEngine::Hybrid;
378 static const bool isExact = false;
379 typedef double ValueType;
380 typedef storm::models::symbolic::Mdp<ddType, ValueType> ModelType;
381
382 static void checkLibraryAvailable() {
383#ifndef STORM_HAVE_CUDD
384 GTEST_SKIP() << "Library CUDD not available.";
385#endif
386 }
387
388 static storm::Environment createEnvironment() {
389 storm::Environment env;
390 env.solver().setForceSoundness(true);
391 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::OptimisticValueIteration);
394 return env;
395 }
396};
397class HybridCuddDoubleGuessingValueIterationEnvironment {
398 public:
399 static const storm::dd::DdType ddType = storm::dd::DdType::CUDD;
400 static const MdpEngine engine = MdpEngine::Hybrid;
401 static const bool isExact = false;
402 typedef double ValueType;
403 typedef storm::models::symbolic::Mdp<ddType, ValueType> ModelType;
404
405 static void checkLibraryAvailable() {
406#ifndef STORM_HAVE_CUDD
407 GTEST_SKIP() << "Library CUDD not available.";
408#endif
409 }
410
411 static storm::Environment createEnvironment() {
412 storm::Environment env;
413 env.solver().setForceSoundness(true);
414 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::GuessingValueIteration);
417 return env;
418 }
419};
420class HybridSylvanRationalPolicyIterationEnvironment {
421 public:
422 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan;
423 static const MdpEngine engine = MdpEngine::Hybrid;
424 static const bool isExact = true;
425 typedef storm::RationalNumber ValueType;
426 typedef storm::models::symbolic::Mdp<ddType, ValueType> ModelType;
427
428 static void checkLibraryAvailable() {
429#ifndef STORM_HAVE_SYLVAN
430 GTEST_SKIP() << "Library Sylvan not available.";
431#endif
432 }
433
434 static storm::Environment createEnvironment() {
435 storm::Environment env;
436 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::PolicyIteration);
437 return env;
438 }
439};
440class DdCuddDoubleValueIterationEnvironment {
441 public:
442 static const storm::dd::DdType ddType = storm::dd::DdType::CUDD;
443 static const MdpEngine engine = MdpEngine::PrismDd;
444 static const bool isExact = false;
445 typedef double ValueType;
446 typedef storm::models::symbolic::Mdp<ddType, ValueType> ModelType;
447
448 static void checkLibraryAvailable() {
449#ifndef STORM_HAVE_CUDD
450 GTEST_SKIP() << "Library CUDD not available.";
451#endif
452 }
453
454 static storm::Environment createEnvironment() {
455 storm::Environment env;
456 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
458 return env;
459 }
460};
461class JaniDdCuddDoubleValueIterationEnvironment {
462 public:
463 static const storm::dd::DdType ddType = storm::dd::DdType::CUDD;
464 static const MdpEngine engine = MdpEngine::JaniDd;
465 static const bool isExact = false;
466 typedef double ValueType;
467 typedef storm::models::symbolic::Mdp<ddType, ValueType> ModelType;
468
469 static void checkLibraryAvailable() {
470#ifndef STORM_HAVE_CUDD
471 GTEST_SKIP() << "Library CUDD not available.";
472#endif
473 }
474
475 static storm::Environment createEnvironment() {
476 storm::Environment env;
477 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
479 return env;
480 }
481};
482class DdSylvanDoubleValueIterationEnvironment {
483 public:
484 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan;
485 static const MdpEngine engine = MdpEngine::PrismDd;
486 static const bool isExact = false;
487 typedef double ValueType;
488 typedef storm::models::symbolic::Mdp<ddType, ValueType> ModelType;
489
490 static void checkLibraryAvailable() {
491#ifndef STORM_HAVE_SYLVAN
492 GTEST_SKIP() << "Library Sylvan not available.";
493#endif
494 }
495
496 static storm::Environment createEnvironment() {
497 storm::Environment env;
498 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
500 return env;
501 }
502};
503class DdCuddDoublePolicyIterationEnvironment {
504 public:
505 static const storm::dd::DdType ddType = storm::dd::DdType::CUDD;
506 static const MdpEngine engine = MdpEngine::PrismDd;
507 static const bool isExact = false;
508 typedef double ValueType;
509 typedef storm::models::symbolic::Mdp<ddType, ValueType> ModelType;
510
511 static void checkLibraryAvailable() {
512#ifndef STORM_HAVE_CUDD
513 GTEST_SKIP() << "Library CUDD not available.";
514#endif
515 }
516
517 static storm::Environment createEnvironment() {
518 storm::Environment env;
519 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::PolicyIteration);
521 return env;
522 }
523};
524class DdSylvanRationalRationalSearchEnvironment {
525 public:
526 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan;
527 static const MdpEngine engine = MdpEngine::PrismDd;
528 static const bool isExact = true;
529 typedef storm::RationalNumber ValueType;
530 typedef storm::models::symbolic::Mdp<ddType, ValueType> ModelType;
531
532 static void checkLibraryAvailable() {
533#ifndef STORM_HAVE_SYLVAN
534 GTEST_SKIP() << "Library Sylvan not available.";
535#endif
536 }
537
538 static storm::Environment createEnvironment() {
539 storm::Environment env;
540 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::RationalSearch);
541 return env;
542 }
543};
544
545template<typename TestType>
546class MdpPrctlModelCheckerTest : public ::testing::Test {
547 public:
548 typedef typename TestType::ValueType ValueType;
549 typedef typename storm::models::sparse::Mdp<ValueType> SparseModelType;
550 typedef typename storm::models::symbolic::Mdp<TestType::ddType, ValueType> SymbolicModelType;
551
552 MdpPrctlModelCheckerTest() : _environment(TestType::createEnvironment()) {}
553
554 void SetUp() override {
555#ifndef STORM_HAVE_Z3
556 GTEST_SKIP() << "Z3 not available.";
557#endif
558 if constexpr (TestType::engine == MdpEngine::Hybrid || TestType::engine == MdpEngine::PrismDd || TestType::engine == MdpEngine::JaniDd) {
559 TestType::checkLibraryAvailable();
560 }
561 }
562
563 storm::Environment const& env() const {
564 return _environment;
565 }
566 ValueType parseNumber(std::string const& input) const {
568 }
569 ValueType precision() const {
570 return TestType::isExact ? parseNumber("0") : parseNumber("1e-6");
571 }
572 bool isSparseModel() const {
573 return std::is_same<typename TestType::ModelType, SparseModelType>::value;
574 }
575 bool isSymbolicModel() const {
576 return std::is_same<typename TestType::ModelType, SymbolicModelType>::value;
577 }
578
583 bool requiresUniqueFixedPointWithoutEcElimination() const {
584 return TestType::engine == MdpEngine::PrismDd && env().solver().minMax().getMethod() == storm::solver::MinMaxMethod::RationalSearch;
585 }
586
591 template<typename ModelPtr, typename CheckerPtr, typename TaskType>
592 void checkTaskWithoutUniqueFixedPoint(ModelPtr const& model, CheckerPtr& checker, TaskType const& task, std::string const& expected) {
593 if (requiresUniqueFixedPointWithoutEcElimination()) {
594 STORM_SILENT_EXPECT_THROW(checker->check(env(), task), storm::exceptions::UncheckedRequirementException);
595 } else {
596 auto result = checker->check(env(), task);
597 expectQuantitativeResultAtInitialState(model, result, parseNumber(expected));
598 }
599 }
600
601 template<typename MT = typename TestType::ModelType>
602 typename std::enable_if<std::is_same<MT, SparseModelType>::value,
603 std::pair<std::shared_ptr<MT>, std::vector<std::shared_ptr<storm::logic::Formula const>>>>::type
604 buildModelFormulas(std::string const& pathToPrismFile, std::string const& formulasAsString, std::string const& constantDefinitionString = "") const {
605 std::pair<std::shared_ptr<MT>, std::vector<std::shared_ptr<storm::logic::Formula const>>> result;
606 storm::prism::Program program = storm::api::parseProgram(pathToPrismFile);
607 program = program.preprocess(constantDefinitionString);
608 if (TestType::engine == MdpEngine::PrismSparse) {
610 result.first = storm::api::buildSparseModel<ValueType>(program, result.second)->template as<MT>();
611 } else if (TestType::engine == MdpEngine::JaniSparse) {
612 auto janiData = storm::api::convertPrismToJani(program, storm::api::parsePropertiesForPrismProgram(formulasAsString, program));
613 janiData.first.substituteFunctions();
614 result.second = storm::api::extractFormulasFromProperties(janiData.second);
615 result.first = storm::api::buildSparseModel<ValueType>(janiData.first, result.second)->template as<MT>();
616 }
617 return result;
618 }
619
620 template<typename MT = typename TestType::ModelType>
621 typename std::enable_if<std::is_same<MT, SymbolicModelType>::value,
622 std::pair<std::shared_ptr<MT>, std::vector<std::shared_ptr<storm::logic::Formula const>>>>::type
623 buildModelFormulas(std::string const& pathToPrismFile, std::string const& formulasAsString, std::string const& constantDefinitionString = "") const {
624 std::pair<std::shared_ptr<MT>, std::vector<std::shared_ptr<storm::logic::Formula const>>> result;
625 storm::prism::Program program = storm::api::parseProgram(pathToPrismFile);
626 program = program.preprocess(constantDefinitionString);
627 if (TestType::engine == MdpEngine::Hybrid || TestType::engine == MdpEngine::PrismDd) {
629 result.first = storm::api::buildSymbolicModel<TestType::ddType, ValueType>(this->env(), program, result.second)->template as<MT>();
630 } else if (TestType::engine == MdpEngine::JaniDd) {
631 auto janiData = storm::api::convertPrismToJani(program, storm::api::parsePropertiesForPrismProgram(formulasAsString, program));
632 janiData.first.substituteFunctions();
633 result.second = storm::api::extractFormulasFromProperties(janiData.second);
634 result.first = storm::api::buildSymbolicModel<TestType::ddType, ValueType>(this->env(), janiData.first, result.second)->template as<MT>();
635 }
636 return result;
637 }
638
639 std::vector<storm::modelchecker::CheckTask<storm::logic::Formula, ValueType>> getTasks(
640 std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas) const {
641 std::vector<storm::modelchecker::CheckTask<storm::logic::Formula, ValueType>> result;
642 for (auto const& f : formulas) {
643 result.emplace_back(*f);
644 }
645 return result;
646 }
647
648 template<typename MT = typename TestType::ModelType>
649 typename std::enable_if<std::is_same<MT, SparseModelType>::value, std::shared_ptr<storm::modelchecker::AbstractModelChecker<MT>>>::type createModelChecker(
650 std::shared_ptr<MT> const& model) const {
651 if (TestType::engine == MdpEngine::PrismSparse || TestType::engine == MdpEngine::JaniSparse) {
652 return std::make_shared<storm::modelchecker::SparseMdpPrctlModelChecker<SparseModelType>>(*model);
653 }
654 }
655
656 template<typename MT = typename TestType::ModelType>
657 typename std::enable_if<std::is_same<MT, SymbolicModelType>::value, std::shared_ptr<storm::modelchecker::AbstractModelChecker<MT>>>::type
658 createModelChecker(std::shared_ptr<MT> const& model) const {
659 if (TestType::engine == MdpEngine::Hybrid) {
660 return std::make_shared<storm::modelchecker::HybridMdpPrctlModelChecker<SymbolicModelType>>(*model);
661 } else if (TestType::engine == MdpEngine::PrismDd || TestType::engine == MdpEngine::JaniDd) {
662 return std::make_shared<storm::modelchecker::SymbolicMdpPrctlModelChecker<SymbolicModelType>>(*model);
663 }
664 }
665
666 template<typename MT = typename TestType::ModelType>
667 typename std::enable_if<std::is_same<MT, SparseModelType>::value, void>::type execute(std::shared_ptr<MT> const& model,
668 std::function<void()> const& f) const {
669 f();
670 }
671
672 template<typename MT = typename TestType::ModelType>
673 typename std::enable_if<std::is_same<MT, SymbolicModelType>::value, void>::type execute(std::shared_ptr<MT> const& model,
674 std::function<void()> const& f) const {
675 model->getManager().execute(f);
676 }
677
678 bool getQualitativeResultAtInitialState(std::shared_ptr<storm::models::Model<ValueType>> const& model,
679 std::unique_ptr<storm::modelchecker::CheckResult>& result) {
680 auto filter = getInitialStateFilter(model);
681 result->filter(*filter);
682 return result->asQualitativeCheckResult().forallTrue();
683 }
684
685 storm::utility::ExtendedValueType<ValueType> getQuantitativeResultAtInitialState(std::shared_ptr<storm::models::Model<ValueType>> const& model,
686 std::unique_ptr<storm::modelchecker::CheckResult>& result) {
687 auto filter = getInitialStateFilter(model);
688 result->filter(*filter);
689 return result->asQuantitativeCheckResult<ValueType>().getMin();
690 }
691
696 void expectQuantitativeResultAtInitialState(std::shared_ptr<storm::models::Model<ValueType>> const& model,
697 std::unique_ptr<storm::modelchecker::CheckResult>& result, ValueType const& expected) {
698 EXPECT_NEAR(expected, this->getQuantitativeResultAtInitialState(model, result), this->precision());
699 if (!result->isExplicitQuantitativeCheckResult()) {
700 return; // Only explicit results carry bounds.
701 }
702 // The result is filtered to the initial states at this point, so the first entry belongs to the first initial state.
703 auto const& explicitResult = result->template asExplicitQuantitativeCheckResult<ValueType>();
704 ValueType const tolerance = TestType::isExact ? this->parseNumber("0") : this->parseNumber("1e-12");
705 if (explicitResult.hasLowerBounds()) {
706 EXPECT_LE(explicitResult.getLowerBoundVector().front(), expected + tolerance) << "The lower bound exceeds the expected value.";
707 }
708 if (explicitResult.hasUpperBounds()) {
709 EXPECT_LE(expected, explicitResult.getUpperBoundVector().front() + tolerance) << "The upper bound falls below the expected value.";
710 }
711 }
712
716 void expectExactResultAtInitialState(std::shared_ptr<storm::models::Model<ValueType>> const& model,
717 std::unique_ptr<storm::modelchecker::CheckResult>& result, ValueType const& expected) {
718 expectQuantitativeResultAtInitialState(model, result, expected);
719 if (!result->isExplicitQuantitativeCheckResult()) {
720 return; // Only explicit results carry bounds.
721 }
722 auto const& explicitResult = result->template asExplicitQuantitativeCheckResult<ValueType>();
723 ASSERT_TRUE(explicitResult.hasLowerBounds()) << "No lower bound was reported although the values are exact.";
724 ASSERT_TRUE(explicitResult.hasUpperBounds()) << "No upper bound was reported although the values are exact.";
725 EXPECT_EQ(explicitResult.getLowerBoundVector(), explicitResult.getUpperBoundVector()) << "The bounds do not pin the values down.";
726 }
727
728 private:
729 storm::Environment _environment;
730
731 std::unique_ptr<storm::modelchecker::QualitativeCheckResult> getInitialStateFilter(std::shared_ptr<storm::models::Model<ValueType>> const& model) const {
732 if (isSparseModel()) {
733 return std::make_unique<storm::modelchecker::ExplicitQualitativeCheckResult<ValueType>>(model->template as<SparseModelType>()->getInitialStates());
734 } else {
735 return std::make_unique<storm::modelchecker::SymbolicQualitativeCheckResult<TestType::ddType>>(
736 model->template as<SymbolicModelType>()->getReachableStates(), model->template as<SymbolicModelType>()->getInitialStates());
737 }
738 }
739};
740
741typedef ::testing::Types<SparseDoubleValueIterationViOpGaussSeidelMultEnvironment, SparseDoubleValueIterationViOpRegularMultEnvironment,
742 SparseDoubleValueIterationNativeGaussSeidelMultEnvironment, SparseDoubleValueIterationNativeRegularMultEnvironment,
743 JaniSparseDoubleValueIterationEnvironment, SparseDoubleIntervalIterationEnvironment, SparseDoubleSoundValueIterationEnvironment,
744 SparseDoubleOptimisticValueIterationEnvironment, SparseDoubleGuessingValueIterationEnvironment,
745 SparseDoubleTopologicalValueIterationEnvironment, SparseDoubleTopologicalSoundValueIterationEnvironment,
746 SparseDoubleTopologicalGuessingValueIterationEnvironment, SparseDoubleLPEnvironment, SparseDoubleViToLPEnvironment,
747 SparseRationalPolicyIterationEnvironment, SparseRationalViToPiEnvironment, SparseRationalRationalSearchEnvironment,
748 HybridCuddDoubleValueIterationEnvironment, HybridSylvanDoubleValueIterationEnvironment, HybridCuddDoubleSoundValueIterationEnvironment,
749 HybridCuddDoubleOptimisticValueIterationEnvironment, HybridCuddDoubleGuessingValueIterationEnvironment,
750 HybridSylvanRationalPolicyIterationEnvironment, DdCuddDoubleValueIterationEnvironment, JaniDdCuddDoubleValueIterationEnvironment,
751 DdSylvanDoubleValueIterationEnvironment, DdCuddDoublePolicyIterationEnvironment, DdSylvanRationalRationalSearchEnvironment>
753
754TYPED_TEST_SUITE(MdpPrctlModelCheckerTest, TestingTypes, );
755
756TYPED_TEST(MdpPrctlModelCheckerTest, Dice) {
757 std::string formulasString = "Pmin=? [F \"two\"]";
758 formulasString += "; Pmax=? [F \"two\"]";
759 formulasString += "; Pmin=? [F \"three\"]";
760 formulasString += "; Pmax=? [F \"three\"]";
761 formulasString += "; Pmin=? [F \"four\"]";
762 formulasString += "; Pmax=? [F \"four\"]";
763 formulasString += "; Rmin=? [F \"done\"]";
764 formulasString += "; Rmax=? [F \"done\"]";
765
766 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/mdp/two_dice.nm", formulasString);
767 auto model = std::move(modelFormulas.first);
768 auto tasks = this->getTasks(modelFormulas.second);
769 this->execute(model, [&]() {
770 EXPECT_EQ(169ul, model->getNumberOfStates());
771 EXPECT_EQ(436ul, model->getNumberOfTransitions());
772 ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp);
773
774 auto checker = this->createModelChecker(model);
775 std::unique_ptr<storm::modelchecker::CheckResult> result;
776
777 result = checker->check(this->env(), tasks[0]);
778 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/36"));
779
780 result = checker->check(this->env(), tasks[1]);
781 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/36"));
782
783 result = checker->check(this->env(), tasks[2]);
784 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("2/36"));
785
786 result = checker->check(this->env(), tasks[3]);
787 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("2/36"));
788
789 result = checker->check(this->env(), tasks[4]);
790 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("3/36"));
791
792 result = checker->check(this->env(), tasks[5]);
793 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("3/36"));
794
795 result = checker->check(this->env(), tasks[6]);
796 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("22/3"));
797
798 result = checker->check(this->env(), tasks[7]);
799 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("22/3"));
800 });
801}
802
803STORM_EXPENSIVE_TYPED_TEST(MdpPrctlModelCheckerTest, AsynchronousLeader) {
804 std::string formulasString = "Pmin=? [F \"elected\"]";
805 formulasString += "; Pmax=? [F \"elected\"]";
806 formulasString += "; Pmin=? [F<=25 \"elected\"]";
807 formulasString += "; Pmax=? [F<=25 \"elected\"]";
808 formulasString += "; Rmin=? [F \"elected\"]";
809 formulasString += "; Rmax=? [F \"elected\"]";
810
811 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/mdp/leader4.nm", formulasString);
812 auto model = std::move(modelFormulas.first);
813 auto tasks = this->getTasks(modelFormulas.second);
814 this->execute(model, [&]() {
815 EXPECT_EQ(3172ul, model->getNumberOfStates());
816 EXPECT_EQ(7144ul, model->getNumberOfTransitions());
817 ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp);
818 auto checker = this->createModelChecker(model);
819 std::unique_ptr<storm::modelchecker::CheckResult> result;
820
821 result = checker->check(this->env(), tasks[0]);
822 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1"));
823
824 result = checker->check(this->env(), tasks[1]);
825 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1"));
826
827 result = checker->check(this->env(), tasks[2]);
828 this->expectExactResultAtInitialState(model, result, this->parseNumber("1/16"));
829
830 result = checker->check(this->env(), tasks[3]);
831 this->expectExactResultAtInitialState(model, result, this->parseNumber("1/16"));
832
833 result = checker->check(this->env(), tasks[4]);
834 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("30/7"));
835
836 result = checker->check(this->env(), tasks[5]);
837 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("30/7"));
838 });
839}
840
841TYPED_TEST(MdpPrctlModelCheckerTest, MaybeStateEndComponent) {
842 // The best scheduler leaves x=0 and x=1 through their probabilistic choices, reaching the target with
843 // probability 1/2 * 1/2.
844 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/mdp/maybe_state_end_component.nm", "Pmax=? [F \"target\"]");
845 auto model = std::move(modelFormulas.first);
846 auto tasks = this->getTasks(modelFormulas.second);
847 EXPECT_EQ(4ul, model->getNumberOfStates());
848 ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp);
849
850 auto checker = this->createModelChecker(model);
851 this->checkTaskWithoutUniqueFixedPoint(model, checker, tasks[0], "1/4");
852}
853
854STORM_EXPENSIVE_TYPED_TEST(MdpPrctlModelCheckerTest, consensus) {
855 std::string formulasString = "Pmax=? [F \"finished\"]";
856 formulasString += "; Pmax=? [F \"all_coins_equal_1\"]";
857 formulasString += "; P<0.8 [F \"all_coins_equal_1\"]";
858 formulasString += "; P<0.9 [F \"all_coins_equal_1\"]";
859 formulasString += "; Rmax=? [F \"all_coins_equal_1\"]";
860 formulasString += "; Rmin=? [F \"all_coins_equal_1\"]";
861 formulasString += "; Rmax=? [F \"finished\"]";
862 formulasString += "; Rmin=? [F \"finished\"]";
863
864 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/mdp/coin2-2.nm", formulasString);
865 auto model = std::move(modelFormulas.first);
866 auto tasks = this->getTasks(modelFormulas.second);
867 this->execute(model, [&]() {
868 EXPECT_EQ(272ul, model->getNumberOfStates());
869 EXPECT_EQ(492ul, model->getNumberOfTransitions());
870 ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp);
871 auto checker = this->createModelChecker(model);
872 std::unique_ptr<storm::modelchecker::CheckResult> result;
873
874 result = checker->check(this->env(), tasks[0]);
875 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1"));
876
877 result = checker->check(this->env(), tasks[1]);
878 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("57/64"));
879
880 result = checker->check(this->env(), tasks[2]);
881 EXPECT_FALSE(this->getQualitativeResultAtInitialState(model, result));
882
883 result = checker->check(this->env(), tasks[3]);
884 EXPECT_TRUE(this->getQualitativeResultAtInitialState(model, result));
885
886 result = checker->check(this->env(), tasks[4]);
887 EXPECT_TRUE(storm::utility::isInfinity(this->getQuantitativeResultAtInitialState(model, result)));
888
889 result = checker->check(this->env(), tasks[5]);
890 EXPECT_TRUE(storm::utility::isInfinity(this->getQuantitativeResultAtInitialState(model, result)));
891
892 result = checker->check(this->env(), tasks[6]);
893 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("75"));
894
895 result = checker->check(this->env(), tasks[7]);
896 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("48"));
897 });
898}
899
900TYPED_TEST(MdpPrctlModelCheckerTest, TinyRewards) {
901 std::string formulasString = "Rmin=? [F \"target\"]";
902 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/mdp/tiny_rewards.nm", formulasString);
903 auto model = std::move(modelFormulas.first);
904 auto tasks = this->getTasks(modelFormulas.second);
905 this->execute(model, [&]() {
906 EXPECT_EQ(3ul, model->getNumberOfStates());
907 EXPECT_EQ(4ul, model->getNumberOfTransitions());
908 ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp);
909 auto checker = this->createModelChecker(model);
910
911 // This example considers a zero-reward end component that does not reach the target
912 // For some methods this requires end-component elimination which is (currently) not supported in the Dd engine
913 this->checkTaskWithoutUniqueFixedPoint(model, checker, tasks[0], "1");
914 });
915}
916
917TYPED_TEST(MdpPrctlModelCheckerTest, SimpleProtocolMaybeStateEndComponent) {
918 // State 1 has a self-loop, so the maybe states contain an end component and the fixed point is not unique.
919 std::string formulasString = "Pmax=? [ (s<=1) U (s=3) ]";
920 formulasString += "; Pmax=? [ !(s=3) U (!(s<=1) & !(s=3)) ]";
921 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/mdp/simple_protocol.nm", formulasString);
922 auto model = std::move(modelFormulas.first);
923 auto tasks = this->getTasks(modelFormulas.second);
924 this->execute(model, [&]() {
925 EXPECT_EQ(4ul, model->getNumberOfStates());
926 ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp);
927 auto checker = this->createModelChecker(model);
928
929 this->checkTaskWithoutUniqueFixedPoint(model, checker, tasks[0], "99/100");
930 this->checkTaskWithoutUniqueFixedPoint(model, checker, tasks[1], "1/100");
931 });
932}
933
934TYPED_TEST(MdpPrctlModelCheckerTest, Team) {
935 std::string formulasString = "R{\"w_1_total\"}max=? [ C ]";
936 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/mdp/multiobj_team3.nm", formulasString);
937 auto model = std::move(modelFormulas.first);
938 auto tasks = this->getTasks(modelFormulas.second);
939 this->execute(model, [&]() {
940 EXPECT_EQ(12475ul, model->getNumberOfStates());
941 EXPECT_EQ(15228ul, model->getNumberOfTransitions());
942 ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp);
943 auto checker = this->createModelChecker(model);
944 std::unique_ptr<storm::modelchecker::CheckResult> result;
945
946 // This example considers an expected total reward formula, which is not supported in all engines
947
948 if (TypeParam::engine == MdpEngine::PrismSparse || TypeParam::engine == MdpEngine::JaniSparse) {
949 result = checker->check(this->env(), tasks[0]);
950 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("114/49"));
951 } else {
952 EXPECT_FALSE(checker->canHandle(tasks[0]));
953 }
954 });
955}
956
957TYPED_TEST(MdpPrctlModelCheckerTest, LtlProbabilitiesCoin) {
958#ifdef STORM_HAVE_LTL_MODELCHECKING_SUPPORT
959 std::string formulasString = "Pmin=? [!(GF \"all_coins_equal_1\")]";
960 formulasString += "; Pmax=? [F \"all_coins_equal_1\" U \"finished\"]";
961 formulasString += "; P>0.4 [!(GF \"all_coins_equal_1\")]";
962 formulasString += "; P<0.6 [F \"all_coins_equal_1\" U \"finished\"]";
963 // The following example results in an automaton with acceptance condition not in DNF (Streett, using Spot)
964 formulasString += "; Pmax=?[ (GF \"all_coins_equal_1\") & ((GF \"all_coins_equal_0\") | (FG \"finished\"))]";
965
966 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/mdp/coin2-2.nm", formulasString);
967 auto model = std::move(modelFormulas.first);
968 auto tasks = this->getTasks(modelFormulas.second);
969 this->execute(model, [&]() {
970 EXPECT_EQ(272ul, model->getNumberOfStates());
971 EXPECT_EQ(492ul, model->getNumberOfTransitions());
972 ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp);
973 auto checker = this->createModelChecker(model);
974 std::unique_ptr<storm::modelchecker::CheckResult> result;
975
976 // LTL not supported in all engines (Hybrid, PrismDd, JaniDd)
977 if (TypeParam::engine == MdpEngine::PrismSparse || TypeParam::engine == MdpEngine::JaniSparse) {
978 result = checker->check(this->env(), tasks[0]);
979 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("4/9"));
980
981 result = checker->check(this->env(), tasks[1]);
982 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("5/9"));
983
984 result = checker->check(this->env(), tasks[2]);
985 EXPECT_TRUE(this->getQualitativeResultAtInitialState(model, result));
986
987 result = checker->check(this->env(), tasks[3]);
988 EXPECT_TRUE(this->getQualitativeResultAtInitialState(model, result));
989
990 result = checker->check(this->env(), tasks[4]);
991 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("5/9"));
992
993 } else {
994 EXPECT_FALSE(checker->canHandle(tasks[0]));
995 }
996 });
997#else
998 GTEST_SKIP();
999#endif
1000}
1001
1002TYPED_TEST(MdpPrctlModelCheckerTest, LtlDice) {
1003#ifdef STORM_HAVE_LTL_MODELCHECKING_SUPPORT
1004 std::string formulasString = "Pmax=? [ X (((s1=1) U (s1=3)) U (s1=7))]";
1005 formulasString += "; Pmax=? [ (F (X (s1=6 & (XX s1=5)))) & (F G (d1!=5))]";
1006 formulasString += "; Pmax=? [ F s1=3 U (\"three\")]";
1007 formulasString += "; Pmin=? [! F (s2=6) & X \"done\"]";
1008 // Acceptance condition not in DNF (Streett, using Spot)
1009 formulasString += "; Pmax=? [ ( (G F !(\"two\")) | F G (\"three\") ) & ( (G F !(\"five\") ) | F G (\"seven\") )]";
1010
1011 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/mdp/two_dice.nm", formulasString);
1012 auto model = std::move(modelFormulas.first);
1013 auto tasks = this->getTasks(modelFormulas.second);
1014 this->execute(model, [&]() {
1015 EXPECT_EQ(169ul, model->getNumberOfStates());
1016 EXPECT_EQ(436ul, model->getNumberOfTransitions());
1017 ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp);
1018 auto checker = this->createModelChecker(model);
1019 std::unique_ptr<storm::modelchecker::CheckResult> result;
1020
1021 // LTL not supported in all engines (Hybrid, PrismDd, JaniDd)
1022 if (TypeParam::engine == MdpEngine::PrismSparse || TypeParam::engine == MdpEngine::JaniSparse) {
1023 result = checker->check(this->env(), tasks[0]);
1024 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/6"));
1025
1026 result = checker->check(this->env(), tasks[1]);
1027 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/24"));
1028
1029 result = checker->check(this->env(), tasks[2]);
1030 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/36"));
1031
1032 result = checker->check(this->env(), tasks[3]);
1033 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("5/6"));
1034
1035 result = checker->check(this->env(), tasks[4]);
1036 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("31/36"));
1037
1038 } else {
1039 EXPECT_FALSE(checker->canHandle(tasks[0]));
1040 }
1041 });
1042#else
1043 GTEST_SKIP();
1044#endif
1045}
1046
1047TYPED_TEST(MdpPrctlModelCheckerTest, LtlCoinFlips) {
1048#ifdef STORM_HAVE_LTL_MODELCHECKING_SUPPORT
1049 std::string formulasString = "Pmax=? [ G (true U (heads | \"done\")) ]";
1050 formulasString += "; Pmin=? [ G (true U (heads | \"done\")) ]";
1051 formulasString += "; Pmax=? [ G (true U<=10 (heads | \"done\")) ]";
1052 formulasString += "; Pmin=? [ G (true U<=10 (heads | \"done\")) ]";
1053 formulasString += "; Pmax=? [ X G (true U<=0 (heads | \"done\")) ]";
1054 formulasString += "; Pmax=? [ true U[10,12] heads ]";
1055 formulasString += "; Pmax=? [ X (true U[0,0] heads) ]";
1056 formulasString += "; Pmax=? [ G (!(P>=1 [\"done\"]) U<=10 (heads | P>=1 [ \"done\"])) ]";
1057 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/mdp/coin_flips.nm", formulasString);
1058 auto model = std::move(modelFormulas.first);
1059 auto tasks = this->getTasks(modelFormulas.second);
1060 this->execute(model, [&]() {
1061 EXPECT_EQ(61ul, model->getNumberOfStates());
1062 EXPECT_EQ(177ul, model->getNumberOfTransitions());
1063 ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp);
1064 auto checker = this->createModelChecker(model);
1065 std::unique_ptr<storm::modelchecker::CheckResult> result;
1066
1067 // LTL not supported in all engines (Hybrid, PrismDd, JaniDd)
1068 if (TypeParam::engine == MdpEngine::PrismSparse || TypeParam::engine == MdpEngine::JaniSparse) {
1069 result = checker->check(this->env(), tasks[0]);
1070 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1"));
1071
1072 result = checker->check(this->env(), tasks[1]);
1073 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("0"));
1074
1075 result = checker->check(this->env(), tasks[2]);
1076 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1021/1024"));
1077
1078 result = checker->check(this->env(), tasks[3]);
1079 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("0"));
1080
1081 result = checker->check(this->env(), tasks[4]);
1082 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/524288"));
1083
1084 result = checker->check(this->env(), tasks[5]);
1085 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("7/8"));
1086
1087 result = checker->check(this->env(), tasks[6]);
1088 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/2"));
1089
1090 result = checker->check(this->env(), tasks[7]);
1091 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1021/1024"));
1092
1093 } else {
1094 EXPECT_FALSE(checker->canHandle(tasks[0]));
1095 }
1096 });
1097#else
1098 GTEST_SKIP();
1099#endif
1100}
1101
1102TYPED_TEST(MdpPrctlModelCheckerTest, HOADice) {
1103 // "P=? [ F "three" & (X s=1)]"
1104 std::string formulasString = "; P=?[HOA: {\"" STORM_TEST_RESOURCES_DIR "/hoa/automaton_Fandp0Xp1.hoa\", \"p0\" -> \"three\", \"p1\" -> s2=1 }]";
1105 // "P=? [!(s2=6) U "done"]"
1106 formulasString += "; P=?[HOA: {\"" STORM_TEST_RESOURCES_DIR "/hoa/automaton_UXp0p1.hoa\", \"p0\" -> !(s2=6), \"p1\" -> \"done\" }]";
1107
1108 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/mdp/two_dice.nm", formulasString);
1109 auto model = std::move(modelFormulas.first);
1110 auto tasks = this->getTasks(modelFormulas.second);
1111 this->execute(model, [&]() {
1112 EXPECT_EQ(169ul, model->getNumberOfStates());
1113 EXPECT_EQ(436ul, model->getNumberOfTransitions());
1114 ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp);
1115 auto checker = this->createModelChecker(model);
1116 std::unique_ptr<storm::modelchecker::CheckResult> result;
1117
1118 // Not supported in all engines (Hybrid, PrismDd, JaniDd)
1119 if (TypeParam::engine == MdpEngine::PrismSparse || TypeParam::engine == MdpEngine::JaniSparse) {
1120 result = checker->check(tasks[0]);
1121 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("0"));
1122
1123 result = checker->check(tasks[1]);
1124 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("3/4"));
1125 } else {
1126 EXPECT_FALSE(checker->canHandle(tasks[0]));
1127 }
1128 });
1129}
1130
1131TYPED_TEST(MdpPrctlModelCheckerTest, SmallDiscount) {
1132 if (TypeParam::isExact || std::is_same<TypeParam, SparseDoubleLPEnvironment>::value || std::is_same<TypeParam, SparseDoubleViToLPEnvironment>::value) {
1133 GTEST_SKIP() << "Exact computations for discounted properties are not supported.";
1134 }
1135 std::string formulasString = "Rmax=? [ C ]";
1136 formulasString += "; Rmax=? [ Cdiscount=9/10 ]";
1137 formulasString += "; Rmax=? [ Cdiscount=15/16 ]";
1138 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/mdp/small_discount.nm", formulasString);
1139 auto model = std::move(modelFormulas.first);
1140 auto tasks = this->getTasks(modelFormulas.second);
1141 EXPECT_EQ(4ul, model->getNumberOfStates());
1142 EXPECT_EQ(6ul, model->getNumberOfTransitions());
1143 ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp);
1144 auto checker = this->createModelChecker(model);
1145
1146 if (TypeParam::engine == MdpEngine::PrismSparse || TypeParam::engine == MdpEngine::JaniSparse) {
1147 std::unique_ptr<storm::modelchecker::CheckResult> result = checker->check(this->env(), tasks[0]);
1148 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("5"));
1149 result = checker->check(this->env(), tasks[1]);
1150 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("18/5"));
1151 result = checker->check(this->env(), tasks[2]);
1152 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("15/4"));
1153 } else {
1154 EXPECT_FALSE(checker->canHandle(tasks[0]));
1155 EXPECT_FALSE(checker->canHandle(tasks[1]));
1156 EXPECT_FALSE(checker->canHandle(tasks[2]));
1157 }
1158}
1159
1160TYPED_TEST(MdpPrctlModelCheckerTest, OneStateDiscounting) {
1161 if (TypeParam::isExact || std::is_same<TypeParam, SparseDoubleLPEnvironment>::value || std::is_same<TypeParam, SparseDoubleViToLPEnvironment>::value) {
1162 GTEST_SKIP() << "Exact computations for discounted properties are not supported.";
1163 }
1164 std::string formulasString = "Rmax=? [ Cdiscount=9/10 ]";
1165 formulasString += "; Rmax=? [ C<=5discount=9/10 ]";
1166 formulasString += "; Rmax=? [ C<=10discount=9/10 ]";
1167 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/mdp/one_state.nm", formulasString);
1168 auto model = std::move(modelFormulas.first);
1169 auto tasks = this->getTasks(modelFormulas.second);
1170 EXPECT_EQ(1ul, model->getNumberOfStates());
1171 EXPECT_EQ(2ul, model->getNumberOfTransitions());
1172 ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp);
1173 auto checker = this->createModelChecker(model);
1174
1175 if ((TypeParam::engine == MdpEngine::PrismSparse || TypeParam::engine == MdpEngine::JaniSparse)) {
1176 std::unique_ptr<storm::modelchecker::CheckResult> result = checker->check(this->env(), tasks[0]);
1177 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1000"));
1178 result = checker->check(this->env(), tasks[1]);
1179 this->expectExactResultAtInitialState(model, result, this->parseNumber("40951/100"));
1180 result = checker->check(this->env(), tasks[2]);
1181 this->expectExactResultAtInitialState(model, result, this->parseNumber("6513215599/10000000"));
1182 } else {
1183 EXPECT_FALSE(checker->canHandle(tasks[0]));
1184 EXPECT_FALSE(checker->canHandle(tasks[1]));
1185 EXPECT_FALSE(checker->canHandle(tasks[2]));
1186 }
1187}
1188
1189TYPED_TEST(MdpPrctlModelCheckerTest, StepBoundedReachability) {
1190 std::string formulasString = "Pmax=? [ F<=0 x=5];"; // 0
1191 formulasString += "Pmax=? [ F<=1 x=5];"; // 1/2
1192 formulasString += "Pmax=? [ F<=2 x=5];"; // 3/4
1193 formulasString += "Pmax=? [ F[2,2] x=5];"; // 1/4
1194 formulasString += "Pmax=? [ F[2,3] x=5];"; // 3/8
1195 formulasString += "Pmin=? [ F[2,3] x=5];"; // 0
1196 formulasString += "Pmax=? [ x<2 U[2,2] x=5];"; // 1/4
1197 formulasString += "Pmax=? [ x<2 U[2,3] x=5];"; // 1/4
1198 formulasString += "Pmax=? [ x<3 U[2,2] x=5];"; // 1/4
1199 formulasString += "Pmax=? [ x<3 U<=4 x=5];"; // 7/8
1200 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/mdp/chain.nm", formulasString);
1201 auto model = std::move(modelFormulas.first);
1202 auto tasks = this->getTasks(modelFormulas.second);
1203 EXPECT_EQ(7ul, model->getNumberOfStates());
1204 EXPECT_EQ(16ul, model->getNumberOfTransitions());
1205 ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp);
1206 auto checker = this->createModelChecker(model);
1207
1208 if (TypeParam::engine == MdpEngine::PrismSparse || TypeParam::engine == MdpEngine::JaniSparse) {
1209 std::unique_ptr<storm::modelchecker::CheckResult> result = checker->check(this->env(), tasks[0]);
1210 this->expectExactResultAtInitialState(model, result, this->parseNumber("0"));
1211 result = checker->check(this->env(), tasks[1]);
1212 this->expectExactResultAtInitialState(model, result, this->parseNumber("1/2"));
1213 result = checker->check(this->env(), tasks[2]);
1214 this->expectExactResultAtInitialState(model, result, this->parseNumber("3/4"));
1215 result = checker->check(this->env(), tasks[3]);
1216 this->expectExactResultAtInitialState(model, result, this->parseNumber("1/4"));
1217 result = checker->check(this->env(), tasks[4]);
1218 this->expectExactResultAtInitialState(model, result, this->parseNumber("3/8"));
1219 result = checker->check(this->env(), tasks[5]);
1220 this->expectExactResultAtInitialState(model, result, this->parseNumber("0"));
1221 result = checker->check(this->env(), tasks[6]);
1222 this->expectExactResultAtInitialState(model, result, this->parseNumber("1/4"));
1223 result = checker->check(this->env(), tasks[7]);
1224 this->expectExactResultAtInitialState(model, result, this->parseNumber("1/4"));
1225 result = checker->check(this->env(), tasks[8]);
1226 this->expectExactResultAtInitialState(model, result, this->parseNumber("1/4"));
1227 result = checker->check(this->env(), tasks[9]);
1228 this->expectExactResultAtInitialState(model, result, this->parseNumber("7/8"));
1229 }
1230}
1231
1232TYPED_TEST(MdpPrctlModelCheckerTest, SimpleCommProtocol) {
1233 // see simple_comm_protocol.props
1234 std::string formulasString = "Pmax=? [ F (s = 3) ]; ";
1235 formulasString += "Pmax=? [ (s<=1) U (s=3) ]; ";
1236 formulasString += "Pmin=? [ (s<=1) U (s=3) ]; ";
1237 formulasString += "Pmax=? [ !(s=3) U (!(s<=1) & !(s=3)) ]; ";
1238
1239 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/mdp/simple_comm_protocol.prism", formulasString);
1240 auto model = std::move(modelFormulas.first);
1241 auto tasks = this->getTasks(modelFormulas.second);
1242
1243 ASSERT_EQ(4ul, tasks.size());
1244 this->execute(model, [&]() {
1245 EXPECT_EQ(4ul, model->getNumberOfStates());
1246 EXPECT_EQ(6ul, model->getNumberOfTransitions());
1247 ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp);
1248 auto checker = this->createModelChecker(model);
1249 std::unique_ptr<storm::modelchecker::CheckResult> result;
1250
1251 result = checker->check(this->env(), tasks[0]);
1252 EXPECT_NEAR(this->parseNumber("1"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1253
1254 result = checker->check(this->env(), tasks[2]);
1255 EXPECT_NEAR(this->parseNumber("0"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1256
1257 // guard against #1136
1258 if (!(TypeParam::engine == MdpEngine::PrismDd && this->env().solver().minMax().getMethod() == storm::solver::MinMaxMethod::RationalSearch)) {
1259 result = checker->check(this->env(), tasks[1]);
1260 EXPECT_NEAR(this->parseNumber("99/100"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1261
1262 result = checker->check(this->env(), tasks[3]);
1263 EXPECT_NEAR(this->parseNumber("1/100"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1264 }
1265 });
1266}
1267
1268TYPED_TEST(MdpPrctlModelCheckerTest, SimpleCommProtocolLTL) {
1269#ifdef STORM_HAVE_LTL_MODELCHECKING_SUPPORT
1270 // see simple_comm_protocol.props
1271 std::string formulasString = "Pmax=? [ (s<=1) W (s=3) ]; ";
1272 formulasString += "Pmin=? [ (s<=1) W (s=3) ]; ";
1273 formulasString += "Pmax=? [ !(s=3) U (!(s<=1) & !(s=3)) ]; ";
1274 formulasString += "Pmax=? [ !(s=2) W ((s=3 & !(s=2))) ]; ";
1275 formulasString += "Pmin=? [ !(s=2) W ((s=3 & !(s=2))) ]; ";
1276 formulasString += "Pmax=? [(!(s=2) W ((s=2) W (!(s=2) W ((s=2) W G !(s=2)))))]; ";
1277 formulasString += "Pmin=? [(!(s=2) W ((s=2) W (!(s=2) W ((s=2) W G !(s=2)))))]; ";
1278 formulasString += "Pmax=? [ (s=2) R !(s=3) ]; ";
1279 formulasString += "Pmin=? [ (s=2) R !(s=3) ]; ";
1280
1281 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/mdp/simple_comm_protocol.prism", formulasString);
1282 auto model = std::move(modelFormulas.first);
1283 auto tasks = this->getTasks(modelFormulas.second);
1284
1285 ASSERT_EQ(9ul, tasks.size());
1286 this->execute(model, [&]() {
1287 EXPECT_EQ(4ul, model->getNumberOfStates());
1288 EXPECT_EQ(6ul, model->getNumberOfTransitions());
1289 ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp);
1290 auto checker = this->createModelChecker(model);
1291 std::unique_ptr<storm::modelchecker::CheckResult> result;
1292
1293 // LTL not supported in all engines (Hybrid, PrismDd, JaniDd)
1294 if (TypeParam::engine == MdpEngine::PrismSparse || TypeParam::engine == MdpEngine::JaniSparse) {
1295 result = checker->check(this->env(), tasks[0]);
1296 EXPECT_NEAR(this->parseNumber("1"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1297
1298 result = checker->check(this->env(), tasks[1]);
1299 auto const weakUntil = this->getQuantitativeResultAtInitialState(model, result);
1300 EXPECT_NEAR(this->parseNumber("99/100"), weakUntil, this->precision());
1301
1302 result = checker->check(this->env(), tasks[2]);
1303 auto const weakUntilDual = this->getQuantitativeResultAtInitialState(model, result);
1304 EXPECT_NEAR(this->parseNumber("1/100"), weakUntilDual, this->precision());
1305
1306 EXPECT_NEAR(this->parseNumber("1"), weakUntil + weakUntilDual, this->precision());
1307
1308 result = checker->check(this->env(), tasks[3]);
1309 EXPECT_NEAR(this->parseNumber("1"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1310
1311 result = checker->check(this->env(), tasks[4]);
1312 EXPECT_NEAR(this->parseNumber("99/100"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1313
1314 result = checker->check(this->env(), tasks[5]);
1315 EXPECT_NEAR(this->parseNumber("1"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1316
1317 result = checker->check(this->env(), tasks[6]);
1318 EXPECT_NEAR(this->parseNumber("999999/1000000"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1319
1320 result = checker->check(this->env(), tasks[7]);
1321 EXPECT_NEAR(this->parseNumber("1"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1322
1323 result = checker->check(this->env(), tasks[8]);
1324 EXPECT_NEAR(this->parseNumber("1/100"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1325 } else {
1326 EXPECT_FALSE(checker->canHandle(tasks[0]));
1327 STORM_SILENT_EXPECT_THROW(checker->check(this->env(), tasks[0]), storm::exceptions::InvalidArgumentException);
1328 EXPECT_FALSE(checker->canHandle(tasks[8]));
1329 STORM_SILENT_EXPECT_THROW(checker->check(this->env(), tasks[8]), storm::exceptions::InvalidArgumentException);
1330 }
1331 });
1332#else
1333 GTEST_SKIP() << "Spot not available.";
1334#endif
1335}
1336
1337} // namespace
std::unique_ptr< storm::modelchecker::QualitativeCheckResult > getInitialStateFilter(std::shared_ptr< storm::models::sparse::Model< storm::Interval > > const &model)
double getQuantitativeResultAtInitialState(std::shared_ptr< storm::models::sparse::Model< storm::Interval > > const &model, std::unique_ptr< storm::modelchecker::CheckResult > &result)
SolverEnvironment & solver()
void setMultiplicationStyle(storm::solver::MultiplicationStyle value)
storm::solver::MinMaxMethod const & getMethod() const
void setPrecision(storm::RationalNumber value)
void setMethod(storm::solver::MinMaxMethod value, bool isSetFromDefault=false)
void setType(storm::solver::MultiplierType value, bool isSetFromDefault=false)
TopologicalSolverEnvironment & topological()
MinMaxSolverEnvironment & minMax()
MultiplierEnvironment & multiplier()
void setUnderlyingMinMaxMethod(storm::solver::MinMaxMethod value, bool isSetFromDefault=false)
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
std::shared_ptr< storm::models::symbolic::Model< LibraryType, ValueType > > buildSymbolicModel(storm::Environment const &env, storm::languages::SymbolicModelDescription const &model, std::vector< std::shared_ptr< storm::logic::Formula const > > const &formulas, bool buildFullModel=false, bool applyMaximumProgress=true, bool fixDeadlocks=true)
Definition builder.h:37
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::vector< std::shared_ptr< storm::logic::Formula const > > extractFormulasFromProperties(std::vector< storm::jani::Property > const &properties)
std::pair< storm::jani::Model, std::vector< storm::jani::Property > > convertPrismToJani(storm::prism::Program const &program, storm::converter::PrismToJaniConverterOptions options)
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
NumberType parseNumber(std::string const &value)
Parse number from string.
storm::storage::BitVector filter(std::vector< T > const &values, std::function< bool(T const &value)> const &function)
Retrieves a bit vector containing all the indices for which the value at this position makes the give...
Definition vector.h:487
std::conditional_t< storm::NumberTraits< ValueType >::HasInfinity, ValueType, ExtendedNumber< ValueType > > ExtendedValueType
The type to use for values that may be infinite.
bool isInfinity(ValueType const &a)
TargetType convertNumber(SourceType const &number)
TYPED_TEST(GraphTestAR, SymbolicProb01StochasticGameDieSmall)
Definition GraphTest.cpp:64
TYPED_TEST_SUITE(GraphTestAR, TestingTypes,)
::testing::Types< Cudd, Sylvan > TestingTypes
Definition GraphTest.cpp:61
#define STORM_EXPENSIVE_TYPED_TEST(test_suite_name, test_name)
Definition storm_gtest.h:33
#define STORM_SILENT_EXPECT_THROW(statement, expected_exception)
Definition storm_gtest.h:21