Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
FailableElements.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4#include <memory>
5
7
8namespace storm::dft {
9namespace storage {
10
11// Forward declarations
12template<typename ValueType>
13class DFT;
14
15namespace elements {
16
17template<typename ValueType>
18class DFTBE;
19template<typename ValueType>
20class DFTDependency;
21
22} // namespace elements
23
35 public:
41 public:
42 // Define iterator
43 using iterator_category = std::input_iterator_tag;
44 using value_type = size_t;
45 using difference_type = std::ptrdiff_t;
46 using pointer = size_t*;
47 using reference = size_t&;
48
61 const_iterator(bool dependency, bool conflicting, storm::storage::BitVector::const_iterator const& iterBE,
62 std::list<size_t>::const_iterator const& iterDependency, std::list<size_t>::const_iterator nonConflictEnd,
63 std::list<size_t>::const_iterator conflictBegin);
64
70 const_iterator(const_iterator const& other) = default;
71
77 const_iterator& operator=(const_iterator const& other) = default;
78
85
91 uint_fast64_t operator*() const;
92
99 bool operator!=(const_iterator const& other) const;
100
107 bool operator==(const_iterator const& other) const;
108
114 bool isFailureDueToDependency() const;
115
121 bool isConflictingDependency() const;
122
130 template<typename ValueType>
131 std::shared_ptr<storm::dft::storage::elements::DFTBE<ValueType> const> asBE(storm::dft::storage::DFT<ValueType> const& dft) const;
132
141 template<typename ValueType>
142 std::shared_ptr<storm::dft::storage::elements::DFTDependency<ValueType> const> asDependency(storm::dft::storage::DFT<ValueType> const& dft) const;
143
144 private:
145 // Whether dependencies are currently considered.
146 bool dependency;
147 // Whether the iterator currently points to a conflicting dependency.
148 bool conflicting;
149 // Iterators for underlying data structures
151 std::list<size_t>::const_iterator itDep;
152
153 // Pointers marking end of non-conflict list and beginning of conflict list
154 // Used for sequential iteration over all dependencies
155 std::list<size_t>::const_iterator nonConflictEnd;
156 std::list<size_t>::const_iterator conflictBegin;
157 };
158
164 FailableElements(size_t maxBEId) : currentlyFailableBE(maxBEId) {}
165
172 void addBE(size_t id);
173
182 void addDependency(size_t id, bool isConflicting);
183
190 void removeBE(size_t id);
191
198 void removeDependency(size_t id);
199
204 void clear();
205
214 FailableElements::const_iterator begin(bool forceBE = false) const;
215
222 FailableElements::const_iterator end(bool forceBE = false) const;
223
229 bool hasDependencies() const;
230
236 bool hasBEs() const;
237
244 std::string getCurrentlyFailableString(bool forceBE = false) const;
245
246 private:
247 // We use a BitVector for BEs but a list for dependencies, because usually only a few dependencies are failable at the same time.
248 // In contrast, usually most BEs are failable.
249 // The lists of failable elements are sorted by increasing id.
250 storm::storage::BitVector currentlyFailableBE;
251 std::list<size_t> failableConflictingDependencies;
252 std::list<size_t> failableNonconflictingDependencies;
253};
254
255} // namespace storage
256} // namespace storm::dft
Represents a Dynamic Fault Tree.
Definition DFT.h:52
uint_fast64_t operator*() const
Returns the id of the current failable element.
std::shared_ptr< storm::dft::storage::elements::DFTBE< ValueType > const > asBE(storm::dft::storage::DFT< ValueType > const &dft) const
Return the current iterator as a BE which fails next.
const_iterator & operator++()
Increment the iterator.
const_iterator(const_iterator const &other)=default
Constructs an iterator by copying the given iterator.
bool operator==(const_iterator const &other) const
Compares the iterator with another iterator for equality.
const_iterator & operator=(const_iterator const &other)=default
Assigns the contents of the given iterator to the current one via copying the former's contents.
bool isConflictingDependency() const
Return whether the current dependency failure is conflicting.
bool isFailureDueToDependency() const
Return whether the current failure is due to a dependency (or the BE itself).
std::shared_ptr< storm::dft::storage::elements::DFTDependency< ValueType > const > asDependency(storm::dft::storage::DFT< ValueType > const &dft) const
Return the current iterator as a dependency which triggers next.
bool operator!=(const_iterator const &other) const
Compares the iterator with another iterator for inequality.
Handling of currently failable elements (BEs) either due to their own failure or because of dependenc...
void removeBE(size_t id)
Remove BE from list of failable elements.
void removeDependency(size_t id)
Remove dependency from list of failable elements.
bool hasDependencies() const
Whether failable dependencies are present.
FailableElements::const_iterator end(bool forceBE=false) const
Iterator after last failable element.
std::string getCurrentlyFailableString(bool forceBE=false) const
Get a string representation of the currently failable elements.
void addBE(size_t id)
Add failable BE.
void addDependency(size_t id, bool isConflicting)
Add failable dependency.
void clear()
Clear list of currently failable elements.
FailableElements::const_iterator begin(bool forceBE=false) const
Iterator to first failable element.
bool hasBEs() const
Whether failable BEs are present.
A class that enables iterating over the indices of the bit vector whose corresponding bits are set to...
Definition BitVector.h:25
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18