Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
FailableElements.cpp
Go to the documentation of this file.
2
3#include <sstream>
4
7
8namespace storm::dft {
9namespace storage {
10
12 std::list<size_t>::const_iterator const& iterDependency, std::list<size_t>::const_iterator nonConflictEnd,
13 std::list<size_t>::const_iterator conflictBegin)
14 : dependency(dependency), conflicting(conflicting), itBE(iterBE), itDep(iterDependency), nonConflictEnd(nonConflictEnd), conflictBegin(conflictBegin) {
15 STORM_LOG_ASSERT(conflicting || itDep != nonConflictEnd, "No non-conflicting dependencies present.");
16}
17
19 if (dependency) {
20 ++itDep;
21 if (!conflicting && itDep == nonConflictEnd) {
22 // All non-conflicting dependencies considered -> start with conflicting ones
23 conflicting = true;
24 itDep = conflictBegin;
25 }
26 } else {
27 ++itBE;
28 }
29 return *this;
30}
31
33 if (dependency) {
34 return *itDep;
35 } else {
36 return *itBE;
37 }
38}
39
41 if (dependency != other.dependency) {
42 return true;
43 }
44 if (dependency) {
45 if (conflicting != other.conflicting) {
46 return true;
47 } else {
48 return itDep != other.itDep;
49 }
50 } else {
51 return itBE != other.itBE;
52 }
53}
54
56 return !(*this != other);
57}
58
60 return dependency;
61}
62
64 return conflicting;
65}
66
67template<typename ValueType>
68std::shared_ptr<storm::dft::storage::elements::DFTBE<ValueType> const> FailableElements::const_iterator::asBE(
69 storm::dft::storage::DFT<ValueType> const& dft) const {
70 size_t nextFailId = **this;
71 STORM_LOG_ASSERT(!isFailureDueToDependency(), "The current iterator is not a BE failure but a dependency failure.");
72 return dft.getBasicElement(nextFailId);
73}
74
75template<typename ValueType>
76std::shared_ptr<storm::dft::storage::elements::DFTDependency<ValueType> const> FailableElements::const_iterator::asDependency(
77 storm::dft::storage::DFT<ValueType> const& dft) const {
78 size_t nextFailId = **this;
79 STORM_LOG_ASSERT(isFailureDueToDependency(), "The current iterator is not a dependency failure but a BE failure.");
80 return dft.getDependency(nextFailId);
81}
82
83void FailableElements::addBE(size_t id) {
84 currentlyFailableBE.set(id);
85}
86
87void FailableElements::addDependency(size_t id, bool isConflicting) {
88 std::list<size_t>& failableList = (isConflicting ? failableConflictingDependencies : failableNonconflictingDependencies);
89 for (auto it = failableList.begin(); it != failableList.end(); ++it) {
90 if (*it > id) {
91 failableList.insert(it, id);
92 return;
93 } else if (*it == id) {
94 // Dependency already contained
95 return;
96 }
97 }
98 failableList.push_back(id);
99}
100
102 currentlyFailableBE.set(id, false);
103}
104
106 auto iter = std::find(failableConflictingDependencies.begin(), failableConflictingDependencies.end(), id);
107 if (iter != failableConflictingDependencies.end()) {
108 failableConflictingDependencies.erase(iter);
109 return;
110 }
111 iter = std::find(failableNonconflictingDependencies.begin(), failableNonconflictingDependencies.end(), id);
112 if (iter != failableNonconflictingDependencies.end()) {
113 failableNonconflictingDependencies.erase(iter);
114 return;
115 }
116}
117
119 currentlyFailableBE.clear();
120 failableConflictingDependencies.clear();
121 failableNonconflictingDependencies.clear();
122}
123
125 bool dependency = hasDependencies() && !forceBE;
126 bool conflicting = failableNonconflictingDependencies.empty();
127 auto itDep = conflicting ? failableConflictingDependencies.begin() : failableNonconflictingDependencies.begin();
128 return FailableElements::const_iterator(dependency, conflicting, currentlyFailableBE.begin(), itDep, failableNonconflictingDependencies.end(),
129 failableConflictingDependencies.begin());
130}
131
133 bool dependency = hasDependencies() && !forceBE;
134 return FailableElements::const_iterator(dependency, true, currentlyFailableBE.end(), failableConflictingDependencies.end(),
135 failableNonconflictingDependencies.end(), failableConflictingDependencies.begin());
136}
137
139 return !failableConflictingDependencies.empty() || !failableNonconflictingDependencies.empty();
140}
141
143 return !currentlyFailableBE.empty();
144}
145
146std::string FailableElements::getCurrentlyFailableString(bool forceBE) const {
147 std::stringstream stream;
148 stream << "{";
149 if (hasDependencies() && !forceBE) {
150 stream << "Dependencies: ";
151 }
152 for (auto it = begin(forceBE); it != end(forceBE); ++it) {
153 stream << *it << ", ";
154 }
155 stream << "}";
156 return stream.str();
157}
158
159// Explicit instantiations.
160template std::shared_ptr<storm::dft::storage::elements::DFTBE<double> const> FailableElements::const_iterator::asBE(
161 storm::dft::storage::DFT<double> const& dft) const;
162template std::shared_ptr<storm::dft::storage::elements::DFTDependency<double> const> FailableElements::const_iterator::asDependency(
163 storm::dft::storage::DFT<double> const& dft) const;
164
165template std::shared_ptr<storm::dft::storage::elements::DFTBE<storm::RationalFunction> const> FailableElements::const_iterator::asBE(
167template std::shared_ptr<storm::dft::storage::elements::DFTDependency<storm::RationalFunction> const> FailableElements::const_iterator::asDependency(
169
170} // namespace storage
171} // namespace storm::dft
Represents a Dynamic Fault Tree.
Definition DFT.h:52
std::shared_ptr< storm::dft::storage::elements::DFTDependency< ValueType > const > getDependency(size_t index) const
Definition DFT.h:224
std::shared_ptr< storm::dft::storage::elements::DFTBE< ValueType > const > getBasicElement(size_t index) const
Definition DFT.h:210
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.
bool operator==(const_iterator const &other) const
Compares the iterator with another iterator for equality.
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).
const_iterator(bool dependency, bool conflicting, storm::storage::BitVector::const_iterator const &iterBE, std::list< size_t >::const_iterator const &iterDependency, std::list< size_t >::const_iterator nonConflictEnd, std::list< size_t >::const_iterator conflictBegin)
Construct a new iterator.
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.
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:23
const_iterator end() const
Returns an iterator pointing at the element past the back of the bit vector.
bool empty() const
Retrieves whether no bits are set to true in this bit vector.
void clear()
Removes all set bits from the bit vector.
void set(uint64_t index, bool value=true)
Sets the given truth value at the given index.
const_iterator begin() const
Returns an iterator to the indices of the set bits in the bit vector.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11