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