Storm
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>
8
9#include <initializer_list>
10#include <memory>
13
14namespace storm::dft {
15namespace utility {
16
18 public:
22 RelevantEvents() = default;
23
35 RelevantEvents(std::initializer_list<std::string> init) {
36 insert(init.begin(), init.end());
37 }
38
46 template<typename ForwardIt>
47 RelevantEvents(ForwardIt first, ForwardIt last) {
48 insert(first, last);
49 }
50
51 bool operator==(RelevantEvents const& rhs) const {
52 return this->allRelevant == rhs.allRelevant || this->names == rhs.names;
53 }
54
55 bool operator!=(RelevantEvents const& rhs) const {
56 return !(*this == rhs);
57 }
58
65 template<typename ValueType>
66 size_t count(std::shared_ptr<storm::dft::storage::DFT<ValueType>> const dft) const {
67 if (this->allRelevant) {
68 return dft->nrElements();
69 }
70 size_t rval{0};
71 for (auto const& name : names) {
72 if (dft->existsName(name)) {
73 rval++;
74 }
75 }
76 return rval;
77 }
78
85 template<typename ForwardIt>
86 void insertNamesFromProperties(ForwardIt first, ForwardIt last) {
87 if (this->allRelevant) {
88 return;
89 }
90
91 // Get necessary labels from properties
92 std::vector<std::shared_ptr<storm::logic::AtomicLabelFormula const>> atomicLabels{};
93 std::for_each(first, last, [&atomicLabels](auto const& property) { property->gatherAtomicLabelFormulas(atomicLabels); });
94
95 // Add relevant event names from properties
96 for (auto const& atomic : atomicLabels) {
97 std::string label = atomic->getLabel();
98 if (label == "failed" or label == "skipped") {
99 // Ignore as these label will always be added if necessary
100 } else {
101 // Get name of event
102 if (boost::ends_with(label, "_failed")) {
103 // length of "_failed" = 7
104 this->names.insert(label.substr(0, label.size() - 7));
105 } else if (boost::ends_with(label, "_dc")) {
106 // length of "_dc" = 3
107 this->names.insert(label.substr(0, label.size() - 3));
108 } else if (label.find("_claimed_") != std::string::npos) {
110 storm::exceptions::InvalidArgumentException,
111 "Claiming labels will not be exported but are required for label '" << label << "'. Try setting --labels-claiming.");
112 } else {
113 STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Label '" << label << "' not known.");
114 }
115 }
116 }
117 }
118
125 void insert(std::string const& name) {
126 if (name == "all") {
127 setAllRelevant();
128 }
129 names.insert(name);
130 }
131
139 template<typename ForwardIt>
140 void insert(ForwardIt first, ForwardIt last) {
141 // check if the name "all" occurs
142 if (std::any_of(first, last, [](auto const& name) { return name == "all"; })) {
143 setAllRelevant();
144 } else {
145 this->names.insert(first, last);
146 }
147 }
148
155 template<typename ValueType>
157 for (std::string const& relevantName : this->names) {
158 if (!dft.existsName(relevantName)) {
159 return false;
160 }
161 }
162 return true;
163 }
164
168 bool isRelevant(std::string const& name) const {
169 if (this->allRelevant) {
170 return true;
171 } else {
172 return this->names.find(name) != this->names.end();
173 }
174 }
175
182 if (!this->allRelevant) {
183 if (other.allRelevant) {
184 setAllRelevant();
185 } else {
186 this->names.insert(other.names.begin(), other.names.end());
187 }
188 }
189 return *this;
190 }
191
192 private:
193 void setAllRelevant() {
194 this->allRelevant = true;
195 this->names.clear();
196 }
197
198 // Names of relevant events.
199 std::set<std::string> names{};
200
201 // Whether all elements are relevant.
202 bool allRelevant{false};
203};
204
205} // namespace utility
206} // namespace storm::dft
Represents a Dynamic Fault Tree.
Definition DFT.h:52
bool existsName(std::string const &name) const
Check whether an element with the given name exists.
Definition DFT.cpp:678
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.
bool isRelevant(std::string const &name) const
void insertNamesFromProperties(ForwardIt first, ForwardIt last)
Add relevant event names required by the labels in properties of a range.
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:30
SettingsType const & getModule()
Get module.