Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DFTElement.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdlib>
4#include <functional>
5#include <iostream>
6#include <map>
7#include <memory>
8#include <set>
9#include <string>
10#include <vector>
11
17
18namespace storm::dft {
19namespace storage {
20namespace elements {
21
22using std::size_t;
23
24// Forward declarations
25template<typename ValueType>
26class DFTGate;
27
28template<typename ValueType>
29class DFTDependency;
30
31template<typename ValueType>
32class DFTRestriction;
33
38template<typename ValueType>
40 using DFTGatePointer = std::shared_ptr<DFTGate<ValueType>>;
41 using DFTGateVector = std::vector<DFTGatePointer>;
42 using DFTDependencyPointer = std::shared_ptr<DFTDependency<ValueType>>;
43 using DFTDependencyVector = std::vector<DFTDependencyPointer>;
44 using DFTRestrictionPointer = std::shared_ptr<DFTRestriction<ValueType>>;
45 using DFTRestrictionVector = std::vector<DFTRestrictionPointer>;
46
47 public:
53 DFTElement(size_t id, std::string const& name) : mId(id), mName(name), mRank(-1), mRelevant(false), mAllowDC(true) {
54 // Intentionally left empty.
55 }
56
62 virtual std::shared_ptr<DFTElement<ValueType>> clone() const = 0;
63
67 virtual ~DFTElement() = default;
68
73 virtual size_t id() const {
74 return mId;
75 }
76
81 virtual void setId(size_t id) {
82 this->mId = id;
83 }
84
89 virtual std::string const& name() const {
90 return mName;
91 }
92
98
103 virtual std::string typestring() const {
105 }
106
111 virtual size_t rank() const {
112 return mRank;
113 }
114
119 virtual void setRank(size_t rank) {
120 this->mRank = rank;
121 }
122
128 virtual bool isRelevant() const {
129 return mRelevant;
130 }
131
136 virtual void setRelevance(bool relevant) const {
137 this->mRelevant = relevant;
138 }
139
144 virtual void setAllowDC(bool allowDC) const {
145 this->mAllowDC = allowDC;
146 }
147
152 virtual bool isBasicElement() const {
153 return false;
154 }
155
160 virtual bool isGate() const {
161 return false;
162 }
163
168 virtual bool isStaticElement() const {
169 return false;
170 }
171
176 virtual bool isSpareGate() const {
177 return false;
178 }
179
184 virtual bool isDependency() const {
185 return false;
186 }
187
192 virtual bool isRestriction() const {
193 return false;
194 }
195
200 virtual std::size_t nrChildren() const = 0;
201
206 bool hasParents() const {
207 return !mParents.empty();
208 }
209
214 size_t nrParents() const {
215 return mParents.size();
216 }
217
222 DFTGateVector const& parents() const {
223 return mParents;
224 }
225
230 void addParent(DFTGatePointer const& parent) {
231 if (std::find(this->parents().begin(), this->parents().end(), parent) == this->parents().end()) {
232 // Parent does not exist yet
233 mParents.push_back(parent);
234 }
235 }
236
241 std::vector<size_t> parentIds() const {
242 std::vector<size_t> ids;
243 for (auto parent : this->parents()) {
244 ids.push_back(parent->id());
245 }
246 return ids;
247 }
248
253 bool hasOnlyStaticParents() const {
254 for (auto const& parent : this->parents()) {
255 if (!parent->isStaticElement()) {
256 return false;
257 }
258 }
259 return true;
260 }
261
266 bool hasRestrictions() const {
267 return !mRestrictions.empty();
268 }
269
274 size_t nrRestrictions() const {
275 return mRestrictions.size();
276 }
277
282 DFTRestrictionVector const& restrictions() const {
283 return mRestrictions;
284 }
285
290 void addRestriction(DFTRestrictionPointer const& restriction) {
291 if (std::find(this->restrictions().begin(), this->restrictions().end(), restriction) == this->restrictions().end()) {
292 // Restriction does not exist yet
293 mRestrictions.push_back(restriction);
294 }
295 }
296
302 return !mOutgoingDependencies.empty();
303 }
304
309 size_t nrOutgoingDependencies() const {
310 return mOutgoingDependencies.size();
311 }
312
317 DFTDependencyVector const& outgoingDependencies() const {
319 }
320
325 void addOutgoingDependency(DFTDependencyPointer const& outgoingDependency) {
326 STORM_LOG_ASSERT(outgoingDependency->triggerEvent()->id() == this->id(), "Ids do not match.");
327 if (std::find(this->outgoingDependencies().begin(), this->outgoingDependencies().end(), outgoingDependency) == this->outgoingDependencies().end()) {
328 // Outgoing dependency does not exist yet
329 mOutgoingDependencies.push_back(outgoingDependency);
330 }
331 }
332
333 virtual void extendSpareModule(std::set<size_t>& elementsInModule) const;
334
337
341 virtual std::vector<size_t> independentUnit() const;
342
347 virtual void extendUnit(std::set<size_t>& unit) const;
348
355 virtual std::vector<size_t> independentSubDft(bool blockParents, bool sparesAsLeaves = false) const;
356
361 virtual void extendSubDft(std::set<size_t>& elemsInSubtree, std::vector<size_t> const& parentsOfSubRoot, bool blockParents, bool sparesAsLeaves) const;
362
368 virtual bool isTypeEqualTo(DFTElement<ValueType> const& other) const {
369 return type() == other.type();
370 }
371
376 virtual std::string toString() const = 0;
377
378 protected:
379 std::size_t mId;
380 std::string mName;
381 std::size_t mRank;
382 DFTGateVector mParents;
383 DFTDependencyVector mOutgoingDependencies;
384 DFTRestrictionVector mRestrictions;
385 mutable bool mRelevant; // Must be mutable to allow changes later on. TODO: avoid mutable
386 mutable bool mAllowDC; // Must be mutable to allow changes later on. TODO: avoid mutable
387};
388
389template<typename ValueType>
390inline std::ostream& operator<<(std::ostream& os, DFTElement<ValueType> const& element) {
391 return os << element.toString();
392}
393
394} // namespace elements
395} // namespace storage
396} // namespace storm::dft
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 bool checkDontCareAnymore(storm::dft::storage::DFTState< ValueType > &state, storm::dft::storage::DFTStateSpaceGenerationQueues< ValueType > &queues) const
virtual std::string toString() const =0
Print information about element to string.
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
void addOutgoingDependency(DFTDependencyPointer const &outgoingDependency)
Add outgoing dependency.
Definition DFTElement.h:325
virtual bool isBasicElement() const
Checks whether the element is a basic element.
Definition DFTElement.h:152
std::vector< size_t > parentIds() const
Return Ids of parents.
Definition DFTElement.h:241
virtual std::size_t nrChildren() const =0
Get number of children.
virtual bool isRelevant() const
Get whether the element is relevant.
Definition DFTElement.h:128
void addParent(DFTGatePointer const &parent)
Add parent.
Definition DFTElement.h:230
virtual void setRelevance(bool relevant) const
Set the relevancy of the element.
Definition DFTElement.h:136
DFTDependencyVector const & outgoingDependencies() const
Get outgoing dependencies.
Definition DFTElement.h:317
virtual bool isDependency() const
Check whether the element is a dependency.
Definition DFTElement.h:184
void addRestriction(DFTRestrictionPointer const &restriction)
Add restriction.
Definition DFTElement.h:290
virtual std::vector< size_t > independentUnit() const
Computes the independent unit of this element, that is, all elements which are direct or indirect suc...
virtual void setId(size_t id)
Set id.
Definition DFTElement.h:81
size_t nrOutgoingDependencies() const
Return the number of outgoing dependencies.
Definition DFTElement.h:309
size_t nrRestrictions() const
Return the number of restrictions.
Definition DFTElement.h:274
virtual bool isGate() const
Check whether the element is a gate.
Definition DFTElement.h:160
virtual size_t rank() const
Get rank.
Definition DFTElement.h:111
bool hasRestrictions() const
Return whether the element has restrictions.
Definition DFTElement.h:266
virtual ~DFTElement()=default
Destructor.
virtual bool isSpareGate() const
Check whether the element is a SPARE gate.
Definition DFTElement.h:176
virtual bool isRestriction() const
Check whether the element is a restriction.
Definition DFTElement.h:192
virtual void setAllowDC(bool allowDC) const
Set whether Don't Care propagation is allowed for this element.
Definition DFTElement.h:144
DFTGateVector const & parents() const
Get parents.
Definition DFTElement.h:222
virtual bool isTypeEqualTo(DFTElement< ValueType > const &other) const
Check whether two elements have the same type.
Definition DFTElement.h:368
virtual void extendSpareModule(std::set< size_t > &elementsInModule) const
virtual bool isStaticElement() const
Check whether the element is static, ie a BE or a static gate (AND, OR, VOT).
Definition DFTElement.h:168
DFTRestrictionVector const & restrictions() const
Get restrictions.
Definition DFTElement.h:282
bool hasParents() const
Return whether the element has parents.
Definition DFTElement.h:206
virtual void setRank(size_t rank)
Set rank.
Definition DFTElement.h:119
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.
bool hasOnlyStaticParents() const
Check whether the element has only static gates as parents.
Definition DFTElement.h:253
DFTElement(size_t id, std::string const &name)
Constructor.
Definition DFTElement.h:53
virtual std::shared_ptr< DFTElement< ValueType > > clone() const =0
Create a shallow copy of the element.
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 ...
bool hasOutgoingDependencies() const
Return whether the element has outgoing dependencies.
Definition DFTElement.h:301
virtual storm::dft::storage::elements::DFTElementType type() const =0
Get type.
size_t nrParents() const
Return the number of parents.
Definition DFTElement.h:214
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
std::ostream & operator<<(std::ostream &os, DFTElement< ValueType > const &element)
Definition DFTElement.h:390
DFTElementType
Element types in a DFT.
std::string toString(DFTElementType const &type)