Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DftModelCheckerTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
6
7namespace {
8
9// Configurations for DFT analysis
10struct DftAnalysisConfig {
11 bool useSR;
12 bool useMod;
13 bool useDC;
14};
15
16class NoOptimizationsConfig {
17 public:
18 typedef double ValueType;
19
20 static DftAnalysisConfig createConfig() {
21 return DftAnalysisConfig{false, false, false};
22 }
23};
24
25class DontCareOnlyConfig {
26 public:
27 typedef double ValueType;
28
29 static DftAnalysisConfig createConfig() {
30 return DftAnalysisConfig{false, false, true};
31 }
32};
33
34class ModularisationOnlyConfig {
35 public:
36 typedef double ValueType;
37
38 static DftAnalysisConfig createConfig() {
39 return DftAnalysisConfig{false, true, false};
40 }
41};
42
43class SymmetryReductionOnlyConfig {
44 public:
45 typedef double ValueType;
46
47 static DftAnalysisConfig createConfig() {
48 return DftAnalysisConfig{true, false, false};
49 }
50};
51
52class ModularisationConfig {
53 public:
54 typedef double ValueType;
55
56 static DftAnalysisConfig createConfig() {
57 return DftAnalysisConfig{false, true, true};
58 }
59};
60
61class SymmetryReductionConfig {
62 public:
63 typedef double ValueType;
64
65 static DftAnalysisConfig createConfig() {
66 return DftAnalysisConfig{true, false, true};
67 }
68};
69
70class AllOptimizationsConfig {
71 public:
72 typedef double ValueType;
73
74 static DftAnalysisConfig createConfig() {
75 return DftAnalysisConfig{true, true, true};
76 }
77};
78
79// General base class for testing of DFT model checking
80template<typename TestType>
81class DftModelCheckerTest : public ::testing::Test {
82 public:
83 typedef typename TestType::ValueType ValueType;
84
85 DftModelCheckerTest() : config(TestType::createConfig()) {}
86
87 DftAnalysisConfig const& getConfig() const {
88 return config;
89 }
90
91 double analyze(std::string const& file, std::string const& property) {
92 // Load, build and prepare DFT
93 std::shared_ptr<storm::dft::storage::DFT<double>> dft =
94 storm::dft::api::prepareForMarkovAnalysis<double>(*(storm::dft::api::loadDFTGalileoFile<double>(file)));
95 EXPECT_TRUE(storm::dft::api::isWellFormed(*dft).first);
96
97 // Create property
98 std::vector<std::shared_ptr<storm::logic::Formula const>> properties = storm::api::extractFormulasFromProperties(storm::api::parseProperties(property));
99
100 // Create relevant names
101 std::vector<std::string> relevantNames;
102 if (!config.useDC) {
103 relevantNames.push_back("all");
104 }
105 storm::dft::utility::RelevantEvents relevantEvents = storm::dft::api::computeRelevantEvents(properties, relevantNames);
106
107 // Perform model checking
109 storm::dft::api::analyzeDFT<double>(*dft, properties, config.useSR, config.useMod, relevantEvents, false);
110 return boost::get<double>(results[0]);
111 }
112
113 double analyzeMTTF(std::string const& file) {
114 std::string property = "Tmin=? [F \"failed\"]";
115 return analyze(file, property);
116 }
117
118 double analyzeReliability(std::string const& file, double bound) {
119 std::string property = "Pmin=? [F<=" + std::to_string(bound) + " \"failed\"]";
120 return analyze(file, property);
121 }
122
123 double analyzeReachability(std::string const& file) {
124 std::string property = "Pmin=? [F \"failed\"]";
125 return analyze(file, property);
126 }
127
128 double precision() {
129 return 1e-12;
130 }
131
132 double precisionReliability() {
133 return 1e-10;
134 }
135
136 private:
137 DftAnalysisConfig config;
138};
139
140typedef ::testing::Types<NoOptimizationsConfig, DontCareOnlyConfig, ModularisationOnlyConfig, SymmetryReductionOnlyConfig, ModularisationConfig,
141 SymmetryReductionConfig, AllOptimizationsConfig>
143
144TYPED_TEST_SUITE(DftModelCheckerTest, TestingTypes, );
145
146TYPED_TEST(DftModelCheckerTest, AndMTTF) {
147 double result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/and.dft");
148 EXPECT_NEAR(result, 3, this->precision());
149}
150
151TYPED_TEST(DftModelCheckerTest, OrMTTF) {
152 double result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/or.dft");
153 EXPECT_NEAR(result, 1, this->precision());
154}
155
156TYPED_TEST(DftModelCheckerTest, VotingMTTF) {
157 double result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/voting.dft");
158 EXPECT_NEAR(result, 5 / 3.0, this->precision());
159 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/voting2.dft");
160 EXPECT_NEAR(result, 10 / 17.0, this->precision());
161 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/voting3.dft");
162 EXPECT_NEAR(result, 2685 / 1547.0, this->precision());
163 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/voting4.dft");
164 EXPECT_NEAR(result, 5 / 6.0, this->precision());
165}
166
167TYPED_TEST(DftModelCheckerTest, PandMTTF) {
168 double result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/pand.dft");
169 EXPECT_EQ(result, storm::utility::infinity<double>());
170}
171
172TYPED_TEST(DftModelCheckerTest, PorMTTF) {
173 double result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/por.dft");
174 EXPECT_EQ(result, storm::utility::infinity<double>());
175}
176
177TYPED_TEST(DftModelCheckerTest, FdepMTTF) {
178 double result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/fdep2.dft");
179 EXPECT_NEAR(result, 2, this->precision());
180 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/fdep3.dft");
181 EXPECT_NEAR(result, 5 / 2.0, this->precision());
182
183 if (this->getConfig().useMod) {
184 STORM_SILENT_EXPECT_THROW(this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/fdep.dft"), storm::exceptions::NotSupportedException);
185 STORM_SILENT_EXPECT_THROW(this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/fdep4.dft"), storm::exceptions::NotSupportedException);
186 STORM_SILENT_EXPECT_THROW(this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/fdep5.dft"), storm::exceptions::NotSupportedException);
187 } else {
188 double result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/fdep.dft");
189 EXPECT_NEAR(result, 2 / 3.0, this->precision());
190 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/fdep4.dft");
191 EXPECT_NEAR(result, 1, this->precision());
192 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/fdep5.dft");
193 EXPECT_NEAR(result, 3, this->precision());
194 }
195}
196
197TYPED_TEST(DftModelCheckerTest, PdepMTTF) {
198 double result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/pdep.dft");
199 EXPECT_NEAR(result, 8 / 3.0, this->precision());
200 if (this->getConfig().useMod && !this->getConfig().useDC) {
201 STORM_SILENT_EXPECT_THROW(this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/pdep2.dft"), storm::exceptions::NotSupportedException);
202 } else {
203 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/pdep2.dft");
204 EXPECT_NEAR(result, 38 / 15.0, this->precision());
205 }
206 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/pdep3.dft");
207 EXPECT_NEAR(result, 67 / 24.0, this->precision());
208
209 if (this->getConfig().useMod) {
210 STORM_SILENT_EXPECT_THROW(this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/pdep4.dft"), storm::exceptions::NotSupportedException);
211 } else {
212 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/pdep4.dft");
213 EXPECT_EQ(result, storm::utility::infinity<double>());
214 }
215}
216
217TYPED_TEST(DftModelCheckerTest, SpareMTTF) {
218 double result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/spare.dft");
219 EXPECT_NEAR(result, 46 / 13.0, this->precision());
220 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/spare2.dft");
221 EXPECT_NEAR(result, 43 / 23.0, this->precision());
222 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/spare3.dft");
223 EXPECT_NEAR(result, 14 / 11.0, this->precision());
224 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/spare4.dft");
225 EXPECT_NEAR(result, 18836 / 3887.0, this->precision());
226 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/spare5.dft");
227 EXPECT_NEAR(result, 8 / 3.0, this->precision());
228 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/spare6.dft");
229 EXPECT_NEAR(result, 7 / 5.0, this->precision());
230 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/spare7.dft");
231 EXPECT_NEAR(result, 551 / 150.0, this->precision());
232 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/spare8.dft");
233 EXPECT_NEAR(result, 249 / 52.0, this->precision()); // DFTCalc has result of 4.33779 due to different semantics of nested spares
234 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/spare_dc.dft");
235 EXPECT_NEAR(result, 78311 / 182700.0, this->precision());
236 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/modules3.dft");
237 EXPECT_NEAR(result, 7 / 6.0, this->precision());
238}
239
240TYPED_TEST(DftModelCheckerTest, SeqMTTF) {
241 double result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/seq.dft");
242 EXPECT_NEAR(result, 4, this->precision());
243 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/seq2.dft");
244 EXPECT_NEAR(result, 6, this->precision());
245 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/seq3.dft");
246 EXPECT_NEAR(result, 6, this->precision());
247 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/seq4.dft");
248 EXPECT_NEAR(result, 6, this->precision());
249 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/seq5.dft");
250 EXPECT_EQ(result, storm::utility::infinity<double>());
251 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/seq6.dft");
252 EXPECT_NEAR(result, 30000, this->precision());
253
254 if (this->getConfig().useMod) {
255 STORM_SILENT_EXPECT_THROW(this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/seq7.dft"), storm::exceptions::NotSupportedException);
256 } else {
257 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/seq7.dft");
258 EXPECT_EQ(result, storm::utility::infinity<double>());
259 }
260 result = this->analyzeReliability(STORM_TEST_RESOURCES_DIR "/dft/seq7.dft", 1.0);
261 EXPECT_NEAR(result, 0.08, this->precision());
262 result = this->analyzeReachability(STORM_TEST_RESOURCES_DIR "/dft/seq7.dft");
263 EXPECT_NEAR(result, 0.08, this->precision());
264 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/seq8.dft");
265 EXPECT_NEAR(result, 11 / 8.0, this->precision());
266}
267
268TYPED_TEST(DftModelCheckerTest, Mutex) {
269 double result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/mutex.dft");
270 EXPECT_NEAR(result, 1 / 2.0, this->precision());
271 result = this->analyzeReliability(STORM_TEST_RESOURCES_DIR "/dft/mutex.dft", 1.0);
272 EXPECT_NEAR(result, 0.8646647168, this->precisionReliability());
273 result = this->analyzeReachability(STORM_TEST_RESOURCES_DIR "/dft/mutex.dft");
274 EXPECT_NEAR(result, 1, this->precision());
275
276 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/mutex2.dft");
277 EXPECT_EQ(result, storm::utility::infinity<double>());
278 result = this->analyzeReliability(STORM_TEST_RESOURCES_DIR "/dft/mutex2.dft", 1.0);
279 EXPECT_NEAR(result, 0, this->precision());
280 result = this->analyzeReachability(STORM_TEST_RESOURCES_DIR "/dft/mutex2.dft");
281 EXPECT_NEAR(result, 0, this->precision());
282
283 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/mutex3.dft");
284 EXPECT_EQ(result, storm::utility::infinity<double>());
285 result = this->analyzeReliability(STORM_TEST_RESOURCES_DIR "/dft/mutex3.dft", 1.0);
286 EXPECT_NEAR(result, 0, this->precision());
287 result = this->analyzeReachability(STORM_TEST_RESOURCES_DIR "/dft/mutex3.dft");
288 EXPECT_NEAR(result, 0, this->precision());
289
290 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/mutex4.dft");
291 EXPECT_EQ(result, storm::utility::infinity<double>());
292 result = this->analyzeReliability(STORM_TEST_RESOURCES_DIR "/dft/mutex4.dft", 1.0);
293 EXPECT_NEAR(result, 0.5842978146, this->precisionReliability());
294 result = this->analyzeReachability(STORM_TEST_RESOURCES_DIR "/dft/mutex4.dft");
295 EXPECT_NEAR(result, 5 / 8.0, this->precision());
296}
297
298TYPED_TEST(DftModelCheckerTest, Symmetry) {
299 double result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/symmetry6.dft");
300 EXPECT_NEAR(result, 2804183 / 2042040.0, this->precision());
301 result = this->analyzeReliability(STORM_TEST_RESOURCES_DIR "/dft/symmetry6.dft", 1.0);
302 EXPECT_NEAR(result, 0.3421934224, this->precisionReliability());
303
304 result = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/pdep_symmetry.dft");
305 EXPECT_NEAR(result, 6553 / 5376.0, this->precision());
306 result = this->analyzeReliability(STORM_TEST_RESOURCES_DIR "/dft/pdep_symmetry.dft", 1.0);
307 EXPECT_NEAR(result, 0.4223514414, this->precisionReliability());
308}
309
310TYPED_TEST(DftModelCheckerTest, HecsReliability) {
311 if (!this->getConfig().useDC) {
312 // Skip configurations because it takes too long
313 GTEST_SKIP();
314 return;
315 }
316 double result = this->analyzeReliability(STORM_TEST_RESOURCES_DIR "/dft/hecs_2_2.dft", 1.0);
317 EXPECT_NEAR(result, 0.00021997582, this->precisionReliability());
318}
319} // namespace
std::vector< boost::variant< ValueType, approximation_result > > dft_results
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::pair< bool, std::string > isWellFormed(storm::dft::storage::DFT< ValueType > const &dft, bool validForMarkovianAnalysis=true)
Check whether the DFT is well-formed.
Definition storm-dft.h:64
storm::dft::utility::RelevantEvents computeRelevantEvents(std::vector< std::shared_ptr< storm::logic::Formula const > > const &properties, std::vector< std::string > const &additionalRelevantEventNames)
Get relevant event ids from given relevant event names and labels in properties.
SFTBDDChecker::ValueType ValueType
TYPED_TEST(GraphTestAR, SymbolicProb01StochasticGameDieSmall)
Definition GraphTest.cpp:49
TYPED_TEST_SUITE(GraphTestAR, TestingTypes,)
::testing::Types< Cudd, Sylvan > TestingTypes
Definition GraphTest.cpp:46
#define STORM_SILENT_EXPECT_THROW(statement, expected_exception)