Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
MonotonicityResult.cpp
Go to the documentation of this file.
2
3#include <sstream>
4
10
11namespace storm {
12namespace analysis {
13
14template<typename VariableType>
16 this->done = false;
17 this->somewhereMonotonicity = true;
18 this->allMonotonicity = true;
19}
20
21template<typename VariableType>
23 monotonicityResult.insert(std::pair<VariableType, MonotonicityResult<VariableType>::Monotonicity>(std::move(var), std::move(mon)));
24}
25
26template<typename VariableType>
28 assert(!isDoneForVar(var));
29 if (force) {
31 if (monotonicityResult.find(var) == monotonicityResult.end()) {
32 addMonotonicityResult(std::move(var), std::move(mon));
33 } else {
34 monotonicityResult[var] = mon;
35 }
36 } else {
39 }
40
41 if (monotonicityResult.find(var) == monotonicityResult.end()) {
42 addMonotonicityResult(std::move(var), std::move(mon));
43 } else {
44 auto monRes = monotonicityResult[var];
45 if (monRes == MonotonicityResult<VariableType>::Monotonicity::Unknown || monRes == mon ||
47 return;
49 monotonicityResult[var] = mon;
50 } else {
52 }
53 }
54 if (monotonicityResult[var] == MonotonicityResult<VariableType>::Monotonicity::Unknown) {
55 setAllMonotonicity(false);
56 setSomewhereMonotonicity(false);
57 } else {
58 setSomewhereMonotonicity(true);
59 }
60 }
61}
62
63template<typename VariableType>
65 auto itr = monotonicityResult.find(var);
66 if (itr != monotonicityResult.end()) {
67 return itr->second;
68 }
69 return Monotonicity::Unknown;
70}
71
72template<typename VariableType>
73std::map<VariableType, typename MonotonicityResult<VariableType>::Monotonicity> const& MonotonicityResult<VariableType>::getMonotonicityResult() const {
74 return monotonicityResult;
75}
76
77template<typename VariableType>
78std::pair<std::set<VariableType>, std::set<VariableType>> MonotonicityResult<VariableType>::splitVariables(
79 std::set<VariableType> const& consideredVariables) const {
80 std::set<VariableType> nonMonotoneVariables;
81 std::set<VariableType> monotoneVariables;
82 for (auto var : consideredVariables) {
83 if (isDoneForVar(var)) {
84 auto res = getMonotonicity(var);
85 if (res == Monotonicity::Not || res == Monotonicity::Unknown) {
86 nonMonotoneVariables.insert(var);
87 } else {
88 monotoneVariables.insert(var);
89 }
90 } else {
91 nonMonotoneVariables.insert(var);
92 }
93 }
94 return std::make_pair(std::move(monotoneVariables), std::move(nonMonotoneVariables));
95}
96
97template<typename VariableType>
99 std::stringstream stream;
100 auto countIncr = 0;
101 auto countDecr = 0;
102 for (auto res : getMonotonicityResult()) {
103 stream << res.first.name() << " " << res.second << "; ";
104 countIncr += (res.second == Monotonicity::Incr) ? 1 : 0;
105 countDecr += (res.second == Monotonicity::Decr) ? 1 : 0;
106 }
107 return "#Incr: " + std::to_string(countIncr) + " #Decr: " + std::to_string(countDecr) + "\n" + stream.str();
108}
109
110template<typename VariableType>
112 this->done = done;
113}
114
115template<typename VariableType>
117 doneVariables.insert(variable);
118}
119
120template<typename VariableType>
122 return done;
123}
124
125template<typename VariableType>
127 return doneVariables.find(var) != doneVariables.end();
128}
129
130template<typename VariableType>
132 this->somewhereMonotonicity = somewhereMonotonicity;
133}
134
135template<typename VariableType>
137 if (!somewhereMonotonicity) {
138 for (auto itr : monotonicityResult) {
139 if (isDoneForVar(itr.first) && itr.second != MonotonicityResult<VariableType>::Monotonicity::Unknown &&
141 setSomewhereMonotonicity(true);
142 break;
143 }
144 }
145 }
146 return monotonicityResult.size() > 0 && somewhereMonotonicity;
147}
148
149template<typename VariableType>
151 this->allMonotonicity = allMonotonicity;
152}
153
154template<typename VariableType>
156 return allMonotonicity;
157}
158
159template<typename VariableType>
160std::shared_ptr<MonotonicityResult<VariableType>> MonotonicityResult<VariableType>::copy() const {
161 std::shared_ptr<MonotonicityResult<VariableType>> copy = std::make_shared<MonotonicityResult<VariableType>>();
162 copy->monotonicityResult = std::map<VariableType, Monotonicity>(monotonicityResult);
163 copy->setAllMonotonicity(allMonotonicity);
164 copy->setSomewhereMonotonicity(somewhereMonotonicity);
165 copy->setDone(done);
166 copy->setDoneVariables(doneVariables);
167 return copy;
168}
169
170template<typename VariableType>
171void MonotonicityResult<VariableType>::setDoneVariables(std::set<VariableType> doneVariables) {
172 this->doneVariables = doneVariables;
173}
174
175template<typename VariableType>
176void MonotonicityResult<VariableType>::splitBasedOnMonotonicity(const std::set<VariableType>& consideredVariables, std::set<VariableType>& monotoneIncr,
177 std::set<VariableType>& monotoneDecr, std::set<VariableType>& notMonotone) const {
178 for (auto& var : consideredVariables) {
179 if (!isDoneForVar(var)) {
180 notMonotone.insert(var);
181 } else {
182 auto mon = getMonotonicity(var);
183 if (mon == Monotonicity::Unknown || mon == Monotonicity::Not) {
184 notMonotone.insert(var);
185 } else if (mon == Monotonicity::Incr) {
186 monotoneIncr.insert(var);
187 } else {
188 monotoneDecr.insert(var);
189 }
190 }
191 }
192}
193
194template<typename VariableType>
196 if (monotonicityResult.find(var) == monotonicityResult.end()) {
197 return false;
198 } else {
199 auto monRes = monotonicityResult.at(var);
200 return isDoneForVar(var) && (monRes == Monotonicity::Incr || monRes == Monotonicity::Decr || monRes == Monotonicity::Constant);
201 }
202}
203
205} // namespace analysis
206} // namespace storm
std::map< VariableType, Monotonicity > const & getMonotonicityResult() const
Returns the results so far.
void splitBasedOnMonotonicity(std::set< VariableType > const &consideredVariables, std::set< VariableType > &monotoneIncr, std::set< VariableType > &monotoneDecr, std::set< VariableType > &notMontone) const
void setDone(bool done=true)
Sets the done bool to the given truth value.
MonotonicityResult()
Constructs a new MonotonicityResult object.
void addMonotonicityResult(VariableType var, Monotonicity mon)
Adds a new variable with a given Monotonicity to the map.
void setAllMonotonicity(bool done=true)
Sets the allMonotonicity bool to the given truth value.
Monotonicity getMonotonicity(VariableType var) const
Returns the current monotonicity of a given parameter.
void setSomewhereMonotonicity(bool done=true)
Sets the somewhereMonotonicity bool to the given truth value.
void updateMonotonicityResult(VariableType var, Monotonicity mon, bool force=false)
Updates the Monotonicity of a variable based on its value so far and a new value.
std::pair< std::set< VariableType >, std::set< VariableType > > splitVariables(std::set< VariableType > const &consideredVariables) const
bool isAllMonotonicity() const
Returns if all Variables are monotone.
std::string toString() const
Constructs a string output of all variables and their corresponding Monotonicity.
std::shared_ptr< MonotonicityResult< VariableType > > copy() const
Constructs a new MonotonicityResult object that is a copy of the current one.
void setDoneVariables(std::set< VariableType > doneVariables)
bool existsMonotonicity()
Checks if there is any variable that is monotone.
bool isMonotone(VariableType var) const
bool isDone() const
Checks if the result is complete.
MonotonicityKind
The results of monotonicity checking for a single Parameter Region.