Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
RobustMdpPrctlModelCheckerTest.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"
20
21std::unique_ptr<storm::modelchecker::QualitativeCheckResult> getInitialStateFilter(
22 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> const& model) {
23 return std::make_unique<storm::modelchecker::ExplicitQualitativeCheckResult<double>>(model->getInitialStates());
24}
25
26std::unique_ptr<storm::modelchecker::QualitativeCheckResult> getInitialStateFilter(std::shared_ptr<storm::models::sparse::Model<double>> const& model) {
27 return std::make_unique<storm::modelchecker::ExplicitQualitativeCheckResult<double>>(model->getInitialStates());
28}
29
30std::unique_ptr<storm::modelchecker::QualitativeCheckResult> getInitialStateFilter(
31 std::shared_ptr<storm::models::sparse::Model<storm::RationalNumber>> const& model) {
32 return std::make_unique<storm::modelchecker::ExplicitQualitativeCheckResult<storm::RationalNumber>>(model->getInitialStates());
33}
34
36 std::unique_ptr<storm::modelchecker::CheckResult>& result) {
37 auto filter = getInitialStateFilter(model);
38 result->filter(*filter);
39 return result->asQuantitativeCheckResult<storm::RationalNumber>().getMin();
40}
41
42std::unique_ptr<storm::modelchecker::QualitativeCheckResult> getInitialStateFilter(
43 std::shared_ptr<storm::models::sparse::Model<storm::RationalInterval>> const& model) {
44 return std::make_unique<storm::modelchecker::ExplicitQualitativeCheckResult<storm::RationalNumber>>(model->getInitialStates());
45}
46
48 std::unique_ptr<storm::modelchecker::CheckResult>& result) {
49 auto filter = getInitialStateFilter(model);
50 result->filter(*filter);
51 return result->asQuantitativeCheckResult<double>().getMin();
52}
53
55 std::unique_ptr<storm::modelchecker::CheckResult>& result) {
56 auto filter = getInitialStateFilter(model);
57 result->filter(*filter);
58 return result->asQuantitativeCheckResult<double>().getMin();
59}
60
62 std::unique_ptr<storm::modelchecker::CheckResult>& result) {
63 auto filter = getInitialStateFilter(model);
64 result->filter(*filter);
65 return result->asQuantitativeCheckResult<storm::RationalNumber>().getMin();
66}
67
68void expectSolutionBoundsSound(std::unique_ptr<storm::modelchecker::CheckResult> const& result, double expected) {
69 auto const& explicitResult = result->asExplicitQuantitativeCheckResult<double>();
70 ASSERT_TRUE(explicitResult.hasLowerBounds() || explicitResult.hasUpperBounds()) << "No bound on the solution was reported.";
71 if (explicitResult.hasLowerBounds()) {
72 EXPECT_LE(explicitResult.getLowerBoundVector().front(), expected + 0.0001) << "The lower bound exceeds the expected value.";
73 }
74 if (explicitResult.hasUpperBounds()) {
75 EXPECT_LE(expected, explicitResult.getUpperBoundVector().front() + 0.0001) << "The upper bound falls below the expected value.";
76 }
77}
78
79void expectSolutionBoundsSound(std::unique_ptr<storm::modelchecker::CheckResult> const& result, storm::RationalNumber const& expected) {
80 auto const& explicitResult = result->asExplicitQuantitativeCheckResult<storm::RationalNumber>();
81 ASSERT_TRUE(explicitResult.hasLowerBounds() || explicitResult.hasUpperBounds()) << "No bound on the solution was reported.";
82 if (explicitResult.hasLowerBounds()) {
83 EXPECT_LE(explicitResult.getLowerBoundVector().front(), expected) << "The lower bound exceeds the expected value.";
84 }
85 if (explicitResult.hasUpperBounds()) {
86 EXPECT_LE(expected, explicitResult.getUpperBoundVector().front()) << "The upper bound falls below the expected value.";
87 }
88}
89
90template<typename ValueType>
91void expectBoundsEncloseValues(std::unique_ptr<storm::modelchecker::CheckResult> const& result) {
92 auto const& explicitResult = result->asExplicitQuantitativeCheckResult<ValueType>();
93 EXPECT_TRUE(explicitResult.getSolutionBounds().encloses(explicitResult.getValueVector())) << "The bounds do not enclose the values of all states.";
94}
95
96void expectThrow(std::string const& path, std::string const& formulaString) {
97 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> modelPtr = storm::parser::parseDirectEncodingModel<storm::Interval>(path);
98 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(storm::api::parseProperties(formulaString));
99
101 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
102
103 std::shared_ptr<storm::models::sparse::Mdp<storm::Interval>> mdp = modelPtr->as<storm::models::sparse::Mdp<storm::Interval>>();
104 ASSERT_EQ(storm::models::ModelType::Mdp, modelPtr->getType());
106
108 STORM_SILENT_EXPECT_THROW(checker.check(env, task), storm::exceptions::NotImplementedException);
109}
110
111void checkModel(std::string const& path, std::string const& formulaString, double maxmin, double maxmax, double minmax, double minmin, bool produceScheduler) {
112 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> modelPtr = storm::parser::parseDirectEncodingModel<storm::Interval>(path);
113 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(storm::api::parseProperties(formulaString));
115 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
116 env.solver().setForceSoundness(true);
117
118 std::shared_ptr<storm::models::sparse::Mdp<storm::Interval>> mdp = modelPtr->as<storm::models::sparse::Mdp<storm::Interval>>();
119 ASSERT_EQ(storm::models::ModelType::Mdp, modelPtr->getType());
121 taskMax.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Robust);
122 taskMax.setProduceSchedulers(produceScheduler);
123
125 auto resultMax = checker.check(env, taskMax);
127 EXPECT_NEAR(maxmin, getQuantitativeResultAtInitialState(mdp, resultMax), 0.0001);
128 expectSolutionBoundsSound(resultMax, maxmin);
129 taskMax.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Cooperative);
130 auto resultMaxNonRobust = checker.check(env, taskMax);
131 expectBoundsEncloseValues<double>(resultMaxNonRobust);
132 EXPECT_NEAR(maxmax, getQuantitativeResultAtInitialState(mdp, resultMaxNonRobust), 0.0001);
133 expectSolutionBoundsSound(resultMaxNonRobust, maxmax);
134
136 taskMin.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Robust);
137 taskMin.setProduceSchedulers(produceScheduler);
138
139 auto resultMin = checker.check(env, taskMin);
141 EXPECT_NEAR(minmax, getQuantitativeResultAtInitialState(mdp, resultMin), 0.0001);
142 expectSolutionBoundsSound(resultMin, minmax);
143 taskMin.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Cooperative);
144 auto resultMinNonRobust = checker.check(env, taskMin);
145 expectBoundsEncloseValues<double>(resultMinNonRobust);
146 EXPECT_NEAR(minmin, getQuantitativeResultAtInitialState(mdp, resultMinNonRobust), 0.0001);
147 expectSolutionBoundsSound(resultMinNonRobust, minmin);
148}
149
150void checkPrismModelForQuantitativeResult(std::string const& path, std::string const& formulaString, double minmin, double minmax, double maxmin, double maxmax,
151 std::string constantsString) {
153 program = program.preprocess(constantsString);
154
155 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(storm::api::parseProperties(formulaString));
156 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> modelPtr = storm::api::buildSparseModel<storm::Interval>(program, formulas);
157
159 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
160
161 std::shared_ptr<storm::models::sparse::Mdp<storm::Interval>> mdp = modelPtr->as<storm::models::sparse::Mdp<storm::Interval>>();
162 ASSERT_EQ(storm::models::ModelType::Mdp, modelPtr->getType());
163
165 taskMinMin.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Minimize);
166
168 auto resultMinMin = checker.check(env, taskMinMin);
169 EXPECT_NEAR(minmin, getQuantitativeResultAtInitialState(mdp, resultMinMin), 0.0001);
170
172 taskMinMax.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Maximize);
173
174 auto resultMinMax = checker.check(env, taskMinMax);
175 EXPECT_NEAR(minmax, getQuantitativeResultAtInitialState(mdp, resultMinMax), 0.0001);
176
178 taskMaxMin.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Minimize);
179
180 auto resultMaxMin = checker.check(env, taskMaxMin);
181 EXPECT_NEAR(maxmin, getQuantitativeResultAtInitialState(mdp, resultMaxMin), 0.0001);
182
184 taskMaxMin.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Maximize);
185
186 auto resultMaxMax = checker.check(env, taskMaxMax);
187 EXPECT_NEAR(maxmax, getQuantitativeResultAtInitialState(mdp, resultMaxMax), 0.0001);
188}
189
190void checkModelRational(std::string const& path, std::string const& formulaString, storm::RationalNumber maxmin, storm::RationalNumber maxmax,
191 storm::RationalNumber minmax, storm::RationalNumber minmin, bool produceScheduler) {
192 std::shared_ptr<storm::models::sparse::Model<storm::RationalInterval>> modelPtr = storm::parser::parseDirectEncodingModel<storm::RationalInterval>(path);
193
194 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(storm::api::parseProperties(formulaString));
196 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
197 env.solver().setForceSoundness(true);
198
199 std::shared_ptr<storm::models::sparse::Mdp<storm::RationalInterval>> mdp = modelPtr->as<storm::models::sparse::Mdp<storm::RationalInterval>>();
200 ASSERT_EQ(storm::models::ModelType::Mdp, modelPtr->getType());
202 taskMax.setProduceSchedulers(produceScheduler);
203
205 taskMax.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Robust);
206 auto resultMax = checker.check(env, taskMax);
208 EXPECT_EQ(maxmin, getQuantitativeResultAtInitialState(mdp, resultMax));
209 expectSolutionBoundsSound(resultMax, maxmin);
210 taskMax.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Cooperative);
211 auto resultMaxNonRobust = checker.check(env, taskMax);
213 EXPECT_EQ(maxmax, getQuantitativeResultAtInitialState(mdp, resultMaxNonRobust));
214 expectSolutionBoundsSound(resultMaxNonRobust, maxmax);
215
217 taskMin.setProduceSchedulers(produceScheduler);
218
219 taskMin.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Robust);
220 auto resultMin = checker.check(env, taskMin);
222 EXPECT_EQ(minmax, getQuantitativeResultAtInitialState(mdp, resultMin));
223 expectSolutionBoundsSound(resultMin, minmax);
224 taskMin.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Cooperative);
225 auto resultMinNonRobust = checker.check(env, taskMin);
227 EXPECT_EQ(minmin, getQuantitativeResultAtInitialState(mdp, resultMinNonRobust));
228}
229
230TEST(RobustMdpModelCheckerTest, RobotMinMaxTest) {
231#ifndef STORM_HAVE_SMT_SOLVER
232 GTEST_SKIP() << "No SMT solver available.";
233#endif
234 // Maxima reachability rewards using PRISM format.
235 checkPrismModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/imdp/robot.prism",
236 "Pmin=? [ F \"goal2\"];Pmin=? [ F \"goal2\"];Pmax=? [ F \"goal2\"];Pmax=? [ F \"goal2\"]", 0.4, 0.6, 1.0, 1.0,
237 "delta=0.1");
238}
239
240void makeUncertainAndCheck(std::string const& path, std::string const& formulaString, double amountOfUncertainty) {
242 program = program.preprocess("");
243 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas =
245 std::shared_ptr<storm::models::sparse::Model<double>> modelPtr = storm::api::buildSparseModel<double>(program, formulas);
246
247 auto mdp = modelPtr->as<storm::models::sparse::Mdp<double>>();
248
249 ASSERT_TRUE(formulas[0]->isProbabilityOperatorFormula());
250 // These tests cases where written with max in mind.
251 ASSERT_TRUE(formulas[0]->asProbabilityOperatorFormula().getOptimalityType() == storm::solver::OptimizationDirection::Maximize);
254
255 // First compute certain value
257 auto exresult = checker.check(env, task);
258 double certainValue = getQuantitativeResultAtInitialState(mdp, exresult);
259
260 storm::Environment envIntervals;
261 envIntervals.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
262 auto transformer = storm::transformer::AddUncertainty<double>(modelPtr);
263 auto imdp = transformer.transform(amountOfUncertainty)->as<storm::models::sparse::Mdp<storm::Interval>>();
265 auto iresultMin = checker.check(env, task);
266 double minValue = getQuantitativeResultAtInitialState(mdp, iresultMin);
267 EXPECT_LE(minValue, certainValue);
268 task.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Cooperative);
269 auto iresultMax = checker.check(env, task);
270 double maxValue = getQuantitativeResultAtInitialState(mdp, iresultMax);
271 EXPECT_LE(certainValue, maxValue);
272}
273
274void makeUncertainAndCheckRational(std::string const& path, std::string const& formulaString, storm::RationalNumber amountOfUncertainty) {
276 program = program.preprocess("");
277 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas =
279 std::shared_ptr<storm::models::sparse::Model<storm::RationalNumber>> modelPtr = storm::api::buildSparseModel<storm::RationalNumber>(program, formulas);
280 auto mdp = modelPtr->as<storm::models::sparse::Mdp<storm::RationalNumber>>();
281
282 ASSERT_TRUE(formulas[0]->isProbabilityOperatorFormula());
283 ASSERT_TRUE(formulas[0]->asProbabilityOperatorFormula().getOptimalityType() == storm::solver::OptimizationDirection::Maximize);
284
288 auto exresult = checker.check(env, taskCertain);
289 auto const certainValue = getQuantitativeResultAtInitialState(modelPtr, exresult);
290
291 storm::Environment envIntervals;
292 envIntervals.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
294 auto imdp = transformer.transform(amountOfUncertainty)->as<storm::models::sparse::Mdp<storm::RationalInterval>>();
296
298 taskMin.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Minimize);
299 auto iresultMin = ichecker.check(envIntervals, taskMin);
300 auto const minValue = getQuantitativeResultAtInitialState(imdp, iresultMin);
301 EXPECT_LE(minValue, certainValue);
302
304 taskMax.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Maximize);
305 auto iresultMax = ichecker.check(envIntervals, taskMax);
306 auto const maxValue = getQuantitativeResultAtInitialState(imdp, iresultMax);
307 EXPECT_LE(certainValue, maxValue);
308}
309
310// TODO: Add next properties
311
312TEST(RobustMDPModelCheckingTest, Tiny01maxmin) {
313 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-01.drn", "Pmax=? [ F \"target\"];Pmin=? [ F \"target\"]", 0.4, 0.5, 0.5, 0.4, false);
314}
315
316TEST(RobustMDPModelCheckingTest, Tiny03maxmin) {
317 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-03.drn", "Pmax=? [ F \"target\"];Pmin=? [ F \"target\"]", 0.4, 0.6, 0.5, 0.3, true);
318}
319
320TEST(RobustMDPModelCheckingTest, BoundedTiny03maxmin) {
321 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-03.drn", "Pmax=? [ F<=1 \"target\"];Pmin=? [ F<=1 \"target\"]", 0.4, 0.6, 0.5, 0.3, true);
322 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-03.drn", "Pmax=? [ F[1,1] \"target\"];Pmin=? [ F[1,1] \"target\"]", 0.4, 0.6, 0.5, 0.3, true);
323}
324
325TEST(RobustMDPModelCheckingTest, BoundedMaxmin) {
326 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-bounded.drn", "Pmax=? [ F<=4 \"target\"];Pmin=? [ F<=4 \"target\"]", 0.6528, 0.81, 0.81, 0.6528, true);
327 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-bounded.drn", "Pmax=? [ F[0,4] \"target\"];Pmin=? [ F[0,4] \"target\"]", 0.6528, 0.81, 0.81, 0.6528, true);
328 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-bounded.drn", "Pmax=? [ F[4,4] \"target\"];Pmin=? [ F[4,4] \"target\"]", 0.1952, 0.324, 0.324, 0.1952,
329 true);
330 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-bounded.drn", "Pmax=? [ F[4,5] \"target\"];Pmin=? [ F[4,5] \"target\"]", 0.3236, 0.50292, 0.50292, 0.3236,
331 true);
332 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-bounded.drn", "Pmax=? [ F[4,6] \"target\"];Pmin=? [ F[4,6] \"target\"]", 0.37928, 0.57888, 0.57888, 0.37928,
333 true);
334 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-bounded.drn", "Pmax=? [ F[2,2] \"target\"];Pmin=? [ F[2,2] \"target\"]", 0.32, 0.45, 0.45, 0.32, true);
335 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-bounded.drn", "Pmax=? [ F<=2 \"target\"];Pmin=? [ F<=2 \"target\"]", 0.32, 0.45, 0.45, 0.32, true);
336}
337
338TEST(RobustMDPModelCheckingTest, Tiny04maxmin) {
339 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-04.drn", "Pmax=? [ F \"target\"];Pmin=? [ F \"target\"]", 1, 1, 0.42857, 0.42, false);
340}
341
342TEST(RobustMDPModelCheckingTest, Tiny05maxmin) {
343 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-05.drn", "Pmax=? [ F \"target\"];Pmin=? [ F \"target\"]", 0.3, 0.4, 0.4, 0.3, false);
344}
345
346TEST(RobustMDPModelCheckingTest, Tiny04MinRewards) {
347 // The reward of a state is collected every time the state is visited. Only the cycle 0 -> 2 -> 0 can be repeated without reaching infinite reward, and
348 // state 0 reaches the target with (fixed) probability 0.3. From state 1 (reached with probability 0.4) one has to move on to state 2 (reward 1).
349 // This yields V0 = 1 + 0.4 * (1 + V2) + 0.3 * V2 with V2 = 1 + V0, i.e., V0 = 7. Rmax is infinite as the sink state 4 is reachable.
350 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-04.drn", "Rmin=? [ F \"target\" ];Rmin=? [ F \"target\" ]", 7, 7, 7, 7, false);
351}
352
353TEST(RobustMDPModelCheckingTest, RewardsTargetTransitionInterval) {
354 // The self-loop probability p is in [0.2, 0.5], the probability of moving to the target is in [0.5, 0.8]. The expected reward 1 / (1 - p) is thus in
355 // [1.25, 2]. This requires that the interval of the transition to the target state is respected when resolving the uncertainty.
356 // Arguments: Rmax robust, Rmax cooperative, Rmin robust, Rmin cooperative.
357 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-09.drn", "Rmax=? [ F \"target\" ];Rmin=? [ F \"target\" ]", 1.25, 2, 2, 1.25, false);
358}
359
360TEST(RobustMDPModelCheckingTest, RewardsTargetStateBeforeMaybeStates) {
361 // Same as above, but 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
362 // the remaining states.
363 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-11.drn", "Rmax=? [ F \"target\" ];Rmin=? [ F \"target\" ]", 1.25, 2, 2, 1.25, false);
364}
365
366TEST(RobustMDPModelCheckingTest, RewardsTargetStateBeforeSeveralMaybeStates) {
367 // The bounds of the maybe states must not be mixed up, otherwise state 2 would get the larger bound of state 1.
368 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-14.drn", "Rmax=? [ F \"target\" ];Rmin=? [ F \"target\" ]", 2.25, 3, 3, 2.25, false);
369 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-14.drn", "Tmax=? [ F \"target\" ];Tmin=? [ F \"target\" ]", 2.25, 3, 3, 2.25, false);
370}
371
372TEST(RobustMDPModelCheckingTest, ReachabilityTimes) {
373 // Action 0 has self-loop probability p in [0.2, 0.5], i.e., expected time 1 / (1 - p) in [1.25, 2]. Action 1 has expected time 1 + 0.5 * 1 = 1.5.
374 // Arguments: Tmax robust, Tmax cooperative, Tmin robust, Tmin cooperative.
375 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-10.drn", "Tmax=? [ F \"target\" ];Tmin=? [ F \"target\" ]", 1.5, 2, 1.5, 1.25, false);
376}
377
378TEST(RobustMDPModelCheckingTest, ReachabilityTimesSingleAction) {
379 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-09.drn", "Tmax=? [ F \"target\" ];Tmin=? [ F \"target\" ]", 1.25, 2, 2, 1.25, false);
380 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-11.drn", "Tmax=? [ F \"target\" ];Tmin=? [ F \"target\" ]", 1.25, 2, 2, 1.25, false);
381}
382
383TEST(RobustMDPModelCheckingTest, GraphPreservationRequired) {
384 // The self-loop interval [0, 1] allows to never reach the target, i.e., the graph of the model is not preserved.
385 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> modelPtr =
386 storm::parser::parseDirectEncodingModel<storm::Interval>(STORM_TEST_RESOURCES_DIR "/imdp/tiny-12.drn");
387 auto mdp = modelPtr->as<storm::models::sparse::Mdp<storm::Interval>>();
388 EXPECT_FALSE(mdp->getTransitionMatrix().isProbabilisticGraphPreserving());
390 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
392 for (std::string const formulaString : {"Pmax=? [ F \"target\" ]", "Rmin=? [ F \"target\" ]", "Tmin=? [ F \"target\" ]"}) {
393 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas =
396 task.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Cooperative);
397 STORM_SILENT_EXPECT_THROW(checker.check(env, task), storm::exceptions::InvalidSettingsException);
398 }
399}
400
401TEST(RobustMDPModelCheckingTest, GraphPreservationAfterTightening) {
402 // 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.
403 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> modelPtr =
404 storm::parser::parseDirectEncodingModel<storm::Interval>(STORM_TEST_RESOURCES_DIR "/imdp/tiny-13.drn");
405 EXPECT_FALSE(modelPtr->getTransitionMatrix().hasOnlyPositiveEntries());
406 EXPECT_TRUE(modelPtr->getTransitionMatrix().isProbabilisticGraphPreserving());
407 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-13.drn", "Tmax=? [ F \"target\" ];Tmin=? [ F \"target\" ]", 2, 2, 2, 2, false);
408}
409
410TEST(RobustMDPModelCheckingTest, MinRewardsUniqueSolution) {
411 // There is no end component with zero reward among the states with finite reward, i.e., the solution of the equation system is unique and no upper
412 // reward bounds are required. Arguments: Rmin robust, Rmin cooperative, Rmin robust, Rmin cooperative.
413 // Choosing action 0 in state 0 yields 2 + 1 / (1 - p) with self-loop probability p in [0.2, 0.5], which is cheaper than action 1 (cost 6).
414 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-08.drn", "Rmin=? [ F \"target\" ];Rmin=? [ F \"target\" ]", 4, 3.25, 4, 3.25, false);
415}
416
417TEST(RobustMDPModelCheckingTest, MinRewardsNonUniqueSolution) {
418 // State 0 has a zero-reward self loop, i.e., there is an end component with zero reward. The solution is not unique and we cannot compute the required
419 // upper reward bounds for interval models.
420 expectThrow(STORM_TEST_RESOURCES_DIR "/imdp/tiny-07.drn", "Rmin=? [ F \"target\" ]");
421}
422
423TEST(RobustMDPModelCheckingTest, CumulativeRewards) {
424 // Arguments: Rmax robust, Rmax cooperative, Rmin robust, Rmin cooperative
425 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-06.drn", "Rmax=? [ C<=0 ];Rmin=? [ C<=0 ]", 0, 0, 0, 0, false);
426 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-06.drn", "Rmax=? [ C<=1 ];Rmin=? [ C<=1 ]", 7, 7, 1, 1, false);
427 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-06.drn", "Rmax=? [ C<=2 ];Rmin=? [ C<=2 ]", 9, 9.5, 9, 7.5, false);
428 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/tiny-06.drn", "Rmax=? [ C<=3 ];Rmin=? [ C<=3 ]", 11, 11.5, 11, 9.5, false);
429}
430
431TEST(RobustMDPModelCheckingTest, CumulativeRewardsNoUncertaintyResolutionMode) {
432 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> modelPtr =
433 storm::parser::parseDirectEncodingModel<storm::Interval>(STORM_TEST_RESOURCES_DIR "/imdp/tiny-06.drn");
434 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas =
437 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
438 auto mdp = modelPtr->as<storm::models::sparse::Mdp<storm::Interval>>();
442}
443
444TEST(RobustMDPModelCheckingTest, CrowdsQuotientIMDP) {
445 // Ensuring equivalent behavior when checking identical model as IDTMC and IMDP (cf. CrowdsQuotientIDTMC)
446 checkModel(STORM_TEST_RESOURCES_DIR "/imdp/crowds-quotient-3-5.drn", "Pmax=? [ F \"observe0Greater1\"]; Pmin=? [ F \"observe0Greater1\"]", 0.1383409,
447 0.1383409, 0.1383409, 0.1383409, false);
448}
449
450// ---- RationalInterval tests (exact arithmetic) ----
451
452TEST(RobustRationalMDPModelCheckingTest, CumulativeRewards) {
453 checkModelRational(STORM_TEST_RESOURCES_DIR "/imdp/tiny-06.drn", "Rmax=? [ C<=2 ];Rmin=? [ C<=2 ]", storm::RationalNumber(9), storm::RationalNumber("19/2"),
454 storm::RationalNumber(9), storm::RationalNumber("15/2"), false);
455 checkModelRational(STORM_TEST_RESOURCES_DIR "/imdp/tiny-06.drn", "Rmax=? [ C<=3 ];Rmin=? [ C<=3 ]", storm::RationalNumber(11),
456 storm::RationalNumber("23/2"), storm::RationalNumber(11), storm::RationalNumber("19/2"), false);
457}
458
459TEST(RobustRationalMDPModelCheckingTest, Tiny01maxmin) {
460 checkModelRational(STORM_TEST_RESOURCES_DIR "/imdp/tiny-01.drn", "Pmax=? [ F \"target\"];Pmin=? [ F \"target\"]", storm::RationalNumber("2/5"),
461 storm::RationalNumber("1/2"), storm::RationalNumber("1/2"), storm::RationalNumber("2/5"), false);
462}
463
464TEST(RobustRationalMDPModelCheckingTest, Tiny03maxmin) {
465 checkModelRational(STORM_TEST_RESOURCES_DIR "/imdp/tiny-03.drn", "Pmax=? [ F \"target\"];Pmin=? [ F \"target\"]", storm::RationalNumber("2/5"),
466 storm::RationalNumber("3/5"), storm::RationalNumber("1/2"), storm::RationalNumber("3/10"), true);
467}
468
469TEST(RobustRationalMDPModelCheckingTest, BoundedTiny03maxmin) {
470 checkModelRational(STORM_TEST_RESOURCES_DIR "/imdp/tiny-03.drn", "Pmax=? [ F<=1 \"target\"];Pmin=? [ F<=1 \"target\"]", storm::RationalNumber("2/5"),
471 storm::RationalNumber("3/5"), storm::RationalNumber("1/2"), storm::RationalNumber("3/10"), true);
472 checkModelRational(STORM_TEST_RESOURCES_DIR "/imdp/tiny-03.drn", "Pmax=? [ F[1,1] \"target\"];Pmin=? [ F[1,1] \"target\"]", storm::RationalNumber("2/5"),
473 storm::RationalNumber("3/5"), storm::RationalNumber("1/2"), storm::RationalNumber("3/10"), true);
474}
475
476TEST(RobustRationalMDPModelCheckingTest, BoundedMaxmin) {
477 checkModelRational(STORM_TEST_RESOURCES_DIR "/imdp/tiny-bounded.drn", "Pmax=? [ F<=4 \"target\"];Pmin=? [ F<=4 \"target\"]",
478 storm::RationalNumber("408/625"), storm::RationalNumber("81/100"), storm::RationalNumber("81/100"), storm::RationalNumber("408/625"),
479 true);
480 checkModelRational(STORM_TEST_RESOURCES_DIR "/imdp/tiny-bounded.drn", "Pmax=? [ F[0,4] \"target\"];Pmin=? [ F[0,4] \"target\"]",
481 storm::RationalNumber("408/625"), storm::RationalNumber("81/100"), storm::RationalNumber("81/100"), storm::RationalNumber("408/625"),
482 true);
483 checkModelRational(STORM_TEST_RESOURCES_DIR "/imdp/tiny-bounded.drn", "Pmax=? [ F[4,4] \"target\"];Pmin=? [ F[4,4] \"target\"]",
484 storm::RationalNumber("122/625"), storm::RationalNumber("81/250"), storm::RationalNumber("81/250"), storm::RationalNumber("122/625"),
485 true);
486 checkModelRational(STORM_TEST_RESOURCES_DIR "/imdp/tiny-bounded.drn", "Pmax=? [ F[4,5] \"target\"];Pmin=? [ F[4,5] \"target\"]",
487 storm::RationalNumber("809/2500"), storm::RationalNumber("12573/25000"), storm::RationalNumber("12573/25000"),
488 storm::RationalNumber("809/2500"), true);
489 checkModelRational(STORM_TEST_RESOURCES_DIR "/imdp/tiny-bounded.drn", "Pmax=? [ F[4,6] \"target\"];Pmin=? [ F[4,6] \"target\"]",
490 storm::RationalNumber("4741/12500"), storm::RationalNumber("1809/3125"), storm::RationalNumber("1809/3125"),
491 storm::RationalNumber("4741/12500"), true);
492 checkModelRational(STORM_TEST_RESOURCES_DIR "/imdp/tiny-bounded.drn", "Pmax=? [ F[2,2] \"target\"];Pmin=? [ F[2,2] \"target\"]",
493 storm::RationalNumber("8/25"), storm::RationalNumber("9/20"), storm::RationalNumber("9/20"), storm::RationalNumber("8/25"), true);
494 checkModelRational(STORM_TEST_RESOURCES_DIR "/imdp/tiny-bounded.drn", "Pmax=? [ F<=2 \"target\"];Pmin=? [ F<=2 \"target\"]", storm::RationalNumber("8/25"),
495 storm::RationalNumber("9/20"), storm::RationalNumber("9/20"), storm::RationalNumber("8/25"), true);
496}
497
498TEST(RobustRationalMDPModelCheckingTest, Tiny04maxmin) {
499 // Fill in exact rational values once test output is known.
500 checkModelRational(STORM_TEST_RESOURCES_DIR "/imdp/tiny-04.drn", "Pmax=? [ F \"target\"];Pmin=? [ F \"target\"]", storm::RationalNumber(1),
501 storm::RationalNumber(1), storm::RationalNumber("42857140807299/100000000000000"), storm::RationalNumber("21/50"), false);
502}
503
504TEST(RobustRationalMDPModelCheckingTest, Tiny05maxmin) {
505 checkModelRational(STORM_TEST_RESOURCES_DIR "/imdp/tiny-05.drn", "Pmax=? [ F \"target\"];Pmin=? [ F \"target\"]", storm::RationalNumber("3/10"),
506 storm::RationalNumber("2/5"), storm::RationalNumber("2/5"), storm::RationalNumber("3/10"), false);
507}
508
509TEST(RobustMDPModelCheckingTest, AddUncertaintyCoin22max) {
510#ifndef STORM_HAVE_SMT_SOLVER
511 GTEST_SKIP() << "No SMT solver available.";
512#endif
513 makeUncertainAndCheck(STORM_TEST_RESOURCES_DIR "/mdp/coin2-2.nm", "Pmax=? [F \"all_coins_equal_1\"]", 0.1);
514 makeUncertainAndCheck(STORM_TEST_RESOURCES_DIR "/mdp/coin2-2.nm", "Pmax=? [F \"all_coins_equal_1\"]", 0.2);
515}
516
517TEST(RobustRationalMDPModelCheckingTest, AddUncertaintyCoin22max) {
518#ifndef STORM_HAVE_SMT_SOLVER
519 GTEST_SKIP() << "No SMT solver available.";
520#endif
521 makeUncertainAndCheckRational(STORM_TEST_RESOURCES_DIR "/mdp/coin2-2.nm", "Pmax=? [F \"all_coins_equal_1\"]", storm::RationalNumber("1/10"));
522 makeUncertainAndCheckRational(STORM_TEST_RESOURCES_DIR "/mdp/coin2-2.nm", "Pmax=? [F \"all_coins_equal_1\"]", storm::RationalNumber("1/5"));
523}
void expectBoundsEncloseValues(std::unique_ptr< storm::modelchecker::CheckResult > const &result)
void expectSolutionBoundsSound(std::unique_ptr< storm::modelchecker::CheckResult > const &result, double expected)
TEST(RobustMdpModelCheckerTest, RobotMinMaxTest)
std::unique_ptr< storm::modelchecker::QualitativeCheckResult > getInitialStateFilter(std::shared_ptr< storm::models::sparse::Model< storm::Interval > > const &model)
storm::ExtendedRationalNumber getQuantitativeResultAtInitialState(std::shared_ptr< storm::models::sparse::Model< storm::RationalNumber > > const &model, std::unique_ptr< storm::modelchecker::CheckResult > &result)
void checkPrismModelForQuantitativeResult(std::string const &path, std::string const &formulaString, double minmin, double minmax, double maxmin, double maxmax, std::string constantsString)
void expectThrow(std::string const &path, std::string const &formulaString)
void checkModel(std::string const &path, std::string const &formulaString, double maxmin, double maxmax, double minmax, double minmin, bool produceScheduler)
void checkModelRational(std::string const &path, std::string const &formulaString, storm::RationalNumber maxmin, storm::RationalNumber maxmax, storm::RationalNumber minmax, storm::RationalNumber minmin, bool produceScheduler)
void makeUncertainAndCheckRational(std::string const &path, std::string const &formulaString, storm::RationalNumber amountOfUncertainty)
void makeUncertainAndCheck(std::string const &path, std::string const &formulaString, double amountOfUncertainty)
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 decision process.
Definition Mdp.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
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)
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