Storm 1.11.1.1
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
13
17
18#include "storm/api/builder.h"
19#include "storm/api/storm.h"
23#include "storm/utility/graph.h"
24
25class AssumptionMakerTest : public ::testing::Test {
26 protected:
27 void SetUp() override {
28#ifndef STORM_HAVE_Z3
29 GTEST_SKIP() << "Z3 not available.";
30#endif
31 }
32};
33
34TEST_F(AssumptionMakerTest, Brp_without_bisimulation) {
35 std::string programFile = STORM_TEST_RESOURCES_DIR "/pdtmc/brp16_2.pm";
36 std::string formulaAsString = "P=? [F s=4 & i=N ]";
37 std::string constantsAsString = ""; // e.g. pL=0.9,TOACK=0.5
38
39 // Program and formula
41 program = storm::utility::prism::preprocess(program, constantsAsString);
42 std::vector<std::shared_ptr<const storm::logic::Formula>> formulas =
44 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> model =
45 storm::api::buildSparseModel<storm::RationalFunction>(program, formulas)->as<storm::models::sparse::Dtmc<storm::RationalFunction>>();
47 ASSERT_TRUE(simplifier.simplify(*(formulas[0])));
48 model = simplifier.getSimplifiedModel();
50
51 // Create the region
53 auto region = storm::api::parseRegion<storm::RationalFunction>("0.00001 <= pK <= 0.999999, 0.00001 <= pL <= 0.999999", vars);
54
55 ASSERT_EQ(193ul, model->getNumberOfStates());
56 ASSERT_EQ(383ul, model->getNumberOfTransitions());
57
58 auto *extender = new storm::analysis::OrderExtender<storm::RationalFunction, double>(model, formulas[0]);
59 auto criticalTuple = extender->toOrder(region, nullptr);
60 ASSERT_EQ(183ul, std::get<1>(criticalTuple));
61 ASSERT_EQ(186ul, std::get<2>(criticalTuple));
62
63 auto assumptionMaker = storm::analysis::AssumptionMaker<storm::RationalFunction, double>(model->getTransitionMatrix());
64 auto result = assumptionMaker.createAndCheckAssumptions(std::get<1>(criticalTuple), std::get<2>(criticalTuple), std::get<0>(criticalTuple), region);
65
66 EXPECT_EQ(3ul, result.size());
67
68 for (auto res : result) {
69 EXPECT_EQ(storm::analysis::AssumptionStatus::UNKNOWN, res.second);
70 EXPECT_EQ(true, res.first->getFirstOperand()->isVariable());
71 EXPECT_EQ(true, res.first->getSecondOperand()->isVariable());
72 }
73
74 assumptionMaker.initializeCheckingOnSamples(formulas[0], model, region, 10);
75 result = assumptionMaker.createAndCheckAssumptions(std::get<1>(criticalTuple), std::get<2>(criticalTuple), std::get<0>(criticalTuple), region);
76 EXPECT_EQ(1ul, result.size());
77 auto itr = result.begin();
78 EXPECT_EQ(storm::analysis::AssumptionStatus::UNKNOWN, itr->second);
79 EXPECT_EQ(true, itr->first->getFirstOperand()->isVariable());
80 EXPECT_EQ(true, itr->first->getSecondOperand()->isVariable());
81 EXPECT_EQ("186", itr->first->getFirstOperand()->asVariableExpression().getVariable().getName());
82 EXPECT_EQ("183", itr->first->getSecondOperand()->asVariableExpression().getVariable().getName());
83 EXPECT_EQ(storm::expressions::RelationType::Greater, itr->first->getRelationType());
84}
85
87 std::string programFile = STORM_TEST_RESOURCES_DIR "/pdtmc/simple1.pm";
88 std::string formulaAsString = "P=? [F s=3 ]";
89 std::string constantsAsString = "";
90
92 program = storm::utility::prism::preprocess(program, constantsAsString);
93 std::vector<std::shared_ptr<const storm::logic::Formula>> formulas =
95 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> model =
96 storm::api::buildSparseModel<storm::RationalFunction>(program, formulas)->as<storm::models::sparse::Dtmc<storm::RationalFunction>>();
98 ASSERT_TRUE(simplifier.simplify(*(formulas[0])));
99 model = simplifier.getSimplifiedModel();
100
101 // Create the region
103 auto region = storm::api::parseRegion<storm::RationalFunction>("0.00001 <= p <= 0.999999", vars);
104
105 ASSERT_EQ(5ul, model->getNumberOfStates());
106 ASSERT_EQ(8ul, model->getNumberOfTransitions());
107
109 above.set(3);
111 below.set(4);
113 options.forceTopologicalSort();
114 auto decomposition = storm::storage::StronglyConnectedComponentDecomposition<storm::RationalFunction>(model->getTransitionMatrix(), options);
115 auto statesSorted = storm::utility::graph::getTopologicalSort(model->getTransitionMatrix());
116 auto order = std::shared_ptr<storm::analysis::Order>(new storm::analysis::Order(above, below, 5, decomposition, statesSorted));
117
118 auto assumptionMaker = storm::analysis::AssumptionMaker<storm::RationalFunction, double>(model->getTransitionMatrix());
119 auto result = assumptionMaker.createAndCheckAssumptions(1, 2, order, region);
120 EXPECT_EQ(0ul, result.size());
121 assumptionMaker.initializeCheckingOnSamples(formulas[0], model, region, 10);
122 result = assumptionMaker.createAndCheckAssumptions(1, 2, order, region);
123 EXPECT_EQ(0ul, result.size());
124
125 region = storm::api::parseRegion<storm::RationalFunction>("0.500001 <= p <= 0.999999", vars);
126 std::vector<std::vector<double>> samples;
127 assumptionMaker.setSampleValues(samples);
128 result = assumptionMaker.createAndCheckAssumptions(1, 2, order, region);
129 EXPECT_EQ(1ul, result.size());
130 auto itr = result.begin();
131 EXPECT_EQ(storm::analysis::AssumptionStatus::VALID, itr->second);
132 EXPECT_EQ(true, itr->first->getFirstOperand()->isVariable());
133 EXPECT_EQ(true, itr->first->getSecondOperand()->isVariable());
134 EXPECT_EQ("1", itr->first->getFirstOperand()->asVariableExpression().getVariable().getName());
135 EXPECT_EQ("2", itr->first->getSecondOperand()->asVariableExpression().getVariable().getName());
136 EXPECT_EQ(storm::expressions::RelationType::Greater, itr->first->getRelationType());
137}
138
140 std::string programFile = STORM_TEST_RESOURCES_DIR "/pdtmc/casestudy1.pm";
141 std::string formulaAsString = "P=? [F s=3 ]";
142 std::string constantsAsString = "";
143
144 storm::prism::Program program = storm::api::parseProgram(programFile);
145 program = storm::utility::prism::preprocess(program, constantsAsString);
146 std::vector<std::shared_ptr<const storm::logic::Formula>> formulas =
148 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> model =
149 storm::api::buildSparseModel<storm::RationalFunction>(program, formulas)->as<storm::models::sparse::Dtmc<storm::RationalFunction>>();
151 ASSERT_TRUE(simplifier.simplify(*(formulas[0])));
152 model = simplifier.getSimplifiedModel();
154 // Create the region
156 auto region = storm::api::parseRegion<storm::RationalFunction>("0.00001 <= p <= 0.999999", vars);
157
158 ASSERT_EQ(5ul, model->getNumberOfStates());
159 ASSERT_EQ(8ul, model->getNumberOfTransitions());
160
162 above.set(3);
164 below.set(4);
165
167 options.forceTopologicalSort();
168 auto decomposition = storm::storage::StronglyConnectedComponentDecomposition<storm::RationalFunction>(model->getTransitionMatrix(), options);
169 auto statesSorted = storm::utility::graph::getTopologicalSort(model->getTransitionMatrix());
170 auto order = std::shared_ptr<storm::analysis::Order>(new storm::analysis::Order(above, below, 5, decomposition, statesSorted));
171
172 auto assumptionMaker = storm::analysis::AssumptionMaker<storm::RationalFunction, double>(model->getTransitionMatrix());
173 auto result = assumptionMaker.createAndCheckAssumptions(1, 2, order, region);
174
175 EXPECT_EQ(1ul, result.size());
176 auto itr = result.begin();
177 EXPECT_EQ(storm::analysis::AssumptionStatus::VALID, itr->second);
178 EXPECT_EQ(true, itr->first->getFirstOperand()->isVariable());
179 EXPECT_EQ(true, itr->first->getSecondOperand()->isVariable());
180 EXPECT_EQ("1", itr->first->getFirstOperand()->asVariableExpression().getVariable().getName());
181 EXPECT_EQ("2", itr->first->getSecondOperand()->asVariableExpression().getVariable().getName());
182 EXPECT_EQ(storm::expressions::RelationType::Greater, itr->first->getRelationType());
183}
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:38
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:16
void set(uint64_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:1851
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.