Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
TestBdd.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
5#include "storm-dft/api/io.h"
11
12namespace {
13
14struct SftTestData {
15 std::string testname;
16 std::string filepath;
17 std::string bddHash;
18 double probabilityAtTimeboundOne;
19 double mttf;
20 std::vector<double> birnbaum;
21 std::vector<double> CIF;
22 std::vector<double> DIF;
23 std::vector<double> RAW;
24 std::vector<double> RRW;
25
26 friend std::ostream &operator<<(std::ostream &os, SftTestData const &data) {
27 auto printVector = [&os](std::vector<double> const &arr) {
28 os << ", {";
29 for (auto const &i : arr) {
30 os << i;
31 // will leave trailing ", " but its simpler
32 // and would still be a valid initializer
33 os << ", ";
34 }
35 os << '}';
36 };
37
38 os << "{\"" << data.testname << '"';
39 os << ", \"" << data.filepath << '"';
40 os << ", \"" << data.bddHash << '"';
41 os << ", " << data.probabilityAtTimeboundOne;
42 os << ", " << data.mttf;
43 printVector(data.birnbaum);
44 printVector(data.CIF);
45 printVector(data.DIF);
46 printVector(data.RAW);
47 printVector(data.RRW);
48 os << '}';
49 return os;
50 }
51};
52
53class SftBddTest : public testing::TestWithParam<SftTestData> {
54 protected:
55 void SetUp() override {
56#ifdef STORM_HAVE_SYLVAN
57 auto const &param{TestWithParam::GetParam()};
58 auto dft{storm::dft::api::loadDFTGalileoFile<double>(param.filepath)};
59 storm::Environment env;
60 checker = std::make_shared<storm::dft::modelchecker::SFTBDDChecker>(dft, std::make_shared<storm::dft::storage::SylvanBddManager>(env));
61#else
62 GTEST_SKIP() << "Library Sylvan not available.";
63#endif
64 }
65
66 std::shared_ptr<storm::dft::modelchecker::SFTBDDChecker> checker;
67};
68
69TEST_P(SftBddTest, bddHash) {
70#ifdef STORM_HAVE_SYLVAN
71 auto const &param{TestWithParam::GetParam()};
72 EXPECT_EQ(checker->getTransformator()->transformTopLevel().GetShaHash(), param.bddHash);
73#else
74 GTEST_SKIP() << "Library Sylvan not available.";
75#endif
76}
77
78TEST_P(SftBddTest, ProbabilityAtTimeOne) {
79 auto const &param{TestWithParam::GetParam()};
80 EXPECT_NEAR(checker->getProbabilityAtTimebound(1), param.probabilityAtTimeboundOne, 1e-6);
81}
82
83TEST_P(SftBddTest, MTTF) {
84 auto const &param{TestWithParam::GetParam()};
85 EXPECT_NEAR(storm::dft::utility::MTTFHelperProceeding(checker->getDFT()), param.mttf, 1e-5);
86 EXPECT_NEAR(storm::dft::utility::MTTFHelperVariableChange(checker->getDFT()), param.mttf, 1e-5);
87}
88
89template<typename T1, typename T2>
90void expectVectorNear(T1 const &v1, T2 const &v2, double const precision = 1e-6) {
91 ASSERT_EQ(v1.size(), v2.size());
92 for (size_t i{0}; i < v1.size(); ++i) {
93 if (!std::isinf(v1[i])) {
94 EXPECT_NEAR(v1[i], v2[i], precision);
95 } else {
96 EXPECT_EQ(v1[i], v2[i]);
97 }
98 }
99}
100
101TEST_P(SftBddTest, Birnbaum) {
102 auto const &param{TestWithParam::GetParam()};
103 expectVectorNear(checker->getAllBirnbaumFactorsAtTimebound(1), param.birnbaum);
104}
105
106TEST_P(SftBddTest, CIF) {
107 auto const &param{TestWithParam::GetParam()};
108 expectVectorNear(checker->getAllCIFsAtTimebound(1), param.CIF);
109}
110
111TEST_P(SftBddTest, DIF) {
112 auto const &param{TestWithParam::GetParam()};
113 expectVectorNear(checker->getAllDIFsAtTimebound(1), param.DIF);
114}
115
116TEST_P(SftBddTest, RAW) {
117 auto const &param{TestWithParam::GetParam()};
118 expectVectorNear(checker->getAllRAWsAtTimebound(1), param.RAW);
119}
120
121TEST_P(SftBddTest, RRW) {
122 auto const &param{TestWithParam::GetParam()};
123 expectVectorNear(checker->getAllRRWsAtTimebound(1), param.RRW);
124}
125
126std::vector<SftTestData> sftTestData{
127 {
128 "And",
129 STORM_TEST_RESOURCES_DIR "/dft/bdd/AndTest.dft",
130 "07251c962e40a962c342b8673fd18b45a1461ebd917f83f6720aa106cf277f9f",
131 0.25,
132 2.164042561,
133 {0.5, 0.5},
134 {1, 1},
135 {1, 1},
136 {2, 2},
137 {INFINITY, INFINITY},
138 },
139 {
140 "Or",
141 STORM_TEST_RESOURCES_DIR "/dft/bdd/OrTest.dft",
142 "c5cf2304417926961c3e1ce1d876fc2886ece1365fd946bfd3e1abd71401696d",
143 0.75,
144 0.7213475204,
145 {0.5, 0.5},
146 {0.3333333333, 0.3333333333},
147 {0.666667, 0.666667},
148 {1.333333333, 1.333333333},
149 {1.5, 1.5},
150 },
151 {
152 "AndOr",
153 STORM_TEST_RESOURCES_DIR "/dft/bdd/AndOrTest.dft",
154 "fc1e9a418e3c207e81ffa7fde7768f027b6996732c4216c1ed5de6861dbc86ae",
155 0.5625,
156 1.082021281,
157 {0.375, 0.375, 0.375, 0.375},
158 {0.3333333333, 0.3333333333, 0.3333333333, 0.3333333333},
159 {0.666667, 0.666667, 0.666667, 0.666667},
160 {1.333333333, 1.333333333, 1.333333333, 1.333333333},
161 {1.5, 1.5, 1.5, 1.5},
162 },
163 {
164 "Vot",
165 STORM_TEST_RESOURCES_DIR "/dft/bdd/VotTest.dft",
166 "c005a8d6ad70cc497e1efa3733b0dc52e94c465572d3f1fc5de4983ddd178094",
167 0.6875,
168 0.8415721072,
169 {0.375, 0.375, 0.375, 0.375},
170 {0.27272727, 0.27272727, 0.27272727, 0.27272727},
171 {0.636364, 0.636364, 0.636364, 0.636364},
172 {1.27272727, 1.27272727, 1.27272727, 1.27272727},
173 {1.375, 1.375, 1.375, 1.375},
174 },
175 {
176 "Importance",
177 STORM_TEST_RESOURCES_DIR "/dft/bdd/ImportanceTest.dft",
178 "38221c1eb557dd6f15cf33faf61e18c4e426fab2fb909c56ac0d5f4ff0be499f",
179 0.2655055433,
180 1.977074913,
181 {0.531011, 0.368041, 0.224763, 0.0596235, 0.0543206, 0.0810368, 0},
182 {1, 0.693094, 0.153453, 0.112283, 0.09231, 0.192934, 0},
183 {1, 0.846547, 0.306906, 0.556142, 0.501849, 0.703097, 0.5},
184 {2, 1.693094106, 1.693094106, 1.112283035, 1.112283035, 1.112283035, 1},
185 {INFINITY, 3.25832778, 1.18127, 1.126485175, 1.1016977, 1.23905588, 1},
186 },
187};
188INSTANTIATE_TEST_SUITE_P(SFTs, SftBddTest, testing::ValuesIn(sftTestData), [](auto const &info) { return info.param.testname; });
189
190TEST(TestBdd, AndOrRelevantEvents) {
191#ifdef STORM_HAVE_SYLVAN
192 auto dft = storm::dft::api::loadDFTGalileoFile<double>(STORM_TEST_RESOURCES_DIR "/dft/bdd/AndOrTest.dft");
194 auto manager = std::make_shared<storm::dft::storage::SylvanBddManager>(env);
195 storm::dft::utility::RelevantEvents relevantEvents{"F", "F1", "F2", "x1"};
197
198 auto const result = transformer.transformRelevantEvents();
199
200 EXPECT_EQ(result.size(), 4ul);
201
202 EXPECT_EQ(result.at("F").GetShaHash(), "fc1e9a418e3c207e81ffa7fde7768f027b6996732c4216c1ed5de6861dbc86ae");
203 EXPECT_EQ(result.at("F1").GetShaHash(), "c5cf2304417926961c3e1ce1d876fc2886ece1365fd946bfd3e1abd71401696d");
204 EXPECT_EQ(result.at("F2").GetShaHash(), "a4f129fa27c6cd32625b088811d4b12f8059ae0547ee035c083deed9ef9d2c59");
205 EXPECT_EQ(result.at("x1").GetShaHash(), "b0d991484e405a391b6d3d241fed9c00d4a2e5bf6f57300512394d819253893d");
206#else
207 GTEST_SKIP() << "Library Sylvan not available.";
208#endif
209}
210
211TEST(TestBdd, AndOrRelevantEventsChecked) {
212#ifdef STORM_HAVE_SYLVAN
213 auto dft = storm::dft::api::loadDFTGalileoFile<double>(STORM_TEST_RESOURCES_DIR "/dft/bdd/AndOrTest.dft");
215 auto manager{std::make_shared<storm::dft::storage::SylvanBddManager>(env)};
216 storm::dft::utility::RelevantEvents relevantEvents{"F", "F1", "F2", "x1"};
217 auto transformator{std::make_shared<storm::dft::transformations::SftToBddTransformator<double>>(dft, manager, relevantEvents)};
218
219 storm::dft::modelchecker::SFTBDDChecker checker{transformator};
220
221 auto relevantEventsBdds = transformator->transformRelevantEvents();
222
223 EXPECT_NEAR(checker.getProbabilityAtTimebound(relevantEventsBdds["F"], 1), 0.5625, 1e-6);
224
225 EXPECT_NEAR(checker.getProbabilityAtTimebound(relevantEventsBdds["F1"], 1), 0.75, 1e-6);
226 EXPECT_NEAR(checker.getProbabilityAtTimebound(relevantEventsBdds["F2"], 1), 0.75, 1e-6);
227
228 EXPECT_NEAR(checker.getProbabilityAtTimebound(relevantEventsBdds["x1"], 1), 0.5, 1e-6);
229#else
230 GTEST_SKIP() << "Library Sylvan not available.";
231#endif
232}
233
234TEST(TestBdd, AndOrFormulaFail) {
235#ifdef STORM_HAVE_SYLVAN
236 auto dft = storm::dft::api::loadDFTGalileoFile<double>(STORM_TEST_RESOURCES_DIR "/dft/bdd/AndOrTest.dft");
237 auto const props{storm::api::extractFormulasFromProperties(storm::api::parseProperties("P=? [F < 1 !\"F2_failed\"];"))};
239 storm::dft::adapters::SFTBDDPropertyFormulaAdapter checker{dft, props, std::make_shared<storm::dft::storage::SylvanBddManager>(env)};
240
241 STORM_SILENT_EXPECT_THROW(checker.check(), storm::exceptions::NotSupportedException);
242#else
243 GTEST_SKIP() << "Library Sylvan not available.";
244#endif
245}
246
247TEST(TestBdd, AndOrFormula) {
248#ifdef STORM_HAVE_SYLVAN
249 auto dft = storm::dft::api::loadDFTGalileoFile<double>(STORM_TEST_RESOURCES_DIR "/dft/bdd/AndOrTest.dft");
250 auto const props{
252 "P=? [F <= 1 \"F_failed\"];"
253 "P=? [F <= 1 \"F1_failed\" & \"F2_failed\"];"
254 "P=? [F = 1 !\"failed\"];"
255 "P=? [F = 1 !\"F1_failed\"];"
256 "P=? [F = 1 !\"F2_failed\"];"
257 "P=? [F <= 1 \"F1_failed\"];"
258 "P=? [F <= 1 \"F2_failed\"];"))};
260 storm::dft::adapters::SFTBDDPropertyFormulaAdapter checker{dft, props, std::make_shared<storm::dft::storage::SylvanBddManager>(env)};
261
262 auto const resultProbs{checker.check()};
263 auto const result{checker.formulasToBdd()};
264
265 EXPECT_EQ(result.size(), 8ul);
266
267 EXPECT_EQ(resultProbs[0], resultProbs[1]);
268 EXPECT_EQ(resultProbs[1], resultProbs[2]);
269 EXPECT_NEAR(resultProbs[0], 0.5625, 1e-6);
270
271 EXPECT_NEAR(resultProbs[3], 1 - resultProbs[0], 1e-6);
272
273 EXPECT_EQ(resultProbs[6], resultProbs[7]);
274 EXPECT_NEAR(resultProbs[6], 0.75, 1e-6);
275
276 EXPECT_EQ(resultProbs[4], resultProbs[5]);
277 EXPECT_NEAR(resultProbs[4], 1 - resultProbs[6], 1e-6);
278
279 EXPECT_EQ(result[0], result[1]);
280 EXPECT_EQ(result[1], result[2]);
281 EXPECT_EQ(result[2], result[0]);
282
283 EXPECT_EQ(result[0].GetBDD(), result[1].GetBDD());
284 EXPECT_EQ(result[1].GetBDD(), result[2].GetBDD());
285 EXPECT_EQ(result[2].GetBDD(), result[0].GetBDD());
286
287 EXPECT_EQ(result[0].GetBDD(), (!result[3]).GetBDD());
288 EXPECT_NE(result[0].GetBDD(), result[3].GetBDD());
289
290 EXPECT_EQ(result[6].GetBDD(), (!result[4]).GetBDD());
291 EXPECT_NE(result[6].GetBDD(), result[4].GetBDD());
292
293 EXPECT_EQ(result[7].GetBDD(), (!result[5]).GetBDD());
294 EXPECT_NE(result[7].GetBDD(), result[5].GetBDD());
295
296 EXPECT_NE(result[3].GetBDD(), result[4].GetBDD());
297
298 EXPECT_EQ(result[0].GetShaHash(), "fc1e9a418e3c207e81ffa7fde7768f027b6996732c4216c1ed5de6861dbc86ae");
299 EXPECT_EQ(result[1].GetShaHash(), "fc1e9a418e3c207e81ffa7fde7768f027b6996732c4216c1ed5de6861dbc86ae");
300 EXPECT_EQ(result[2].GetShaHash(), "fc1e9a418e3c207e81ffa7fde7768f027b6996732c4216c1ed5de6861dbc86ae");
301 EXPECT_EQ(result[3].GetShaHash(), "fc1e9a418e3c207e81ffa7fde7768f027b6996732c4216c1ed5de6861dbc86ae");
302 EXPECT_EQ(result[4].GetShaHash(), "c5cf2304417926961c3e1ce1d876fc2886ece1365fd946bfd3e1abd71401696d");
303 EXPECT_EQ(result[5].GetShaHash(), "a4f129fa27c6cd32625b088811d4b12f8059ae0547ee035c083deed9ef9d2c59");
304 EXPECT_EQ(result[6].GetShaHash(), "c5cf2304417926961c3e1ce1d876fc2886ece1365fd946bfd3e1abd71401696d");
305 EXPECT_EQ(result[7].GetShaHash(), "a4f129fa27c6cd32625b088811d4b12f8059ae0547ee035c083deed9ef9d2c59");
306#else
307 GTEST_SKIP() << "Library Sylvan not available.";
308#endif
309}
310
311} // namespace
TEST(OrderTest, Simple)
Definition OrderTest.cpp:15
std::vector< ValueType > check(size_t const chunksize=0)
Calculate the properties specified by the formulas.
Main class for the SFTBDDChecker.
ValueType getProbabilityAtTimebound(ValueType timebound)
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)
std::ostream & operator<<(std::ostream &out, Counterexample const &counterexample)
std::shared_ptr< storm::dft::storage::DFT< ValueType > > loadDFTGalileoFile(std::string const &file)
Load DFT from Galileo file.
Definition io.cpp:14
double MTTFHelperVariableChange(std::shared_ptr< storm::dft::storage::DFT< double > > const dft, double const stepsize)
Tries to numerically approximate the mttf of the given dft by integrating 1 - cdf(dft) by changing th...
double MTTFHelperProceeding(std::shared_ptr< storm::dft::storage::DFT< double > > const dft, double const stepsize, double const precision)
Tries to numerically approximate the mttf of the given dft by integrating 1 - cdf(dft) with Simpson's...
SettingsManager const & manager()
Retrieves the settings manager.
#define STORM_SILENT_EXPECT_THROW(statement, expected_exception)
Definition storm_gtest.h:19