Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
RobustDtmcPrctlModelCheckerTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
8#include "storm/api/builder.h"
16
17std::unique_ptr<storm::modelchecker::QualitativeCheckResult> getInitialStateFilter(
18 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> const& model) {
19 return std::make_unique<storm::modelchecker::ExplicitQualitativeCheckResult>(model->getInitialStates());
20}
21
22std::unique_ptr<storm::modelchecker::QualitativeCheckResult> getInitialStateFilter(std::shared_ptr<storm::models::sparse::Model<double>> const& model) {
23 return std::make_unique<storm::modelchecker::ExplicitQualitativeCheckResult>(model->getInitialStates());
24}
25
27 std::unique_ptr<storm::modelchecker::CheckResult>& result) {
28 auto filter = getInitialStateFilter(model);
29 result->filter(*filter);
30 return result->asQuantitativeCheckResult<double>().getMin();
31}
32
34 std::unique_ptr<storm::modelchecker::CheckResult>& result) {
35 auto filter = getInitialStateFilter(model);
36 result->filter(*filter);
37 return result->asQuantitativeCheckResult<double>().getMin();
38}
39
40void expectThrow(std::string const& path, std::string const& formulaString,
41 std::optional<storm::UncertaintyResolutionMode> uncertaintyResolutionMode = std::nullopt) {
42 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> modelPtr = storm::parser::DirectEncodingParser<storm::Interval>::parseModel(path);
43 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(storm::api::parseProperties(formulaString));
44
46 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
47
48 std::shared_ptr<storm::models::sparse::Dtmc<storm::Interval>> dtmc = modelPtr->as<storm::models::sparse::Dtmc<storm::Interval>>();
49 ASSERT_EQ(storm::models::ModelType::Dtmc, modelPtr->getType());
51 if (uncertaintyResolutionMode.has_value()) {
52 task.setUncertaintyResolutionMode(uncertaintyResolutionMode.value());
53 }
54
57}
58
59void expectThrowPrism(std::string const& path, std::string const& formulaString) {
61 program = storm::utility::prism::preprocess(program, "");
62
63 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(storm::api::parseProperties(formulaString));
64 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> modelPtr = storm::api::buildSparseModel<storm::Interval>(program, formulas);
65
67 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
68
69 std::shared_ptr<storm::models::sparse::Dtmc<storm::Interval>> dtmc = modelPtr->as<storm::models::sparse::Dtmc<storm::Interval>>();
70 ASSERT_EQ(storm::models::ModelType::Dtmc, modelPtr->getType());
72
74 STORM_SILENT_EXPECT_THROW(checker.check(env, task), storm::exceptions::InvalidArgumentException);
75}
76
77void checkExplicitModelForQuantitativeResult(std::string const& path, std::string const& formulaString, double min, double max) {
78 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> modelPtr = storm::parser::DirectEncodingParser<storm::Interval>::parseModel(path);
79 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(storm::api::parseProperties(formulaString));
81 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
82
83 std::shared_ptr<storm::models::sparse::Dtmc<storm::Interval>> dtmc = modelPtr->as<storm::models::sparse::Dtmc<storm::Interval>>();
84 ASSERT_EQ(storm::models::ModelType::Dtmc, modelPtr->getType());
86 taskMax.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Maximize);
87
89 auto resultMax = checker.check(env, taskMax);
90 EXPECT_NEAR(max, getQuantitativeResultAtInitialState(dtmc, resultMax), 0.0001);
91
93 taskMin.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Minimize);
94
95 auto resultMin = checker.check(env, taskMin);
96 EXPECT_NEAR(min, getQuantitativeResultAtInitialState(dtmc, resultMin), 0.0001);
97}
98
99void checkPrismModelForQuantitativeResult(std::string const& path, std::string const& formulaString, double min, double max) {
101 program = storm::utility::prism::preprocess(program, "");
102
103 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(storm::api::parseProperties(formulaString));
104 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> modelPtr = storm::api::buildSparseModel<storm::Interval>(program, formulas);
105
107 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
108
109 std::shared_ptr<storm::models::sparse::Dtmc<storm::Interval>> dtmc = modelPtr->as<storm::models::sparse::Dtmc<storm::Interval>>();
110 ASSERT_EQ(storm::models::ModelType::Dtmc, modelPtr->getType());
112 taskMax.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Maximize);
113
115 auto resultMax = checker.check(env, taskMax);
116 EXPECT_NEAR(max, getQuantitativeResultAtInitialState(dtmc, resultMax), 0.0001);
117
119 taskMin.setUncertaintyResolutionMode(storm::UncertaintyResolutionMode::Minimize);
120
121 auto resultMin = checker.check(env, taskMin);
122 EXPECT_NEAR(min, getQuantitativeResultAtInitialState(dtmc, resultMin), 0.0001);
123}
124
125void checkModelForQualitativeResult(std::string const& path, std::string const& formulaString, std::vector<storm::storage::BitVector> expectedResultVector) {
126 std::shared_ptr<storm::models::sparse::Model<storm::Interval>> modelPtr = storm::parser::DirectEncodingParser<storm::Interval>::parseModel(path);
127 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(storm::api::parseProperties(formulaString));
129 env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration);
130
131 std::shared_ptr<storm::models::sparse::Dtmc<storm::Interval>> dtmc = modelPtr->as<storm::models::sparse::Dtmc<storm::Interval>>();
132 ASSERT_EQ(storm::models::ModelType::Dtmc, modelPtr->getType());
134
136 auto result = checker.check(env, task1);
137
138 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
139
140 for (size_t i = 0; i < expectedResultVector[0].size(); i++) {
141 EXPECT_EQ(expectedResultVector[0].get(i), result->asExplicitQualitativeCheckResult()[i]);
142 }
143
145
146 result = checker.check(env, task2);
147
148 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
149
150 for (size_t i = 0; i < expectedResultVector[1].size(); i++) {
151 EXPECT_EQ(expectedResultVector[1].get(i), result->asExplicitQualitativeCheckResult()[i]);
152 }
153}
154
155TEST(RobustDtmcModelCheckerTest, Tiny01ReachMaxMinProbs) {
156 // Maximal Reachability probabilities using explicit format.
157 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-01.drn", "P=? [ F \"target\"];P=? [ F \"target\"]", 0.3, 0.5);
158}
159
160TEST(RobustDtmcModelCheckerTest, Tiny01MaxReachProbNoUncertaintyResolutionMode) {
161 // Nature requires a resolution mode, expect thrown.
162 expectThrow(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-01.drn", "P=? [ F \"target\"];",
163 std::make_optional<storm::UncertaintyResolutionMode>(storm::UncertaintyResolutionMode::Unset));
164}
165
166TEST(RobustDtmcModelCheckerTest, Tiny01MaxReachProbNoOptimizationDirectionButRobust) {
167 // Nature requires a resolution mode, expect thrown.
168 expectThrow(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-01.drn", "P=? [ F \"target\"];",
169 std::make_optional<storm::UncertaintyResolutionMode>(storm::UncertaintyResolutionMode::Robust));
170}
171
172TEST(RobustDtmcModelCheckerTest, Tiny02GloballyMaxMinProbs) {
173 // Globally not yet supported, expect throw.
174 expectThrow(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-02.drn", "P=? [ G \"target\"];P=? [ G \"target\"]");
175}
176
177TEST(RobustDtmcModelCheckerTest, DieIntervalsMaxMin) {
178#ifndef STORM_HAVE_Z3
179 GTEST_SKIP() << "Z3 not available.";
180#endif
181 // Maxima reachability probabilities using PRISM format.
182 checkPrismModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/die-intervals.pm", "P=? [ F \"one\"];P=? [ F \"one\"]", 9.0 / 189.0, 72.0 / 189.0);
183}
184
185TEST(RobustDtmcModelCheckerTest, BrpIntervalsMaxMin) {
186#ifndef STORM_HAVE_Z3
187 GTEST_SKIP() << "Z3 not available.";
188#endif
189 // Maxima reachability probabilities using PRISM format.
190 checkPrismModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/brp-32-2-intervals.pm", "P=? [ F \"error\" ];P=? [ F \"error\" ]",
191 2.559615918664207e-10, 0.0008464876763422187);
192}
193
194TEST(RobustDtmcModelCheckerTest, DieIntervalsMaxMinRewards) {
195#ifndef STORM_HAVE_Z3
196 GTEST_SKIP() << "Z3 not available.";
197#endif
198 // Maxima reachability rewards using PRISM format.
199 checkPrismModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/die-intervals.pm", "R=? [ F \"done\"];R=? [ F \"done\"]", 3.25, 4.6);
200}
201
202TEST(RobustDtmcModelCheckerTest, Tiny03MaxMinRewards) {
203 // Maxima reachability rewards using explicit format.
204 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-03.drn", "R=? [ F \"target\"];R=? [ F \"target\"]", 6.5, 8.5);
205}
206
207TEST(RobustDtmcModelCheckerTest, Tiny03RewardsNoUncertaintyResolutionMode) {
208 // Nature requires a resolution mode, expect thrown.
209 expectThrow(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-03.drn", "R=? [ F \"target\"]", storm::UncertaintyResolutionMode::Unset);
210}
211
212TEST(RobustDtmcModelCheckerTest, Tiny04MaxMinRewards) {
213 // Maxima reachability rewards using explicit format - infinite reward case.
214 checkExplicitModelForQuantitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-04.drn", "R=? [ F \"target\"];R=? [ F \"target\"]",
215 std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity());
216}
217
218TEST(RobustDtmcModelCheckerTest, TinyO2Propositional) {
219 // Propositional formula using explicit format.
220 std::vector<storm::storage::BitVector> expectedResults;
221 auto result1 = storm::storage::BitVector(3);
222 result1.set(0);
223 result1.set(2);
224 expectedResults.push_back(result1);
225 result1.complement();
226 expectedResults.push_back(result1);
227
228 checkModelForQualitativeResult(STORM_TEST_RESOURCES_DIR "/idtmc/tiny-02.drn", "\"target\";!\"target\"", expectedResults);
229}
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 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)
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:13
Base class for all sparse models.
Definition Model.h:32
static std::shared_ptr< storm::models::sparse::Model< ValueType, RewardModelType > > parseModel(std::string const &fil, DirectEncodingParserOptions const &options=DirectEncodingParserOptions())
Load a model in DRN format from a file and create the model.
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
storm::prism::Program parseProgram(std::string const &filename, bool prismCompatibility, bool simplify)
std::vector< storm::jani::Property > parseProperties(storm::parser::FormulaParser &formulaParser, std::string const &inputString, 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)
storm::prism::Program preprocess(storm::prism::Program const &program, std::map< storm::expressions::Variable, storm::expressions::Expression > const &constantDefinitions)
Definition prism.cpp:13
#define STORM_SILENT_EXPECT_THROW(statement, expected_exception)
Definition storm_gtest.h:31