6template<
typename ValueType>
11 dfsCounters[id] = DfsCounter{};
12 modInfos[id] = ModularizationInfo{};
24 STORM_LOG_ASSERT(topModInfo.submodules.size() == 1,
"Top element should form unique module.");
35template<
typename ValueType>
37 auto &counter{dfsCounters.at(element->id())};
40 if (counter.firstVisit == 0) {
43 counter.firstVisit = lastDate;
46 for (
auto const &child : getChildren(element)) {
47 populateDfsCounters(child);
50 counter.secondVisit = lastDate;
52 if (counter.secondVisit == 0) {
54 STORM_LOG_WARN(
"Modularizer encountered a cycle containing the element " << *element <<
".");
57 counter.lastVisit = lastDate;
60template<
typename ValueType>
61void DftModularizer<ValueType>::obtainModules(DFTElementCPointer
const element) {
62 auto &counter{dfsCounters.at(element->id())};
63 auto &modInfo{modInfos.at(element->id())};
65 if (counter.minFirstVisit == 0) {
68 modInfo.elements.insert(element->id());
71 counter.minFirstVisit = counter.secondVisit;
73 counter.maxLastVisit = counter.firstVisit;
74 for (
auto const &child : getChildren(element)) {
78 auto const &childCounter{dfsCounters.at(child->id())};
79 counter.minFirstVisit = std::min({counter.minFirstVisit, childCounter.firstVisit, childCounter.minFirstVisit});
80 counter.maxLastVisit = std::max({counter.maxLastVisit, childCounter.lastVisit, childCounter.maxLastVisit});
83 auto const &childInfo{modInfos.at(child->id())};
85 modInfo.elements.insert(childInfo.elements.begin(), childInfo.elements.end());
86 modInfo.submodules.insert(childInfo.submodules.begin(), childInfo.submodules.end());
87 modInfo.fullyStatic = modInfo.fullyStatic && childInfo.fullyStatic;
88 if (!childInfo.isStatic && !childInfo.isModule) {
89 modInfo.isStatic =
false;
93 if (!element->isStaticElement()) {
94 modInfo.isStatic =
false;
95 modInfo.fullyStatic =
false;
98 if (counter.firstVisit < counter.minFirstVisit && counter.maxLastVisit < counter.secondVisit) {
101 element->isBasicElement());
103 modInfo.elements = {};
104 modInfo.submodules = {
module};
105 modInfo.isModule =
true;
110template<
typename ValueType>
111std::vector<typename DftModularizer<ValueType>::DFTElementCPointer> DftModularizer<ValueType>::getChildren(DFTElementCPointer
const element) {
112 std::vector<DFTElementCPointer> children{};
113 if (element->isDependency()) {
114 auto const dependency{std::static_pointer_cast<storm::dft::storage::elements::DFTDependency<ValueType>
const>(element)};
115 auto const triggerElement{std::static_pointer_cast<storm::dft::storage::elements::DFTElement<ValueType>
const>(dependency->triggerEvent())};
116 children.push_back(triggerElement);
117 children.insert(children.end(), dependency->dependentEvents().begin(), dependency->dependentEvents().end());
118 }
else if (element->isGate() || element->isRestriction()) {
119 auto const parent{std::static_pointer_cast<storm::dft::storage::elements::DFTChildren<ValueType>
const>(element)};
120 children.insert(children.end(), parent->children().begin(), parent->children().end());
122 STORM_LOG_ASSERT(element->isBasicElement(),
"Element " << *element <<
" has invalid type.");
128 std::vector<DFTElementCPointer> affectingElements{};
129 for (
auto const &child : children) {
130 if (child->isBasicElement()) {
132 auto const be{std::static_pointer_cast<storm::dft::storage::elements::DFTBE<ValueType>
const>(child)};
133 for (
auto const &ingoingDependency : be->ingoingDependencies()) {
134 if (ingoingDependency->id() != element->id() && !containsElement(affectingElements, ingoingDependency)) {
135 affectingElements.push_back(ingoingDependency);
140 for (
auto const &restriction : child->restrictions()) {
141 if (restriction->id() != element->id() && !containsElement(affectingElements, restriction)) {
142 affectingElements.push_back(restriction);
146 for (
auto const &outgoingDependency : child->outgoingDependencies()) {
147 if (outgoingDependency->id() != element->id() && !containsElement(affectingElements, outgoingDependency)) {
148 affectingElements.push_back(outgoingDependency);
153 children.insert(children.end(), affectingElements.begin(), affectingElements.end());
157template<
typename ValueType>
158bool DftModularizer<ValueType>::containsElement(std::vector<DFTElementCPointer>
const &list, DFTElementCPointer
const element) {
159 return std::find_if(list.begin(), list.end(), [&element](
auto const &elem) { return element->id() == elem->id(); }) != list.end();
162template<
typename ValueType>
163std::vector<typename DftModularizer<ValueType>::DFTElementCPointer> DftModularizer<ValueType>::getAffectingElements(DFTElementCPointer
const element) {
164 std::vector<DFTElementCPointer> affectingElements{};
166 if (element->isBasicElement()) {
167 auto const be{std::static_pointer_cast<storm::dft::storage::elements::DFTBE<ValueType>
const>(element)};
168 auto const &dependencies{be->ingoingDependencies()};
169 affectingElements.insert(affectingElements.end(), dependencies.begin(), dependencies.end());
172 auto const &restrictions{element->restrictions()};
173 affectingElements.insert(affectingElements.end(), restrictions.begin(), restrictions.end());
175 auto const &dependencies{element->outgoingDependencies()};
176 affectingElements.insert(affectingElements.end(), dependencies.begin(), dependencies.end());
178 return affectingElements;
182template class DftModularizer<double>;
183template class DftModularizer<RationalFunction>;
Represents a Dynamic Fault Tree.
std::set< size_t > getAllIds() const
Get Ids of all elements.
DFTElementCPointer getTopLevelElement() const
Represents an independent module/subtree.
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_WARN(message)
#define STORM_LOG_ASSERT(cond, message)