Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DtmcPrctlModelCheckerTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
10#include "storm/api/builder.h"
34
35namespace {
36
37enum class DtmcEngine { PrismSparse, JaniSparse, Hybrid, PrismDd, JaniDd };
38
39#ifdef STORM_HAVE_GMM
40class SparseGmmxxGmresIluEnvironment {
41 public:
42 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // unused for sparse models
43 static const DtmcEngine engine = DtmcEngine::PrismSparse;
44 static const bool isExact = false;
45 typedef double ValueType;
46 typedef storm::models::sparse::Dtmc<ValueType> ModelType;
47 static storm::Environment createEnvironment() {
48 storm::Environment env;
49 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Gmmxx);
50 env.solver().gmmxx().setMethod(storm::solver::GmmxxLinearEquationSolverMethod::Gmres);
51 env.solver().gmmxx().setPreconditioner(storm::solver::GmmxxLinearEquationSolverPreconditioner::Ilu);
53 return env;
54 }
55};
56
57class JaniSparseGmmxxGmresIluEnvironment {
58 public:
59 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // unused for sparse models
60 static const DtmcEngine engine = DtmcEngine::JaniSparse;
61 static const bool isExact = false;
62 typedef double ValueType;
63 typedef storm::models::sparse::Dtmc<ValueType> ModelType;
64 static storm::Environment createEnvironment() {
65 storm::Environment env;
66 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Gmmxx);
67 env.solver().gmmxx().setMethod(storm::solver::GmmxxLinearEquationSolverMethod::Gmres);
68 env.solver().gmmxx().setPreconditioner(storm::solver::GmmxxLinearEquationSolverPreconditioner::Ilu);
70 return env;
71 }
72};
73
74class SparseGmmxxGmresDiagEnvironment {
75 public:
76 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // unused for sparse models
77 static const DtmcEngine engine = DtmcEngine::PrismSparse;
78 static const bool isExact = false;
79 typedef double ValueType;
80 typedef storm::models::sparse::Dtmc<ValueType> ModelType;
81 static storm::Environment createEnvironment() {
82 storm::Environment env;
83 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Gmmxx);
84 env.solver().gmmxx().setMethod(storm::solver::GmmxxLinearEquationSolverMethod::Gmres);
85 env.solver().gmmxx().setPreconditioner(storm::solver::GmmxxLinearEquationSolverPreconditioner::Diagonal);
87 return env;
88 }
89};
90
91class SparseGmmxxBicgstabIluEnvironment {
92 public:
93 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // unused for sparse models
94 static const DtmcEngine engine = DtmcEngine::PrismSparse;
95 static const bool isExact = false;
96 typedef double ValueType;
97 typedef storm::models::sparse::Dtmc<ValueType> ModelType;
98 static storm::Environment createEnvironment() {
99 storm::Environment env;
100 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Gmmxx);
101 env.solver().gmmxx().setMethod(storm::solver::GmmxxLinearEquationSolverMethod::Bicgstab);
102 env.solver().gmmxx().setPreconditioner(storm::solver::GmmxxLinearEquationSolverPreconditioner::Ilu);
104 return env;
105 }
106};
107#endif
108
109class SparseEigenDGmresEnvironment {
110 public:
111 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // unused for sparse models
112 static const DtmcEngine engine = DtmcEngine::PrismSparse;
113 static const bool isExact = false;
114 typedef double ValueType;
115 typedef storm::models::sparse::Dtmc<ValueType> ModelType;
116 static storm::Environment createEnvironment() {
117 storm::Environment env;
118 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Eigen);
119 env.solver().eigen().setMethod(storm::solver::EigenLinearEquationSolverMethod::DGmres);
120 env.solver().eigen().setPreconditioner(storm::solver::EigenLinearEquationSolverPreconditioner::Ilu);
122 return env;
123 }
124};
125
126class SparseEigenDoubleLUEnvironment {
127 public:
128 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // unused for sparse models
129 static const DtmcEngine engine = DtmcEngine::PrismSparse;
130 static const bool isExact = false;
131 typedef double ValueType;
132 typedef storm::models::sparse::Dtmc<ValueType> ModelType;
133 static storm::Environment createEnvironment() {
134 storm::Environment env;
135 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Eigen);
136 env.solver().eigen().setMethod(storm::solver::EigenLinearEquationSolverMethod::SparseLU);
137 return env;
138 }
139};
140
141class SparseEigenRationalLUEnvironment {
142 public:
143 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // unused for sparse models
144 static const DtmcEngine engine = DtmcEngine::PrismSparse;
145 static const bool isExact = true;
146 typedef storm::RationalNumber ValueType;
147 typedef storm::models::sparse::Dtmc<ValueType> ModelType;
148 static storm::Environment createEnvironment() {
149 storm::Environment env;
150 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Eigen);
151 env.solver().eigen().setMethod(storm::solver::EigenLinearEquationSolverMethod::SparseLU);
152 return env;
153 }
154};
155
156class SparseRationalEliminationEnvironment {
157 public:
158 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // unused for sparse models
159 static const DtmcEngine engine = DtmcEngine::PrismSparse;
160 static const bool isExact = true;
161 typedef storm::RationalNumber ValueType;
162 typedef storm::models::sparse::Dtmc<ValueType> ModelType;
163 static storm::Environment createEnvironment() {
164 storm::Environment env;
165 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Elimination);
166 return env;
167 }
168};
169
170class SparseNativeJacobiEnvironment {
171 public:
172 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // unused for sparse models
173 static const DtmcEngine engine = DtmcEngine::PrismSparse;
174 static const bool isExact = false;
175 typedef double ValueType;
176 typedef storm::models::sparse::Dtmc<ValueType> ModelType;
177 static storm::Environment createEnvironment() {
178 storm::Environment env;
179 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Native);
180 env.solver().native().setMethod(storm::solver::NativeLinearEquationSolverMethod::Jacobi);
182 return env;
183 }
184};
185
186class SparseNativeWalkerChaeEnvironment {
187 public:
188 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // unused for sparse models
189 static const DtmcEngine engine = DtmcEngine::PrismSparse;
190 static const bool isExact = false;
191 typedef double ValueType;
192 typedef storm::models::sparse::Dtmc<ValueType> ModelType;
193 static storm::Environment createEnvironment() {
194 storm::Environment env;
195 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Native);
196 env.solver().native().setMethod(storm::solver::NativeLinearEquationSolverMethod::WalkerChae);
199 return env;
200 }
201};
202
203class SparseNativeSorEnvironment {
204 public:
205 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // unused for sparse models
206 static const DtmcEngine engine = DtmcEngine::PrismSparse;
207 static const bool isExact = false;
208 typedef double ValueType;
209 typedef storm::models::sparse::Dtmc<ValueType> ModelType;
210 static storm::Environment createEnvironment() {
211 storm::Environment env;
212 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Native);
213 env.solver().native().setMethod(storm::solver::NativeLinearEquationSolverMethod::SOR);
215 return env;
216 }
217};
218
219class SparseNativePowerEnvironment {
220 public:
221 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // unused for sparse models
222 static const DtmcEngine engine = DtmcEngine::PrismSparse;
223 static const bool isExact = false;
224 typedef double ValueType;
225 typedef storm::models::sparse::Dtmc<ValueType> ModelType;
226 static storm::Environment createEnvironment() {
227 storm::Environment env;
228 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Native);
229 env.solver().native().setMethod(storm::solver::NativeLinearEquationSolverMethod::Power);
231 return env;
232 }
233};
234
235class SparseNativeSoundValueIterationEnvironment {
236 public:
237 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // unused for sparse models
238 static const DtmcEngine engine = DtmcEngine::PrismSparse;
239 static const bool isExact = false;
240 typedef double ValueType;
241 typedef storm::models::sparse::Dtmc<ValueType> ModelType;
242 static storm::Environment createEnvironment() {
243 storm::Environment env;
244 env.solver().setForceSoundness(true);
245 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Native);
246 env.solver().native().setMethod(storm::solver::NativeLinearEquationSolverMethod::SoundValueIteration);
248 return env;
249 }
250};
251
252class SparseNativeOptimisticValueIterationEnvironment {
253 public:
254 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // unused for sparse models
255 static const DtmcEngine engine = DtmcEngine::PrismSparse;
256 static const bool isExact = false;
257 typedef double ValueType;
258 typedef storm::models::sparse::Dtmc<ValueType> ModelType;
259 static storm::Environment createEnvironment() {
260 storm::Environment env;
261 env.solver().setForceSoundness(true);
262 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Native);
263 env.solver().native().setMethod(storm::solver::NativeLinearEquationSolverMethod::OptimisticValueIteration);
265 return env;
266 }
267};
268
269class SparseNativeGuessingValueIterationEnvironment {
270 public:
271 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // unused for sparse models
272 static const DtmcEngine engine = DtmcEngine::PrismSparse;
273 static const bool isExact = false;
274 typedef double ValueType;
275 typedef storm::models::sparse::Dtmc<ValueType> ModelType;
276 static storm::Environment createEnvironment() {
277 storm::Environment env;
278 env.solver().setForceSoundness(true);
279 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Native);
280 env.solver().native().setMethod(storm::solver::NativeLinearEquationSolverMethod::GuessingValueIteration);
283 return env;
284 }
285};
286
287class SparseNativeIntervalIterationEnvironment {
288 public:
289 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // unused for sparse models
290 static const DtmcEngine engine = DtmcEngine::PrismSparse;
291 static const bool isExact = false;
292 typedef double ValueType;
293 typedef storm::models::sparse::Dtmc<ValueType> ModelType;
294 static storm::Environment createEnvironment() {
295 storm::Environment env;
296 env.solver().setForceSoundness(true);
297 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Native);
298 env.solver().native().setMethod(storm::solver::NativeLinearEquationSolverMethod::IntervalIteration);
301 return env;
302 }
303};
304
305class SparseNativeRationalSearchEnvironment {
306 public:
307 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // unused for sparse models
308 static const DtmcEngine engine = DtmcEngine::PrismSparse;
309 static const bool isExact = true;
310 typedef storm::RationalNumber ValueType;
311 typedef storm::models::sparse::Dtmc<ValueType> ModelType;
312 static storm::Environment createEnvironment() {
313 storm::Environment env;
314 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Native);
315 env.solver().native().setMethod(storm::solver::NativeLinearEquationSolverMethod::RationalSearch);
316 return env;
317 }
318};
319
320class SparseTopologicalEigenLUEnvironment {
321 public:
322 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan; // unused for sparse models
323 static const DtmcEngine engine = DtmcEngine::PrismSparse;
324 static const bool isExact = true;
325 typedef storm::RationalNumber ValueType;
326 typedef storm::models::sparse::Dtmc<ValueType> ModelType;
327 static storm::Environment createEnvironment() {
328 storm::Environment env;
329 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Topological);
330 env.solver().topological().setUnderlyingEquationSolverType(storm::solver::EquationSolverType::Eigen);
331 env.solver().eigen().setMethod(storm::solver::EigenLinearEquationSolverMethod::SparseLU);
332 return env;
333 }
334};
335
336#ifdef STORM_HAVE_GMM
337class HybridSylvanGmmxxGmresEnvironment {
338 public:
339 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan;
340 static const DtmcEngine engine = DtmcEngine::Hybrid;
341 static const bool isExact = false;
342 typedef double ValueType;
343 typedef storm::models::symbolic::Dtmc<ddType, ValueType> ModelType;
344
345 static void checkLibraryAvailable() {
346#ifndef STORM_HAVE_SYLVAN
347 GTEST_SKIP() << "Library Sylvan not available.";
348#endif
349 }
350
351 static storm::Environment createEnvironment() {
352 storm::Environment env;
353 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Gmmxx);
354 env.solver().gmmxx().setMethod(storm::solver::GmmxxLinearEquationSolverMethod::Gmres);
356 return env;
357 }
358};
359#endif
360
361class HybridCuddNativeJacobiEnvironment {
362 public:
363 static const storm::dd::DdType ddType = storm::dd::DdType::CUDD;
364 static const DtmcEngine engine = DtmcEngine::Hybrid;
365 static const bool isExact = false;
366 typedef double ValueType;
367 typedef storm::models::symbolic::Dtmc<ddType, ValueType> ModelType;
368
369 static void checkLibraryAvailable() {
370#ifndef STORM_HAVE_CUDD
371 GTEST_SKIP() << "Library CUDD not available.";
372#endif
373 }
374
375 static storm::Environment createEnvironment() {
376 storm::Environment env;
377 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Native);
378 env.solver().native().setMethod(storm::solver::NativeLinearEquationSolverMethod::Jacobi);
380 return env;
381 }
382};
383
384class HybridCuddNativeSoundValueIterationEnvironment {
385 public:
386 static const storm::dd::DdType ddType = storm::dd::DdType::CUDD;
387 static const DtmcEngine engine = DtmcEngine::Hybrid;
388 static const bool isExact = false;
389 typedef double ValueType;
390 typedef storm::models::symbolic::Dtmc<ddType, ValueType> ModelType;
391
392 static void checkLibraryAvailable() {
393#ifndef STORM_HAVE_CUDD
394 GTEST_SKIP() << "Library CUDD not available.";
395#endif
396 }
397
398 static storm::Environment createEnvironment() {
399 storm::Environment env;
400 env.solver().setForceSoundness(true);
401 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Native);
402 env.solver().native().setMethod(storm::solver::NativeLinearEquationSolverMethod::Power);
404 return env;
405 }
406};
407
408class HybridSylvanNativeRationalSearchEnvironment {
409 public:
410 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan;
411 static const DtmcEngine engine = DtmcEngine::Hybrid;
412 static const bool isExact = true;
413 typedef storm::RationalNumber ValueType;
414 typedef storm::models::symbolic::Dtmc<ddType, ValueType> ModelType;
415
416 static void checkLibraryAvailable() {
417#ifndef STORM_HAVE_SYLVAN
418 GTEST_SKIP() << "Library Sylvan not available.";
419#endif
420 }
421
422 static storm::Environment createEnvironment() {
423 storm::Environment env;
424 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Native);
425 env.solver().native().setMethod(storm::solver::NativeLinearEquationSolverMethod::RationalSearch);
426 return env;
427 }
428};
429
430class DdSylvanNativePowerEnvironment {
431 public:
432 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan;
433 static const DtmcEngine engine = DtmcEngine::PrismDd;
434 static const bool isExact = false;
435 typedef double ValueType;
436 typedef storm::models::symbolic::Dtmc<ddType, ValueType> ModelType;
437
438 static void checkLibraryAvailable() {
439#ifndef STORM_HAVE_SYLVAN
440 GTEST_SKIP() << "Library Sylvan not available.";
441#endif
442 }
443
444 static storm::Environment createEnvironment() {
445 storm::Environment env;
446 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Native);
447 env.solver().native().setMethod(storm::solver::NativeLinearEquationSolverMethod::Power);
449 return env;
450 }
451};
452
453class JaniDdSylvanNativePowerEnvironment {
454 public:
455 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan;
456 static const DtmcEngine engine = DtmcEngine::JaniDd;
457 static const bool isExact = false;
458 typedef double ValueType;
459 typedef storm::models::symbolic::Dtmc<ddType, ValueType> ModelType;
460
461 static void checkLibraryAvailable() {
462#ifndef STORM_HAVE_SYLVAN
463 GTEST_SKIP() << "Library Sylvan not available.";
464#endif
465 }
466
467 static storm::Environment createEnvironment() {
468 storm::Environment env;
469 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Native);
470 env.solver().native().setMethod(storm::solver::NativeLinearEquationSolverMethod::Power);
472 return env;
473 }
474};
475
476class DdCuddNativeJacobiEnvironment {
477 public:
478 static const storm::dd::DdType ddType = storm::dd::DdType::CUDD;
479 static const DtmcEngine engine = DtmcEngine::PrismDd;
480 static const bool isExact = false;
481 typedef double ValueType;
482 typedef storm::models::symbolic::Dtmc<ddType, ValueType> ModelType;
483
484 static void checkLibraryAvailable() {
485#ifndef STORM_HAVE_CUDD
486 GTEST_SKIP() << "Library CUDD not available.";
487#endif
488 }
489
490 static storm::Environment createEnvironment() {
491 storm::Environment env;
492 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Native);
493 env.solver().native().setMethod(storm::solver::NativeLinearEquationSolverMethod::Power);
495 return env;
496 }
497};
498
499class DdSylvanRationalSearchEnvironment {
500 public:
501 static const storm::dd::DdType ddType = storm::dd::DdType::Sylvan;
502 static const DtmcEngine engine = DtmcEngine::PrismDd;
503 static const bool isExact = true;
504 typedef storm::RationalNumber ValueType;
505 typedef storm::models::symbolic::Dtmc<ddType, ValueType> ModelType;
506
507 static void checkLibraryAvailable() {
508#ifndef STORM_HAVE_SYLVAN
509 GTEST_SKIP() << "Library Sylvan not available.";
510#endif
511 }
512
513 static storm::Environment createEnvironment() {
514 storm::Environment env;
515 env.solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Native);
516 env.solver().native().setMethod(storm::solver::NativeLinearEquationSolverMethod::RationalSearch);
517 return env;
518 }
519};
520
521template<typename TestType>
522class DtmcPrctlModelCheckerTest : public ::testing::Test {
523 public:
524 typedef typename TestType::ValueType ValueType;
525 typedef typename storm::models::sparse::Dtmc<ValueType> SparseModelType;
526 typedef typename storm::models::symbolic::Dtmc<TestType::ddType, ValueType> SymbolicModelType;
527
528 DtmcPrctlModelCheckerTest() : _environment(TestType::createEnvironment()) {}
529
530 void SetUp() override {
531#ifndef STORM_HAVE_SMT_SOLVER
532 GTEST_SKIP() << "No SMT solver available.";
533#endif
534 if constexpr (TestType::engine == DtmcEngine::Hybrid || TestType::engine == DtmcEngine::PrismDd || TestType::engine == DtmcEngine::JaniDd) {
535 TestType::checkLibraryAvailable();
536 }
537 }
538
539 storm::Environment const& env() const {
540 return _environment;
541 }
542 ValueType parseNumber(std::string const& input) const {
544 }
545 ValueType precision() const {
546 return TestType::isExact ? parseNumber("0") : parseNumber("1e-6");
547 }
548 bool isSparseModel() const {
549 return std::is_same<typename TestType::ModelType, SparseModelType>::value;
550 }
551 bool isSymbolicModel() const {
552 return std::is_same<typename TestType::ModelType, SymbolicModelType>::value;
553 }
554
555 template<typename MT = typename TestType::ModelType>
556 typename std::enable_if<std::is_same<MT, SparseModelType>::value,
557 std::pair<std::shared_ptr<MT>, std::vector<std::shared_ptr<storm::logic::Formula const>>>>::type
558 buildModelFormulas(std::string const& pathToPrismFile, std::string const& formulasAsString, std::string const& constantDefinitionString = "") const {
559 std::pair<std::shared_ptr<MT>, std::vector<std::shared_ptr<storm::logic::Formula const>>> result;
560 storm::prism::Program program = storm::api::parseProgram(pathToPrismFile);
561 program = program.preprocess(constantDefinitionString);
562 if (TestType::engine == DtmcEngine::PrismSparse) {
564 result.first = storm::api::buildSparseModel<ValueType>(program, result.second)->template as<MT>();
565 } else if (TestType::engine == DtmcEngine::JaniSparse) {
566 auto janiData = storm::api::convertPrismToJani(program, storm::api::parsePropertiesForPrismProgram(formulasAsString, program));
567 result.second = storm::api::extractFormulasFromProperties(janiData.second);
568 result.first = storm::api::buildSparseModel<ValueType>(janiData.first, result.second)->template as<MT>();
569 }
570
571 return result;
572 }
573
574 template<typename MT = typename TestType::ModelType>
575 typename std::enable_if<std::is_same<MT, SymbolicModelType>::value,
576 std::pair<std::shared_ptr<MT>, std::vector<std::shared_ptr<storm::logic::Formula const>>>>::type
577 buildModelFormulas(std::string const& pathToPrismFile, std::string const& formulasAsString, std::string const& constantDefinitionString = "") const {
578 std::pair<std::shared_ptr<MT>, std::vector<std::shared_ptr<storm::logic::Formula const>>> result;
579 storm::prism::Program program = storm::api::parseProgram(pathToPrismFile);
580 program = program.preprocess(constantDefinitionString);
581 if (TestType::engine == DtmcEngine::Hybrid || TestType::engine == DtmcEngine::PrismDd) {
583 result.first = storm::api::buildSymbolicModel<TestType::ddType, ValueType>(this->env(), program, result.second)->template as<MT>();
584 } else if (TestType::engine == DtmcEngine::JaniDd) {
585 auto janiData = storm::api::convertPrismToJani(program, storm::api::parsePropertiesForPrismProgram(formulasAsString, program));
586 janiData.first.substituteFunctions();
587 result.second = storm::api::extractFormulasFromProperties(janiData.second);
588 result.first = storm::api::buildSymbolicModel<TestType::ddType, ValueType>(this->env(), janiData.first, result.second)->template as<MT>();
589 }
590 return result;
591 }
592
593 // buildModelFormulas for JANI file input
594 template<typename MT = typename TestType::ModelType>
595 typename std::enable_if<std::is_same<MT, SparseModelType>::value,
596 std::pair<std::shared_ptr<MT>, std::vector<std::shared_ptr<storm::logic::Formula const>>>>::type
597 buildJaniModelFormulas(std::string const& pathToJaniFile) const {
598 std::pair<std::shared_ptr<MT>, std::vector<std::shared_ptr<storm::logic::Formula const>>> result;
599 auto janiData = storm::api::parseJaniModel(pathToJaniFile);
600 result.second = storm::api::extractFormulasFromProperties(janiData.second);
601 result.first = storm::api::buildSparseModel<ValueType>(janiData.first, result.second)->template as<MT>();
602 return result;
603 }
604
605 template<typename MT = typename TestType::ModelType>
606 typename std::enable_if<std::is_same<MT, SymbolicModelType>::value,
607 std::pair<std::shared_ptr<MT>, std::vector<std::shared_ptr<storm::logic::Formula const>>>>::type
608 buildJaniModelFormulas(std::string const& pathToJaniFile) const {
609 std::pair<std::shared_ptr<MT>, std::vector<std::shared_ptr<storm::logic::Formula const>>> result;
610 auto janiData = storm::api::parseJaniModel(pathToJaniFile);
611 janiData.first.substituteFunctions();
612 result.second = storm::api::extractFormulasFromProperties(janiData.second);
613 result.first = storm::api::buildSymbolicModel<TestType::ddType, ValueType>(this->env(), janiData.first, result.second)->template as<MT>();
614 return result;
615 }
616
617 std::vector<storm::modelchecker::CheckTask<storm::logic::Formula, ValueType>> getTasks(
618 std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas) const {
619 std::vector<storm::modelchecker::CheckTask<storm::logic::Formula, ValueType>> result;
620 for (auto const& f : formulas) {
621 result.emplace_back(*f);
622 }
623 return result;
624 }
625
626 template<typename MT = typename TestType::ModelType>
627 typename std::enable_if<std::is_same<MT, SparseModelType>::value, std::shared_ptr<storm::modelchecker::AbstractModelChecker<MT>>>::type createModelChecker(
628 std::shared_ptr<MT> const& model) const {
629 if (TestType::engine == DtmcEngine::PrismSparse || TestType::engine == DtmcEngine::JaniSparse) {
630 return std::make_shared<storm::modelchecker::SparseDtmcPrctlModelChecker<SparseModelType>>(*model);
631 }
632 }
633
634 template<typename MT = typename TestType::ModelType>
635 typename std::enable_if<std::is_same<MT, SymbolicModelType>::value, std::shared_ptr<storm::modelchecker::AbstractModelChecker<MT>>>::type
636 createModelChecker(std::shared_ptr<MT> const& model) const {
637 if (TestType::engine == DtmcEngine::Hybrid) {
638 return std::make_shared<storm::modelchecker::HybridDtmcPrctlModelChecker<SymbolicModelType>>(*model);
639 } else if (TestType::engine == DtmcEngine::PrismDd || TestType::engine == DtmcEngine::JaniDd) {
640 return std::make_shared<storm::modelchecker::SymbolicDtmcPrctlModelChecker<SymbolicModelType>>(*model);
641 }
642 }
643
644 template<typename MT = typename TestType::ModelType>
645 typename std::enable_if<std::is_same<MT, SparseModelType>::value, void>::type execute(std::shared_ptr<MT> const& model,
646 std::function<void()> const& f) const {
647 f();
648 }
649
650 template<typename MT = typename TestType::ModelType>
651 typename std::enable_if<std::is_same<MT, SymbolicModelType>::value, void>::type execute(std::shared_ptr<MT> const& model,
652 std::function<void()> const& f) const {
653 model->getManager().execute(f);
654 }
655
656 bool getQualitativeResultAtInitialState(std::shared_ptr<storm::models::Model<ValueType>> const& model,
657 std::unique_ptr<storm::modelchecker::CheckResult>& result) {
658 auto filter = getInitialStateFilter(model);
659 result->filter(*filter);
660 return result->asQualitativeCheckResult().forallTrue();
661 }
662
663 storm::utility::ExtendedValueType<ValueType> getQuantitativeResultAtInitialState(std::shared_ptr<storm::models::Model<ValueType>> const& model,
664 std::unique_ptr<storm::modelchecker::CheckResult>& result) {
665 auto filter = getInitialStateFilter(model);
666 result->filter(*filter);
667 return result->asQuantitativeCheckResult<ValueType>().getMin();
668 }
669
674 void expectQuantitativeResultAtInitialState(std::shared_ptr<storm::models::Model<ValueType>> const& model,
675 std::unique_ptr<storm::modelchecker::CheckResult>& result, ValueType const& expected) {
676 EXPECT_NEAR(expected, this->getQuantitativeResultAtInitialState(model, result), this->precision());
677 if (!result->isExplicitQuantitativeCheckResult()) {
678 return; // Only explicit results carry bounds.
679 }
680 // The result is filtered to the initial states at this point, so the first entry belongs to the first initial state.
681 auto const& explicitResult = result->template asExplicitQuantitativeCheckResult<ValueType>();
682 ValueType const tolerance = TestType::isExact ? this->parseNumber("0") : this->parseNumber("1e-12");
683 if (explicitResult.hasLowerBounds()) {
684 EXPECT_LE(explicitResult.getLowerBoundVector().front(), expected + tolerance) << "The lower bound exceeds the expected value.";
685 }
686 if (explicitResult.hasUpperBounds()) {
687 EXPECT_LE(expected, explicitResult.getUpperBoundVector().front() + tolerance) << "The upper bound falls below the expected value.";
688 }
689 }
690
694 void expectExactResultAtInitialState(std::shared_ptr<storm::models::Model<ValueType>> const& model,
695 std::unique_ptr<storm::modelchecker::CheckResult>& result, ValueType const& expected) {
696 expectQuantitativeResultAtInitialState(model, result, expected);
697 if (!result->isExplicitQuantitativeCheckResult()) {
698 return; // Only explicit results carry bounds.
699 }
700 auto const& explicitResult = result->template asExplicitQuantitativeCheckResult<ValueType>();
701 ASSERT_TRUE(explicitResult.hasLowerBounds()) << "No lower bound was reported although the values are exact.";
702 ASSERT_TRUE(explicitResult.hasUpperBounds()) << "No upper bound was reported although the values are exact.";
703 EXPECT_EQ(explicitResult.getLowerBoundVector(), explicitResult.getUpperBoundVector()) << "The bounds do not pin the values down.";
704 }
705
706 private:
707 storm::Environment _environment;
708
709 std::unique_ptr<storm::modelchecker::QualitativeCheckResult> getInitialStateFilter(std::shared_ptr<storm::models::Model<ValueType>> const& model) const {
710 if (isSparseModel()) {
711 return std::make_unique<storm::modelchecker::ExplicitQualitativeCheckResult<ValueType>>(model->template as<SparseModelType>()->getInitialStates());
712 } else {
713 return std::make_unique<storm::modelchecker::SymbolicQualitativeCheckResult<TestType::ddType>>(
714 model->template as<SymbolicModelType>()->getReachableStates(), model->template as<SymbolicModelType>()->getInitialStates());
715 }
716 }
717};
718
719typedef ::testing::Types<
720#ifdef STORM_HAVE_GMM
721 SparseGmmxxGmresIluEnvironment, JaniSparseGmmxxGmresIluEnvironment, SparseGmmxxGmresDiagEnvironment, SparseGmmxxBicgstabIluEnvironment,
722 HybridSylvanGmmxxGmresEnvironment,
723#endif
724 SparseEigenDGmresEnvironment, SparseEigenDoubleLUEnvironment, SparseEigenRationalLUEnvironment, SparseRationalEliminationEnvironment,
725 SparseNativeJacobiEnvironment, SparseNativeWalkerChaeEnvironment, SparseNativeSorEnvironment, SparseNativePowerEnvironment,
726 SparseNativeSoundValueIterationEnvironment, SparseNativeOptimisticValueIterationEnvironment, SparseNativeGuessingValueIterationEnvironment,
727 SparseNativeIntervalIterationEnvironment, SparseNativeRationalSearchEnvironment, SparseTopologicalEigenLUEnvironment, HybridCuddNativeJacobiEnvironment,
728 HybridCuddNativeSoundValueIterationEnvironment, HybridSylvanNativeRationalSearchEnvironment, DdSylvanNativePowerEnvironment,
729 JaniDdSylvanNativePowerEnvironment, DdCuddNativeJacobiEnvironment, DdSylvanRationalSearchEnvironment>
731
732TYPED_TEST_SUITE(DtmcPrctlModelCheckerTest, TestingTypes, );
733
734TYPED_TEST(DtmcPrctlModelCheckerTest, Die) {
735 std::string formulasString = "P=? [F \"one\"]";
736 formulasString += "; P=? [F \"two\"]";
737 formulasString += "; P=? [F \"three\"]";
738 formulasString += "; R=? [F \"done\"]";
739
740 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/dtmc/die.pm", formulasString);
741 auto model = std::move(modelFormulas.first);
742 auto tasks = this->getTasks(modelFormulas.second);
743 this->execute(model, [&]() {
744 EXPECT_EQ(13ul, model->getNumberOfStates());
745 EXPECT_EQ(20ul, model->getNumberOfTransitions());
746 ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc);
747 auto checker = this->createModelChecker(model);
748 std::unique_ptr<storm::modelchecker::CheckResult> result;
749
750 result = checker->check(this->env(), tasks[0]);
751 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/6"));
752
753 result = checker->check(this->env(), tasks[1]);
754 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/6"));
755
756 result = checker->check(this->env(), tasks[2]);
757 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/6"));
758
759 result = checker->check(this->env(), tasks[3]);
760 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("11/3"));
761 });
762}
763
764STORM_EXPENSIVE_TYPED_TEST(DtmcPrctlModelCheckerTest, Crowds) {
765 std::string formulasString = "P=? [F observe0>1]";
766 formulasString += "; P=? [F \"observeIGreater1\"]";
767 formulasString += "; P=? [F observe1>1]";
768
769 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/dtmc/crowds-4-3.pm", formulasString);
770 auto model = std::move(modelFormulas.first);
771 auto tasks = this->getTasks(modelFormulas.second);
772 this->execute(model, [&]() {
773 EXPECT_EQ(726ul, model->getNumberOfStates());
774 EXPECT_EQ(1146ul, model->getNumberOfTransitions());
775 ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc);
776 auto checker = this->createModelChecker(model);
777 std::unique_ptr<storm::modelchecker::CheckResult> result;
778
779 result = checker->check(this->env(), tasks[0]);
780 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("78686542099694893/1268858272000000000"));
781
782 result = checker->check(this->env(), tasks[1]);
783 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("40300855878315123/1268858272000000000"));
784
785 result = checker->check(this->env(), tasks[2]);
786 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("13433618626105041/1268858272000000000"));
787 });
788}
789
790TYPED_TEST(DtmcPrctlModelCheckerTest, SynchronousLeader) {
791 std::string formulasString = "P=? [F \"elected\"]";
792 formulasString += "; P=? [F<=5 \"elected\"]";
793 formulasString += "; R=? [F \"elected\"]";
794
795 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/dtmc/leader-3-5.pm", formulasString);
796 auto model = std::move(modelFormulas.first);
797 auto tasks = this->getTasks(modelFormulas.second);
798 this->execute(model, [&]() {
799 EXPECT_EQ(273ul, model->getNumberOfStates());
800 EXPECT_EQ(397ul, model->getNumberOfTransitions());
801 ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc);
802 auto checker = this->createModelChecker(model);
803 std::unique_ptr<storm::modelchecker::CheckResult> result;
804
805 result = checker->check(this->env(), tasks[0]);
806 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1"));
807
808 result = checker->check(this->env(), tasks[1]);
809 this->expectExactResultAtInitialState(model, result, this->parseNumber("24/25"));
810
811 result = checker->check(this->env(), tasks[2]);
812 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("25/24"));
813 });
814}
815
816TEST(DtmcPrctlModelCheckerTest, BoundedReachability) {
817 std::string formulasString = "P=? [F<=1 \"a\"]";
818 formulasString += "; P=? [F[1,1] \"a\"]";
819 formulasString += "; P=? [F[0,2] \"a\"]";
820
821 std::shared_ptr<storm::models::sparse::Model<double>> modelPtr =
822 storm::parser::parseDirectEncodingModel<double>(STORM_TEST_RESOURCES_DIR "/dtmc/tiny-01.drn");
823 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(storm::api::parseProperties(formulasString));
825
826 std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc = modelPtr->as<storm::models::sparse::Dtmc<double>>();
827 ASSERT_EQ(storm::models::ModelType::Dtmc, modelPtr->getType());
829
830 // Unrolling a step bound ends at the values, so each of them is reported as its own lower and upper bound.
831 auto expectExactValue = [](std::unique_ptr<storm::modelchecker::CheckResult> const& result, double expected) {
832 EXPECT_NEAR(expected, result->asQuantitativeCheckResult<double>().getMin(), 0.0001);
833 auto const& explicitResult = result->asExplicitQuantitativeCheckResult<double>();
834 ASSERT_TRUE(explicitResult.hasLowerBounds());
835 ASSERT_TRUE(explicitResult.hasUpperBounds());
836 EXPECT_EQ(explicitResult.getLowerBoundVector(), explicitResult.getUpperBoundVector());
837 };
838
840 auto result = checker.check(env, task);
841 auto filter = std::make_unique<storm::modelchecker::ExplicitQualitativeCheckResult<double>>(dtmc->getInitialStates());
842 result->filter(*filter);
843 expectExactValue(result, 0.2);
844
846
847 result = checker.check(env, task);
848 filter = std::make_unique<storm::modelchecker::ExplicitQualitativeCheckResult<double>>(dtmc->getInitialStates());
849 result->filter(*filter);
850 expectExactValue(result, 0.2);
851
853
854 result = checker.check(env, task);
855 filter = std::make_unique<storm::modelchecker::ExplicitQualitativeCheckResult<double>>(dtmc->getInitialStates());
856 result->filter(*filter);
857 expectExactValue(result, 0.366);
858}
859
860TEST(DtmcPrctlModelCheckerTest, AllUntilProbabilities) {
861#ifndef STORM_HAVE_SMT_SOLVER
862 GTEST_SKIP() << "No SMT solver available.";
863#endif
864 std::string formulasString = "P=? [F \"one\"]";
865 formulasString += "; P=? [F \"two\"]";
866 formulasString += "; P=? [F \"three\"]";
867
868 storm::prism::Program program = storm::api::parseProgram(STORM_TEST_RESOURCES_DIR "/dtmc/die.pm");
870 std::vector<storm::modelchecker::CheckTask<storm::logic::Formula, double>> tasks;
871 for (auto const& f : formulas) {
872 tasks.emplace_back(*f);
873 }
874 auto model = storm::api::buildSparseModel<double>(program, formulas)->template as<storm::models::sparse::Dtmc<double>>();
875 EXPECT_EQ(13ul, model->getNumberOfStates());
876 EXPECT_EQ(20ul, model->getNumberOfTransitions());
877
878 storm::storage::SparseMatrix<double> matrix = model->getTransitionMatrix();
879 storm::storage::BitVector initialStates(13);
880 initialStates.set(0);
881 storm::storage::BitVector phiStates(13);
882 storm::storage::BitVector psiStates(13);
883 psiStates.set(7);
884 psiStates.set(8);
885 psiStates.set(9);
886 psiStates.set(10);
887 psiStates.set(11);
888 psiStates.set(12);
890 storm::solver::SolveGoal<double> goal(*model, tasks[0]);
891 std::vector<double> result = storm::modelchecker::helper::SparseDtmcPrctlHelper<double>::computeAllUntilProbabilities(env, std::move(goal), matrix,
892 initialStates, phiStates, psiStates);
893
894 EXPECT_NEAR(1.0 / 6, result[7], 1e-6);
895 EXPECT_NEAR(1.0 / 6, result[8], 1e-6);
896 EXPECT_NEAR(1.0 / 6, result[9], 1e-6);
897 EXPECT_NEAR(1.0 / 6, result[10], 1e-6);
898 EXPECT_NEAR(1.0 / 6, result[11], 1e-6);
899 EXPECT_NEAR(1.0 / 6, result[12], 1e-6);
900
901 phiStates.set(6);
902 psiStates.set(1);
903 storm::solver::SolveGoal<double> goal2(*model, tasks[0]);
904 result = storm::modelchecker::helper::SparseDtmcPrctlHelper<double>::computeAllUntilProbabilities(env, std::move(goal2), matrix, initialStates, phiStates,
905 psiStates);
906
907 EXPECT_NEAR(1, result[0], 1e-6);
908 EXPECT_NEAR(0.5, result[1], 1e-6);
909 EXPECT_NEAR(0.5, result[2], 1e-6);
910 EXPECT_NEAR(0.25, result[5], 1e-6);
911 EXPECT_NEAR(0, result[7], 1e-6);
912 EXPECT_NEAR(0, result[8], 1e-6);
913 EXPECT_NEAR(0, result[9], 1e-6);
914 EXPECT_NEAR(0.125, result[10], 1e-6);
915 EXPECT_NEAR(0.125, result[11], 1e-6);
916 EXPECT_NEAR(0, result[12], 1e-6);
917}
918
919TYPED_TEST(DtmcPrctlModelCheckerTest, LtlProbabilitiesDie) {
920#ifdef STORM_HAVE_LTL_MODELCHECKING_SUPPORT
921 std::string formulasString = "P=? [(X s>0) U (s=7 & d=2)]";
922 formulasString += "; P=? [ X (((s=1) U (s=3)) U (s=7))]";
923 formulasString += "; P=? [ (F (X (s=6 & (XX s=5)))) & (F G (d!=5))]";
924 formulasString += "; P=? [ F (s=3 U (\"three\"))]";
925 formulasString += "; P=? [ F s=3 U (\"three\")]";
926 formulasString += "; P=? [ F (s=6) & X \"done\"]";
927 formulasString += "; P=? [ (F s=6) & (X \"done\")]";
928
929 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/dtmc/die.pm", formulasString);
930 auto model = std::move(modelFormulas.first);
931 auto tasks = this->getTasks(modelFormulas.second);
932 this->execute(model, [&]() {
933 EXPECT_EQ(13ul, model->getNumberOfStates());
934 EXPECT_EQ(20ul, model->getNumberOfTransitions());
935 ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc);
936 auto checker = this->createModelChecker(model);
937 std::unique_ptr<storm::modelchecker::CheckResult> result;
938
939 // LTL not supported in all engines (Hybrid, PrismDd, JaniDd)
940 if (TypeParam::engine == DtmcEngine::PrismSparse || TypeParam::engine == DtmcEngine::JaniSparse) {
941 result = checker->check(tasks[0]);
942 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/6"));
943
944 result = checker->check(tasks[1]);
945 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/6"));
946
947 result = checker->check(tasks[2]);
948 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/24"));
949
950 result = checker->check(tasks[3]);
951 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/6"));
952
953 result = checker->check(tasks[4]);
954 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("0"));
955
956 result = checker->check(tasks[5]);
957 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/6"));
958
959 result = checker->check(tasks[6]);
960 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("0"));
961 } else {
962 EXPECT_FALSE(checker->canHandle(tasks[0]));
963 }
964 });
965#else
966 GTEST_SKIP();
967#endif
968}
969
970TYPED_TEST(DtmcPrctlModelCheckerTest, LtlProbabilitiesSynchronousLeader) {
971#ifdef STORM_HAVE_LTL_MODELCHECKING_SUPPORT
972 std::string formulasString = "P=? [X (u1=true U \"elected\")]";
973 formulasString += "; P=? [X !(u1=true U \"elected\")]";
974 formulasString += "; P=? [X v1=2 & X v1=1]";
975 formulasString += "; P=? [(X v1=2) & (X v1=1)]";
976 formulasString += "; P=? [(!X v1=2) & (X v1=1)]";
977
978 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/dtmc/leader-3-5.pm", formulasString);
979 auto model = std::move(modelFormulas.first);
980 auto tasks = this->getTasks(modelFormulas.second);
981 this->execute(model, [&]() {
982 EXPECT_EQ(273ul, model->getNumberOfStates());
983 EXPECT_EQ(397ul, model->getNumberOfTransitions());
984 ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc);
985 auto checker = this->createModelChecker(model);
986 std::unique_ptr<storm::modelchecker::CheckResult> result;
987
988 // LTL not supported in all engines (Hybrid, PrismDd, JaniDd)
989 if (TypeParam::engine == DtmcEngine::PrismSparse || TypeParam::engine == DtmcEngine::JaniSparse) {
990 result = checker->check(tasks[0]);
991 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("16/25"));
992
993 result = checker->check(tasks[1]);
994 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("9/25"));
995
996 result = checker->check(tasks[2]);
997 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/25"));
998
999 result = checker->check(tasks[3]);
1000 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("0"));
1001
1002 result = checker->check(tasks[4]);
1003 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/5"));
1004
1005 } else {
1006 EXPECT_FALSE(checker->canHandle(tasks[0]));
1007 }
1008 });
1009#else
1010 GTEST_SKIP();
1011#endif
1012}
1013
1014TYPED_TEST(DtmcPrctlModelCheckerTest, HOAProbabilitiesDie) {
1015 // "P=? [(X s>0) U (s=7 & d=2)]"
1016 std::string formulasString = "P=?[HOA: {\"" STORM_TEST_RESOURCES_DIR "/hoa/automaton_UXp0p1.hoa\", \"p0\" -> (s>0), \"p1\" -> (s=7 & d=2) }]";
1017 // "P=? [(X s>0) U (d=4 | d=2)]"
1018 formulasString += "; P=?[HOA: {\"" STORM_TEST_RESOURCES_DIR "/hoa/automaton_UXp0p1.hoa\", \"p0\" -> (s>0), \"p1\" -> (d=4 | d=2) }]";
1019 // "P=? [ (F s=4) & (X \"three\")]"
1020 formulasString += "; P=?[HOA: {\"" STORM_TEST_RESOURCES_DIR "/hoa/automaton_Fandp0Xp1.hoa\", \"p0\" -> (s=4), \"p1\" -> \"three\" }]";
1021 // "P=? [ (F s=6) & (X \"done\")]"
1022 formulasString += "; P=?[HOA: {\"" STORM_TEST_RESOURCES_DIR "/hoa/automaton_Fandp0Xp1.hoa\", \"p0\" -> (s=6), \"p1\" -> \"done\" }]";
1023 // "P=? [ (F s=6) & (X !\"done\")]"
1024 formulasString += "; P=?[HOA: {\"" STORM_TEST_RESOURCES_DIR "/hoa/automaton_Fandp0Xp1.hoa\", \"p0\" -> (s=6), \"p1\" -> !\"done\" }]";
1025 // "P=? [ (F (s=4 | s=5)) & (X (\"three\" | \"five\"))]"
1026 formulasString += "; P=?[HOA: {\"" STORM_TEST_RESOURCES_DIR "/hoa/automaton_Fandp0Xp1.hoa\", \"p0\" -> (s=4 | s=5), \"p1\" -> s=7 & (d=3 | d=5) }]";
1027 // "P=? [ (F (s=4 | s=5)) & (X (\"three\" | \"five\"))]"
1028 formulasString += "; P>0.3[HOA: {\"" STORM_TEST_RESOURCES_DIR "/hoa/automaton_Fandp0Xp1.hoa\", \"p0\" -> (s=4 | s=5), \"p1\" -> s=7 & (d=3 | d=5) }]";
1029
1030 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/dtmc/die.pm", formulasString);
1031 auto model = std::move(modelFormulas.first);
1032 auto tasks = this->getTasks(modelFormulas.second);
1033 this->execute(model, [&]() {
1034 EXPECT_EQ(13ul, model->getNumberOfStates());
1035 EXPECT_EQ(20ul, model->getNumberOfTransitions());
1036 ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc);
1037 auto checker = this->createModelChecker(model);
1038 std::unique_ptr<storm::modelchecker::CheckResult> result;
1039
1040 // Not supported in all engines (Hybrid, PrismDd, JaniDd)
1041 if (TypeParam::engine == DtmcEngine::PrismSparse || TypeParam::engine == DtmcEngine::JaniSparse) {
1042 result = checker->check(tasks[0]);
1043 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/6"));
1044
1045 result = checker->check(tasks[1]);
1046 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/3"));
1047
1048 result = checker->check(tasks[2]);
1049 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/6"));
1050
1051 result = checker->check(tasks[3]);
1052 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/6"));
1053
1054 result = checker->check(tasks[4]);
1055 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/8"));
1056
1057 result = checker->check(tasks[5]);
1058 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("1/3"));
1059
1060 result = checker->check(tasks[6]);
1061 EXPECT_TRUE(this->getQualitativeResultAtInitialState(model, result));
1062 } else {
1063 EXPECT_FALSE(checker->canHandle(tasks[0]));
1064 }
1065 });
1066}
1067
1068TYPED_TEST(DtmcPrctlModelCheckerTest, SmallDiscount) {
1069 if (TypeParam::isExact) {
1070 GTEST_SKIP() << "Exact computations for discounted properties are not supported.";
1071 }
1072 std::string formulasString = "R=? [ C ]";
1073 formulasString += "; R=? [ Cdiscount=9/10 ]";
1074 formulasString += "; R=? [ Cdiscount=15/16 ]";
1075 formulasString += "; R=? [ C<5discount=9/10 ]";
1076 formulasString += "; R=? [ C<5discount=15/16 ]";
1077 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/dtmc/small_discount.nm", formulasString);
1078 auto model = std::move(modelFormulas.first);
1079 auto tasks = this->getTasks(modelFormulas.second);
1080 EXPECT_EQ(3ul, model->getNumberOfStates());
1081 EXPECT_EQ(4ul, model->getNumberOfTransitions());
1082 ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc);
1083 auto checker = this->createModelChecker(model);
1084
1085 if (TypeParam::engine == DtmcEngine::PrismSparse || TypeParam::engine == DtmcEngine::JaniSparse) {
1086 std::unique_ptr<storm::modelchecker::CheckResult> result = checker->check(this->env(), tasks[0]);
1087 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("5"));
1088
1089 result = checker->check(this->env(), tasks[1]);
1090 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("45/14"));
1091 result = checker->check(this->env(), tasks[2]);
1092 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("15/4"));
1093 result = checker->check(this->env(), tasks[3]);
1094 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("12591/6250"));
1095 result = checker->check(this->env(), tasks[4]);
1096 this->expectQuantitativeResultAtInitialState(model, result, this->parseNumber("555/256"));
1097 } else {
1098 EXPECT_FALSE(checker->canHandle(tasks[0]));
1099 EXPECT_FALSE(checker->canHandle(tasks[1]));
1100 EXPECT_FALSE(checker->canHandle(tasks[2]));
1101 EXPECT_FALSE(checker->canHandle(tasks[3]));
1102 EXPECT_FALSE(checker->canHandle(tasks[4]));
1103 }
1104}
1105
1106TYPED_TEST(DtmcPrctlModelCheckerTest, DieJaniProperties) {
1107 // Properties are from JANI file in specific order
1108 auto modelFormulas = this->buildJaniModelFormulas(STORM_TEST_RESOURCES_DIR "/dtmc/die_janiproperties.jani");
1109 auto model = std::move(modelFormulas.first);
1110 auto tasks = this->getTasks(modelFormulas.second);
1111 this->execute(model, [&]() {
1112 EXPECT_EQ(13ul, model->getNumberOfStates());
1113 EXPECT_EQ(20ul, model->getNumberOfTransitions());
1114 ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc);
1115 auto checker = this->createModelChecker(model);
1116 std::unique_ptr<storm::modelchecker::CheckResult> result;
1117
1118 // N0: Probability to throw a six
1119 result = checker->check(this->env(), tasks[0]);
1120 EXPECT_NEAR(this->parseNumber("1/6"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1121
1122 // N1: Expected number of coin flips
1123 result = checker->check(this->env(), tasks[1]);
1124 EXPECT_NEAR(this->parseNumber("11/3"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1125
1126 // N9: Until vs weak until
1127 result = checker->check(this->env(), tasks[9]);
1128 EXPECT_NEAR(this->parseNumber("0"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1129
1130 // N10: Weak until dual
1131 result = checker->check(this->env(), tasks[10]);
1132 auto const weakUntilDual = this->getQuantitativeResultAtInitialState(model, result);
1133 EXPECT_NEAR(this->parseNumber("1/4"), weakUntilDual, this->precision());
1134
1135 // N11: Release dual
1136 result = checker->check(this->env(), tasks[11]);
1137 auto const releaseDual = this->getQuantitativeResultAtInitialState(model, result);
1138 EXPECT_NEAR(this->parseNumber("1/6"), releaseDual, this->precision());
1139
1140 // Properties below need LTL
1141#ifdef STORM_HAVE_LTL_MODELCHECKING_SUPPORT
1142 // N2: Conjunction of path formulas
1143 if (checker->canHandle(tasks[2])) {
1144 result = checker->check(this->env(), tasks[2]);
1145 EXPECT_NEAR(this->parseNumber("1/12"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1146 }
1147
1148 // N3: Disjunction of path formulas
1149 if (checker->canHandle(tasks[3])) {
1150 result = checker->check(this->env(), tasks[3]);
1151 EXPECT_NEAR(this->parseNumber("11/12"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1152 }
1153
1154 // N4: Negation of a path formula
1155 if (checker->canHandle(tasks[4])) {
1156 result = checker->check(this->env(), tasks[4]);
1157 EXPECT_NEAR(this->parseNumber("5/6"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1158 }
1159
1160 // N5: Implication of path formulas
1161 if (checker->canHandle(tasks[5])) {
1162 result = checker->check(this->env(), tasks[5]);
1163 EXPECT_NEAR(this->parseNumber("11/12"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1164 }
1165
1166 // N6: Conjunction of state formulas
1167
1168 // N7: Weak until
1169 if (checker->canHandle(tasks[7])) {
1170 result = checker->check(this->env(), tasks[7]);
1171 auto const weakUntil = this->getQuantitativeResultAtInitialState(model, result);
1172 EXPECT_NEAR(this->parseNumber("3/4"), weakUntil, this->precision());
1173 EXPECT_NEAR(this->parseNumber("1"), weakUntil + weakUntilDual, this->precision());
1174 }
1175
1176 // N8: Release
1177 if (checker->canHandle(tasks[8])) {
1178 result = checker->check(this->env(), tasks[8]);
1179 auto const release = this->getQuantitativeResultAtInitialState(model, result);
1180 EXPECT_NEAR(this->parseNumber("5/6"), release, this->precision());
1181 EXPECT_NEAR(this->parseNumber("1"), release + releaseDual, this->precision());
1182 }
1183#endif
1184 });
1185}
1186
1187TYPED_TEST(DtmcPrctlModelCheckerTest, SimpleCommProtocol) {
1188 // see simple_comm_protocol.props
1189 std::string formulasString = "P=? [ F (s = 3) ]; ";
1190 formulasString += "P=? [ (s<=1) U (s=3) ]; ";
1191 formulasString += "P=? [ !(s=3) U (!(s<=1) & !(s=3)) ]; ";
1192
1193 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/dtmc/simple_comm_protocol.prism", formulasString);
1194 auto model = std::move(modelFormulas.first);
1195 auto tasks = this->getTasks(modelFormulas.second);
1196
1197 ASSERT_EQ(3ul, tasks.size());
1198 this->execute(model, [&]() {
1199 EXPECT_EQ(4ul, model->getNumberOfStates());
1200 EXPECT_EQ(5ul, model->getNumberOfTransitions());
1201 ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc);
1202 auto checker = this->createModelChecker(model);
1203 std::unique_ptr<storm::modelchecker::CheckResult> result;
1204
1205 result = checker->check(this->env(), tasks[0]);
1206 EXPECT_NEAR(this->parseNumber("1"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1207
1208 result = checker->check(this->env(), tasks[1]);
1209 EXPECT_NEAR(this->parseNumber("99/100"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1210
1211 result = checker->check(this->env(), tasks[2]);
1212 EXPECT_NEAR(this->parseNumber("1/100"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1213 });
1214}
1215
1216TYPED_TEST(DtmcPrctlModelCheckerTest, SimpleCommProtocolLTL) {
1217#ifdef STORM_HAVE_LTL_MODELCHECKING_SUPPORT
1218 // see simple_comm_protocol.props
1219 std::string formulasString = "P=? [ (s<=1) W (s=3) ]; ";
1220 formulasString += "P=? [ !(s=3) U (!(s<=1) & !(s=3)) ]; ";
1221 formulasString += "P=? [ !(s=2) W ((s=3 & !(s=2))) ]; ";
1222 formulasString += "P=? [(!(s=2) W ((s=2) W (!(s=2) W ((s=2) W G !(s=2)))))]; ";
1223 formulasString += "P=? [ (s=2) R !(s=3) ]; ";
1224
1225 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/dtmc/simple_comm_protocol.prism", formulasString);
1226 auto model = std::move(modelFormulas.first);
1227 auto tasks = this->getTasks(modelFormulas.second);
1228
1229 ASSERT_EQ(5ul, tasks.size());
1230 this->execute(model, [&]() {
1231 EXPECT_EQ(4ul, model->getNumberOfStates());
1232 EXPECT_EQ(5ul, model->getNumberOfTransitions());
1233 ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc);
1234 auto checker = this->createModelChecker(model);
1235 std::unique_ptr<storm::modelchecker::CheckResult> result;
1236
1237 // LTL not supported in all engines (Hybrid, PrismDd, JaniDd)
1238 if (TypeParam::engine == DtmcEngine::PrismSparse || TypeParam::engine == DtmcEngine::JaniSparse) {
1239 result = checker->check(this->env(), tasks[0]);
1240 auto const weakUntil = this->getQuantitativeResultAtInitialState(model, result);
1241 EXPECT_NEAR(this->parseNumber("99/100"), weakUntil, this->precision());
1242
1243 result = checker->check(this->env(), tasks[1]);
1244 auto const weakUntilDual = this->getQuantitativeResultAtInitialState(model, result);
1245 EXPECT_NEAR(this->parseNumber("1/100"), weakUntilDual, this->precision());
1246
1247 EXPECT_NEAR(this->parseNumber("1"), weakUntil + weakUntilDual, this->precision());
1248
1249 result = checker->check(this->env(), tasks[2]);
1250 EXPECT_NEAR(this->parseNumber("99/100"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1251
1252 result = checker->check(this->env(), tasks[3]);
1253 EXPECT_NEAR(this->parseNumber("999999/1000000"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1254
1255 result = checker->check(this->env(), tasks[4]);
1256 EXPECT_NEAR(this->parseNumber("1/100"), this->getQuantitativeResultAtInitialState(model, result), this->precision());
1257 } else {
1258 EXPECT_FALSE(checker->canHandle(tasks[0]));
1259 STORM_SILENT_EXPECT_THROW(checker->check(this->env(), tasks[0]), storm::exceptions::InvalidArgumentException);
1260 EXPECT_FALSE(checker->canHandle(tasks[4]));
1261 STORM_SILENT_EXPECT_THROW(checker->check(this->env(), tasks[4]), storm::exceptions::InvalidArgumentException);
1262 }
1263 });
1264#else
1265 GTEST_SKIP() << "Spot not available.";
1266#endif
1267}
1268
1269} // namespace
TEST(RegionConstraintCheckerTest, AffineConstraintHoldsThroughout)
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)
void setPrecision(storm::RationalNumber value)
void setMethod(storm::solver::EigenLinearEquationSolverMethod value, bool isSetFromDefault=false)
void setPreconditioner(storm::solver::EigenLinearEquationSolverPreconditioner value)
SolverEnvironment & solver()
void setMethod(storm::solver::GmmxxLinearEquationSolverMethod value)
void setPrecision(storm::RationalNumber value)
void setPreconditioner(storm::solver::GmmxxLinearEquationSolverPreconditioner value)
void setMaximalNumberOfIterations(uint64_t value)
void setPrecision(storm::RationalNumber value)
void setMethod(storm::solver::NativeLinearEquationSolverMethod value, bool isSetFromDefault=false)
TopologicalSolverEnvironment & topological()
void setLinearEquationSolverType(storm::solver::EquationSolverType const &value, bool isSetFromDefault=false)
EigenSolverEnvironment & eigen()
NativeSolverEnvironment & native()
GmmxxSolverEnvironment & gmmxx()
void setUnderlyingEquationSolverType(storm::solver::EquationSolverType value, bool isSetFromDefault=false)
virtual std::unique_ptr< CheckResult > check(Environment const &env, CheckTask< storm::logic::Formula, SolutionType > const &checkTask)
Checks the provided formula.
static std::vector< SolutionType > computeAllUntilProbabilities(Environment const &env, storm::solver::SolveGoal< ValueType, SolutionType > &&goal, storm::storage::SparseMatrix< ValueType > const &transitionMatrix, storm::storage::BitVector const &initialStates, storm::storage::BitVector const &phiStates, storm::storage::BitVector const &psiStates)
This class represents a discrete-time Markov chain.
Definition Dtmc.h:16
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
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
A class that holds a possibly non-square matrix in the compressed row storage format.
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::vector< storm::jani::Property > parseProperties(storm::parser::FormulaParser &formulaParser, std::string const &inputString, boost::optional< std::set< std::string > > const &propertyFilter)
std::pair< storm::jani::Model, std::vector< storm::jani::Property > > parseJaniModel(std::string const &filename, boost::optional< std::vector< std::string > > const &propertyFilter)
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
NumberType parseNumber(std::string const &value)
Parse number from string.
template STORM_PARSERS_API std::shared_ptr< storm::models::sparse::Model< double > > parseDirectEncodingModel< double >(std::filesystem::path const &file, DirectEncodingParserOptions const &options)
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.
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