Storm 1.13.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
ModelIndex.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4#include <ctime>
5#include <sstream>
6
8
9namespace storm::umb {
10
12 if (creationDate) {
13 std::time_t t = static_cast<std::time_t>(creationDate.value());
14 return std::ctime(&t);
15 } else {
16 return "unknown";
17 }
18}
20 if (std::time_t result; std::time(&result) == static_cast<std::time_t>(-1)) {
21 STORM_LOG_WARN("No creation time is set for UMB index: unable to get the current time.");
22 creationDate.reset();
23 } else {
24 creationDate.emplace(result);
25 }
26}
27
28const std::string DefaultAnnotationAlias = "default";
29
31 auto isAllowed = [](auto ch) { return (std::isalnum(ch) && !std::isupper(ch)) || ch == '_' || ch == '-'; };
32 if (alias.empty()) {
33 return DefaultAnnotationAlias; // empty identifier is not allowed, so we return a default name
34 }
35
36 std::stringstream identifier;
37 for (auto ch : alias) {
38 if (isAllowed(ch)) {
39 identifier << ch;
40 } else if (ch == ' ') { // replace spaces with underscores
41 identifier << '_';
42 } else { // replace other characters with their hex representation
43 identifier << "0x" << std::setw(2) << std::setfill('0') << std::hex << static_cast<int>(ch);
44 }
45 }
46 return identifier.str();
47}
48
50 return std::find(appliesTo.begin(), appliesTo.end(), AppliesTo::States) != appliesTo.end();
51}
52
54 return std::find(appliesTo.begin(), appliesTo.end(), AppliesTo::Choices) != appliesTo.end();
55}
56
58 return std::find(appliesTo.begin(), appliesTo.end(), AppliesTo::Branches) != appliesTo.end();
59}
60
62 return std::find(appliesTo.begin(), appliesTo.end(), AppliesTo::Observations) != appliesTo.end();
63}
64
66 return std::find(appliesTo.begin(), appliesTo.end(), AppliesTo::Players) != appliesTo.end();
67}
68
70 return annotation("aps", createIfMissing);
71}
72
76
78 return annotation("rewards", createIfMissing);
79}
80
84
85storm::OptionalRef<ModelIndex::AnnotationMap> ModelIndex::annotation(std::string const& annotationsType, bool createIfMissing) {
86 if (createIfMissing) {
87 if (!annotations.has_value()) {
88 annotations.emplace();
89 }
90 return (*annotations)[annotationsType];
91 }
92 if (annotations.has_value()) {
93 if (auto it = annotations->find(annotationsType); it != annotations->end()) {
94 return it->second;
95 }
96 }
97 return {};
98}
99
101 if (annotations.has_value()) {
102 if (auto it = annotations->find(annotationsType); it != annotations->end()) {
103 return it->second;
104 }
105 }
106 return {};
107}
108
109std::optional<std::string> ModelIndex::findAPName(std::string const& id) const {
110 return findAnnotationName("aps", id);
111}
112
113std::optional<std::string> ModelIndex::findRewardName(std::string const& id) const {
114 return findAnnotationName("rewards", id);
115}
116
117std::optional<std::string> ModelIndex::findAnnotationName(std::string const& annotationsType, std::string const& id) const {
118 if (id.empty()) { // the empty id indicates that we want the default annotation
119 return findAnnotationName(annotationsType, DefaultAnnotationAlias);
120 }
121
122 auto map = annotation(annotationsType);
123 if (!map.has_value()) {
124 return {};
125 }
126
127 // First try to find a suitable alias matching id
128 for (auto const& [name, annotation] : map.value()) {
129 if (annotation.alias == id) {
130 return name;
131 }
132 }
133
134 // If no alias matches, check if there is an annotation with the right identifier
135 if (map->contains(id)) {
136 return id;
137 }
138 return {};
139}
140
141} // namespace storm::umb
Helper class that optionally holds a reference to an object of type T.
Definition OptionalRef.h:48
#define STORM_LOG_WARN(message)
Definition logging.h:25
const std::string DefaultAnnotationAlias
std::vector< storm::SerializedEnum< AppliesToDeclaration > > appliesTo
Definition ModelIndex.h:86
static std::string getValidIdentifierFromAlias(std::string const &alias)
Takes an alias (which can be an arbitrary string) and converts it to a valid identifier in [0-9a-z_-]...
std::optional< std::string > alias
Definition ModelIndex.h:80
std::string creationDateAsString() const
std::optional< uint64_t > creationDate
Definition ModelIndex.h:29
std::optional< std::map< std::string, AnnotationMap > > annotations
Definition ModelIndex.h:109
storm::OptionalRef< AnnotationMap const > rewards() const
std::optional< std::string > findAPName(std::string const &id) const
Finds a name of the annotation (i.e.
storm::OptionalRef< AnnotationMap > annotation(std::string const &annotationsType, bool createIfMissing=false)
std::optional< std::string > findAnnotationName(std::string const &annotationsType, std::string const &id) const
storm::OptionalRef< AnnotationMap const > aps() const
std::optional< std::string > findRewardName(std::string const &id) const