Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
RobustDtmcPrctlModelCheckerTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
4#include "test/storm_gtest.h"
5
10#include "storm/api/builder.h"
19
20std::unique_ptr<storm::modelchecker::QualitativeCheckResult> getInitialStateFilter(
21 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> const& model) {
22 return std::make_unique<storm::modelchecker::ExplicitQualitativeCheckResult<double>>(model->getInitialStates());
23}
24
25std::unique_ptr<storm::modelchecker::QualitativeCheckResult> getInitialStateFilter(std::shared_ptr<storm::models::sparse::Model<double>> const& model) {
26 return std::make_unique<storm::modelchecker::ExplicitQualitativeCheckResult<double>>(model->getInitialStates());
27}
28
30 std::unique_ptr<storm::modelchecker::CheckResult>& result) {
31 auto filter = getInitialStateFilter(model);
32 result->filter(*filter);
33 return result->asQuantitativeCheckResult<double>().getMin();
34}
35
37 std::unique_ptr<storm::modelchecker::CheckResult>& result) {
38 auto filter = getInitialStateFilter(model);
39 result->filter(*filter);
40 return result->asQuantitativeCheckResult<double>().getMin();
41}
42
43void expectThrow(std::string const& path, std::string const& formulaString,
44 std::optional<storm::UncertaintyResolutionMode> uncertaintyResolutionMode = std::nullopt) {
45 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> modelPtr = storm::parser::parseDirectEncodingModel<storm::Interval>(path);
46 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(storm::api::parseProperties(formulaString));
47
49 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
50
51 std::shared_ptr<storm::models::sparse::Dtmc<storm::Interval>> dtmc = modelPtr->as<storm::models::sparse::Dtmc<storm::Interval>>();
52 ASSERT_EQ(storm::models::ModelType::Dtmc, modelPtr->getType());
54 if (uncertaintyResolutionMode.has_value()) {
55 task.setUncertaintyResolutionMode(uncertaintyResolutionMode.value());
56 }
57
60}
61
62void expectThrowPrism(std::string const& path, std::string const& formulaString) {
64 program = program.preprocess("");
65
66 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(storm::api::parseProperties(formulaString));
67 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> modelPtr = storm::api::buildSparseModel<storm::Interval>(program, formulas);
68
70 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
71
72 std::shared_ptr<storm::models::sparse::Dtmc<storm::Interval>> dtmc = modelPtr->as<storm::models::sparse::Dtmc<storm::Interval>>();
73 ASSERT_EQ(storm::models::ModelType::Dtmc, modelPtr->getType());
75
77 STORM_SILENT_EXPECT_THROW(checker.check(env, task), storm::exceptions::InvalidArgumentException);
78}
79
80void checkExplicitModelForQuantitativeResult(std::string const& path, std::string const& formulaString, double min, double max) {
81 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> modelPtr = storm::parser::parseDirectEncodingModel<storm::Interval>(path);
82 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(storm::api::parseProperties(formulaString));
84 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
85
86 std::shared_ptr<storm::models::sparse::Dtmc<storm::Interval>> dtmc = modelPtr->as<storm::models::sparse::Dtmc<storm::Interval>>();
87 ASSERT_EQ(storm::models::ModelType::Dtmc, modelPtr->getType());
89 taskMax.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Maximize);
90
92 auto resultMax = checker.check(env, taskMax);
93 EXPECT_NEAR(max, getQuantitativeResultAtInitialState(dtmc, resultMax), 0.0001);
94
96 taskMin.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Minimize);
97
98 auto resultMin = checker.check(env, taskMin);
99 EXPECT_NEAR(min, getQuantitativeResultAtInitialState(dtmc, resultMin), 0.0001);
100}
101
102void checkPrismModelForQuantitativeResult(std::string const& path, std::string const& formulaString, double min, double max) {
104 program = program.preprocess("");
105
106 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(storm::api::parseProperties(formulaString));
107 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> modelPtr = storm::api::buildSparseModel<storm::Interval>(program, formulas);
108
110 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
111
112 std::shared_ptr<storm::models::sparse::Dtmc<storm::Interval>> dtmc = modelPtr->as<storm::models::sparse::Dtmc<storm::Interval>>();
113 ASSERT_EQ(storm::models::ModelType::Dtmc, modelPtr->getType());
115 taskMax.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Maximize);
116
118 auto resultMax = checker.check(env, taskMax);
119 EXPECT_NEAR(max, getQuantitativeResultAtInitialState(dtmc, resultMax), 0.0001);
120
122 taskMin.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Minimize);
123
124 auto resultMin = checker.check(env, taskMin);
125 EXPECT_NEAR(min, getQuantitativeResultAtInitialState(dtmc, resultMin), 0.0001);
126}
127
128void checkModelForQualitativeResult(std::string const& path, std::string const& formulaString, std::vector<storm::storage::BitVector> expectedResultVector) {
129 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> modelPtr = storm::parser::parseDirectEncodingModel<storm::Interval>(path);
130 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(storm::api::parseProperties(formulaString));
132 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
133
134 std::shared_ptr<storm::models::sparse::Dtmc<storm::Interval>> dtmc = modelPtr->as<storm::models::sparse::Dtmc<storm::Interval>>();
135 ASSERT_EQ(storm::models::ModelType::Dtmc, modelPtr->getType());
137
139 auto result = checker.check(env, task1);
140
141 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
142
143 for (size_t i = 0; i < expectedResultVector[0].size(); i++) {
144 EXPECT_EQ(expectedResultVector[0].get(i), result->template asExplicitQualitativeCheckResult<double>()[i]);
145 }
146
148
149 result = checker.check(env, task2);
150
151 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
152
153 for (size_t i = 0; i < expectedResultVector[1].size(); i++) {
154 EXPECT_EQ(expectedResultVector[1].get(i), result->template asExplicitQualitativeCheckResult<double>()[i]);
155 }
156}
157
158std::unique_ptr<storm::modelchecker::QualitativeCheckResult> getInitialStateFilter(
159 std::shared_ptr<storm::models::sparse::Model<storm::RationalNumber>> const& model) {
160 return std::make_unique<storm::modelchecker::ExplicitQualitativeCheckResult<storm::RationalNumber>>(model->getInitialStates());
161}
162
164 std::unique_ptr<storm::modelchecker::CheckResult>& result) {
165 auto filter = getInitialStateFilter(model);
166 result->filter(*filter);
167 return result->asQuantitativeCheckResult<storm::RationalNumber>().getMin();
168}
169
170std::unique_ptr<storm::modelchecker::QualitativeCheckResult> getInitialStateFilter(
171 std::shared_ptr<storm::models::sparse::Model<storm::RationalInterval>> const& model) {
172 return std::make_unique<storm::modelchecker::ExplicitQualitativeCheckResult<storm::RationalNumber>>(model->getInitialStates());
173}
174
176 std::unique_ptr<storm::modelchecker::CheckResult>& result) {
177 auto filter = getInitialStateFilter(model);
178 result->filter(*filter);
179 return result->asQuantitativeCheckResult<storm::RationalNumber>().getMin();
180}
181
182void expectThrowRational(std::string const& path, std::string const& formulaString,
183 std::optional<storm::UncertaintyResolutionMode> uncertaintyResolutionMode = std::nullopt) {
184 std::shared_ptr<storm::models::sparse::Model<storm::RationalInterval>> modelPtr = storm::parser::parseDirectEncodingModel<storm::RationalInterval>(path);
185
186 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(storm::api::parseProperties(formulaString));
187
189 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
190
191 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalInterval>> dtmc = modelPtr->as<storm::models::sparse::Dtmc<storm::RationalInterval>>();
192 ASSERT_EQ(storm::models::ModelType::Dtmc, modelPtr->getType());
194 if (uncertaintyResolutionMode.has_value()) {
195 task.setUncertaintyResolutionMode(uncertaintyResolutionMode.value());
196 }
197
200}
201
202void checkExplicitModelForQuantitativeResultRational(std::string const& path, std::string const& formulaString, storm::ExtendedRationalNumber min,
204 std::shared_ptr<storm::models::sparse::Model<storm::RationalInterval>> modelPtr = storm::parser::parseDirectEncodingModel<storm::RationalInterval>(path);
205 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(storm::api::parseProperties(formulaString));
207 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
208
209 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalInterval>> dtmc = modelPtr->as<storm::models::sparse::Dtmc<storm::RationalInterval>>();
210 ASSERT_EQ(storm::models::ModelType::Dtmc, modelPtr->getType());
212 taskMax.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Maximize);
213
215 auto resultMax = checker.check(env, taskMax);
216 EXPECT_EQ(max, getQuantitativeResultAtInitialState(dtmc, resultMax));
217
219 taskMin.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Minimize);
220
221 auto resultMin = checker.check(env, taskMin);
222 EXPECT_EQ(min, getQuantitativeResultAtInitialState(dtmc, resultMin));
223}
224
225void checkPrismModelForQuantitativeResultRational(std::string const& path, std::string const& formulaString, storm::RationalNumber min,
226 storm::RationalNumber max) {
228 program = program.preprocess("");
229
230 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(storm::api::parseProperties(formulaString));
231 std::shared_ptr<storm::models::sparse::Model<storm::RationalInterval>> modelPtr = storm::api::buildSparseModel<storm::RationalInterval>(program, formulas);
232
234 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
235
236 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalInterval>> dtmc = modelPtr->as<storm::models::sparse::Dtmc<storm::RationalInterval>>();
237 ASSERT_EQ(storm::models::ModelType::Dtmc, modelPtr->getType());
239 taskMax.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Maximize);
240
242 auto resultMax = checker.check(env, taskMax);
243 EXPECT_EQ(max, getQuantitativeResultAtInitialState(dtmc, resultMax));
244
246 taskMin.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Minimize);
247
248 auto resultMin = checker.check(env, taskMin);
249 EXPECT_EQ(min, getQuantitativeResultAtInitialState(dtmc, resultMin));
250}
251
252void makeUncertainAndCheckRational(std::string const& path, std::string const& formulaString, storm::RationalNumber amountOfUncertainty) {
254 program = program.preprocess("");
255 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas =
257 std::shared_ptr<storm::models::sparse::Model<storm::RationalNumber>> modelPtr = storm::api::buildSparseModel<storm::RationalNumber>(program, formulas);
258 auto dtmc = modelPtr->as<storm::models::sparse::Dtmc<storm::RationalNumber>>();
259
263 auto exresult = checker.check(env, taskCertain);
264 auto const certainValue = getQuantitativeResultAtInitialState(modelPtr, exresult);
265
266 storm::Environment envIntervals;
267 envIntervals.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
269 auto idtmc = transformer.transform(amountOfUncertainty)->as<storm::models::sparse::Dtmc<storm::RationalInterval>>();
271
273 taskMin.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Minimize);
274 auto iresultMin = ichecker.check(envIntervals, taskMin);
275 auto const minValue = getQuantitativeResultAtInitialState(idtmc, iresultMin);
276 EXPECT_LE(minValue, certainValue);
277
279 taskMax.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Maximize);
280 auto iresultMax = ichecker.check(envIntervals, taskMax);
281 auto const maxValue = getQuantitativeResultAtInitialState(idtmc, iresultMax);
282 EXPECT_LE(certainValue, maxValue);
283}
284
285TEST(RobustDtmcModelCheckerTest, Tiny01ReachMaxMinProbs) {
286 // Maximal Reachability probabilities using explicit format.
287 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-01.drn", "P=? [ F \"target\"];P=? [ F \"target\"]", 0.3, 0.5);
288}
289
290TEST(RobustDtmcModelCheckerTest, Tiny01MaxReachProbNoUncertaintyResolutionMode) {
291 // Nature requires a resolution mode, expect thrown.
292 expectThrow(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-01.drn", "P=? [ F \"target\"];",
293 std::make_optional<storm::UncertaintyResolutionMode>(storm::UncertaintyResolutionMode::Unset));
294}
295
296TEST(RobustDtmcModelCheckerTest, Tiny01MaxReachProbNoOptimizationDirectionButRobust) {
297 // Nature requires a resolution mode, expect thrown.
298 expectThrow(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-01.drn", "P=? [ F \"target\"];",
299 std::make_optional<storm::UncertaintyResolutionMode>(storm::UncertaintyResolutionMode::Robust));
300}
301
302TEST(RobustDtmcModelCheckerTest, Tiny02GloballyMaxMinProbs) {
303 // Globally not yet supported, expect throw.
304 expectThrow(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-02.drn", "P=? [ G \"target\"];P=? [ G \"target\"]");
305}
306
307TEST(RobustDtmcModelCheckerTest, DieIntervalsMaxMin) {
308#ifndef STORM_HAVE_SMT_SOLVER
309 GTEST_SKIP() << "No SMT solver available.";
310#endif
311 // Maxima reachability probabilities using PRISM format.
312 checkPrismModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/die-intervals.pm", "P=? [ F \"one\"];P=? [ F \"one\"]", 9.0 / 189.0, 72.0 / 189.0);
313}
314
315TEST(RobustDtmcModelCheckerTest, BrpIntervalsMaxMin) {
316#ifndef STORM_HAVE_SMT_SOLVER
317 GTEST_SKIP() << "No SMT solver available.";
318#endif
319 // Maxima reachability probabilities using PRISM format.
320 checkPrismModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/brp-32-2-intervals.pm", "P=? [ F \"error\" ];P=? [ F \"error\" ]",
321 2.559615918664207e-10, 0.0008464876763422187);
322}
323
324TEST(RobustDtmcModelCheckerTest, DieIntervalsMaxMinRewards) {
325#ifndef STORM_HAVE_SMT_SOLVER
326 GTEST_SKIP() << "No SMT solver available.";
327#endif
328 // Maxima reachability rewards using PRISM format.
329 checkPrismModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/die-intervals.pm", "R=? [ F \"done\"];R=? [ F \"done\"]", 3.25, 4.6);
330}
331
332TEST(RobustDtmcModelCheckerTest, Tiny03MaxMinRewards) {
333 // Maxima reachability rewards using explicit format.
334 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-03.drn", "R=? [ F \"target\"];R=? [ F \"target\"]", 6.5, 8.5);
335}
336
337TEST(RobustDtmcModelCheckerTest, Tiny03RewardsNoUncertaintyResolutionMode) {
338 // Nature requires a resolution mode, expect thrown.
339 expectThrow(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-03.drn", "R=? [ F \"target\"]", storm::UncertaintyResolutionMode::Unset);
340}
341
342TEST(RobustDtmcModelCheckerTest, Tiny04MaxMinRewards) {
343 // Maxima reachability rewards using explicit format - infinite reward case.
344 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-04.drn", "R=? [ F \"target\"];R=? [ F \"target\"]",
345 std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity());
346}
347
348TEST(RobustDtmcModelCheckerTest, Tiny03CumulativeRewards) {
349 // Rewards are collected in the first k states of a path, starting at the initial state (which has reward 0).
350 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-03.drn", "R=? [ C<=0 ];R=? [ C<=0 ]", 0, 0);
351 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-03.drn", "R=? [ C<=1 ];R=? [ C<=1 ]", 0, 0);
352 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-03.drn", "R=? [ C<=2 ];R=? [ C<=2 ]", 6.5, 8.5);
353 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-03.drn", "R=? [ C<=10 ];R=? [ C<=10 ]", 6.5, 8.5);
354}
355
356TEST(RobustDtmcModelCheckerTest, Tiny04CumulativeRewards) {
357 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-04.drn", "R=? [ C<=2 ];R=? [ C<=2 ]", 6.5, 8.5);
358 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-04.drn", "R=? [ C<=3 ];R=? [ C<=3 ]", 6.8, 9.2);
359 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-04.drn", "R=? [ C<=4 ];R=? [ C<=4 ]", 7.1, 9.9);
360}
361
362TEST(RobustDtmcModelCheckerTest, Tiny03CumulativeRewardsNoUncertaintyResolutionMode) {
363 expectThrow(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-03.drn", "R=? [ C<=2 ]", storm::UncertaintyResolutionMode::Unset);
364}
365
366TEST(RobustDtmcModelCheckerTest, Tiny03CumulativeRewardsRobust) {
367 expectThrow(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-03.drn", "R=? [ C<=2 ]", storm::UncertaintyResolutionMode::Robust);
368}
369
370TEST(RobustDtmcModelCheckerTest, ReachabilityTimes) {
371 // The self-loop probability p is in [0.2, 0.5], i.e., the expected time 1 / (1 - p) is in [1.25, 2].
372 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-06.drn", "T=? [ F \"target\" ];T=? [ F \"target\" ]", 1.25, 2);
373 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-03.drn", "T=? [ F \"target\" ];T=? [ F \"target\" ]", 2, 2);
374}
375
376TEST(RobustDtmcModelCheckerTest, ReachabilityTimesAndRewardsTargetStateBeforeMaybeStates) {
377 // The target state has a smaller index than the other state. The values of target states must not be mixed up with the values of the remaining states.
378 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-07.drn", "T=? [ F \"target\" ];T=? [ F \"target\" ]", 1.25, 2);
379 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-07.drn", "R=? [ F \"target\" ];R=? [ F \"target\" ]", 1.25, 2);
380}
381
382TEST(RobustDtmcModelCheckerTest, SolutionBoundsTargetStateBeforeSeveralMaybeStates) {
383 // The bounds of the maybe states must not be mixed up, otherwise state 2 would get the larger bound of state 1.
384 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> modelPtr =
385 storm::parser::parseDirectEncodingModel<storm::Interval>(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-10.drn");
386 std::shared_ptr<storm::models::sparse::Dtmc<storm::Interval>> dtmc = modelPtr->as<storm::models::sparse::Dtmc<storm::Interval>>();
388 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
389 env.solver().setForceSoundness(true);
391 std::vector<std::pair<storm::UncertaintyResolutionMode, double>> const modesAndExpectedValues = {{storm::UncertaintyResolutionMode::Maximize, 3},
392 {storm::UncertaintyResolutionMode::Minimize, 2.25}};
393 for (std::string const formulaString : {"R=? [ F \"target\" ]", "T=? [ F \"target\" ]"}) {
394 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas =
396 for (auto const& [mode, expected] : modesAndExpectedValues) {
398 task.setUncertaintyResolutionMode(mode);
399 auto result = checker.check(env, task);
400 auto const& explicitResult = result->asExplicitQuantitativeCheckResult<double>();
401 ASSERT_TRUE(explicitResult.hasLowerBounds() || explicitResult.hasUpperBounds()) << "No bound on the solution was reported.";
402 EXPECT_TRUE(explicitResult.getSolutionBounds().encloses(explicitResult.getValueVector())) << "The bounds do not enclose the values of all states.";
403 EXPECT_NEAR(expected, getQuantitativeResultAtInitialState(dtmc, result), 0.0001);
404 }
405 }
406}
407
408TEST(RobustDtmcModelCheckerTest, GraphPreservationRequired) {
409 // The self-loop interval [0, 1] allows to never reach the target, i.e., the graph of the model is not preserved.
410 expectThrow(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-08.drn", "T=? [ F \"target\" ]", storm::UncertaintyResolutionMode::Maximize);
411 expectThrow(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-08.drn", "R=? [ F \"target\" ]", storm::UncertaintyResolutionMode::Maximize);
412 expectThrow(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-08.drn", "P=? [ F \"target\" ]", storm::UncertaintyResolutionMode::Maximize);
413}
414
415TEST(RobustDtmcModelCheckerTest, GraphPreservationAfterTightening) {
416 // The self-loop interval [0, 0.5] is tightened to [0.5, 0.5] as the other transition has probability at most 0.5. The model is graph preserving.
417 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-09.drn", "T=? [ F \"target\" ];T=? [ F \"target\" ]", 2, 2);
418}
419
420TEST(RobustDtmcModelCheckerTest, ReachabilityTimesNoUncertaintyResolutionMode) {
421 expectThrow(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-06.drn", "T=? [ F \"target\" ]", storm::UncertaintyResolutionMode::Unset);
422}
423
424TEST(RobustDtmcModelCheckerTest, ReachabilityTimesRobust) {
425 expectThrow(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-06.drn", "T=? [ F \"target\" ]", storm::UncertaintyResolutionMode::Robust);
426}
427
428TEST(RobustDtmcModelCheckerTest, CrowdsQuotientIDTMC) {
429 // Ensuring equivalent behavior when checking identical model as IDTMC and IMDP (cf. CrowdsQuotientIMDP)
430 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/crowds-quotient-3-5.drn",
431 "P=? [ F \"observe0Greater1\"];P=? [ F \"observe0Greater1\"]", 0.1383409, 0.1383409);
432}
433
434TEST(RobustDtmcModelCheckerTest, TinyO2Propositional) {
435 // Propositional formula using explicit format.
436 std::vector<storm::storage::BitVector> expectedResults;
437 auto result1 = storm::storage::BitVector(3);
438 result1.set(0);
439 result1.set(2);
440 expectedResults.push_back(result1);
441 result1.complement();
442 expectedResults.push_back(result1);
443
444 checkModelForQualitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-02.drn", "\"target\";!\"target\"", expectedResults);
445}
446
447TEST(RobustDtmcModelCheckerTest, Tiny05StepBounded) {
448 // Maxima bounded reachability probabilities using explicit format.
449 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-05.drn", "P=? [ F<=0 \"a\"];P=? [ F<=0 \"a\"]", 0, 0);
450 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-05.drn", "P=? [ F<=1 \"a\"];P=? [ F<=1 \"a\"]", 0.2, 0.2);
451 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-05.drn", "P=? [ F<=2 \"a\"];P=? [ F<=2 \"a\"]", 0.36, 0.366);
452}
453
454TEST(RobustDtmcModelCheckerTest, BoundedMaxmin) {
455 // Maxima bounded reachability probabilities using explicit format.
456 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-bounded.drn", "P=? [ F<=4 \"target\"];P=? [ F<=4 \"target\"]", 0.6528, 0.81);
457 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-bounded.drn", "P=? [ F[0,4] \"target\"];P=? [ F[0,4] \"target\"]", 0.6528,
458 0.81);
459 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-bounded.drn", "P=? [ F[4,4] \"target\"];P=? [ F[4,4] \"target\"]", 0.1952,
460 0.324);
461 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-bounded.drn", "P=? [ F[4,5] \"target\"];P=? [ F[4,5] \"target\"]", 0.3236,
462 0.50292);
463 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-bounded.drn", "P=? [ F[4,6] \"target\"];P=? [ F[4,6] \"target\"]", 0.37928,
464 0.57888);
465 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-bounded.drn", "P=? [ F[2,2] \"target\"];P=? [ F[2,2] \"target\"]", 0.32,
466 0.45);
467 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-bounded.drn", "P=? [ F<=2 \"target\"];P=? [ F<=2 \"target\"]", 0.32, 0.45);
468}
469
470// ---- RationalInterval tests (exact arithmetic) ----
471
472TEST(RobustRationalDtmcModelCheckerTest, Tiny01ReachMaxMinProbs) {
473 checkExplicitModelForQuantitativeResultRational(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-01.drn", "P=? [ F \"target\"];P=? [ F \"target\"]",
474 storm::RationalNumber("3/10"), storm::RationalNumber("1/2"));
475}
476
477TEST(RobustRationalDtmcModelCheckerTest, Tiny01MaxReachProbNoUncertaintyResolutionMode) {
478 expectThrowRational(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-01.drn", "P=? [ F \"target\"];",
479 std::make_optional<storm::UncertaintyResolutionMode>(storm::UncertaintyResolutionMode::Unset));
480}
481
482TEST(RobustRationalDtmcModelCheckerTest, Tiny01MaxReachProbNoOptimizationDirectionButRobust) {
483 expectThrowRational(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-01.drn", "P=? [ F \"target\"];",
484 std::make_optional<storm::UncertaintyResolutionMode>(storm::UncertaintyResolutionMode::Robust));
485}
486
487TEST(RobustRationalDtmcModelCheckerTest, Tiny02GloballyMaxMinProbs) {
488 expectThrowRational(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-02.drn", "P=? [ G \"target\"];P=? [ G \"target\"]");
489}
490
491TEST(RobustRationalDtmcModelCheckerTest, DieIntervalsMaxMin) {
492#ifndef STORM_HAVE_SMT_SOLVER
493 GTEST_SKIP() << "No SMT solver available.";
494#endif
495 checkPrismModelForQuantitativeResultRational(STORM_TEST_RESOURCES_DIR "/idtmc/die-intervals.pm", "P=? [ F \"one\"];P=? [ F \"one\"]",
496 storm::RationalNumber("4483008223/94143178827"), storm::RationalNumber("35864065784/94143178827"));
497}
498
499TEST(RobustRationalDtmcModelCheckerTest, BrpIntervalsMaxMin) {
500#ifndef STORM_HAVE_SMT_SOLVER
501 GTEST_SKIP() << "No SMT solver available.";
502#endif
504 STORM_TEST_RESOURCES_DIR "/idtmc/brp-32-2-intervals.pm", "P=? [ F \"error\" ];P=? [ F \"error\" ]",
505 // The number is to large to be represented as a literal, so we construct it from strings.
506 storm::RationalNumber("10238464074071514998168131748974289312176706851339248682605279417683104172439385084862067764341447739354976890683145110072150529"
507 "29484271217452553595194641992099205093706027267658909966207049695357884534755950707204946503657943965652247014748702342577938440"
508 "579441829932769922685028147340905022682454110960938051"
509 "/"
510 "40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
511 "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
512 "000000000000000000000000000000000000000000000000000000000000000"),
513 storm::RationalNumber("73421101667166357614487085157865792442422423664718103404519649530149236548299533815461648662459394997073289369183682645650367121"
514 "4626220291672876565353557862092334897"
515 "/"
516 "86736173798840354720596224069595336914062500000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
517 "0000000000000000000000000000000000000000"));
518}
519
520TEST(RobustRationalDtmcModelCheckerTest, DieIntervalsMaxMinRewards) {
521#ifndef STORM_HAVE_SMT_SOLVER
522 GTEST_SKIP() << "No SMT solver available.";
523#endif
524 checkPrismModelForQuantitativeResultRational(STORM_TEST_RESOURCES_DIR "/idtmc/die-intervals.pm", "R=? [ F \"done\"];R=? [ F \"done\"]",
525 storm::RationalNumber("15544649/4782969"), storm::RationalNumber("76715008330675523/16677181699666569"));
526}
527
528TEST(RobustRationalDtmcModelCheckerTest, Tiny03MaxMinRewards) {
529 checkExplicitModelForQuantitativeResultRational(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-03.drn", "R=? [ F \"target\"];R=? [ F \"target\"]",
530 storm::RationalNumber("13/2"), storm::RationalNumber("17/2"));
531}
532
533TEST(RobustRationalDtmcModelCheckerTest, Tiny03RewardsNoUncertaintyResolutionMode) {
534 expectThrowRational(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-03.drn", "R=? [ F \"target\"]", storm::UncertaintyResolutionMode::Unset);
535}
536
537TEST(RobustRationalDtmcModelCheckerTest, Tiny04MaxMinRewards) {
538 checkExplicitModelForQuantitativeResultRational(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-04.drn", "R=? [ F \"target\"];R=? [ F \"target\"]",
541}
542
543TEST(RobustRationalDtmcModelCheckerTest, Tiny03CumulativeRewards) {
544 checkExplicitModelForQuantitativeResultRational(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-03.drn", "R=? [ C<=1 ];R=? [ C<=1 ]", storm::RationalNumber(0),
545 storm::RationalNumber(0));
546 checkExplicitModelForQuantitativeResultRational(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-03.drn", "R=? [ C<=2 ];R=? [ C<=2 ]", storm::RationalNumber("13/2"),
547 storm::RationalNumber("17/2"));
548}
549
550TEST(RobustRationalDtmcModelCheckerTest, Tiny04CumulativeRewards) {
551 checkExplicitModelForQuantitativeResultRational(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-04.drn", "R=? [ C<=3 ];R=? [ C<=3 ]", storm::RationalNumber("34/5"),
552 storm::RationalNumber("46/5"));
553}
554
555TEST(RobustRationalDtmcModelCheckerTest, Tiny03CumulativeRewardsNoUncertaintyResolutionMode) {
556 expectThrowRational(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-03.drn", "R=? [ C<=2 ]", storm::UncertaintyResolutionMode::Unset);
557}
558
559TEST(RobustRationalDtmcModelCheckerTest, ReachabilityTimes) {
560 // Value iteration reaches the exact value after finitely many steps as the model is acyclic (apart from the target).
561 checkExplicitModelForQuantitativeResultRational(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-03.drn", "T=? [ F \"target\" ];T=? [ F \"target\" ]",
562 storm::RationalNumber(2), storm::RationalNumber(2));
563}
564
565TEST(RobustRationalDtmcModelCheckerTest, AddUncertaintyBrpMax) {
566#ifndef STORM_HAVE_SMT_SOLVER
567 GTEST_SKIP() << "No SMT solver available.";
568#endif
569 makeUncertainAndCheckRational(STORM_TEST_RESOURCES_DIR "/dtmc/brp-16-2.pm", "P=? [ F \"target\"]", storm::RationalNumber("1/10"));
570 makeUncertainAndCheckRational(STORM_TEST_RESOURCES_DIR "/dtmc/brp-16-2.pm", "P=? [ F \"target\"]", storm::RationalNumber("1/20"));
571}
void checkPrismModelForQuantitativeResult(std::string const &path, std::string const &formulaString, double min, double max)
TEST(RobustDtmcModelCheckerTest, Tiny01ReachMaxMinProbs)
std::unique_ptr< storm::modelchecker::QualitativeCheckResult > getInitialStateFilter(std::shared_ptr< storm::models::sparse::Model< storm::Interval > > const &model)
void checkModelForQualitativeResult(std::string const &path, std::string const &formulaString, std::vector< storm::storage::BitVector > expectedResultVector)
void expectThrow(std::string const &path, std::string const &formulaString, std::optional< storm::UncertaintyResolutionMode > uncertaintyResolutionMode=std::nullopt)
void checkExplicitModelForQuantitativeResult(std::string const &path, std::string const &formulaString, double min, double max)
void checkPrismModelForQuantitativeResultRational(std::string const &path, std::string const &formulaString, storm::RationalNumber min, storm::RationalNumber max)
void expectThrowPrism(std::string const &path, std::string const &formulaString)
double getQuantitativeResultAtInitialState(std::shared_ptr< storm::models::sparse::Model< storm::Interval > > const &model, std::unique_ptr< storm::modelchecker::CheckResult > &result)
void makeUncertainAndCheckRational(std::string const &path, std::string const &formulaString, storm::RationalNumber amountOfUncertainty)
void checkExplicitModelForQuantitativeResultRational(std::string const &path, std::string const &formulaString, storm::ExtendedRationalNumber min, storm::ExtendedRationalNumber max)
void expectThrowRational(std::string const &path, std::string const &formulaString, std::optional< storm::UncertaintyResolutionMode > uncertaintyResolutionMode=std::nullopt)
SolverEnvironment & solver()
void setMethod(storm::solver::MinMaxMethod value, bool isSetFromDefault=false)
MinMaxSolverEnvironment & minMax()
This class represents the base class of all exception classes.
virtual std::unique_ptr< CheckResult > check(Environment const &env, CheckTask< storm::logic::Formula, SolutionType > const &checkTask)
Checks the provided formula.
This class represents a discrete-time Markov chain.
Definition Dtmc.h:16
Base class for all sparse models.
Definition Model.h:34
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
This class is a convenience transformer to add uncertainty.
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::vector< storm::jani::Property > parseProperties(storm::parser::FormulaParser &formulaParser, std::string const &inputString, boost::optional< std::set< 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
template STORM_PARSERS_API std::shared_ptr< storm::models::sparse::Model< storm::RationalInterval > > parseDirectEncodingModel< storm::RationalInterval >(std::filesystem::path const &file, DirectEncodingParserOptions const &options)
template STORM_PARSERS_API std::shared_ptr< storm::models::sparse::Model< storm::Interval > > parseDirectEncodingModel< storm::Interval >(std::filesystem::path const &file, DirectEncodingParserOptions const &options)
ExtendedValueType< ValueType > positiveInfinity()
storm::utility::ExtendedValueType< RationalNumber > ExtendedRationalNumber
The rational number type extended with the two infinities.
#define STORM_SILENT_EXPECT_THROW(statement, expected_exception)
Definition storm_gtest.h:21