Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
CertificateTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
4#include <cmath>
5#include <limits>
6#include <optional>
7#include <sstream>
8#include <string>
9#include <vector>
10
16#include "storm/api/builder.h"
40
41namespace {
42
43// P(F "target") is 12/17 in state 0. States 3 and 4 are the target and a sink, respectively.
44std::string const dtmcWithSink = R"(
45dtmc
46
47module main
48 s : [0..4];
49 [] s=0 -> 0.5 : (s'=1) + 0.5 : (s'=2);
50 [] s=1 -> 0.3 : (s'=0) + 0.7 : (s'=3);
51 [] s=2 -> 0.5 : (s'=3) + 0.5 : (s'=4);
52 [] s=3 -> 1 : (s'=3);
53 [] s=4 -> 1 : (s'=4);
54endmodule
55
56// All states are initial State ids then correspond to the values of s.
57init
58 true
59endinit
60
61label "target" = s=3;
62)";
63
64// The expected number of steps to the target is 40/17 in state 0.
65std::string const dtmcWithoutSink = R"(
66dtmc
67
68module main
69 s : [0..3];
70 [] s=0 -> 0.5 : (s'=1) + 0.5 : (s'=2);
71 [] s=1 -> 0.3 : (s'=0) + 0.7 : (s'=3);
72 [] s=2 -> 1 : (s'=3);
73 [] s=3 -> 1 : (s'=3);
74endmodule
75
76// All states are initial State ids then correspond to the values of s.
77init
78 true
79endinit
80
81label "target" = s=3;
82
83rewards "steps"
84 s<3 : 1;
85endrewards
86)";
87
88// Pmax(F "target") = 1 and Pmin(F "target") = 1/5 in state 0.
89// Rmin(F "target") = 3 in state 0, but Rmax(F "target") is infinite there since the sink can be reached.
90std::string const mdp = R"(
91mdp
92
93module main
94 s : [0..4];
95 [a] s=0 -> 0.5 : (s'=1) + 0.5 : (s'=0);
96 [b] s=0 -> 0.2 : (s'=2) + 0.8 : (s'=4);
97 [a] s=1 -> 1 : (s'=3);
98 [b] s=1 -> 0.5 : (s'=3) + 0.5 : (s'=4);
99 [] s=2 -> 1 : (s'=3);
100 [] s=3 -> 1 : (s'=3);
101 [] s=4 -> 1 : (s'=4);
102endmodule
103
104// All states are initial State ids then correspond to the values of s.
105init
106 true
107endinit
108
109label "target" = s=3;
110
111rewards "steps"
112 s<3 : 1;
113endrewards
114)";
115
116struct CertifiedBounds {
117 double lower{-std::numeric_limits<double>::infinity()};
118 double upper{std::numeric_limits<double>::infinity()};
119};
120
121double parseNumber(std::string const& token) {
122 if (token == "inf") {
123 return std::numeric_limits<double>::infinity();
124 } else if (token == "-inf") {
125 return -std::numeric_limits<double>::infinity();
126 }
127 // Rational numbers are exported as fractions
128 auto const slash = token.find('/');
129 if (slash != std::string::npos) {
130 return std::stod(token.substr(0, slash)) / std::stod(token.substr(slash + 1));
131 }
132 return std::stod(token);
133}
134
138template<typename ValueType>
139CertifiedBounds getBoundsFromSummary(storm::modelchecker::Certificate<ValueType> const& certificate, uint64_t numStates, uint64_t state) {
140 storm::storage::BitVector relevantStates(numStates, false);
141 relevantStates.set(state);
142 std::string const summary = certificate.summaryString(relevantStates);
143 auto const open = summary.find('[');
144 auto const comma = summary.find(", ", open);
145 auto const close = summary.find(']', comma);
146 EXPECT_TRUE(open != std::string::npos && comma != std::string::npos && close != std::string::npos) << summary;
147 return CertifiedBounds{parseNumber(summary.substr(open + 1, comma - open - 1)), parseNumber(summary.substr(comma + 2, close - comma - 2))};
148}
149
150class DoubleFpIIEnvironment {
151 public:
152 typedef double ValueType;
153 static storm::Environment createEnvironment() {
154 storm::Environment env;
157 return env;
158 }
159};
160
161class DoubleFpIITopologicalEnvironment {
162 public:
163 typedef double ValueType;
164 static storm::Environment createEnvironment() {
165 auto env = DoubleFpIIEnvironment::createEnvironment();
167 return env;
168 }
169};
170
171class RationalExPIEnvironment {
172 public:
173 typedef storm::RationalNumber ValueType;
174 static storm::Environment createEnvironment() {
175 storm::Environment env;
177 return env;
178 }
179};
180
181class RationalExPITopologicalEnvironment {
182 public:
183 typedef storm::RationalNumber ValueType;
184 static storm::Environment createEnvironment() {
185 auto env = RationalExPIEnvironment::createEnvironment();
187 return env;
188 }
189};
190
191template<typename TestType>
192class CertificateTest : public ::testing::Test {
193 public:
194 typedef typename TestType::ValueType ValueType;
195 CertificateTest() : _environment(TestType::createEnvironment()) {}
196
197 storm::Environment const& env() const {
198 return _environment;
199 }
200
201 template<typename ModelType, typename ModelCheckerType>
202 std::unique_ptr<storm::modelchecker::CheckResult> checkWithCertificate(std::string const& modelDescription, std::string const& formulaString,
203 std::shared_ptr<ModelType>& model,
204 storm::Environment const* customEnvironment = nullptr) const {
205 storm::prism::Program program = storm::parser::PrismParser::parseFromString(modelDescription, "testfile");
207 model = storm::api::buildSparseModel<ValueType>(program, formulas)->template as<ModelType>();
208 ModelCheckerType checker(*model);
209 storm::modelchecker::CheckTask<storm::logic::Formula, ValueType> task(*formulas[0], true);
210 task.setProduceCertificate(true);
211 return checker.check(customEnvironment ? *customEnvironment : env(), task);
212 }
213
217 void checkCertificate(storm::modelchecker::CheckResult& result, storm::models::sparse::Model<ValueType> const& model, double expectedValue) const {
218 ASSERT_TRUE(result.isExplicitCertificateCheckResult());
219 EXPECT_TRUE(result.isExplicit());
220 EXPECT_TRUE(result.isResultForAllStates());
221 auto& certificateResult = result.template asExplicitCertificateCheckResult<ValueType>();
222 EXPECT_TRUE(certificateResult.checkValidity(model));
223 auto const bounds = getBoundsFromSummary(certificateResult.getCertificate(), model.getNumberOfStates(), 0);
224 // The summary shows a limited number of digits.
225 double const tolerance = 1e-5;
226 if (std::isinf(expectedValue)) {
227 EXPECT_TRUE(std::isinf(bounds.lower) && std::isinf(bounds.upper)) << "[" << bounds.lower << ", " << bounds.upper << "]";
228 } else {
229 EXPECT_LE(bounds.lower, expectedValue + tolerance);
230 EXPECT_GE(bounds.upper, expectedValue - tolerance);
231 EXPECT_LE(bounds.upper - bounds.lower, tolerance);
232 }
233 }
234
235 private:
236 storm::Environment _environment;
237};
238
239typedef ::testing::Types<DoubleFpIIEnvironment, DoubleFpIITopologicalEnvironment, RationalExPIEnvironment, RationalExPITopologicalEnvironment> TestingTypes;
240
241TYPED_TEST_SUITE(CertificateTest, TestingTypes, );
242
243TYPED_TEST(CertificateTest, DtmcReachabilityProbability) {
244 typedef typename TestFixture::ValueType ValueType;
246 std::shared_ptr<ModelType> model;
247 auto result =
248 this->template checkWithCertificate<ModelType, storm::modelchecker::SparseDtmcPrctlModelChecker<ModelType>>(dtmcWithSink, "P=? [F \"target\"]", model);
249 this->checkCertificate(*result, *model, 12.0 / 17.0);
250}
251
252TYPED_TEST(CertificateTest, DtmcConstrainedReachabilityProbability) {
253 typedef typename TestFixture::ValueType ValueType;
255 std::shared_ptr<ModelType> model;
256 // Staying in the states 0 and 1 and moving to the target through state 1 only: v0 = 0.5 * v1, v1 = 0.3 * v0 + 0.7.
257 auto result =
258 this->template checkWithCertificate<ModelType, storm::modelchecker::SparseDtmcPrctlModelChecker<ModelType>>(dtmcWithSink, "P=? [s<2 U s=3]", model);
259 this->checkCertificate(*result, *model, 0.35 / 0.85);
260}
261
262TYPED_TEST(CertificateTest, DtmcReachabilityReward) {
263 typedef typename TestFixture::ValueType ValueType;
265 std::shared_ptr<ModelType> model;
266 auto result = this->template checkWithCertificate<ModelType, storm::modelchecker::SparseDtmcPrctlModelChecker<ModelType>>(
267 dtmcWithoutSink, "R{\"steps\"}=? [F \"target\"]", model);
268 this->checkCertificate(*result, *model, 40.0 / 17.0);
269}
270
271TYPED_TEST(CertificateTest, DtmcReachabilityRewardInfinite) {
272 typedef typename TestFixture::ValueType ValueType;
274 std::shared_ptr<ModelType> model;
275 auto result = this->template checkWithCertificate<ModelType, storm::modelchecker::SparseDtmcPrctlModelChecker<ModelType>>(
276 // The state 4 is a sink, so the expected reward is infinite in all states that can reach it.
277 std::string(dtmcWithSink) + "\nrewards \"steps\"\n s<3 : 1;\nendrewards\n", "R{\"steps\"}=? [F \"target\"]", model);
278 this->checkCertificate(*result, *model, std::numeric_limits<double>::infinity());
279}
280
281TYPED_TEST(CertificateTest, DtmcReachabilityTime) {
282 typedef typename TestFixture::ValueType ValueType;
284 std::shared_ptr<ModelType> model;
285 auto result = this->template checkWithCertificate<ModelType, storm::modelchecker::SparseDtmcPrctlModelChecker<ModelType>>(dtmcWithoutSink,
286 "T=? [F \"target\"]", model);
287 this->checkCertificate(*result, *model, 40.0 / 17.0);
288}
289
290TYPED_TEST(CertificateTest, DtmcEmptyConstraintReachabilityProbability) {
291 typedef typename TestFixture::ValueType ValueType;
293 std::shared_ptr<ModelType> model;
294 // No state satisfies s>4, so the target can only be reached from within the target. This is different from not having a constraint.
295 auto result =
296 this->template checkWithCertificate<ModelType, storm::modelchecker::SparseDtmcPrctlModelChecker<ModelType>>(dtmcWithSink, "P=? [s>4 U s=3]", model);
297 this->checkCertificate(*result, *model, 0.0);
298}
299
300TYPED_TEST(CertificateTest, DtmcNegativeRewardsAreRejected) {
301 typedef typename TestFixture::ValueType ValueType;
303 std::shared_ptr<ModelType> model;
304 std::string const negativeRewards = dtmcWithoutSink + "\nrewards \"negative\"\n s<3 : -1;\nendrewards\n";
305 STORM_SILENT_EXPECT_THROW((this->template checkWithCertificate<ModelType, storm::modelchecker::SparseDtmcPrctlModelChecker<ModelType>>(
306 negativeRewards, "R{\"negative\"}=? [F \"target\"]", model)),
307 storm::exceptions::NotSupportedException);
308}
309
310TYPED_TEST(CertificateTest, SmoothIterationWithGammaOneIsRejected) {
311 typedef typename TestFixture::ValueType ValueType;
313 std::shared_ptr<ModelType> model;
315 storm::Environment env = this->env();
316 env.modelchecker().certificate().setAlgorithm(algorithm);
317 env.modelchecker().certificate().setGamma(1.0);
318 STORM_SILENT_EXPECT_THROW((this->template checkWithCertificate<ModelType, storm::modelchecker::SparseDtmcPrctlModelChecker<ModelType>>(
319 dtmcWithSink, "P=? [F \"target\"]", model, &env)),
320 storm::exceptions::InvalidEnvironmentException);
321 }
322}
323
324TYPED_TEST(CertificateTest, CtmcReachability) {
325 typedef typename TestFixture::ValueType ValueType;
328 builder.addNextValue(0, 1, storm::utility::convertNumber<ValueType>(2.0));
329 builder.addNextValue(1, 2, storm::utility::convertNumber<ValueType>(4.0));
330 builder.addNextValue(2, 2, storm::utility::convertNumber<ValueType>(1.0)); // The target is absorbing
332 labeling.addLabel("init");
333 labeling.addLabelToState("init", 0);
334 labeling.addLabel("target");
335 labeling.addLabelToState("target", 2);
336 ModelType model(builder.build(3, 3), std::move(labeling));
337
338 storm::parser::FormulaParser formulaParser(std::make_shared<storm::expressions::ExpressionManager>());
340 for (auto const& [formulaString, expectedValue] : std::vector<std::pair<std::string, double>>{{"P=? [F \"target\"]", 1.0}, {"T=? [F \"target\"]", 0.75}}) {
341 auto const formula = formulaParser.parseSingleFormulaFromString(formulaString);
343 task.setProduceCertificate(true);
344 auto result = checker.check(this->env(), task);
345 this->checkCertificate(*result, model, expectedValue);
346 }
347}
348
349// Json export
350
351template<typename ValueType>
352double jsonToDouble(storm::json<ValueType> const& j) {
353 if (j.is_string()) {
354 return parseNumber(j.template get<std::string>());
355 }
356 if constexpr (std::is_same_v<ValueType, double>) {
357 return j.template get<double>();
358 }
359 ADD_FAILURE() << "Unexpected json value " << j.dump();
360 return 0.0;
361}
362
363TYPED_TEST(CertificateTest, JsonExportProbability) {
364 typedef typename TestFixture::ValueType ValueType;
366 std::shared_ptr<ModelType> model;
367 auto result =
368 this->template checkWithCertificate<ModelType, storm::modelchecker::SparseDtmcPrctlModelChecker<ModelType>>(dtmcWithSink, "P=? [F \"target\"]", model);
369 ASSERT_TRUE(result->isExplicitCertificateCheckResult());
370 storm::json<ValueType> const j = result->template asExplicitCertificateCheckResult<ValueType>().getCertificate().toJson();
371
372 EXPECT_EQ("reachability-probability", j.at("kind").template get<std::string>());
373 EXPECT_FALSE(j.contains("direction"));
374 EXPECT_FALSE(j.contains("constraint"));
375 ASSERT_EQ(1ull, j.at("target").at("states").size());
376 EXPECT_EQ(3ull, j.at("target").at("states").at(0).template get<uint64_t>());
377 EXPECT_NE(std::string::npos, j.at("target").at("label").template get<std::string>().find("target"));
378
379 auto const& lowerValues = j.at("lower").at("values");
380 auto const& upperValues = j.at("upper").at("values");
381 ASSERT_EQ(5ull, lowerValues.size());
382 ASSERT_EQ(5ull, upperValues.size());
383 EXPECT_LE(jsonToDouble<ValueType>(lowerValues.at(0)), 12.0 / 17.0 + 1e-6);
384 EXPECT_GE(jsonToDouble<ValueType>(upperValues.at(0)), 12.0 / 17.0 - 1e-6);
385 EXPECT_NEAR(12.0 / 17.0, jsonToDouble<ValueType>(lowerValues.at(0)), 1e-6);
386 EXPECT_EQ(1.0, jsonToDouble<ValueType>(lowerValues.at(3)));
387 EXPECT_EQ(0.0, jsonToDouble<ValueType>(upperValues.at(4)));
388 if constexpr (std::is_same_v<ValueType, storm::RationalNumber>) {
389 // Exact values are exported as fractions
390 EXPECT_EQ("12/17", lowerValues.at(0).template get<std::string>());
391 EXPECT_EQ("31/34", lowerValues.at(1).template get<std::string>());
392 EXPECT_EQ("1/2", upperValues.at(2).template get<std::string>());
393 EXPECT_EQ("1", upperValues.at(3).template get<std::string>());
394 }
395
396 auto const& ranks = j.at("lower").at("ranks");
397 ASSERT_EQ(5ull, ranks.size());
398 EXPECT_EQ(2ull, ranks.at(0).template get<uint64_t>());
399 EXPECT_EQ(1ull, ranks.at(1).template get<uint64_t>());
400 EXPECT_EQ(1ull, ranks.at(2).template get<uint64_t>());
401 EXPECT_EQ(0ull, ranks.at(3).template get<uint64_t>());
402 EXPECT_EQ("inf", ranks.at(4).template get<std::string>());
403 EXPECT_FALSE(j.at("upper").contains("ranks"));
404}
405
406TYPED_TEST(CertificateTest, JsonExportConstrainedProbability) {
407 typedef typename TestFixture::ValueType ValueType;
409 std::shared_ptr<ModelType> model;
410 auto result =
411 this->template checkWithCertificate<ModelType, storm::modelchecker::SparseDtmcPrctlModelChecker<ModelType>>(dtmcWithSink, "P=? [s<2 U s=3]", model);
412 storm::json<ValueType> const j = result->template asExplicitCertificateCheckResult<ValueType>().getCertificate().toJson();
413 ASSERT_TRUE(j.contains("constraint"));
414 ASSERT_EQ(2ull, j.at("constraint").at("states").size());
415 EXPECT_EQ(0ull, j.at("constraint").at("states").at(0).template get<uint64_t>());
416 EXPECT_EQ(1ull, j.at("constraint").at("states").at(1).template get<uint64_t>());
417 EXPECT_TRUE(j.at("constraint").contains("label"));
418}
419
420TYPED_TEST(CertificateTest, JsonExportReward) {
421 typedef typename TestFixture::ValueType ValueType;
423 std::shared_ptr<ModelType> model;
424 auto result = this->template checkWithCertificate<ModelType, storm::modelchecker::SparseDtmcPrctlModelChecker<ModelType>>(
425 dtmcWithoutSink, "R{\"steps\"}=? [F \"target\"]", model);
426 ASSERT_TRUE(result->isExplicitCertificateCheckResult());
427 storm::json<ValueType> const j = result->template asExplicitCertificateCheckResult<ValueType>().getCertificate().toJson();
428
429 EXPECT_EQ("reachability-reward", j.at("kind").template get<std::string>());
430 EXPECT_FALSE(j.contains("direction"));
431 EXPECT_EQ("steps", j.at("reward-model").template get<std::string>());
432 ASSERT_EQ(4ull, j.at("choice-rewards").size());
433 for (uint64_t choice = 0; choice < 3; ++choice) {
434 EXPECT_EQ(1.0, jsonToDouble<ValueType>(j.at("choice-rewards").at(choice)));
435 }
436 EXPECT_EQ(0.0, jsonToDouble<ValueType>(j.at("choice-rewards").at(3)));
437 ASSERT_EQ(1ull, j.at("target").at("states").size());
438
439 ASSERT_EQ(4ull, j.at("lower").at("values").size());
440 ASSERT_EQ(4ull, j.at("upper").at("values").size());
441 EXPECT_NEAR(40.0 / 17.0, jsonToDouble<ValueType>(j.at("lower").at("values").at(0)), 1e-6);
442 EXPECT_NEAR(40.0 / 17.0, jsonToDouble<ValueType>(j.at("upper").at("values").at(0)), 1e-6);
443 if constexpr (std::is_same_v<ValueType, storm::RationalNumber>) {
444 EXPECT_EQ("40/17", j.at("upper").at("values").at(0).template get<std::string>());
445 EXPECT_EQ("29/17", j.at("upper").at("values").at(1).template get<std::string>());
446 }
447 // There are no states with infinite value, so the lower bound ranks are all infinite
448 for (auto const& rank : j.at("lower").at("ranks")) {
449 EXPECT_EQ("inf", rank.template get<std::string>());
450 }
451 auto const& upperRanks = j.at("upper").at("ranks");
452 ASSERT_EQ(4ull, upperRanks.size());
453 EXPECT_EQ(2ull, upperRanks.at(0).template get<uint64_t>());
454 EXPECT_EQ(1ull, upperRanks.at(1).template get<uint64_t>());
455 EXPECT_EQ(1ull, upperRanks.at(2).template get<uint64_t>());
456 EXPECT_EQ(0ull, upperRanks.at(3).template get<uint64_t>());
457}
458
459TYPED_TEST(CertificateTest, JsonExportMdpDirectionAndInfinity) {
460 typedef typename TestFixture::ValueType ValueType;
462 {
463 std::shared_ptr<ModelType> model;
464 auto result =
465 this->template checkWithCertificate<ModelType, storm::modelchecker::SparseMdpPrctlModelChecker<ModelType>>(mdp, "Pmin=? [F \"target\"]", model);
466 storm::json<ValueType> const j = result->template asExplicitCertificateCheckResult<ValueType>().getCertificate().toJson();
467 EXPECT_EQ("min", j.at("direction").template get<std::string>());
468 }
469 {
470 // The maximal expected reward is infinite in state 0
471 std::shared_ptr<ModelType> model;
472 auto result = this->template checkWithCertificate<ModelType, storm::modelchecker::SparseMdpPrctlModelChecker<ModelType>>(
473 mdp, "R{\"steps\"}max=? [F \"target\"]", model);
474 storm::json<ValueType> const j = result->template asExplicitCertificateCheckResult<ValueType>().getCertificate().toJson();
475 EXPECT_EQ("max", j.at("direction").template get<std::string>());
476 EXPECT_EQ("inf", j.at("lower").at("values").at(0).template get<std::string>());
477 EXPECT_EQ("inf", j.at("upper").at("values").at(0).template get<std::string>());
478 // The rewards are given for each choice, not each state
479 EXPECT_EQ(model->getNumberOfChoices(), j.at("choice-rewards").size());
480 }
481}
482
483TYPED_TEST(CertificateTest, MdpReachabilityProbability) {
484 typedef typename TestFixture::ValueType ValueType;
486 {
487 std::shared_ptr<ModelType> model;
488 auto result =
489 this->template checkWithCertificate<ModelType, storm::modelchecker::SparseMdpPrctlModelChecker<ModelType>>(mdp, "Pmax=? [F \"target\"]", model);
490 this->checkCertificate(*result, *model, 1.0);
491 }
492 {
493 std::shared_ptr<ModelType> model;
494 auto result =
495 this->template checkWithCertificate<ModelType, storm::modelchecker::SparseMdpPrctlModelChecker<ModelType>>(mdp, "Pmin=? [F \"target\"]", model);
496 this->checkCertificate(*result, *model, 0.2);
497 }
498}
499
500TYPED_TEST(CertificateTest, MdpReachabilityReward) {
501 typedef typename TestFixture::ValueType ValueType;
503 {
504 std::shared_ptr<ModelType> model;
505 auto result = this->template checkWithCertificate<ModelType, storm::modelchecker::SparseMdpPrctlModelChecker<ModelType>>(
506 mdp, "R{\"steps\"}min=? [F \"target\"]", model);
507 this->checkCertificate(*result, *model, 3.0);
508 }
509 {
510 std::shared_ptr<ModelType> model;
511 auto result = this->template checkWithCertificate<ModelType, storm::modelchecker::SparseMdpPrctlModelChecker<ModelType>>(
512 mdp, "R{\"steps\"}max=? [F \"target\"]", model);
513 this->checkCertificate(*result, *model, std::numeric_limits<double>::infinity());
514 }
515}
516
517// The following tests build certificates by hand to make sure that the validity check detects invalid ones.
518class HandMadeCertificateTest : public ::testing::Test {
519 public:
520 typedef storm::RationalNumber ValueType;
521
522 void SetUp() override {
523 storm::prism::Program program = storm::parser::PrismParser::parseFromString(dtmcWithSink, "testfile");
524 model = storm::api::buildSparseModel<ValueType>(program, std::vector<std::shared_ptr<storm::logic::Formula const>>())
525 ->as<storm::models::sparse::Dtmc<ValueType>>();
526 targetStates = storm::storage::BitVector(model->getNumberOfStates(), false);
527 targetStates.set(3);
528 }
529
530 static std::vector<ValueType> rationals(std::vector<std::pair<int, int>> const& fractions) {
531 std::vector<ValueType> result;
532 for (auto const& [numerator, denominator] : fractions) {
534 }
535 return result;
536 }
537
538 std::shared_ptr<storm::models::sparse::Dtmc<ValueType>> model;
539 storm::storage::BitVector targetStates;
540};
541
542TEST_F(HandMadeCertificateTest, UpperBound) {
543 // Every state that can reach the target is assigned the value 1, the sink the value 0.
545 valid.setUpperBoundsCertificate(rationals({{1, 1}, {1, 1}, {1, 1}, {1, 1}, {0, 1}}));
546 EXPECT_TRUE(valid.checkValidity(*model));
547
548 // State 2 reaches the target with probability 1/2 so 2/5 is too small.
549 storm::modelchecker::ReachabilityProbabilityCertificate<ValueType> notInductive(std::nullopt, targetStates);
550 notInductive.setUpperBoundsCertificate(rationals({{1, 1}, {1, 1}, {2, 5}, {1, 1}, {0, 1}}));
551 EXPECT_FALSE(notInductive.checkValidity(*model));
552
553 // Probabilities are non-negative, so upper bounds on them are as well (even if the value is inductive).
555 negative.setUpperBoundsCertificate(rationals({{1, 1}, {1, 1}, {1, 1}, {1, 1}, {-1, 1}}));
556 EXPECT_FALSE(negative.checkValidity(*model));
557
558 // An empty constraint set is a valid constraint (and not the same as having no constraint): The target can only be reached from within the target.
559 storm::modelchecker::ReachabilityProbabilityCertificate<ValueType> emptyConstraint(std::nullopt, targetStates,
560 storm::storage::BitVector(model->getNumberOfStates(), false));
561 emptyConstraint.setUpperBoundsCertificate(rationals({{0, 1}, {0, 1}, {0, 1}, {1, 1}, {0, 1}}));
562 EXPECT_TRUE(emptyConstraint.checkValidity(*model));
563
564 // The upper bound for target states must be at least one.
565 storm::modelchecker::ReachabilityProbabilityCertificate<ValueType> targetTooSmall(std::nullopt, targetStates);
566 targetTooSmall.setUpperBoundsCertificate(rationals({{1, 1}, {1, 1}, {1, 1}, {1, 2}, {0, 1}}));
567 EXPECT_FALSE(targetTooSmall.checkValidity(*model));
568}
569
570TEST_F(HandMadeCertificateTest, LowerBound) {
571 auto const inf = storm::modelchecker::InfRank;
572 // Lower bound 0 everywhere but in the target. Ranks need to decrease towards the target.
574 valid.setLowerBoundsCertificate(rationals({{0, 1}, {0, 1}, {0, 1}, {1, 1}, {0, 1}}), {2, 1, 1, 0, inf});
575 EXPECT_TRUE(valid.checkValidity(*model));
576
577 // State 1 reaches the target with probability 7/10 in one step, so 9/10 is not a lower bound that is inductive.
578 storm::modelchecker::ReachabilityProbabilityCertificate<ValueType> notInductive(std::nullopt, targetStates);
579 notInductive.setLowerBoundsCertificate(rationals({{0, 1}, {9, 10}, {0, 1}, {1, 1}, {0, 1}}), {2, 1, 1, 0, inf});
580 EXPECT_FALSE(notInductive.checkValidity(*model));
581
582 // Claiming that the sink (state 4) has a positive lower bound is wrong, which the infinite rank reveals.
583 storm::modelchecker::ReachabilityProbabilityCertificate<ValueType> sinkWithPositiveBound(std::nullopt, targetStates);
584 sinkWithPositiveBound.setLowerBoundsCertificate(rationals({{0, 1}, {0, 1}, {0, 1}, {1, 1}, {1, 10}}), {2, 1, 1, 0, inf});
585 EXPECT_FALSE(sinkWithPositiveBound.checkValidity(*model));
586
587 // Positive lower bounds require finite ranks.
589 badRanks.setLowerBoundsCertificate(rationals({{0, 1}, {7, 10}, {1, 2}, {1, 1}, {0, 1}}), {inf, inf, inf, 0, inf});
590 EXPECT_FALSE(badRanks.checkValidity(*model));
591}
592
593TEST(CertificateAlgorithmTest, StringConversion) {
596 std::stringstream name;
597 name << algorithm;
598 EXPECT_EQ(algorithm, storm::certificateAlgorithmFromString(name.str()));
599 }
600 STORM_SILENT_EXPECT_THROW(storm::certificateAlgorithmFromString("unknown"), storm::exceptions::UnexpectedException);
601}
602
603} // namespace
TEST_F(ConstraintCollectorTest, PolynomialDenominators)
TEST(RegionConstraintCheckerTest, AffineConstraintHoldsThroughout)
SolverEnvironment & solver()
ModelCheckerEnvironment & modelchecker()
void setPrecision(storm::RationalNumber value)
CertificateModelCheckerEnvironment & certificate()
MinMaxSolverEnvironment & minMax()
A certificate for the result of a model checking query.
Definition Certificate.h:35
virtual std::string summaryString(storm::storage::BitVector const &relevantStates) const =0
virtual bool isExplicit() const
virtual bool isResultForAllStates() const
virtual bool isExplicitCertificateCheckResult() const
This class represents a continuous-time Markov chain.
Definition Ctmc.h:16
This class represents a discrete-time Markov chain.
Definition Dtmc.h:16
This class represents a (discrete-time) Markov decision process.
Definition Mdp.h:16
virtual uint_fast64_t getNumberOfStates() const override
Returns the number of states of the model.
Definition Model.cpp:191
This class manages the labeling of the state space with a number of (atomic) labels.
static storm::prism::Program parseFromString(std::string const &input, std::string const &filename, bool prismCompatability=false)
Parses the given input stream into the PRISM storage classes assuming it complies with the PRISM synt...
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
A class that can be used to build a sparse matrix by adding value by value.
std::vector< storm::jani::Property > parsePropertiesForPrismProgram(std::string const &inputString, storm::prism::Program const &program, boost::optional< std::set< std::string > > const &propertyFilter)
std::vector< std::shared_ptr< storm::logic::Formula const > > extractFormulasFromProperties(std::vector< storm::jani::Property > const &properties)
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
static RankingType const InfRank
Definition RankingType.h:8
NumberType parseNumber(std::string const &value)
Parse number from string.
TargetType convertNumber(SourceType const &number)
nlohmann::basic_json< std::map, std::vector, std::string, bool, int64_t, uint64_t, ValueType > json
Definition JsonForward.h:11
@ ExPI
Interval iteration with floating point numbers where lower bounds are rounded towards the sound direc...
@ FpRoundII
Smooth interval iteration with floating point numbers.
@ FpSmoothII
Interval iteration with floating point numbers.
CertificateAlgorithm certificateAlgorithmFromString(std::string const &algorithm)
TYPED_TEST(GraphTestAR, SymbolicProb01StochasticGameDieSmall)
Definition GraphTest.cpp:64
TYPED_TEST_SUITE(GraphTestAR, TestingTypes,)
::testing::Types< Cudd, Sylvan > TestingTypes
Definition GraphTest.cpp:61
#define STORM_SILENT_EXPECT_THROW(statement, expected_exception)
Definition storm_gtest.h:21