Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DFT.h
Go to the documentation of this file.
1#pragma once
2
3#include <boost/iterator/counting_iterator.hpp>
4#include <list>
5#include <map>
6#include <memory>
7#include <unordered_map>
8#include <vector>
9
18
19namespace storm::dft {
20
21// Forward declarations
22namespace builder {
23template<typename T>
24class DFTBuilder;
25} // namespace builder
26
27namespace utility {
28class RelevantEvents;
29} // namespace utility
30
31namespace storage {
32
33template<typename ValueType>
36 std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType>> const& b) const {
37 if (a->rank() == 0 && b->rank() == 0) {
38 return a->isConstant();
39 } else {
40 return a->rank() < b->rank();
41 }
42 }
43};
44
48template<typename ValueType>
49class DFT {
50 using DFTElementPointer = std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType>>;
51 using DFTElementCPointer = std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType> const>;
52 using DFTElementVector = std::vector<DFTElementPointer>;
53 using DFTGatePointer = std::shared_ptr<storm::dft::storage::elements::DFTGate<ValueType>>;
54 using DFTGateVector = std::vector<DFTGatePointer>;
55 using DFTStatePointer = std::shared_ptr<storm::dft::storage::DFTState<ValueType>>;
56
57 private:
58 DFTElementVector mElements;
59 size_t mNrOfBEs;
60 size_t mNrOfSpares;
61 size_t mNrRepresentatives;
62 size_t mTopLevelIndex;
63 size_t mStateVectorSize;
64 size_t mMaxSpareChildCount;
65 std::map<size_t, storm::dft::storage::DftModule> mModules;
66 std::vector<size_t> mBEs;
67 std::vector<size_t> mDependencies;
68 std::map<size_t, size_t> mRepresentants; // id element -> id representative
69 std::map<size_t, DFTLayoutInfo> mLayoutInfo;
70 mutable std::vector<size_t> mRelevantEvents;
71 std::map<size_t, bool> mDependencyInConflict;
72
73 public:
74 DFT(DFTElementVector const& elements, DFTElementPointer const& tle);
75
77
78 size_t generateStateInfo(DFTStateGenerationInfo& generationInfo, size_t id, storm::storage::BitVector& visited, size_t stateIndex) const;
79
80 size_t performStateGenerationInfoDFS(DFTStateGenerationInfo& generationInfo, std::queue<size_t>& visitQueue, storm::storage::BitVector& visited,
81 size_t stateIndex) const;
82
84
85 size_t stateBitVectorSize() const {
86 // Ensure multiple of 64
87 return (mStateVectorSize / 64 + (mStateVectorSize % 64 != 0)) * 64;
88 }
89
90 size_t nrElements() const {
91 return mElements.size();
92 }
93
94 size_t nrBasicElements() const {
95 return mNrOfBEs;
96 }
97
98 size_t nrDynamicElements() const;
99
100 size_t nrStaticElements() const;
101
102 size_t getTopLevelIndex() const {
103 return mTopLevelIndex;
104 }
105
109
110 size_t getMaxSpareChildCount() const {
111 return mMaxSpareChildCount;
112 }
113
114 std::vector<size_t> getSpareIndices() const {
115 std::vector<size_t> indices;
116 for (auto const& elem : mElements) {
117 if (elem->isSpareGate()) {
118 indices.push_back(elem->id());
119 }
120 }
121 return indices;
122 }
123
124 storm::dft::storage::DftModule const& module(size_t representativeId) const {
125 STORM_LOG_ASSERT(mModules.count(representativeId) > 0, "Representative not found.");
126 return mModules.at(representativeId);
127 }
128
129 std::vector<storm::dft::storage::DftModule> getSpareModules() const {
130 std::vector<storm::dft::storage::DftModule> spareModules;
131 for (auto const& pair : mModules) {
132 if (pair.first != mTopLevelIndex) {
133 spareModules.push_back(pair.second);
134 }
135 }
136 return spareModules;
137 }
138
139 bool isDependencyInConflict(size_t id) const {
140 STORM_LOG_ASSERT(isDependency(id), "Not a dependency.");
141 return mDependencyInConflict.at(id);
142 }
143
145 STORM_LOG_ASSERT(isDependency(id), "Not a dependency.");
146 mDependencyInConflict.at(id) = false;
147 }
148
149 std::vector<size_t> const& getDependencies() const {
150 return mDependencies;
151 }
152
153 std::vector<size_t> nonColdBEs() const {
154 std::vector<size_t> result;
155 for (DFTElementPointer elem : mElements) {
156 if (elem->isBasicElement()) {
157 std::shared_ptr<storm::dft::storage::elements::DFTBE<ValueType>> be =
158 std::static_pointer_cast<storm::dft::storage::elements::DFTBE<ValueType>>(elem);
159 if (be->canFail()) {
160 switch (be->beType()) {
162 result.push_back(be->id());
163 break;
165 auto beExp = std::static_pointer_cast<storm::dft::storage::elements::BEExponential<ValueType>>(be);
166 if (!beExp->isColdBasicElement()) {
167 result.push_back(be->id());
168 }
169 break;
170 }
171 default:
172 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "BE type '" << be->beType() << "' is not supported.");
173 }
174 }
175 }
176 }
177 return result;
178 }
179
184 DFTElementCPointer getElement(size_t index) const {
185 STORM_LOG_ASSERT(index < nrElements(), "Index invalid.");
186 return mElements[index];
187 }
188
189 bool isBasicElement(size_t index) const {
190 return getElement(index)->isBasicElement();
191 }
192
193 bool isGate(size_t index) const {
194 return getElement(index)->isGate();
195 }
196
197 bool isDependency(size_t index) const {
198 return getElement(index)->isDependency();
199 }
200
201 bool isRestriction(size_t index) const {
202 return getElement(index)->isRestriction();
203 }
204
205 std::shared_ptr<storm::dft::storage::elements::DFTBE<ValueType> const> getBasicElement(size_t index) const {
206 STORM_LOG_ASSERT(isBasicElement(index), "Element is no BE.");
207 return std::static_pointer_cast<storm::dft::storage::elements::DFTBE<ValueType> const>(mElements[index]);
208 }
209
210 DFTElementCPointer getTopLevelElement() const {
212 }
213
214 std::shared_ptr<storm::dft::storage::elements::DFTGate<ValueType> const> getGate(size_t index) const {
215 STORM_LOG_ASSERT(isGate(index), "Element is no gate.");
216 return std::static_pointer_cast<storm::dft::storage::elements::DFTGate<ValueType> const>(mElements[index]);
217 }
218
219 std::shared_ptr<storm::dft::storage::elements::DFTDependency<ValueType> const> getDependency(size_t index) const {
220 STORM_LOG_ASSERT(isDependency(index), "Element is no dependency.");
221 return std::static_pointer_cast<storm::dft::storage::elements::DFTDependency<ValueType> const>(mElements[index]);
222 }
223
224 std::shared_ptr<storm::dft::storage::elements::DFTRestriction<ValueType> const> getRestriction(size_t index) const {
225 STORM_LOG_ASSERT(isRestriction(index), "Element is no restriction.");
226 return std::static_pointer_cast<storm::dft::storage::elements::DFTRestriction<ValueType> const>(mElements[index]);
227 }
228
235 void setBEOrder(std::vector<size_t> const& bes) {
236 STORM_LOG_ASSERT(bes.size() == nrBasicElements(), "BEs must be the same size.");
237 STORM_LOG_ASSERT(std::all_of(bes.begin(), bes.end(), [this](size_t id) { return this->getElement(id)->isBasicElement(); }),
238 "All elements must be BEs.");
239 this->mBEs = bes;
240 }
241
247 std::vector<std::shared_ptr<storm::dft::storage::elements::DFTBE<ValueType> const>> getBasicElements() const {
248 std::vector<std::shared_ptr<storm::dft::storage::elements::DFTBE<ValueType> const>> elements;
249 for (size_t id : mBEs) {
250 auto element = getElement(id);
251 STORM_LOG_ASSERT(element->isBasicElement(), "Element is not a BE.");
252 elements.push_back(std::static_pointer_cast<storm::dft::storage::elements::DFTBE<ValueType> const>(element));
253 }
254 return elements;
255 }
256
257 bool canHaveNondeterminism() const;
258
259 uint64_t maxRank() const;
260
261 std::vector<DFT<ValueType>> topModularisation() const;
262
263 bool isRepresentative(size_t id) const {
264 for (auto const& parent : getElement(id)->parents()) {
265 if (parent->isSpareGate()) {
266 return true;
267 }
268 }
269 return false;
270 }
271
272 bool hasRepresentant(size_t id) const {
273 return mRepresentants.find(id) != mRepresentants.end();
274 }
275
276 size_t getRepresentant(size_t id) const {
277 STORM_LOG_ASSERT(hasRepresentant(id), "Element has no representant.");
278 return mRepresentants.find(id)->second;
279 }
280
281 bool hasFailed(DFTStatePointer const& state) const {
282 return state->hasFailed(mTopLevelIndex);
283 }
284
285 bool hasFailed(storm::storage::BitVector const& state, DFTStateGenerationInfo const& stateGenerationInfo) const {
286 return storm::dft::storage::DFTState<ValueType>::hasFailed(state, stateGenerationInfo.getStateIndex(mTopLevelIndex));
287 }
288
289 bool isFailsafe(DFTStatePointer const& state) const {
290 return state->isFailsafe(mTopLevelIndex);
291 }
292
293 bool isFailsafe(storm::storage::BitVector const& state, DFTStateGenerationInfo const& stateGenerationInfo) const {
294 return storm::dft::storage::DFTState<ValueType>::isFailsafe(state, stateGenerationInfo.getStateIndex(mTopLevelIndex));
295 }
296
306 size_t uses(storm::storage::BitVector const& state, DFTStateGenerationInfo const& stateGenerationInfo, size_t id) const {
307 size_t nrUsedChild = storm::dft::storage::DFTState<ValueType>::usesIndex(state, stateGenerationInfo, id);
308 if (nrUsedChild == getMaxSpareChildCount()) {
309 return id;
310 } else {
311 return getChild(id, nrUsedChild);
312 }
313 }
314
315 size_t getChild(size_t spareId, size_t nrUsedChild) const;
316
317 size_t getNrChild(size_t spareId, size_t childId) const;
318
319 std::string getElementsString() const;
320
321 std::string getInfoString() const;
322
323 std::string getModulesString() const;
324
325 std::string getElementsWithStateString(DFTStatePointer const& state) const;
326
327 std::string getStateString(DFTStatePointer const& state) const;
328
329 std::string getStateString(storm::storage::BitVector const& status, DFTStateGenerationInfo const& stateGenerationInfo, size_t id) const;
330
331 std::vector<size_t> immediateFailureCauses(size_t index) const;
332
333 std::vector<size_t> findModularisationRewrite() const;
334
335 void setElementLayoutInfo(size_t id, DFTLayoutInfo const& layoutInfo) {
336 mLayoutInfo[id] = layoutInfo;
337 }
338
339 DFTLayoutInfo const& getElementLayoutInfo(size_t id) const {
340 return mLayoutInfo.at(id);
341 }
342
343 void writeStatsToStream(std::ostream& stream) const;
344
349 std::set<size_t> getAllIds() const;
350
356 bool existsName(std::string const& name) const;
357
363 size_t getIndex(std::string const& name) const;
364
369 std::vector<size_t> const& getRelevantEvents() const;
370
376 void setRelevantEvents(storm::dft::utility::RelevantEvents const& relevantEvents, bool const allowDCForRelevant) const;
377
382 std::string getRelevantEventsString() const;
383
384 private:
385 bool elementIndicesCorrect() const {
386 for (size_t i = 0; i < mElements.size(); ++i) {
387 if (mElements[i]->id() != i) {
388 return false;
389 }
390 }
391 return true;
392 }
393};
394
400std::set<storm::RationalFunctionVariable> getParameters(DFT<storm::RationalFunction> const& dft);
401
402} // namespace storage
403} // namespace storm::dft
Represents a Dynamic Fault Tree.
Definition DFT.h:49
size_t nrBasicElements() const
Definition DFT.h:94
bool hasFailed(DFTStatePointer const &state) const
Definition DFT.h:281
std::vector< size_t > nonColdBEs() const
Definition DFT.h:153
size_t getTopLevelIndex() const
Definition DFT.h:102
bool isRepresentative(size_t id) const
Definition DFT.h:263
void setBEOrder(std::vector< size_t > const &bes)
Set order of BEs.
Definition DFT.h:235
std::string getRelevantEventsString() const
Get a string containing the list of all relevant events.
Definition DFT.cpp:717
std::shared_ptr< storm::dft::storage::elements::DFTDependency< ValueType > const > getDependency(size_t index) const
Definition DFT.h:219
void setRelevantEvents(storm::dft::utility::RelevantEvents const &relevantEvents, bool const allowDCForRelevant) const
Set the relevance flag for all elements according to the given relevant events.
Definition DFT.cpp:691
std::shared_ptr< storm::dft::storage::elements::DFTBE< ValueType > const > getBasicElement(size_t index) const
Definition DFT.h:205
size_t nrDynamicElements() const
Definition DFT.cpp:459
size_t getNrChild(size_t spareId, size_t childId) const
Definition DFT.cpp:609
DFTLayoutInfo const & getElementLayoutInfo(size_t id) const
Definition DFT.h:339
std::string getModulesString() const
Definition DFT.cpp:527
std::set< size_t > getAllIds() const
Get Ids of all elements.
Definition DFT.cpp:670
bool hasRepresentant(size_t id) const
Definition DFT.h:272
std::vector< size_t > findModularisationRewrite() const
Definition DFT.cpp:637
void setDependencyNotInConflict(size_t id)
Definition DFT.h:144
DFTElementCPointer getElement(size_t index) const
Get a pointer to an element in the DFT.
Definition DFT.h:184
void setElementLayoutInfo(size_t id, DFTLayoutInfo const &layoutInfo)
Definition DFT.h:335
void writeStatsToStream(std::ostream &stream) const
Definition DFT.cpp:732
storm::dft::storage::elements::DFTElementType getTopLevelType() const
Definition DFT.h:106
std::string getElementsWithStateString(DFTStatePointer const &state) const
Definition DFT.cpp:536
DFTElementCPointer getTopLevelElement() const
Definition DFT.h:210
std::vector< size_t > const & getDependencies() const
Definition DFT.h:149
bool existsName(std::string const &name) const
Check whether an element with the given name exists.
Definition DFT.cpp:679
size_t nrElements() const
Definition DFT.h:90
std::shared_ptr< storm::dft::storage::elements::DFTGate< ValueType > const > getGate(size_t index) const
Definition DFT.h:214
uint64_t maxRank() const
Definition DFT.cpp:362
std::string getStateString(DFTStatePointer const &state) const
Definition DFT.cpp:559
size_t stateBitVectorSize() const
Definition DFT.h:85
size_t uses(storm::storage::BitVector const &state, DFTStateGenerationInfo const &stateGenerationInfo, size_t id) const
Return id of used child for a given spare gate.
Definition DFT.h:306
std::string getInfoString() const
Definition DFT.cpp:520
bool isDependencyInConflict(size_t id) const
Definition DFT.h:139
size_t getRepresentant(size_t id) const
Definition DFT.h:276
size_t generateStateInfo(DFTStateGenerationInfo &generationInfo, size_t id, storm::storage::BitVector &visited, size_t stateIndex) const
Definition DFT.cpp:276
bool isDependency(size_t index) const
Definition DFT.h:197
DFTStateGenerationInfo buildStateGenerationInfo(storm::dft::storage::DftSymmetries const &symmetries) const
Definition DFT.cpp:105
bool isGate(size_t index) const
Definition DFT.h:193
DFT(DFTElementVector const &elements, DFTElementPointer const &tle)
Definition DFT.cpp:17
std::shared_ptr< storm::dft::storage::elements::DFTRestriction< ValueType > const > getRestriction(size_t index) const
Definition DFT.h:224
size_t nrStaticElements() const
Definition DFT.cpp:485
bool hasFailed(storm::storage::BitVector const &state, DFTStateGenerationInfo const &stateGenerationInfo) const
Definition DFT.h:285
std::vector< size_t > const & getRelevantEvents() const
Get all relevant events.
Definition DFT.cpp:712
std::vector< std::shared_ptr< storm::dft::storage::elements::DFTBE< ValueType > const > > getBasicElements() const
Return list of basic elements.
Definition DFT.h:247
size_t getIndex(std::string const &name) const
Get id for the given element name.
Definition DFT.cpp:684
std::vector< size_t > getSpareIndices() const
Definition DFT.h:114
bool isRestriction(size_t index) const
Definition DFT.h:201
size_t performStateGenerationInfoDFS(DFTStateGenerationInfo &generationInfo, std::queue< size_t > &visitQueue, storm::storage::BitVector &visited, size_t stateIndex) const
Definition DFT.cpp:298
bool isFailsafe(storm::storage::BitVector const &state, DFTStateGenerationInfo const &stateGenerationInfo) const
Definition DFT.h:293
bool canHaveNondeterminism() const
Definition DFT.cpp:632
size_t getMaxSpareChildCount() const
Definition DFT.h:110
std::vector< size_t > immediateFailureCauses(size_t index) const
Definition DFT.cpp:622
size_t getChild(size_t spareId, size_t nrUsedChild) const
Definition DFT.cpp:603
std::vector< storm::dft::storage::DftModule > getSpareModules() const
Definition DFT.h:129
std::string getElementsString() const
Definition DFT.cpp:511
storm::dft::storage::DftModule const & module(size_t representativeId) const
Definition DFT.h:124
std::vector< DFT< ValueType > > topModularisation() const
Definition DFT.cpp:320
DFT< ValueType > optimize() const
Definition DFT.cpp:373
bool isFailsafe(DFTStatePointer const &state) const
Definition DFT.h:289
bool isBasicElement(size_t index) const
Definition DFT.h:189
bool hasFailed(size_t id) const
Definition DFTState.cpp:157
bool isFailsafe(size_t id) const
Definition DFTState.cpp:167
static uint_fast64_t usesIndex(storm::storage::BitVector const &state, DFTStateGenerationInfo const &stateGenerationInfo, size_t id)
Returns the index of the used child for a spare gate.
Definition DFTState.cpp:443
Represents a module/subtree in a DFT.
Definition DftModule.h:18
Abstract base class for basic events (BEs) in DFTs.
Definition DFTBE.h:14
Abstract base class for DFT elements.
Definition DFTElement.h:38
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28
DFTElementType
Element types in a DFT.
std::set< storm::RationalFunctionVariable > getParameters(DFT< storm::RationalFunction > const &dft)
Get all rate/probability parameters occurring in the DFT.
Definition DFT.cpp:826
bool operator()(std::shared_ptr< storm::dft::storage::elements::DFTElement< ValueType > > const &a, std::shared_ptr< storm::dft::storage::elements::DFTElement< ValueType > > const &b) const
Definition DFT.h:35