Storm
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> mDependencies;
70 std::map<size_t, size_t> mRepresentants; // id element -> id representative
71 std::map<size_t, DFTLayoutInfo> mLayoutInfo;
72 mutable std::vector<size_t> mRelevantEvents;
73 std::map<size_t, bool> mDependencyInConflict;
74
75 public:
76 DFT(DFTElementVector const& elements, DFTElementPointer const& tle);
77
79
80 size_t generateStateInfo(DFTStateGenerationInfo& generationInfo, size_t id, storm::storage::BitVector& visited, size_t stateIndex) const;
81
82 size_t performStateGenerationInfoDFS(DFTStateGenerationInfo& generationInfo, std::queue<size_t>& visitQueue, storm::storage::BitVector& visited,
83 size_t stateIndex) const;
84
86
87 void copyElements(std::vector<size_t> elements, storm::dft::builder::DFTBuilder<ValueType> builder) const;
88
89 size_t stateBitVectorSize() const {
90 // Ensure multiple of 64
91 return (mStateVectorSize / 64 + (mStateVectorSize % 64 != 0)) * 64;
92 }
93
94 size_t nrElements() const {
95 return mElements.size();
96 }
97
98 size_t nrBasicElements() const {
99 return mNrOfBEs;
100 }
101
102 size_t nrDynamicElements() const;
103
104 size_t nrStaticElements() const;
105
106 size_t getTopLevelIndex() const {
107 return mTopLevelIndex;
108 }
109
113
114 size_t getMaxSpareChildCount() const {
115 return mMaxSpareChildCount;
116 }
117
118 std::vector<size_t> getSpareIndices() const {
119 std::vector<size_t> indices;
120 for (auto const& elem : mElements) {
121 if (elem->isSpareGate()) {
122 indices.push_back(elem->id());
123 }
124 }
125 return indices;
126 }
127
128 storm::dft::storage::DftModule const& module(size_t representativeId) const {
129 STORM_LOG_ASSERT(mModules.count(representativeId) > 0, "Representative not found.");
130 return mModules.at(representativeId);
131 }
132
133 std::vector<storm::dft::storage::DftModule> getSpareModules() const {
134 std::vector<storm::dft::storage::DftModule> spareModules;
135 for (auto const& pair : mModules) {
136 if (pair.first != mTopLevelIndex) {
137 spareModules.push_back(pair.second);
138 }
139 }
140 return spareModules;
141 }
142
143 bool isDependencyInConflict(size_t id) const {
144 STORM_LOG_ASSERT(isDependency(id), "Not a dependency.");
145 return mDependencyInConflict.at(id);
146 }
147
149 STORM_LOG_ASSERT(isDependency(id), "Not a dependency.");
150 mDependencyInConflict.at(id) = false;
151 }
152
153 std::vector<size_t> const& getDependencies() const {
154 return mDependencies;
155 }
156
157 std::vector<size_t> nonColdBEs() const {
158 std::vector<size_t> result;
159 for (DFTElementPointer elem : mElements) {
160 if (elem->isBasicElement()) {
161 std::shared_ptr<storm::dft::storage::elements::DFTBE<ValueType>> be =
162 std::static_pointer_cast<storm::dft::storage::elements::DFTBE<ValueType>>(elem);
163 if (be->canFail()) {
164 switch (be->beType()) {
166 result.push_back(be->id());
167 break;
169 auto beExp = std::static_pointer_cast<storm::dft::storage::elements::BEExponential<ValueType>>(be);
170 if (!beExp->isColdBasicElement()) {
171 result.push_back(be->id());
172 }
173 break;
174 }
175 default:
176 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "BE type '" << be->beType() << "' is not supported.");
177 }
178 }
179 }
180 }
181 return result;
182 }
183
188 DFTElementCPointer getElement(size_t index) const {
189 STORM_LOG_ASSERT(index < nrElements(), "Index invalid.");
190 return mElements[index];
191 }
192
193 bool isBasicElement(size_t index) const {
194 return getElement(index)->isBasicElement();
195 }
196
197 bool isGate(size_t index) const {
198 return getElement(index)->isGate();
199 }
200
201 bool isDependency(size_t index) const {
202 return getElement(index)->isDependency();
203 }
204
205 bool isRestriction(size_t index) const {
206 return getElement(index)->isRestriction();
207 }
208
209 std::shared_ptr<storm::dft::storage::elements::DFTBE<ValueType> const> getBasicElement(size_t index) const {
210 STORM_LOG_ASSERT(isBasicElement(index), "Element is no BE.");
211 return std::static_pointer_cast<storm::dft::storage::elements::DFTBE<ValueType> const>(mElements[index]);
212 }
213
214 DFTElementCPointer getTopLevelElement() const {
216 }
217
218 std::shared_ptr<storm::dft::storage::elements::DFTGate<ValueType> const> getGate(size_t index) const {
219 STORM_LOG_ASSERT(isGate(index), "Element is no gate.");
220 return std::static_pointer_cast<storm::dft::storage::elements::DFTGate<ValueType> const>(mElements[index]);
221 }
222
223 std::shared_ptr<storm::dft::storage::elements::DFTDependency<ValueType> const> getDependency(size_t index) const {
224 STORM_LOG_ASSERT(isDependency(index), "Element is no dependency.");
225 return std::static_pointer_cast<storm::dft::storage::elements::DFTDependency<ValueType> const>(mElements[index]);
226 }
227
228 std::shared_ptr<storm::dft::storage::elements::DFTRestriction<ValueType> const> getRestriction(size_t index) const {
229 STORM_LOG_ASSERT(isRestriction(index), "Element is no restriction.");
230 return std::static_pointer_cast<storm::dft::storage::elements::DFTRestriction<ValueType> const>(mElements[index]);
231 }
232
233 std::vector<std::shared_ptr<storm::dft::storage::elements::DFTBE<ValueType>>> getBasicElements() const {
234 std::vector<std::shared_ptr<storm::dft::storage::elements::DFTBE<ValueType>>> elements;
235 for (DFTElementPointer elem : mElements) {
236 if (elem->isBasicElement()) {
237 elements.push_back(std::static_pointer_cast<storm::dft::storage::elements::DFTBE<ValueType>>(elem));
238 }
239 }
240 return elements;
241 }
242
243 bool canHaveNondeterminism() const;
244
245 uint64_t maxRank() const;
246
247 std::vector<DFT<ValueType>> topModularisation() const;
248
249 bool isRepresentative(size_t id) const {
250 for (auto const& parent : getElement(id)->parents()) {
251 if (parent->isSpareGate()) {
252 return true;
253 }
254 }
255 return false;
256 }
257
258 bool hasRepresentant(size_t id) const {
259 return mRepresentants.find(id) != mRepresentants.end();
260 }
261
262 size_t getRepresentant(size_t id) const {
263 STORM_LOG_ASSERT(hasRepresentant(id), "Element has no representant.");
264 return mRepresentants.find(id)->second;
265 }
266
267 bool hasFailed(DFTStatePointer const& state) const {
268 return state->hasFailed(mTopLevelIndex);
269 }
270
271 bool hasFailed(storm::storage::BitVector const& state, DFTStateGenerationInfo const& stateGenerationInfo) const {
272 return storm::dft::storage::DFTState<ValueType>::hasFailed(state, stateGenerationInfo.getStateIndex(mTopLevelIndex));
273 }
274
275 bool isFailsafe(DFTStatePointer const& state) const {
276 return state->isFailsafe(mTopLevelIndex);
277 }
278
279 bool isFailsafe(storm::storage::BitVector const& state, DFTStateGenerationInfo const& stateGenerationInfo) const {
280 return storm::dft::storage::DFTState<ValueType>::isFailsafe(state, stateGenerationInfo.getStateIndex(mTopLevelIndex));
281 }
282
292 size_t uses(storm::storage::BitVector const& state, DFTStateGenerationInfo const& stateGenerationInfo, size_t id) const {
293 size_t nrUsedChild = storm::dft::storage::DFTState<ValueType>::usesIndex(state, stateGenerationInfo, id);
294 if (nrUsedChild == getMaxSpareChildCount()) {
295 return id;
296 } else {
297 return getChild(id, nrUsedChild);
298 }
299 }
300
301 size_t getChild(size_t spareId, size_t nrUsedChild) const;
302
303 size_t getNrChild(size_t spareId, size_t childId) const;
304
305 std::string getElementsString() const;
306
307 std::string getInfoString() const;
308
309 std::string getModulesString() const;
310
311 std::string getElementsWithStateString(DFTStatePointer const& state) const;
312
313 std::string getStateString(DFTStatePointer const& state) const;
314
315 std::string getStateString(storm::storage::BitVector const& status, DFTStateGenerationInfo const& stateGenerationInfo, size_t id) const;
316
317 std::vector<size_t> immediateFailureCauses(size_t index) const;
318
319 std::vector<size_t> findModularisationRewrite() const;
320
321 void setElementLayoutInfo(size_t id, DFTLayoutInfo const& layoutInfo) {
322 mLayoutInfo[id] = layoutInfo;
323 }
324
325 DFTLayoutInfo const& getElementLayoutInfo(size_t id) const {
326 return mLayoutInfo.at(id);
327 }
328
329 void writeStatsToStream(std::ostream& stream) const;
330
335 std::set<size_t> getAllIds() const;
336
342 bool existsName(std::string const& name) const;
343
349 size_t getIndex(std::string const& name) const;
350
355 std::vector<size_t> const& getRelevantEvents() const;
356
362 void setRelevantEvents(storm::dft::utility::RelevantEvents const& relevantEvents, bool const allowDCForRelevant) const;
363
368 std::string getRelevantEventsString() const;
369
370 private:
371 bool elementIndicesCorrect() const {
372 for (size_t i = 0; i < mElements.size(); ++i) {
373 if (mElements[i]->id() != i)
374 return false;
375 }
376 return true;
377 }
378};
379
385std::set<storm::RationalFunctionVariable> getParameters(DFT<storm::RationalFunction> const& dft);
386
387} // namespace storage
388} // namespace storm::dft
Represents a Dynamic Fault Tree.
Definition DFT.h:52
size_t nrBasicElements() const
Definition DFT.h:98
bool hasFailed(DFTStatePointer const &state) const
Definition DFT.h:267
std::vector< size_t > nonColdBEs() const
Definition DFT.h:157
size_t getTopLevelIndex() const
Definition DFT.h:106
bool isRepresentative(size_t id) const
Definition DFT.h:249
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:223
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:209
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:325
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:258
std::vector< size_t > findModularisationRewrite() const
Definition DFT.cpp:637
void setDependencyNotInConflict(size_t id)
Definition DFT.h:148
DFTElementCPointer getElement(size_t index) const
Get a pointer to an element in the DFT.
Definition DFT.h:188
void setElementLayoutInfo(size_t id, DFTLayoutInfo const &layoutInfo)
Definition DFT.h:321
void writeStatsToStream(std::ostream &stream) const
Definition DFT.cpp:731
storm::dft::storage::elements::DFTElementType getTopLevelType() const
Definition DFT.h:110
std::string getElementsWithStateString(DFTStatePointer const &state) const
Definition DFT.cpp:536
DFTElementCPointer getTopLevelElement() const
Definition DFT.h:214
std::vector< size_t > const & getDependencies() const
Definition DFT.h:153
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:94
std::shared_ptr< storm::dft::storage::elements::DFTGate< ValueType > const > getGate(size_t index) const
Definition DFT.h:218
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:89
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:292
std::string getInfoString() const
Definition DFT.cpp:520
std::vector< std::shared_ptr< storm::dft::storage::elements::DFTBE< ValueType > > > getBasicElements() const
Definition DFT.h:233
bool isDependencyInConflict(size_t id) const
Definition DFT.h:143
size_t getRepresentant(size_t id) const
Definition DFT.h:262
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:201
DFTStateGenerationInfo buildStateGenerationInfo(storm::dft::storage::DftSymmetries const &symmetries) const
Definition DFT.cpp:105
bool isGate(size_t index) const
Definition DFT.h:197
std::shared_ptr< storm::dft::storage::elements::DFTRestriction< ValueType > const > getRestriction(size_t index) const
Definition DFT.h:228
size_t nrStaticElements() const
Definition DFT.cpp:485
bool hasFailed(storm::storage::BitVector const &state, DFTStateGenerationInfo const &stateGenerationInfo) const
Definition DFT.h:271
std::vector< size_t > const & getRelevantEvents() const
Get all relevant events.
Definition DFT.cpp:711
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:118
bool isRestriction(size_t index) const
Definition DFT.h:205
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:279
void copyElements(std::vector< size_t > elements, storm::dft::builder::DFTBuilder< ValueType > builder) const
bool canHaveNondeterminism() const
Definition DFT.cpp:632
size_t getMaxSpareChildCount() const
Definition DFT.h:114
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:133
std::string getElementsString() const
Definition DFT.cpp:511
storm::dft::storage::DftModule const & module(size_t representativeId) const
Definition DFT.h:128
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:275
bool isBasicElement(size_t index) const
Definition DFT.h:193
bool hasFailed(size_t id) const
Definition DFTState.cpp:155
bool isFailsafe(size_t id) const
Definition DFTState.cpp:165
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:441
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:39
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
#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