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