Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
AssumptionMakerTest.cpp
Go to the documentation of this file.
2#include "storm-config.h"
3#include "test/storm_gtest.h"
4
7
11
12#include "storm/api/builder.h"
13#include "storm/api/storm.h"
17#include "storm/utility/graph.h"
18
19class AssumptionMakerTest : public ::testing::Test {
20 protected:
21 void SetUp() override {
22#ifndef STORM_HAVE_Z3
23 GTEST_SKIP() << "Z3 not available.";
24#endif
25 }
26};
27
28TEST_F(AssumptionMakerTest, Brp_without_bisimulation) {
29 std::string programFile = STORM_TEST_RESOURCES_DIR "/pdtmc/brp16_2.pm";
30 std::string formulaAsString = "P=? [F s=4 & i=N ]";
31 std::string constantsAsString = ""; // e.g. pL=0.9,TOACK=0.5
32
33 // Program and formula
35 program = storm::utility::prism::preprocess(program, constantsAsString);
36 std::vector<std::shared_ptr<const storm::logic::Formula>> formulas =
38 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> model =
39 storm::api::buildSparseModel<storm::RationalFunction>(program, formulas)->as<storm::models::sparse::Dtmc<storm::RationalFunction>>();
41 ASSERT_TRUE(simplifier.simplify(*(formulas[0])));
42 model = simplifier.getSimplifiedModel();
44
45 // Create the region
47 auto region = storm::api::parseRegion<storm::RationalFunction>("0.00001 <= pK <= 0.999999, 0.00001 <= pL <= 0.999999", vars);
48
49 ASSERT_EQ(193ul, model->getNumberOfStates());
50 ASSERT_EQ(383ul, model->getNumberOfTransitions());
51
52 auto *extender = new storm::analysis::OrderExtender<storm::RationalFunction, double>(model, formulas[0]);
53 auto criticalTuple = extender->toOrder(region, nullptr);
54 ASSERT_EQ(183ul, std::get<1>(criticalTuple));
55 ASSERT_EQ(186ul, std::get<2>(criticalTuple));
56
57 auto assumptionMaker = storm::analysis::AssumptionMaker<storm::RationalFunction, double>(model->getTransitionMatrix());
58 auto result = assumptionMaker.createAndCheckAssumptions(std::get<1>(criticalTuple), std::get<2>(criticalTuple), std::get<0>(criticalTuple), region);
59
60 EXPECT_EQ(3ul, result.size());
61
62 for (auto res : result) {
63 EXPECT_EQ(storm::analysis::AssumptionStatus::UNKNOWN, res.second);
64 EXPECT_EQ(true, res.first->getFirstOperand()->isVariable());
65 EXPECT_EQ(true, res.first->getSecondOperand()->isVariable());
66 }
67
68 assumptionMaker.initializeCheckingOnSamples(formulas[0], model, region, 10);
69 result = assumptionMaker.createAndCheckAssumptions(std::get<1>(criticalTuple), std::get<2>(criticalTuple), std::get<0>(criticalTuple), region);
70 EXPECT_EQ(1ul, result.size());
71 auto itr = result.begin();
72 EXPECT_EQ(storm::analysis::AssumptionStatus::UNKNOWN, itr->second);
73 EXPECT_EQ(true, itr->first->getFirstOperand()->isVariable());
74 EXPECT_EQ(true, itr->first->getSecondOperand()->isVariable());
75 EXPECT_EQ("186", itr->first->getFirstOperand()->asVariableExpression().getVariable().getName());
76 EXPECT_EQ("183", itr->first->getSecondOperand()->asVariableExpression().getVariable().getName());
77 EXPECT_EQ(storm::expressions::RelationType::Greater, itr->first->getRelationType());
78}
79
81 std::string programFile = STORM_TEST_RESOURCES_DIR "/pdtmc/simple1.pm";
82 std::string formulaAsString = "P=? [F s=3 ]";
83 std::string constantsAsString = "";
84
86 program = storm::utility::prism::preprocess(program, constantsAsString);
87 std::vector<std::shared_ptr<const storm::logic::Formula>> formulas =
89 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> model =
90 storm::api::buildSparseModel<storm::RationalFunction>(program, formulas)->as<storm::models::sparse::Dtmc<storm::RationalFunction>>();
92 ASSERT_TRUE(simplifier.simplify(*(formulas[0])));
93 model = simplifier.getSimplifiedModel();
94
95 // Create the region
97 auto region = storm::api::parseRegion<storm::RationalFunction>("0.00001 <= p <= 0.999999", vars);
98
99 ASSERT_EQ(5ul, model->getNumberOfStates());
100 ASSERT_EQ(8ul, model->getNumberOfTransitions());
101
103 above.set(3);
105 below.set(4);
107 options.forceTopologicalSort();
108 auto decomposition = storm::storage::StronglyConnectedComponentDecomposition<storm::RationalFunction>(model->getTransitionMatrix(), options);
109 auto statesSorted = storm::utility::graph::getTopologicalSort(model->getTransitionMatrix());
110 auto order = std::shared_ptr<storm::analysis::Order>(new storm::analysis::Order(&above, &below, 5, decomposition, statesSorted));
111
112 auto assumptionMaker = storm::analysis::AssumptionMaker<storm::RationalFunction, double>(model->getTransitionMatrix());
113 auto result = assumptionMaker.createAndCheckAssumptions(1, 2, order, region);
114 EXPECT_EQ(0ul, result.size());
115 assumptionMaker.initializeCheckingOnSamples(formulas[0], model, region, 10);
116 result = assumptionMaker.createAndCheckAssumptions(1, 2, order, region);
117 EXPECT_EQ(0ul, result.size());
118
119 region = storm::api::parseRegion<storm::RationalFunction>("0.500001 <= p <= 0.999999", vars);
120 std::vector<std::vector<double>> samples;
121 assumptionMaker.setSampleValues(samples);
122 result = assumptionMaker.createAndCheckAssumptions(1, 2, order, region);
123 EXPECT_EQ(1ul, result.size());
124 auto itr = result.begin();
125 EXPECT_EQ(storm::analysis::AssumptionStatus::VALID, itr->second);
126 EXPECT_EQ(true, itr->first->getFirstOperand()->isVariable());
127 EXPECT_EQ(true, itr->first->getSecondOperand()->isVariable());
128 EXPECT_EQ("1", itr->first->getFirstOperand()->asVariableExpression().getVariable().getName());
129 EXPECT_EQ("2", itr->first->getSecondOperand()->asVariableExpression().getVariable().getName());
130 EXPECT_EQ(storm::expressions::RelationType::Greater, itr->first->getRelationType());
131}
132
134 std::string programFile = STORM_TEST_RESOURCES_DIR "/pdtmc/casestudy1.pm";
135 std::string formulaAsString = "P=? [F s=3 ]";
136 std::string constantsAsString = "";
137
138 storm::prism::Program program = storm::api::parseProgram(programFile);
139 program = storm::utility::prism::preprocess(program, constantsAsString);
140 std::vector<std::shared_ptr<const storm::logic::Formula>> formulas =
142 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> model =
143 storm::api::buildSparseModel<storm::RationalFunction>(program, formulas)->as<storm::models::sparse::Dtmc<storm::RationalFunction>>();
145 ASSERT_TRUE(simplifier.simplify(*(formulas[0])));
146 model = simplifier.getSimplifiedModel();
148 // Create the region
150 auto region = storm::api::parseRegion<storm::RationalFunction>("0.00001 <= p <= 0.999999", vars);
151
152 ASSERT_EQ(5ul, model->getNumberOfStates());
153 ASSERT_EQ(8ul, model->getNumberOfTransitions());
154
156 above.set(3);
158 below.set(4);
159
161 options.forceTopologicalSort();
162 auto decomposition = storm::storage::StronglyConnectedComponentDecomposition<storm::RationalFunction>(model->getTransitionMatrix(), options);
163 auto statesSorted = storm::utility::graph::getTopologicalSort(model->getTransitionMatrix());
164 auto order = std::shared_ptr<storm::analysis::Order>(new storm::analysis::Order(&above, &below, 5, decomposition, statesSorted));
165
166 auto assumptionMaker = storm::analysis::AssumptionMaker<storm::RationalFunction, double>(model->getTransitionMatrix());
167 auto result = assumptionMaker.createAndCheckAssumptions(1, 2, order, region);
168
169 EXPECT_EQ(1ul, result.size());
170 auto itr = result.begin();
171 EXPECT_EQ(storm::analysis::AssumptionStatus::VALID, itr->second);
172 EXPECT_EQ(true, itr->first->getFirstOperand()->isVariable());
173 EXPECT_EQ(true, itr->first->getSecondOperand()->isVariable());
174 EXPECT_EQ("1", itr->first->getFirstOperand()->asVariableExpression().getVariable().getName());
175 EXPECT_EQ("2", itr->first->getSecondOperand()->asVariableExpression().getVariable().getName());
176 EXPECT_EQ(storm::expressions::RelationType::Greater, itr->first->getRelationType());
177}
TEST_F(AssumptionMakerTest, Brp_without_bisimulation)
std::shared_ptr< ModelType > as()
Casts the model into the model type given by the template parameter.
Definition ModelBase.h:36
This class represents a discrete-time Markov chain.
Definition Dtmc.h:14
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
void set(uint_fast64_t index, bool value=true)
Sets the given truth value at the given index.
This class represents the decomposition of a graph-like structure into its strongly connected compone...
This class performs different steps to simplify the given (parametric) model.
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::set< storm::RationalFunctionVariable > getProbabilityParameters(Model< storm::RationalFunction > const &model)
Get all probability parameters occurring on transitions.
Definition Model.cpp:703
std::vector< uint_fast64_t > getTopologicalSort(storm::storage::SparseMatrix< T > const &matrix, std::vector< uint64_t > const &firstStates)
Performs a topological sort of the states of the system according to the given transitions.
Definition graph.cpp:1861
storm::prism::Program preprocess(storm::prism::Program const &program, std::map< storm::expressions::Variable, storm::expressions::Expression > const &constantDefinitions)
Definition prism.cpp:19
StronglyConnectedComponentDecompositionOptions & forceTopologicalSort(bool value=true)
Enforces that the returned SCCs are sorted in a topological order.