Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DftModule.cpp
Go to the documentation of this file.
2
5
7
8namespace storm::dft {
9namespace storage {
10
11DftModule::DftModule(size_t representative, std::set<size_t> const& elements) : representative(representative), elements(elements) {
12 // Assertion cannot be guaranteed as spare module currently only contain the corresponding BEs and SPAREs
13 // STORM_LOG_ASSERT(std::find(this->elements.begin(), this->elements.end(), representative) != this->elements.end(),
14 // "Representative " + std::to_string(representative) + " must be contained in module.");
15}
16
17template<typename ValueType>
19 std::stringstream stream;
20 stream << "[" << dft.getElement(representative)->name() << "] = {";
21 if (!elements.empty()) {
22 auto it = elements.begin();
23 STORM_LOG_ASSERT(it != elements.end(), "Element not found.");
24 stream << dft.getElement(*it)->name();
25 ++it;
26 while (it != elements.end()) {
27 stream << ", " << dft.getElement(*it)->name();
28 ++it;
29 }
30 }
31 stream << "}";
32 return stream.str();
33}
34DftIndependentModule::DftIndependentModule(size_t representative, std::set<size_t> const& elements, std::set<DftIndependentModule> const& submodules,
35 bool staticElements, bool fullyStatic, bool singleBE)
36 : DftModule(representative, elements), staticElements(staticElements), fullyStatic(fullyStatic), singleBE(singleBE), submodules(submodules) {
37 STORM_LOG_ASSERT(std::find(this->elements.begin(), this->elements.end(), representative) != this->elements.end(),
38 "Representative " + std::to_string(representative) + " must be contained in module.");
39 STORM_LOG_ASSERT(!singleBE || (submodules.empty() && elements.size() == 1), "Module " + std::to_string(representative) + " is not a single BE.");
40}
41
42std::set<size_t> DftIndependentModule::getAllElements() const {
43 std::set<size_t> allElements = elements;
44 for (auto const& submodule : submodules) {
45 allElements.merge(submodule.getAllElements());
46 }
47 return allElements;
48}
49
50template<typename ValueType>
53 std::unordered_set<std::string> depInConflict;
54 for (auto const id : getAllElements()) {
55 auto const tmpElement = dft.getElement(id);
56 builder.cloneElement(tmpElement);
57 // Remember dependency conflict
58 if (tmpElement->isDependency() && dft.isDependencyInConflict(tmpElement->id())) {
59 depInConflict.insert(tmpElement->name());
60 }
61 }
62 builder.setTopLevel(dft.getElement(getRepresentative())->name());
63 auto subdft = builder.build();
64 // Update dependency conflicts
65 for (size_t id : subdft.getDependencies()) {
66 // Set dependencies not in conflict
67 if (depInConflict.find(subdft.getElement(id)->name()) == depInConflict.end()) {
68 subdft.setDependencyNotInConflict(id);
69 }
70 }
71 return subdft;
72}
73
74template<typename ValueType>
75std::string DftIndependentModule::toString(storm::dft::storage::DFT<ValueType> const& dft, std::string const& indentation) const {
76 std::stringstream stream;
77 stream << indentation << DftModule::toString(dft);
78 std::string subIndentation = indentation + " ";
79 for (DftIndependentModule const& submodule : submodules) {
80 stream << "\n" << subIndentation << "Sub-module " << submodule.toString(dft, subIndentation);
81 }
82 return stream.str();
83}
84
85// Explicitly instantiate functions
86template std::string DftModule::toString(storm::dft::storage::DFT<double> const&) const;
88
91template std::string DftIndependentModule::toString(storm::dft::storage::DFT<double> const&, std::string const&) const;
92template std::string DftIndependentModule::toString(storm::dft::storage::DFT<storm::RationalFunction> const&, std::string const&) const;
93
94} // namespace storage
95} // namespace storm::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.
Represents a Dynamic Fault Tree.
Definition DFT.h:52
DFTElementCPointer getElement(size_t index) const
Get a pointer to an element in the DFT.
Definition DFT.h:188
bool isDependencyInConflict(size_t id) const
Definition DFT.h:143
Represents an independent module/subtree.
Definition DftModule.h:66
DftIndependentModule(size_t representative, std::set< size_t > const &elements, std::set< DftIndependentModule > const &submodules, bool staticElements, bool fullyStatic, bool singleBE)
Constructor.
Definition DftModule.cpp:34
std::string toString(storm::dft::storage::DFT< ValueType > const &dft, std::string const &indentation="") const
Get string representation of module.
Definition DftModule.cpp:75
std::set< size_t > getAllElements() const
Returns all elements contained in the module (including sub-modules).
Definition DftModule.cpp:42
storm::dft::storage::DFT< ValueType > getSubtree(storm::dft::storage::DFT< ValueType > const &dft) const
Create subtree corresponding to module.
Definition DftModule.cpp:51
Represents a module/subtree in a DFT.
Definition DftModule.h:18
std::set< size_t > elements
Definition DftModule.h:60
size_t getRepresentative() const
Get representative (top element of subtree).
Definition DftModule.h:31
DftModule(size_t representative, std::set< size_t > const &elements)
Constructor.
Definition DftModule.cpp:11
std::string toString(storm::dft::storage::DFT< ValueType > const &dft) const
Get string representation of module.
Definition DftModule.cpp:18
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11