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
8
9namespace storm {
10namespace analysis {
11
12template<typename VariableType>
14 this->done = false;
15 this->somewhereMonotonicity = true;
16 this->allMonotonicity = true;
17}
18
19template<typename VariableType>
21 monotonicityResult.insert(std::pair<VariableType, MonotonicityResult<VariableType>::Monotonicity>(std::move(var), std::move(mon)));
22}
23
24template<typename VariableType>
26 assert(!isDoneForVar(var));
27 if (force) {
29 if (monotonicityResult.find(var) == monotonicityResult.end()) {
30 addMonotonicityResult(std::move(var), std::move(mon));
31 } else {
32 monotonicityResult[var] = mon;
33 }
34 } else {
37 }
38
39 if (monotonicityResult.find(var) == monotonicityResult.end()) {
40 addMonotonicityResult(std::move(var), std::move(mon));
41 } else {
42 auto monRes = monotonicityResult[var];
43 if (monRes == MonotonicityResult<VariableType>::Monotonicity::Unknown || monRes == mon ||
45 return;
47 monotonicityResult[var] = mon;
48 } else {
50 }
51 }
52 if (monotonicityResult[var] == MonotonicityResult<VariableType>::Monotonicity::Unknown) {
53 setAllMonotonicity(false);
54 setSomewhereMonotonicity(false);
55 } else {
56 setSomewhereMonotonicity(true);
57 }
58 }
59}
60
61template<typename VariableType>
63 auto itr = monotonicityResult.find(var);
64 if (itr != monotonicityResult.end()) {
65 return itr->second;
66 }
67 return Monotonicity::Unknown;
68}
69
70template<typename VariableType>
71std::map<VariableType, typename MonotonicityResult<VariableType>::Monotonicity> const& MonotonicityResult<VariableType>::getMonotonicityResult() const {
72 return monotonicityResult;
73}
74
75template<typename VariableType>
76std::pair<std::set<VariableType>, std::set<VariableType>> MonotonicityResult<VariableType>::splitVariables(
77 std::set<VariableType> const& consideredVariables) const {
78 std::set<VariableType> nonMonotoneVariables;
79 std::set<VariableType> monotoneVariables;
80 for (auto var : consideredVariables) {
81 if (isDoneForVar(var)) {
82 auto res = getMonotonicity(var);
83 if (res == Monotonicity::Not || res == Monotonicity::Unknown) {
84 nonMonotoneVariables.insert(var);
85 } else {
86 monotoneVariables.insert(var);
87 }
88 } else {
89 nonMonotoneVariables.insert(var);
90 }
91 }
92 return std::make_pair(std::move(monotoneVariables), std::move(nonMonotoneVariables));
93}
94
95template<typename VariableType>
97 std::stringstream stream;
98 auto countIncr = 0;
99 auto countDecr = 0;
100 for (auto res : getMonotonicityResult()) {
101 stream << res.first.name() << " " << res.second << "; ";
102 countIncr += (res.second == Monotonicity::Incr) ? 1 : 0;
103 countDecr += (res.second == Monotonicity::Decr) ? 1 : 0;
104 }
105 return "#Incr: " + std::to_string(countIncr) + " #Decr: " + std::to_string(countDecr) + "\n" + stream.str();
106}
107
108template<typename VariableType>
110 this->done = done;
111}
112
113template<typename VariableType>
115 doneVariables.insert(variable);
116}
117
118template<typename VariableType>
120 return done;
121}
122
123template<typename VariableType>
125 return doneVariables.find(var) != doneVariables.end();
126}
127
128template<typename VariableType>
130 this->somewhereMonotonicity = somewhereMonotonicity;
131}
132
133template<typename VariableType>
135 if (!somewhereMonotonicity) {
136 for (auto itr : monotonicityResult) {
137 if (isDoneForVar(itr.first) && itr.second != MonotonicityResult<VariableType>::Monotonicity::Unknown &&
139 setSomewhereMonotonicity(true);
140 break;
141 }
142 }
143 }
144 return monotonicityResult.size() > 0 && somewhereMonotonicity;
145}
146
147template<typename VariableType>
149 this->allMonotonicity = allMonotonicity;
150}
151
152template<typename VariableType>
154 return allMonotonicity;
155}
156
157template<typename VariableType>
158std::shared_ptr<MonotonicityResult<VariableType>> MonotonicityResult<VariableType>::copy() const {
159 std::shared_ptr<MonotonicityResult<VariableType>> copy = std::make_shared<MonotonicityResult<VariableType>>();
160 copy->monotonicityResult = std::map<VariableType, Monotonicity>(monotonicityResult);
161 copy->setAllMonotonicity(allMonotonicity);
162 copy->setSomewhereMonotonicity(somewhereMonotonicity);
163 copy->setDone(done);
164 copy->setDoneVariables(doneVariables);
165 return copy;
166}
167
168template<typename VariableType>
169void MonotonicityResult<VariableType>::setDoneVariables(std::set<VariableType> doneVariables) {
170 this->doneVariables = doneVariables;
171}
172
173template<typename VariableType>
174void MonotonicityResult<VariableType>::splitBasedOnMonotonicity(const std::set<VariableType>& consideredVariables, std::set<VariableType>& monotoneIncr,
175 std::set<VariableType>& monotoneDecr, std::set<VariableType>& notMonotone) const {
176 for (auto& var : consideredVariables) {
177 if (!isDoneForVar(var)) {
178 notMonotone.insert(var);
179 } else {
180 auto mon = getMonotonicity(var);
181 if (mon == Monotonicity::Unknown || mon == Monotonicity::Not) {
182 notMonotone.insert(var);
183 } else if (mon == Monotonicity::Incr) {
184 monotoneIncr.insert(var);
185 } else {
186 monotoneDecr.insert(var);
187 }
188 }
189 }
190}
191
192template<typename VariableType>
194 if (monotonicityResult.find(var) == monotonicityResult.end()) {
195 return false;
196 } else {
197 auto monRes = monotonicityResult.at(var);
198 return isDoneForVar(var) && (monRes == Monotonicity::Incr || monRes == Monotonicity::Decr || monRes == Monotonicity::Constant);
199 }
200}
201
203} // namespace analysis
204} // 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.