Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DFTDependency.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
19template<typename ValueType>
20class DFTDependency : public DFTElement<ValueType> {
21 using DFTElementPointer = std::shared_ptr<DFTElement<ValueType>>;
22 using DFTElementVector = std::vector<DFTElementPointer>;
23
24 public:
31 DFTDependency(size_t id, std::string const& name, ValueType probability) : DFTElement<ValueType>(id, name), mProbability(probability) {
32 // We cannot assert 0<=p<=1 in general, because ValueType might be RationalFunction.
33 }
34
35 std::shared_ptr<DFTElement<ValueType>> clone() const override {
36 return std::shared_ptr<DFTElement<ValueType>>(new DFTDependency<ValueType>(this->id(), this->name(), this->probability()));
37 }
38
42 virtual ~DFTDependency() = default;
43
47
48 std::string typestring() const override {
49 return this->isFDEP() ? "FDEP" : "PDEP";
50 }
51
56 ValueType const& probability() const {
57 return mProbability;
58 }
59
60 bool isDependency() const override {
61 return true;
62 }
63
68 bool isFDEP() const {
69 return storm::utility::isOne(this->probability());
70 }
71
76 DFTElementPointer const& triggerEvent() const {
77 STORM_LOG_ASSERT(mTriggerEvent, "Trigger does not exist.");
78 return mTriggerEvent;
79 }
80
85 void setTriggerElement(DFTElementPointer const& triggerEvent) {
86 mTriggerEvent = triggerEvent;
87 }
88
93 DFTElementVector const& dependentEvents() const {
94 STORM_LOG_ASSERT(mDependentEvents.size() > 0, "Dependent event does not exists.");
95 return mDependentEvents;
96 }
97
102 void addDependentEvent(DFTElementPointer const& dependentEvent) {
103 mDependentEvents.push_back(dependentEvent);
104 }
105
111 bool containsDependentEvent(size_t id) {
112 auto it =
113 std::find_if(this->mDependentEvents.begin(), this->mDependentEvents.end(), [&id](DFTElementPointer elem) -> bool { return elem->id() == id; });
114 return it != this->mDependentEvents.end();
115 }
116
117 virtual size_t nrChildren() const override {
118 return 1;
119 }
120
121 bool isTypeEqualTo(DFTElement<ValueType> const& other) const override {
123 return false;
124 }
125 auto& otherDEP = static_cast<DFTDependency<ValueType> const&>(other);
126 return this->probability() == otherDEP.probability();
127 }
128
129 void extendSpareModule(std::set<size_t>&) const override {
130 // Do nothing
131 }
132
133 std::vector<size_t> independentUnit() const override {
134 std::set<size_t> unit = {this->mId};
135 for (auto const& depEv : mDependentEvents) {
136 depEv->extendUnit(unit);
137 if (unit.count(mTriggerEvent->id()) != 0) {
138 return {};
139 }
140 }
141 return std::vector<size_t>(unit.begin(), unit.end());
142 }
143
144 void extendSubDft(std::set<size_t>& elemsInSubtree, std::vector<size_t> const& parentsOfSubRoot, bool blockParents, bool sparesAsLeaves) const override {
145 if (elemsInSubtree.count(this->id())) {
146 return;
147 }
148 DFTElement<ValueType>::extendSubDft(elemsInSubtree, parentsOfSubRoot, blockParents, sparesAsLeaves);
149 if (elemsInSubtree.empty()) {
150 // Parent in the subdft, ie it is *not* a subdft
151 return;
152 }
153 for (auto const& depEv : mDependentEvents) {
154 depEv->extendSubDft(elemsInSubtree, parentsOfSubRoot, blockParents, sparesAsLeaves);
155 if (elemsInSubtree.empty()) {
156 return;
157 }
158 }
159 if (elemsInSubtree.empty()) {
160 // Parent in the subdft, ie it is *not* a subdft
161 return;
162 }
163 mTriggerEvent->extendSubDft(elemsInSubtree, parentsOfSubRoot, blockParents, sparesAsLeaves);
164 }
165
166 std::string toString() const override {
167 std::stringstream stream;
168 stream << "{" << this->name() << "} " << this->typestring() << "(" << this->triggerEvent()->name() << " => { ";
169 for (auto const& depEv : this->dependentEvents()) {
170 stream << depEv->name() << " ";
171 }
172 stream << "}";
173 if (!this->isFDEP()) {
174 stream << " with probability " << this->probability();
175 }
176 return stream.str();
177 }
178
179 private:
180 ValueType mProbability;
181 DFTElementPointer mTriggerEvent;
182 DFTElementVector mDependentEvents;
183};
184
185} // namespace elements
186} // namespace storage
187} // namespace storm::dft
Dependency gate with probability p.
bool isDependency() const override
Check whether the element is a dependency.
std::string toString() const override
Print information about element to string.
std::shared_ptr< DFTElement< ValueType > > clone() const override
Create a shallow copy of the element.
DFTElementVector const & dependentEvents() const
Get dependent events.
bool isTypeEqualTo(DFTElement< ValueType > const &other) const override
Check whether two elements have the same type.
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.
virtual ~DFTDependency()=default
Destructor.
void setTriggerElement(DFTElementPointer const &triggerEvent)
Set the trigger event, i.e., the first child.
DFTElementPointer const & triggerEvent() const
Get trigger event, i.e., the first child.
ValueType const & probability() const
Get probability of forwarding the failure.
void extendSpareModule(std::set< size_t > &) const override
bool containsDependentEvent(size_t id)
Check whether the given element is a dependent event.
DFTDependency(size_t id, std::string const &name, ValueType probability)
Constructor.
virtual size_t nrChildren() const override
Get number of children.
bool isFDEP() const
Check whether the dependency is an FDEP, i.e., p=1.
std::string typestring() const override
Get type as string.
std::vector< size_t > independentUnit() const override
Computes the independent unit of this element, that is, all elements which are direct or indirect suc...
void addDependentEvent(DFTElementPointer const &dependentEvent)
Add dependent event.
storm::dft::storage::elements::DFTElementType type() const override
Get type.
Abstract base class for DFT elements.
Definition DFTElement.h:39
virtual size_t id() const
Get id.
Definition DFTElement.h:73
virtual std::string const & name() const
Get name.
Definition DFTElement.h:89
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.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
DFTElementType
Element types in a DFT.
bool isOne(ValueType const &a)
Definition constants.cpp:36