Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DFTChildren.h
Go to the documentation of this file.
1#pragma once
2
3#include "DFTElement.h"
4
5namespace storm::dft {
6namespace storage {
7namespace elements {
8
12template<typename ValueType>
13class DFTChildren : public DFTElement<ValueType> {
14 using DFTElementPointer = std::shared_ptr<DFTElement<ValueType>>;
15 using DFTElementVector = std::vector<DFTElementPointer>;
16
17 public:
24 DFTChildren(size_t id, std::string const& name, DFTElementVector const& children) : DFTElement<ValueType>(id, name), mChildren(children) {
25 // Intentionally left empty.
26 }
27
31 virtual ~DFTChildren() = default;
32
37 void addChild(DFTElementPointer element) {
38 mChildren.push_back(element);
39 }
40
45 DFTElementVector const& children() const {
46 return mChildren;
47 }
48
49 size_t nrChildren() const override {
50 return mChildren.size();
51 }
52
58 bool containsChild(size_t id) {
59 auto it = std::find_if(this->mChildren.begin(), this->mChildren.end(), [&id](DFTElementPointer element) -> bool { return element->id() == id; });
60 return it != this->mChildren.end();
61 }
62
63 virtual std::vector<size_t> independentUnit() const override {
64 std::set<size_t> unit = {this->mId};
65 for (auto const& child : mChildren) {
66 child->extendUnit(unit);
67 }
68 return std::vector<size_t>(unit.begin(), unit.end());
69 }
70
71 virtual void extendUnit(std::set<size_t>& unit) const override {
73 for (auto const& child : mChildren) {
74 child->extendUnit(unit);
75 }
76 }
77
78 virtual std::vector<size_t> independentSubDft(bool blockParents, bool sparesAsLeaves = false) const override {
79 auto prelRes = DFTElement<ValueType>::independentSubDft(blockParents);
80 if (prelRes.empty()) {
81 // No elements (especially not this->id) in the prelimanry result, so we know already that it is not a subdft.
82 return prelRes;
83 }
84 std::set<size_t> unit(prelRes.begin(), prelRes.end());
85 std::vector<size_t> pids = this->parentIds();
86 for (auto const& child : mChildren) {
87 child->extendSubDft(unit, pids, blockParents, sparesAsLeaves);
88 if (unit.empty()) {
89 // Parent in the subdft, ie it is *not* a subdft
90 break;
91 }
92 }
93 return std::vector<size_t>(unit.begin(), unit.end());
94 }
95
96 virtual void extendSubDft(std::set<size_t>& elemsInSubtree, std::vector<size_t> const& parentsOfSubRoot, bool blockParents,
97 bool sparesAsLeaves) const override {
98 if (elemsInSubtree.count(this->id()) > 0)
99 return;
100 DFTElement<ValueType>::extendSubDft(elemsInSubtree, parentsOfSubRoot, blockParents, sparesAsLeaves);
101 if (elemsInSubtree.empty()) {
102 // Parent in the subdft, ie it is *not* a subdft
103 return;
104 }
105 for (auto const& child : mChildren) {
106 child->extendSubDft(elemsInSubtree, parentsOfSubRoot, blockParents, sparesAsLeaves);
107 if (elemsInSubtree.empty()) {
108 // Parent in the subdft, ie it is *not* a subdft
109 return;
110 }
111 }
112 }
113
120
128
129 virtual std::string toString() const override {
130 std::stringstream stream;
131 stream << "{" << this->name() << "} " << this->typestring() << "(";
132 typename DFTElementVector::const_iterator it = mChildren.begin();
133 stream << (*it)->name();
134 ++it;
135 while (it != mChildren.end()) {
136 stream << ", " << (*it)->name();
137 ++it;
138 }
139 stream << ")";
140 return stream.str();
141 }
142
143 protected:
150 for (auto const& child : mChildren) {
151 if (state.isFailsafe(child->id())) {
152 return true;
153 }
154 }
155 return false;
156 }
157
164 for (auto const& child : mChildren) {
165 if (state.hasFailed(child->id())) {
166 return true;
167 }
168 }
169 return false;
170 }
171
173
175
176 private:
177 DFTElementVector mChildren;
178};
179
180} // namespace elements
181} // namespace storage
182} // namespace storm::dft
bool hasFailed(size_t id) const
Definition DFTState.cpp:155
bool isFailsafe(size_t id) const
Definition DFTState.cpp:165
Abstract base class for a DFT element with children.
Definition DFTChildren.h:13
virtual void extendUnit(std::set< size_t > &unit) const override
Helper to independent unit computation.
Definition DFTChildren.h:71
bool hasFailsafeChild(storm::dft::storage::DFTState< ValueType > &state) const
Check whether it has a failsafe child.
virtual ~DFTChildren()=default
Destructor.
DFTElementVector const & children() const
Get children.
Definition DFTChildren.h:45
virtual std::string toString() const override
Print information about element to string.
size_t nrChildren() const override
Get number of children.
Definition DFTChildren.h:49
virtual void extendSubDft(std::set< size_t > &elemsInSubtree, std::vector< size_t > const &parentsOfSubRoot, bool blockParents, bool sparesAsLeaves) const override
Helper to the independent subtree computation.
Definition DFTChildren.h:96
bool hasFailedChild(storm::dft::storage::DFTState< ValueType > &state) const
Check whether it has a failed child.
virtual std::vector< size_t > independentSubDft(bool blockParents, bool sparesAsLeaves=false) const override
Computes independent subtrees starting with this element (this), that is, all elements (x) which are ...
Definition DFTChildren.h:78
DFTChildren(size_t id, std::string const &name, DFTElementVector const &children)
Constructor.
Definition DFTChildren.h:24
void addChild(DFTElementPointer element)
Add child.
Definition DFTChildren.h:37
virtual void checkFailsafe(storm::dft::storage::DFTState< ValueType > &state, storm::dft::storage::DFTStateSpaceGenerationQueues< ValueType > &queues) const =0
Check failsafe status.
virtual void fail(storm::dft::storage::DFTState< ValueType > &state, storm::dft::storage::DFTStateSpaceGenerationQueues< ValueType > &queues) const =0
virtual void checkFails(storm::dft::storage::DFTState< ValueType > &state, storm::dft::storage::DFTStateSpaceGenerationQueues< ValueType > &queues) const =0
Check failed status.
bool containsChild(size_t id)
Check whether the given element is contained in the list of children.
Definition DFTChildren.h:58
virtual void failsafe(storm::dft::storage::DFTState< ValueType > &state, storm::dft::storage::DFTStateSpaceGenerationQueues< ValueType > &queues) const =0
virtual std::vector< size_t > independentUnit() const override
Computes the independent unit of this element, that is, all elements which are direct or indirect suc...
Definition DFTChildren.h:63
Abstract base class for DFT elements.
Definition DFTElement.h:39
virtual size_t id() const
Get id.
Definition DFTElement.h:73
virtual void extendUnit(std::set< size_t > &unit) const
Helper to independent unit computation.
virtual std::string typestring() const
Get type as string.
Definition DFTElement.h:103
virtual std::string const & name() const
Get name.
Definition DFTElement.h:89
std::vector< size_t > parentIds() const
Return Ids of parents.
Definition DFTElement.h:241
virtual void extendSubDft(std::set< size_t > &elemsInSubtree, std::vector< size_t > const &parentsOfSubRoot, bool blockParents, bool sparesAsLeaves) const
Helper to the independent subtree computation.
virtual std::vector< size_t > independentSubDft(bool blockParents, bool sparesAsLeaves=false) const
Computes independent subtrees starting with this element (this), that is, all elements (x) which are ...