Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DftModularizationChecker.cpp
Go to the documentation of this file.
2
3#include <sstream>
4
13
14namespace storm::dft {
15namespace modelchecker {
16
17template<typename ValueType>
19 : dft{dft}, modelchecker(true), sylvanBddManager{storm::dft::storage::SylvanBddManager::createWithDefaultEnvironment()} {
20 // Initialize modules
22 auto topModule = modularizer.computeModules(*dft);
23 STORM_LOG_DEBUG("Modularization found the following modules:\n" << topModule.toString(*dft));
24
25 // Gather all dynamic modules
26 populateDynamicModules(topModule);
27}
28
29template<typename ValueType>
30void DftModularizationChecker<ValueType>::populateDynamicModules(storm::dft::storage::DftIndependentModule const& module) {
31 if (!module.isStatic()) {
32 // Found new dynamic module
33 dynamicModules.push_back(module);
34 } else if (!module.isFullyStatic()) {
35 // Module contains dynamic sub-modules -> recursively visit children
36 for (auto const& submodule : module.getSubModules()) {
37 populateDynamicModules(submodule);
38 }
39 }
40}
41
42template<typename ValueType>
43std::vector<ValueType> DftModularizationChecker<ValueType>::check(FormulaVector const& formulas, size_t chunksize) {
44 // Gather time points
46 std::set<ValueType> timepointSet;
47 for (auto const& formula : formulas) {
49 }
50 std::vector<ValueType> timepoints(timepointSet.begin(), timepointSet.end());
51
52 auto newDft = replaceDynamicModules(timepoints);
53
54 storm::dft::adapters::SFTBDDPropertyFormulaAdapter checker{newDft, formulas, sylvanBddManager, {}};
55 return checker.check(chunksize);
56}
57
58template<typename ValueType>
59std::vector<ValueType> DftModularizationChecker<ValueType>::getProbabilitiesAtTimepoints(std::vector<ValueType> const& timepoints, size_t chunksize) {
60 auto newDft = replaceDynamicModules(timepoints);
61 storm::dft::modelchecker::SFTBDDChecker checker{newDft, sylvanBddManager};
62 return checker.getProbabilitiesAtTimepoints(timepoints, chunksize);
63}
64
65template<typename ValueType>
66std::shared_ptr<storm::dft::storage::DFT<ValueType>> DftModularizationChecker<ValueType>::replaceDynamicModules(std::vector<ValueType> const& timepoints) {
67 // Map from module representatives to their sample points
68 std::map<size_t, std::map<ValueType, ValueType>> samplePoints;
69
70 // First analyse all dynamic modules
71 for (auto const& mod : dynamicModules) {
72 STORM_LOG_DEBUG("Analyse dynamic module " << mod.toString(*dft));
73 auto result = analyseDynamicModule(mod, timepoints);
74 // Remember probabilities for module
75 std::map<ValueType, ValueType> activeSamples{};
76 for (size_t i{0}; i < timepoints.size(); ++i) {
77 auto const probability{boost::get<ValueType>(result[i])};
78 auto const timebound{timepoints[i]};
79 activeSamples[timebound] = probability;
80 }
81 samplePoints.insert({mod.getRepresentative(), activeSamples});
82 }
83
84 // Gather all elements contained in dynamic modules
85 std::set<size_t> dynamicElements;
86 for (auto const& mod : dynamicModules) {
87 dynamicElements.merge(mod.getAllElements());
88 }
89
90 // Replace each dynamic module by a single BE which has samples corresponding to the previously computed analysis results
91 storm::dft::builder::DFTBuilder<ValueType> builder{};
92 std::unordered_set<std::string> depInConflict;
93 for (auto const id : dft->getAllIds()) {
94 auto const element{dft->getElement(id)};
95 auto it = samplePoints.find(id);
96 if (it != samplePoints.end()) {
97 // Replace element by BE
98 builder.addBasicElementSamples(element->name(), it->second);
99 } else if (!dynamicElements.contains(id)) {
100 // Element is not part of a dynamic module -> keep
101 builder.cloneElement(element);
102 // Remember dependency conflict
103 if (element->isDependency() && dft->isDependencyInConflict(id)) {
104 depInConflict.insert(element->name());
105 }
106 }
107 }
108 builder.setTopLevel(dft->getTopLevelElement()->name());
109
110 auto newDft = std::make_shared<storm::dft::storage::DFT<ValueType>>(builder.build());
111 // Update dependency conflicts
112 for (size_t id : newDft->getDependencies()) {
113 // Set dependencies not in conflict
114 if (!depInConflict.contains(newDft->getElement(id)->name())) {
115 newDft->setDependencyNotInConflict(id);
116 }
117 }
118 STORM_LOG_DEBUG("Remaining static FT: " << newDft->getElementsString());
119 return newDft;
120}
121
122template<typename ValueType>
123typename storm::dft::modelchecker::DFTModelChecker<ValueType>::dft_results DftModularizationChecker<ValueType>::analyseDynamicModule(
124 storm::dft::storage::DftIndependentModule const& module, std::vector<ValueType> const& timepoints) {
125 STORM_LOG_ASSERT(!module.isStatic() && !module.isFullyStatic(), "Module should be dynamic.");
126 STORM_LOG_ASSERT(!dft->getElement(module.getRepresentative())->isBasicElement(), "Dynamic module should not be a single BE.");
127
128 auto subDft = module.getSubtree(*dft);
129
130 // Create properties
131 std::stringstream propertyStream{};
132 for (auto const timebound : timepoints) {
133 propertyStream << "Pmin=? [F<=" << timebound << "\"failed\"];";
134 }
135 auto const props{storm::api::extractFormulasFromProperties(storm::api::parseProperties(propertyStream.str()))};
136
137 return modelchecker.check(subDft, props, false, false, {});
138}
139
140// Explicitly instantiate the class.
142
143} // namespace modelchecker
144} // namespace storm::dft
static double getTimebound(FormulaCPointer const &formula)
std::vector< ValueType > check(size_t const chunksize=0)
Calculate the properties specified by the formulas.
static void checkForm(FormulaVector const &formulas)
Check if the formulas are of the form 'P=?
void addBasicElementSamples(std::string const &name, std::map< ValueType, ValueType > const &activeSamples)
Create BE with distribution given by sample points and add it to DFT.
storm::dft::storage::DFT< ValueType > build()
Create DFT.
void cloneElement(DFTElementCPointer element)
Clone element and add it via the builder.
void setTopLevel(std::string const &tle)
Set top level element.
std::vector< boost::variant< ValueType, approximation_result > > dft_results
typename DFTModelChecker< ValueType >::property_vector FormulaVector
DftModularizationChecker(std::shared_ptr< storm::dft::storage::DFT< ValueType > > dft)
Initializes and computes all modules.
std::vector< ValueType > getProbabilitiesAtTimepoints(std::vector< ValueType > const &timepoints, size_t chunksize=0)
Calculate the probability of failure for the given time points.
std::vector< ValueType > check(FormulaVector const &formulas, size_t chunksize=0)
Calculate the properties specified by the formulas.
Main class for the SFTBDDChecker.
std::vector< ValueType > getProbabilitiesAtTimepoints(std::vector< ValueType > const &timepoints, size_t const chunksize=0)
Represents a Dynamic Fault Tree.
Definition DFT.h:49
Represents an independent module/subtree.
Definition DftModule.h:66
bool isStatic() const
Returns whether the module contains only static elements (except in sub-modules).
Definition DftModule.h:85
bool isFullyStatic() const
Returns whether the module contains only static elements (also in sub-modules).
Definition DftModule.h:93
std::set< DftIndependentModule > const & getSubModules() const
Returns sub-modules.
Definition DftModule.h:101
size_t getRepresentative() const
Get representative (top element of subtree).
Definition DftModule.h:31
Find modules (independent subtrees) in DFT.
storm::dft::storage::DftIndependentModule computeModules(storm::dft::storage::DFT< ValueType > const &dft)
Compute modules of DFT by applying the LTA/DR algorithm.
#define STORM_LOG_DEBUG(message)
Definition logging.h:21
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
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)
IntegerType mod(IntegerType const &first, IntegerType const &second)