Storm 1.11.1.1
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
16
17namespace storm::dft {
18namespace storage {
19namespace elements {
20
21using std::size_t;
22
23// Forward declarations
24template<typename ValueType>
25class DFTGate;
26
27template<typename ValueType>
28class DFTDependency;
29
30template<typename ValueType>
31class DFTRestriction;
32
37template<typename ValueType>
39 using DFTGatePointer = std::shared_ptr<DFTGate<ValueType>>;
40 using DFTGateVector = std::vector<DFTGatePointer>;
41 using DFTDependencyPointer = std::shared_ptr<DFTDependency<ValueType>>;
42 using DFTDependencyVector = std::vector<DFTDependencyPointer>;
43 using DFTRestrictionPointer = std::shared_ptr<DFTRestriction<ValueType>>;
44 using DFTRestrictionVector = std::vector<DFTRestrictionPointer>;
45
46 public:
52 DFTElement(size_t id, std::string const& name) : mId(id), mName(name), mRank(-1), mRelevant(false), mAllowDC(true) {
53 // Intentionally left empty.
54 }
55
61 virtual std::shared_ptr<DFTElement<ValueType>> clone() const = 0;
62
66 virtual ~DFTElement() = default;
67
72 virtual size_t id() const {
73 return mId;
74 }
75
80 virtual void setId(size_t id) {
81 this->mId = id;
82 }
83
88 virtual std::string const& name() const {
89 return mName;
90 }
91
97
102 virtual std::string typestring() const {
104 }
105
110 virtual size_t rank() const {
111 return mRank;
112 }
113
118 virtual void setRank(size_t rank) {
119 this->mRank = rank;
120 }
121
127 virtual bool isRelevant() const {
128 return mRelevant;
129 }
130
135 virtual void setRelevance(bool relevant) const {
136 this->mRelevant = relevant;
137 }
138
143 virtual void setAllowDC(bool allowDC) const {
144 this->mAllowDC = allowDC;
145 }
146
151 virtual bool isBasicElement() const {
152 return false;
153 }
154
159 virtual bool isGate() const {
160 return false;
161 }
162
167 virtual bool isStaticElement() const {
168 return false;
169 }
170
175 virtual bool isSpareGate() const {
176 return false;
177 }
178
183 virtual bool isDependency() const {
184 return false;
185 }
186
191 virtual bool isRestriction() const {
192 return false;
193 }
194
199 virtual std::size_t nrChildren() const = 0;
200
205 bool hasParents() const {
206 return !mParents.empty();
207 }
208
213 size_t nrParents() const {
214 return mParents.size();
215 }
216
221 DFTGateVector const& parents() const {
222 return mParents;
223 }
224
229 void addParent(DFTGatePointer const& parent) {
230 if (std::find(this->parents().begin(), this->parents().end(), parent) == this->parents().end()) {
231 // Parent does not exist yet
232 mParents.push_back(parent);
233 }
234 }
235
240 std::vector<size_t> parentIds() const {
241 std::vector<size_t> ids;
242 for (auto parent : this->parents()) {
243 ids.push_back(parent->id());
244 }
245 return ids;
246 }
247
252 bool hasOnlyStaticParents() const {
253 for (auto const& parent : this->parents()) {
254 if (!parent->isStaticElement()) {
255 return false;
256 }
257 }
258 return true;
259 }
260
265 bool hasRestrictions() const {
266 return !mRestrictions.empty();
267 }
268
273 size_t nrRestrictions() const {
274 return mRestrictions.size();
275 }
276
281 DFTRestrictionVector const& restrictions() const {
282 return mRestrictions;
283 }
284
289 void addRestriction(DFTRestrictionPointer const& restriction) {
290 if (std::find(this->restrictions().begin(), this->restrictions().end(), restriction) == this->restrictions().end()) {
291 // Restriction does not exist yet
292 mRestrictions.push_back(restriction);
293 }
294 }
295
301 return !mOutgoingDependencies.empty();
302 }
303
308 size_t nrOutgoingDependencies() const {
309 return mOutgoingDependencies.size();
310 }
311
316 DFTDependencyVector const& outgoingDependencies() const {
318 }
319
324 void addOutgoingDependency(DFTDependencyPointer const& outgoingDependency) {
325 STORM_LOG_ASSERT(outgoingDependency->triggerEvent()->id() == this->id(), "Ids do not match.");
326 if (std::find(this->outgoingDependencies().begin(), this->outgoingDependencies().end(), outgoingDependency) == this->outgoingDependencies().end()) {
327 // Outgoing dependency does not exist yet
328 mOutgoingDependencies.push_back(outgoingDependency);
329 }
330 }
331
332 virtual void extendSpareModule(std::set<size_t>& elementsInModule) const;
333
336
340 virtual std::vector<size_t> independentUnit() const;
341
346 virtual void extendUnit(std::set<size_t>& unit) const;
347
354 virtual std::vector<size_t> independentSubDft(bool blockParents, bool sparesAsLeaves = false) const;
355
360 virtual void extendSubDft(std::set<size_t>& elemsInSubtree, std::vector<size_t> const& parentsOfSubRoot, bool blockParents, bool sparesAsLeaves) const;
361
367 virtual bool isTypeEqualTo(DFTElement<ValueType> const& other) const {
368 return type() == other.type();
369 }
370
375 virtual std::string toString() const = 0;
376
377 protected:
378 std::size_t mId;
379 std::string mName;
380 std::size_t mRank;
381 DFTGateVector mParents;
382 DFTDependencyVector mOutgoingDependencies;
383 DFTRestrictionVector mRestrictions;
384 mutable bool mRelevant; // Must be mutable to allow changes later on. TODO: avoid mutable
385 mutable bool mAllowDC; // Must be mutable to allow changes later on. TODO: avoid mutable
386};
387
388template<typename ValueType>
389inline std::ostream& operator<<(std::ostream& os, DFTElement<ValueType> const& element) {
390 return os << element.toString();
391}
392
393} // namespace elements
394} // namespace storage
395} // namespace storm::dft
Abstract base class for DFT elements.
Definition DFTElement.h:38
virtual size_t id() const
Get id.
Definition DFTElement.h:72
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:102
virtual std::string const & name() const
Get name.
Definition DFTElement.h:88
void addOutgoingDependency(DFTDependencyPointer const &outgoingDependency)
Add outgoing dependency.
Definition DFTElement.h:324
virtual bool isBasicElement() const
Checks whether the element is a basic element.
Definition DFTElement.h:151
std::vector< size_t > parentIds() const
Return Ids of parents.
Definition DFTElement.h:240
virtual std::size_t nrChildren() const =0
Get number of children.
virtual bool isRelevant() const
Get whether the element is relevant.
Definition DFTElement.h:127
void addParent(DFTGatePointer const &parent)
Add parent.
Definition DFTElement.h:229
virtual void setRelevance(bool relevant) const
Set the relevancy of the element.
Definition DFTElement.h:135
DFTDependencyVector const & outgoingDependencies() const
Get outgoing dependencies.
Definition DFTElement.h:316
virtual bool isDependency() const
Check whether the element is a dependency.
Definition DFTElement.h:183
void addRestriction(DFTRestrictionPointer const &restriction)
Add restriction.
Definition DFTElement.h:289
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:80
size_t nrOutgoingDependencies() const
Return the number of outgoing dependencies.
Definition DFTElement.h:308
size_t nrRestrictions() const
Return the number of restrictions.
Definition DFTElement.h:273
virtual bool isGate() const
Check whether the element is a gate.
Definition DFTElement.h:159
virtual size_t rank() const
Get rank.
Definition DFTElement.h:110
bool hasRestrictions() const
Return whether the element has restrictions.
Definition DFTElement.h:265
virtual ~DFTElement()=default
Destructor.
virtual bool isSpareGate() const
Check whether the element is a SPARE gate.
Definition DFTElement.h:175
virtual bool isRestriction() const
Check whether the element is a restriction.
Definition DFTElement.h:191
virtual void setAllowDC(bool allowDC) const
Set whether Don't Care propagation is allowed for this element.
Definition DFTElement.h:143
DFTGateVector const & parents() const
Get parents.
Definition DFTElement.h:221
virtual bool isTypeEqualTo(DFTElement< ValueType > const &other) const
Check whether two elements have the same type.
Definition DFTElement.h:367
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:167
DFTRestrictionVector const & restrictions() const
Get restrictions.
Definition DFTElement.h:281
bool hasParents() const
Return whether the element has parents.
Definition DFTElement.h:205
virtual void setRank(size_t rank)
Set rank.
Definition DFTElement.h:118
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:252
DFTElement(size_t id, std::string const &name)
Constructor.
Definition DFTElement.h:52
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:300
virtual storm::dft::storage::elements::DFTElementType type() const =0
Get type.
size_t nrParents() const
Return the number of parents.
Definition DFTElement.h:213
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
DFTElementType
Element types in a DFT.
std::string toString(DFTElementType const &type)