Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
MTTFHelper.cpp
Go to the documentation of this file.
3
4namespace {
5
13void linspace(std::vector<double> &buffer, double start, double const stepsize) {
14 for (size_t i{0}; i < buffer.size(); ++i) {
15 buffer[i] = i * stepsize + start;
16 }
17}
18
19} // namespace
20
21namespace storm::dft {
22namespace utility {
23
24double MTTFHelperProceeding(std::shared_ptr<storm::dft::storage::DFT<double>> const dft, double const stepsize, double const precision) {
25 constexpr size_t chunksize{1001};
27
28 std::vector<double> timepoints{};
29 timepoints.resize(chunksize);
30 linspace(timepoints, 0.0, stepsize);
31 std::vector<double> probabilities{checker.getProbabilitiesAtTimepoints(timepoints)};
32
33 double delta{1.0};
34 double rval{0.0};
35
36 double y1{0.0}, y2{0.0}, y3{1.0 - probabilities[0]};
37 size_t i{1};
38 auto currentStepsize{stepsize};
39 while (std::abs(delta) > precision) {
40 if (i + 1 >= probabilities.size()) {
41 double const start{timepoints.back()};
42 // double stepsize
43 if (currentStepsize < 1e-3) {
44 currentStepsize *= 2;
45 }
46 linspace(timepoints, start, currentStepsize);
47 probabilities = checker.getProbabilitiesAtTimepoints(timepoints);
48 i = 1;
49 }
50
51 y1 = y3;
52 y2 = 1.0 - probabilities[i];
53 y3 = 1.0 - probabilities[i + 1];
54 i += 2;
55
56 delta = y1 + 4.0 * y2 + y3;
57 delta /= 3.0;
58 delta *= currentStepsize;
59 rval += delta;
60 }
61
62 return rval;
63}
64
65double MTTFHelperVariableChange(std::shared_ptr<storm::dft::storage::DFT<double>> const dft, double const stepsize) {
66 constexpr size_t chunksize{1001};
68
69 std::vector<double> timepoints{};
70 timepoints.resize(static_cast<size_t>(1 / stepsize) - 1);
71 for (size_t i{0}; i < timepoints.size(); ++i) {
72 double x = (i + 1) * stepsize;
73 x = x / (1 - x);
74 timepoints[i] = x;
75 }
76
77 std::vector<double> probabilities{checker.getProbabilitiesAtTimepoints(timepoints, chunksize)};
78
79 double rval{0};
80 for (size_t i{0}; i < probabilities.size(); ++i) {
81 double x{(i + 1) * stepsize};
82 x = 1 / (1 - x);
83 x = x * x;
84 auto &p{probabilities[i]};
85 p = (1 - p) * x;
86
87 rval += p;
88 }
89 // remove the ends
90 rval -= (probabilities.front() + probabilities.back()) / 2;
91 // resize
92 rval *= stepsize;
93
94 return rval;
95}
96
97} // namespace utility
98} // namespace storm::dft
std::vector< ValueType > getProbabilitiesAtTimepoints(std::vector< ValueType > const &timepoints, size_t chunksize=0)
Calculate the probability of failure for the given time points.
Represents a Dynamic Fault Tree.
Definition DFT.h:52
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...