Storm 1.13.0.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(
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(
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 }
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(
161template std::shared_ptr<storm::dft::storage::elements::DFTDependency<double> const> FailableElements::const_iterator::asDependency(
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
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
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11