Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
RelevantEvents.h
Go to the documentation of this file.
1#pragma once
2
3#include <boost/algorithm/string.hpp>
7
8#include <initializer_list>
9#include <memory>
11
12namespace storm::dft {
13namespace utility {
14
16 public:
20 RelevantEvents() = default;
21
33 RelevantEvents(std::initializer_list<std::string> init) {
34 insert(init.begin(), init.end());
35 }
36
44 template<typename ForwardIt>
45 RelevantEvents(ForwardIt first, ForwardIt last) {
46 insert(first, last);
47 }
48
49 bool operator==(RelevantEvents const& rhs) const {
50 return this->allRelevant == rhs.allRelevant || this->names == rhs.names;
51 }
52
53 bool operator!=(RelevantEvents const& rhs) const {
54 return !(*this == rhs);
55 }
56
63 template<typename ValueType>
64 size_t count(std::shared_ptr<storm::dft::storage::DFT<ValueType>> const dft) const {
65 if (this->allRelevant) {
66 return dft->nrElements();
67 }
68 size_t rval{0};
69 for (auto const& name : names) {
70 if (dft->existsName(name)) {
71 rval++;
72 }
73 }
74 return rval;
75 }
76
84 template<typename ForwardIt>
85 void insertNamesFromProperties(ForwardIt first, ForwardIt last, bool addLabelsClaiming) {
86 if (this->allRelevant) {
87 return;
88 }
89
90 // Get necessary labels from properties
91 std::vector<std::shared_ptr<storm::logic::AtomicLabelFormula const>> atomicLabels{};
92 std::for_each(first, last, [&atomicLabels](auto const& property) { property->gatherAtomicLabelFormulas(atomicLabels); });
93
94 // Add relevant event names from properties
95 for (auto const& atomic : atomicLabels) {
96 std::string label = atomic->getLabel();
97 if (label == "failed" or label == "skipped") {
98 // Ignore as these label will always be added if necessary
99 } else {
100 // Get name of event
101 if (boost::ends_with(label, "_failed")) {
102 // length of "_failed" = 7
103 this->names.insert(label.substr(0, label.size() - 7));
104 } else if (boost::ends_with(label, "_dc")) {
105 // length of "_dc" = 3
106 this->names.insert(label.substr(0, label.size() - 3));
107 } else if (label.find("_claimed_") != std::string::npos) {
108 STORM_LOG_THROW(addLabelsClaiming, storm::exceptions::InvalidArgumentException,
109 "Claiming labels will not be exported but are required for label '" << label << "'. Try setting --labels-claiming.");
110 } else {
111 STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Label '" << label << "' not known.");
112 }
113 }
114 }
115 }
116
123 void insert(std::string const& name) {
124 if (name == "all") {
125 setAllRelevant();
126 }
127 names.insert(name);
128 }
129
137 template<typename ForwardIt>
138 void insert(ForwardIt first, ForwardIt last) {
139 // check if the name "all" occurs
140 if (std::any_of(first, last, [](auto const& name) { return name == "all"; })) {
141 setAllRelevant();
142 } else {
143 this->names.insert(first, last);
144 }
145 }
146
153 template<typename ValueType>
155 for (std::string const& relevantName : this->names) {
156 if (!dft.existsName(relevantName)) {
157 return false;
158 }
159 }
160 return true;
161 }
162
166 bool isRelevant(std::string const& name) const {
167 if (this->allRelevant) {
168 return true;
169 } else {
170 return this->names.find(name) != this->names.end();
171 }
172 }
173
180 if (!this->allRelevant) {
181 if (other.allRelevant) {
182 setAllRelevant();
183 } else {
184 this->names.insert(other.names.begin(), other.names.end());
185 }
186 }
187 return *this;
188 }
189
190 private:
191 void setAllRelevant() {
192 this->allRelevant = true;
193 this->names.clear();
194 }
195
196 // Names of relevant events.
197 std::set<std::string> names{};
198
199 // Whether all elements are relevant.
200 bool allRelevant{false};
201};
202
203} // namespace utility
204} // namespace storm::dft
Represents a Dynamic Fault Tree.
Definition DFT.h:50
bool checkRelevantNames(storm::dft::storage::DFT< ValueType > const &dft) const
Check that the relevant names correspond to existing elements in the DFT.
void insert(ForwardIt first, ForwardIt last)
Add relevant event names from a range.
void insertNamesFromProperties(ForwardIt first, ForwardIt last, bool addLabelsClaiming)
Add relevant event names required by the labels in properties of a range.
bool isRelevant(std::string const &name) const
RelevantEvents()=default
Constructs empty RelevantEvents object.
RelevantEvents(ForwardIt first, ForwardIt last)
Create relevant events from given event names in a range.
void insert(std::string const &name)
Add relevant event.
RelevantEvents & merge(RelevantEvents const &other)
Merge the given RelevantEvents with *this.
size_t count(std::shared_ptr< storm::dft::storage::DFT< ValueType > > const dft) const
Count the events that are relevant in the given DFT.
bool operator!=(RelevantEvents const &rhs) const
RelevantEvents(std::initializer_list< std::string > init)
Create relevant events from given event names in an initializer list.
bool operator==(RelevantEvents const &rhs) const
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39