Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
ExplicitJaniModelBuilderTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
6#include "storm/api/storm.h"
16
17namespace {
18
19storm::jani::Model getJaniModelFromPrism(std::string const& pathInTestResourcesDir, bool prismCompatability = false) {
21 storm::parser::PrismParser::parse(STORM_TEST_RESOURCES_DIR "/" + pathInTestResourcesDir, prismCompatability);
22 auto m = modelDescription.toJani().preprocess().asJaniModel();
24 EXPECT_TRUE(unsupportedFeatures.empty()) << "Model '" << pathInTestResourcesDir << "' uses unsupported feature(s) " << unsupportedFeatures.toString();
25 return m;
26}
27
28class ExplicitJaniModelBuilderTest : public ::testing::Test {
29 protected:
30 void SetUp() override {
31#ifndef STORM_HAVE_SMT_SOLVER
32 GTEST_SKIP() << "No SMT solver available.";
33#endif
34 }
35};
36
37TEST_F(ExplicitJaniModelBuilderTest, Dtmc) {
38 auto janiModel = getJaniModelFromPrism("/dtmc/die.pm");
39
40 std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
41 EXPECT_EQ(13ul, model->getNumberOfStates());
42 EXPECT_EQ(20ul, model->getNumberOfTransitions());
43
44 janiModel = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/dtmc/die_array.jani").first;
46 EXPECT_EQ(13ul, model->getNumberOfStates());
47 EXPECT_EQ(20ul, model->getNumberOfTransitions());
48
49 janiModel = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/dtmc/die_array_nested.jani").first;
51 EXPECT_EQ(13ul, model->getNumberOfStates());
52 EXPECT_EQ(20ul, model->getNumberOfTransitions());
53
54 janiModel = getJaniModelFromPrism("/dtmc/brp-16-2.pm");
56 EXPECT_EQ(677ul, model->getNumberOfStates());
57 EXPECT_EQ(867ul, model->getNumberOfTransitions());
58
59 janiModel = getJaniModelFromPrism("/dtmc/crowds-5-5.pm");
61 EXPECT_EQ(8607ul, model->getNumberOfStates());
62 EXPECT_EQ(15113ul, model->getNumberOfTransitions());
63
64 janiModel = getJaniModelFromPrism("/dtmc/leader-3-5.pm");
66 EXPECT_EQ(273ul, model->getNumberOfStates());
67 EXPECT_EQ(397ul, model->getNumberOfTransitions());
68
69 janiModel = getJaniModelFromPrism("/dtmc/nand-5-2.pm");
71 EXPECT_EQ(1728ul, model->getNumberOfStates());
72 EXPECT_EQ(2505ul, model->getNumberOfTransitions());
73
74 janiModel = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/dtmc/test_trigonometry.jani").first;
75 auto constants = storm::languages::parseConstantDefinitionString(janiModel.getManager(), "step_size_rad=0.523599"); // step_size = 30 deg
76 janiModel = janiModel.defineUndefinedConstants(constants);
78 EXPECT_EQ(5ul, model->getNumberOfStates());
79 EXPECT_EQ(5ul, model->getNumberOfTransitions());
80}
81
82TEST_F(ExplicitJaniModelBuilderTest, pdtmc) {
83 auto janiModel = getJaniModelFromPrism("/pdtmc/parametric_die.pm");
84 std::shared_ptr<storm::models::sparse::Model<storm::RationalFunction>> model =
86 EXPECT_EQ(13ul, model->getNumberOfStates());
87 EXPECT_EQ(20ul, model->getNumberOfTransitions());
88
89 janiModel = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/pdtmc/die_array_nested.jani").first;
90 janiModel.substituteConstantsFunctionsTranscendentals();
92 EXPECT_EQ(13ul, model->getNumberOfStates());
93 EXPECT_EQ(20ul, model->getNumberOfTransitions());
94
95 janiModel = getJaniModelFromPrism("/pdtmc/brp16_2.pm");
97 EXPECT_EQ(677ul, model->getNumberOfStates());
98 EXPECT_EQ(867ul, model->getNumberOfTransitions());
99}
100
101TEST_F(ExplicitJaniModelBuilderTest, Ctmc) {
102 auto janiModel = getJaniModelFromPrism("/ctmc/cluster2.sm", true);
103
104 std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
105 EXPECT_EQ(276ul, model->getNumberOfStates());
106 EXPECT_EQ(1120ul, model->getNumberOfTransitions());
107
108 janiModel = getJaniModelFromPrism("/ctmc/embedded2.sm", true);
110 EXPECT_EQ(3478ul, model->getNumberOfStates());
111 EXPECT_EQ(14639ul, model->getNumberOfTransitions());
112
113 janiModel = getJaniModelFromPrism("/ctmc/polling2.sm", true);
115 EXPECT_EQ(12ul, model->getNumberOfStates());
116 EXPECT_EQ(22ul, model->getNumberOfTransitions());
117
118 janiModel = getJaniModelFromPrism("/ctmc/fms2.sm", true);
120 EXPECT_EQ(810ul, model->getNumberOfStates());
121 EXPECT_EQ(3699ul, model->getNumberOfTransitions());
122
123 janiModel = getJaniModelFromPrism("/ctmc/tandem5.sm", true);
125 EXPECT_EQ(66ul, model->getNumberOfStates());
126 EXPECT_EQ(189ul, model->getNumberOfTransitions());
127}
128
129TEST_F(ExplicitJaniModelBuilderTest, Mdp) {
130 auto janiModel = getJaniModelFromPrism("/mdp/two_dice.nm");
131
132 std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
133 EXPECT_EQ(169ul, model->getNumberOfStates());
134 EXPECT_EQ(436ul, model->getNumberOfTransitions());
135
136 janiModel = getJaniModelFromPrism("/mdp/leader3.nm");
138 EXPECT_EQ(364ul, model->getNumberOfStates());
139 EXPECT_EQ(654ul, model->getNumberOfTransitions());
140
141 janiModel = getJaniModelFromPrism("/mdp/coin2-2.nm");
143 EXPECT_EQ(272ul, model->getNumberOfStates());
144 EXPECT_EQ(492ul, model->getNumberOfTransitions());
145
146 janiModel = getJaniModelFromPrism("/mdp/csma2-2.nm");
148 EXPECT_EQ(1038ul, model->getNumberOfStates());
149 EXPECT_EQ(1282ul, model->getNumberOfTransitions());
150
151 janiModel = getJaniModelFromPrism("/mdp/firewire3-0.5.nm");
153 EXPECT_EQ(4093ul, model->getNumberOfStates());
154 EXPECT_EQ(5585ul, model->getNumberOfTransitions());
155
156 janiModel = getJaniModelFromPrism("/mdp/wlan0-2-2.nm");
158 EXPECT_EQ(37ul, model->getNumberOfStates());
159 EXPECT_EQ(59ul, model->getNumberOfTransitions());
160
161 janiModel = getJaniModelFromPrism("/mdp/sync.nm");
163 EXPECT_EQ(5ul, model->getNumberOfStates());
164 EXPECT_EQ(24ul, model->getNumberOfTransitions());
165 EXPECT_EQ(12ul, model->getNumberOfChoices());
166
167 janiModel = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/mdp/tiny_rewards.jani").first;
169 options.setBuildChoiceLabels();
170 model = storm::builder::ExplicitModelBuilder<double>(janiModel, options).build();
171 EXPECT_EQ(2ul, model->getChoiceLabeling().getNumberOfLabels());
172
173 janiModel = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/mdp/tiny_rewards4.jani").first;
174 options.setBuildChoiceLabels();
175 model = storm::builder::ExplicitModelBuilder<double>(janiModel, options).build();
176 EXPECT_EQ(2ul, model->getChoiceLabeling().getNumberOfLabels());
177}
178
179TEST_F(ExplicitJaniModelBuilderTest, Ma) {
180 auto janiModel = getJaniModelFromPrism("/ma/simple.ma");
181
182 std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
183 EXPECT_EQ(5ul, model->getNumberOfStates());
184 EXPECT_EQ(8ul, model->getNumberOfTransitions());
185 ASSERT_TRUE(model->isOfType(storm::models::ModelType::MarkovAutomaton));
187
188 janiModel = getJaniModelFromPrism("/ma/hybrid_states.ma");
190 EXPECT_EQ(5ul, model->getNumberOfStates());
191 EXPECT_EQ(13ul, model->getNumberOfTransitions());
192 ASSERT_TRUE(model->isOfType(storm::models::ModelType::MarkovAutomaton));
194
195 janiModel = getJaniModelFromPrism("/ma/stream2.ma");
197 EXPECT_EQ(12ul, model->getNumberOfStates());
198 EXPECT_EQ(14ul, model->getNumberOfTransitions());
199 ASSERT_TRUE(model->isOfType(storm::models::ModelType::MarkovAutomaton));
201
202 janiModel = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/ma/ftwc.jani").first;
203 auto constants = storm::languages::parseConstantDefinitionString(janiModel.getManager(), "N=2,TIME_BOUND=1");
204 janiModel = janiModel.defineUndefinedConstants(constants);
206 EXPECT_EQ(1536ul, model->getNumberOfStates());
207 EXPECT_EQ(6448ul, model->getNumberOfTransitions());
208 ASSERT_TRUE(model->isOfType(storm::models::ModelType::MarkovAutomaton));
210}
211
212TEST_F(ExplicitJaniModelBuilderTest, FailComposition) {
213 auto janiModel = getJaniModelFromPrism("/mdp/system_composition.nm");
214
215 STORM_SILENT_ASSERT_THROW(storm::builder::ExplicitModelBuilder<double>(janiModel).build(), storm::exceptions::WrongFormatException);
216}
217
218TEST_F(ExplicitJaniModelBuilderTest, unassignedVariables) {
219 storm::jani::Model janiModel = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/mdp/unassigned-variables.jani").first;
220 std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
221 EXPECT_EQ(25ul, model->getNumberOfStates());
222 EXPECT_EQ(81ul, model->getNumberOfTransitions());
223}
224
225TEST_F(ExplicitJaniModelBuilderTest, enumerateInitial) {
226 storm::jani::Model janiModel = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/mdp/enumerate_init.jani").first;
227 std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
228 EXPECT_EQ(94ul, model->getNumberOfStates());
229 EXPECT_EQ(145ul, model->getNumberOfTransitions());
230 EXPECT_EQ(72ul, model->getInitialStates().getNumberOfSetBits());
231}
232
233TEST_F(ExplicitJaniModelBuilderTest, SynchronizationVectorOutputActionIndex) {
234 auto janiModel = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/mdp/synchronization_vector_output_action_index.jani").first;
235
237 std::deque<storm::generator::CompressedState> states;
238 auto stateToIdCallback = [&states](storm::generator::CompressedState const& state) {
239 for (uint32_t index = 0; index < states.size(); ++index) {
240 if (states[index] == state) {
241 return index;
242 }
243 }
244 states.push_back(state);
245 return static_cast<uint32_t>(states.size() - 1);
246 };
247
248 auto initialStates = generator.getInitialStates(stateToIdCallback);
249 ASSERT_EQ(1ul, initialStates.size());
250 generator.load(states[initialStates.front()]);
251
252 auto behavior = generator.expand(stateToIdCallback);
253 ASSERT_EQ(3ul, behavior.getNumberOfChoices());
254
255 std::set<std::string> actionNames;
256 for (auto const& choice : behavior.getChoices()) {
257 actionNames.insert(janiModel.getAction(choice.getActionIndex()).getName());
258 }
259 EXPECT_EQ(std::set<std::string>({"d", "e", "f"}), actionNames);
260}
261
262TEST_F(ExplicitJaniModelBuilderTest, AssignmentLevels) {
263 // Transient values passed between automata over several assignment levels. In levels_three_levels and
264 // levels_edge_assignment, the transient assignments of a level used to be taken from the last automaton only.
265 std::map<std::string, std::map<std::string, double>> expected = {{"levels_det_transient", {{"xb=2", 1.0}}},
266 {"levels_random_transient", {{"agree1", 0.5}, {"mismatch", 0.0}, {"agree2", 0.5}}},
267 {"levels_next_state_read", {{"agree1", 0.5}, {"mismatch", 0.0}}},
268 {"levels_receiver_flips", {{"a1b2", 0.125}, {"a2b3", 0.375}, {"a1b3", 0.0}}},
269 {"levels_three_levels", {{"xc=3", 1.0}}},
270 {"levels_edge_assignment", {{"agree1", 0.5}, {"mismatch", 0.0}}}};
271 for (auto const& [file, expectedValues] : expected) {
272 auto modelAndProperties = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/mdp/" + file + ".jani");
273 auto formulas = storm::api::extractFormulasFromProperties(modelAndProperties.second);
274 auto model = storm::api::buildSparseModel<double>(modelAndProperties.first, formulas);
275 ASSERT_EQ(expectedValues.size(), formulas.size()) << file;
276 for (uint64_t i = 0; i < formulas.size(); ++i) {
277 auto result = storm::api::verifyWithSparseEngine<double>(model, storm::api::createTask<double>(formulas[i], true));
278 result->filter(storm::modelchecker::ExplicitQualitativeCheckResult<double>(model->getInitialStates()));
279 EXPECT_NEAR(expectedValues.at(modelAndProperties.second[i].getName()), result->asQuantitativeCheckResult<double>().getMax(), 1e-6)
280 << file << " " << modelAndProperties.second[i].getName();
281 }
282 }
283}
284
285} // namespace
TEST_F(ConstraintCollectorTest, PolynomialDenominators)
storm::models::sparse::Dtmc< double > Dtmc
storm::models::sparse::Mdp< double > Mdp
BuilderOptions & setBuildChoiceLabels(bool newValue=true)
Should the choice labels be built?
std::shared_ptr< storm::models::sparse::Model< ValueType, RewardModelType > > build()
Convert the program given at construction time to an abstract model.
static storm::jani::ModelFeatures getSupportedJaniFeatures()
Returns the jani features with which this builder can deal natively.
std::string const & getName() const
Returns the name of the location.
Definition Action.cpp:9
std::string toString() const
Action const & getAction(uint64_t index) const
Retrieves the action with the given index.
Definition Model.cpp:624
ModelFeatures restrictToFeatures(ModelFeatures const &modelFeatures)
Attempts to eliminate all features of this model that are not in the given set of features.
Definition Model.cpp:1249
SymbolicModelDescription preprocess(std::string const &constantDefinitionString="") const
SymbolicModelDescription toJani(bool makeVariablesGlobal=true) const
A qualitative check result over the states of a sparse model.
This class represents a Markov automaton.
storm::storage::BitVector const & getMarkovianStates() const
Retrieves the set of Markovian states of the model.
static storm::prism::Program parse(std::string const &filename, bool prismCompatability=false)
Parses the given file into the PRISM storage classes assuming it complies with the PRISM syntax.
uint64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > createTask(std::shared_ptr< const storm::logic::Formula > const &formula, bool onlyInitialStatesRelevant=false)
std::vector< std::shared_ptr< storm::logic::Formula const > > extractFormulasFromProperties(std::vector< storm::jani::Property > const &properties)
std::pair< storm::jani::Model, std::vector< storm::jani::Property > > parseJaniModel(std::string const &filename, boost::optional< std::vector< std::string > > const &propertyFilter)
std::unique_ptr< storm::modelchecker::CheckResult > verifyWithSparseEngine(storm::Environment const &env, std::shared_ptr< storm::models::sparse::Dtmc< ValueType > > const &dtmc, storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > const &task, bool preferEliminationChecker=false)
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
storm::storage::BitVector CompressedState
storm::builder::BuilderOptions NextStateGeneratorOptions
std::map< storm::expressions::Variable, storm::expressions::Expression > parseConstantDefinitionString(storm::expressions::ExpressionManager const &manager, std::string const &constantDefinitionString)
Parses a comma-separated string of constant definitions (e.g.
#define STORM_SILENT_ASSERT_THROW(statement, expected_exception)
Definition storm_gtest.h:16