Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
MonotonicityResult.cpp
Go to the documentation of this file.
2
7
8namespace storm {
9namespace analysis {
10
11template<typename VariableType>
13 this->done = false;
14 this->somewhereMonotonicity = true;
15 this->allMonotonicity = true;
16}
17
18template<typename VariableType>
20 monotonicityResult.insert(std::pair<VariableType, MonotonicityResult<VariableType>::Monotonicity>(std::move(var), std::move(mon)));
21}
22
23template<typename VariableType>
25 assert(!isDoneForVar(var));
26 if (force) {
28 if (monotonicityResult.find(var) == monotonicityResult.end()) {
29 addMonotonicityResult(std::move(var), std::move(mon));
30 } else {
31 monotonicityResult[var] = mon;
32 }
33 } else {
36 }
37
38 if (monotonicityResult.find(var) == monotonicityResult.end()) {
39 addMonotonicityResult(std::move(var), std::move(mon));
40 } else {
41 auto monRes = monotonicityResult[var];
42 if (monRes == MonotonicityResult<VariableType>::Monotonicity::Unknown || monRes == mon ||
44 return;
46 monotonicityResult[var] = mon;
47 } else {
49 }
50 }
51 if (monotonicityResult[var] == MonotonicityResult<VariableType>::Monotonicity::Unknown) {
52 setAllMonotonicity(false);
53 setSomewhereMonotonicity(false);
54 } else {
55 setSomewhereMonotonicity(true);
56 }
57 }
58}
59
60template<typename VariableType>
62 auto itr = monotonicityResult.find(var);
63 if (itr != monotonicityResult.end()) {
64 return itr->second;
65 }
66 return Monotonicity::Unknown;
67}
68
69template<typename VariableType>
70std::map<VariableType, typename MonotonicityResult<VariableType>::Monotonicity> MonotonicityResult<VariableType>::getMonotonicityResult() const {
71 return monotonicityResult;
72}
73
74template<typename VariableType>
75std::pair<std::set<VariableType>, std::set<VariableType>> MonotonicityResult<VariableType>::splitVariables(
76 std::set<VariableType> const& consideredVariables) const {
77 std::set<VariableType> nonMonotoneVariables;
78 std::set<VariableType> monotoneVariables;
79 for (auto var : consideredVariables) {
80 if (isDoneForVar(var)) {
81 auto res = getMonotonicity(var);
82 if (res == Monotonicity::Not || res == Monotonicity::Unknown) {
83 nonMonotoneVariables.insert(var);
84 } else {
85 monotoneVariables.insert(var);
86 }
87 } else {
88 nonMonotoneVariables.insert(var);
89 }
90 }
91 return std::make_pair(std::move(monotoneVariables), std::move(nonMonotoneVariables));
92}
93
94template<typename VariableType>
96 std::string result;
97 auto countIncr = 0;
98 auto countDecr = 0;
99 for (auto res : getMonotonicityResult()) {
100 result += res.first.name();
101 switch (res.second) {
103 countIncr++;
104 result += " MonIncr; ";
105 break;
107 countDecr++;
108 result += " MonDecr; ";
109 break;
111 result += " Constant; ";
112 break;
114 result += " NotMon; ";
115 break;
117 result += " Unknown; ";
118 break;
119 default:
120 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException,
121 "Could not get a string from the region monotonicity check result. The case has not been implemented");
122 }
123 }
124 result = "#Incr: " + std::to_string(countIncr) + " #Decr: " + std::to_string(countDecr) + "\n" + result;
125 return result;
126}
127
128template<typename VariableType>
130 this->done = done;
131}
132
133template<typename VariableType>
135 doneVariables.insert(variable);
136}
137
138template<typename VariableType>
140 return done;
141}
142
143template<typename VariableType>
145 return doneVariables.find(var) != doneVariables.end();
146}
147
148template<typename VariableType>
150 this->somewhereMonotonicity = somewhereMonotonicity;
151}
152
153template<typename VariableType>
155 if (!somewhereMonotonicity) {
156 for (auto itr : monotonicityResult) {
157 if (isDoneForVar(itr.first) && itr.second != MonotonicityResult<VariableType>::Monotonicity::Unknown &&
159 setSomewhereMonotonicity(true);
160 break;
161 }
162 }
163 }
164 return monotonicityResult.size() > 0 && somewhereMonotonicity;
165}
166
167template<typename VariableType>
169 this->allMonotonicity = allMonotonicity;
170}
171
172template<typename VariableType>
174 return allMonotonicity;
175}
176
177template<typename VariableType>
178std::shared_ptr<MonotonicityResult<VariableType>> MonotonicityResult<VariableType>::copy() const {
179 std::shared_ptr<MonotonicityResult<VariableType>> copy = std::make_shared<MonotonicityResult<VariableType>>();
180 copy->monotonicityResult = std::map<VariableType, Monotonicity>(monotonicityResult);
181 copy->setAllMonotonicity(allMonotonicity);
182 copy->setSomewhereMonotonicity(somewhereMonotonicity);
183 copy->setDone(done);
184 copy->setDoneVariables(doneVariables);
185 return copy;
186}
187
188template<typename VariableType>
189void MonotonicityResult<VariableType>::setDoneVariables(std::set<VariableType> doneVariables) {
190 this->doneVariables = doneVariables;
191}
192
193template<typename VariableType>
194void MonotonicityResult<VariableType>::splitBasedOnMonotonicity(const std::set<VariableType>& consideredVariables, std::set<VariableType>& monotoneIncr,
195 std::set<VariableType>& monotoneDecr, std::set<VariableType>& notMonotone) const {
196 for (auto& var : consideredVariables) {
197 if (!isDoneForVar(var)) {
198 notMonotone.insert(var);
199 } else {
200 auto mon = getMonotonicity(var);
201 if (mon == Monotonicity::Unknown || mon == Monotonicity::Not) {
202 notMonotone.insert(var);
203 } else if (mon == Monotonicity::Incr) {
204 monotoneIncr.insert(var);
205 } else {
206 monotoneDecr.insert(var);
207 }
208 }
209 }
210}
211
212template<typename VariableType>
214 if (monotonicityResult.find(var) == monotonicityResult.end()) {
215 return false;
216 } else {
217 auto monRes = monotonicityResult.at(var);
218 return isDoneForVar(var) && (monRes == Monotonicity::Incr || monRes == Monotonicity::Decr || monRes == Monotonicity::Constant);
219 }
220}
221
223} // namespace analysis
224} // namespace storm
std::map< VariableType, Monotonicity > 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
Monotonicity
The results of monotonicity checking for a single Parameter Region.
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.
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
LabParser.cpp.
Definition cli.cpp:18