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