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