8template<
typename ValueType>
13 dfsCounters[id] = DfsCounter{};
14 modInfos[id] = ModularizationInfo{};
26 STORM_LOG_ASSERT(topModInfo.submodules.size() == 1,
"Top element should form unique module.");
37template<
typename ValueType>
39 auto &counter{dfsCounters.at(element->id())};
42 if (counter.firstVisit == 0) {
45 counter.firstVisit = lastDate;
48 for (
auto const &child : getChildren(element)) {
49 populateDfsCounters(child);
52 counter.secondVisit = lastDate;
54 if (counter.secondVisit == 0) {
56 STORM_LOG_WARN(
"Modularizer encountered a cycle containing the element " << *element <<
".");
59 counter.lastVisit = lastDate;
62template<
typename ValueType>
63void DftModularizer<ValueType>::obtainModules(DFTElementCPointer
const element) {
64 auto &counter{dfsCounters.at(element->id())};
65 auto &modInfo{modInfos.at(element->id())};
67 if (counter.minFirstVisit == 0) {
70 modInfo.elements.insert(element->id());
73 counter.minFirstVisit = counter.secondVisit;
75 counter.maxLastVisit = counter.firstVisit;
76 for (
auto const &child : getChildren(element)) {
80 auto const &childCounter{dfsCounters.at(child->id())};
81 counter.minFirstVisit = std::min({counter.minFirstVisit, childCounter.firstVisit, childCounter.minFirstVisit});
82 counter.maxLastVisit = std::max({counter.maxLastVisit, childCounter.lastVisit, childCounter.maxLastVisit});
85 auto const &childInfo{modInfos.at(child->id())};
87 modInfo.elements.insert(childInfo.elements.begin(), childInfo.elements.end());
88 modInfo.submodules.insert(childInfo.submodules.begin(), childInfo.submodules.end());
89 modInfo.fullyStatic = modInfo.fullyStatic && childInfo.fullyStatic;
90 if (!childInfo.isStatic && !childInfo.isModule) {
91 modInfo.isStatic =
false;
95 if (!element->isStaticElement()) {
96 modInfo.isStatic =
false;
97 modInfo.fullyStatic =
false;
100 if (counter.firstVisit < counter.minFirstVisit && counter.maxLastVisit < counter.secondVisit) {
103 element->isBasicElement());
105 modInfo.elements = {};
106 modInfo.submodules = {
module};
107 modInfo.isModule =
true;
112template<
typename ValueType>
113std::vector<typename DftModularizer<ValueType>::DFTElementCPointer> DftModularizer<ValueType>::getChildren(DFTElementCPointer
const element) {
114 std::vector<DFTElementCPointer> children{};
115 if (element->isDependency()) {
116 auto const dependency{std::static_pointer_cast<storm::dft::storage::elements::DFTDependency<ValueType>
const>(element)};
117 auto const triggerElement{std::static_pointer_cast<storm::dft::storage::elements::DFTElement<ValueType>
const>(dependency->triggerEvent())};
118 children.push_back(triggerElement);
119 children.insert(children.end(), dependency->dependentEvents().begin(), dependency->dependentEvents().end());
120 }
else if (element->isGate() || element->isRestriction()) {
121 auto const parent{std::static_pointer_cast<storm::dft::storage::elements::DFTChildren<ValueType>
const>(element)};
122 children.insert(children.end(), parent->children().begin(), parent->children().end());
124 STORM_LOG_ASSERT(element->isBasicElement(),
"Element " << *element <<
" has invalid type.");
130 std::vector<DFTElementCPointer> affectingElements{};
131 for (
auto const &child : children) {
132 if (child->isBasicElement()) {
134 auto const be{std::static_pointer_cast<storm::dft::storage::elements::DFTBE<ValueType>
const>(child)};
135 for (
auto const &ingoingDependency : be->ingoingDependencies()) {
136 if (ingoingDependency->id() != element->id() && !containsElement(affectingElements, ingoingDependency)) {
137 affectingElements.push_back(ingoingDependency);
142 for (
auto const &restriction : child->restrictions()) {
143 if (restriction->id() != element->id() && !containsElement(affectingElements, restriction)) {
144 affectingElements.push_back(restriction);
148 for (
auto const &outgoingDependency : child->outgoingDependencies()) {
149 if (outgoingDependency->id() != element->id() && !containsElement(affectingElements, outgoingDependency)) {
150 affectingElements.push_back(outgoingDependency);
155 children.insert(children.end(), affectingElements.begin(), affectingElements.end());
159template<
typename ValueType>
160bool DftModularizer<ValueType>::containsElement(std::vector<DFTElementCPointer>
const &list, DFTElementCPointer
const element) {
161 return std::find_if(list.begin(), list.end(), [&element](
auto const &elem) { return element->id() == elem->id(); }) != list.end();
164template<
typename ValueType>
165std::vector<typename DftModularizer<ValueType>::DFTElementCPointer> DftModularizer<ValueType>::getAffectingElements(DFTElementCPointer
const element) {
166 std::vector<DFTElementCPointer> affectingElements{};
168 if (element->isBasicElement()) {
169 auto const be{std::static_pointer_cast<storm::dft::storage::elements::DFTBE<ValueType>
const>(element)};
170 auto const &dependencies{be->ingoingDependencies()};
171 affectingElements.insert(affectingElements.end(), dependencies.begin(), dependencies.end());
174 auto const &restrictions{element->restrictions()};
175 affectingElements.insert(affectingElements.end(), restrictions.begin(), restrictions.end());
177 auto const &dependencies{element->outgoingDependencies()};
178 affectingElements.insert(affectingElements.end(), dependencies.begin(), dependencies.end());
180 return affectingElements;
184template class DftModularizer<double>;
185template 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)