Storm 1.14.0.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), mon));
22}
23
24template<typename VariableType>
26 STORM_LOG_ASSERT(!isDoneForVar(var), "Already done for variable.");
27 if (force) {
28 STORM_LOG_ASSERT(mon == MonotonicityResult<VariableType>::Monotonicity::Not, "Expected Not monotonicity for force.");
29 if (monotonicityResult.find(var) == monotonicityResult.end()) {
30 addMonotonicityResult(std::move(var), mon);
31 } else {
32 monotonicityResult[var] = mon;
33 }
34 } else {
37 }
38
39 bool unknownMon = false;
40 if (monotonicityResult.find(var) == monotonicityResult.end()) {
41 addMonotonicityResult(std::move(var), mon);
43 } else {
44 auto monRes = monotonicityResult[var];
45 if (monRes == MonotonicityResult<VariableType>::Monotonicity::Unknown || monRes == mon ||
47 return;
49 monotonicityResult[var] = mon;
51 } else {
53 unknownMon = true;
54 }
55 }
56 if (unknownMon) {
57 setAllMonotonicity(false);
59 } else {
61 }
62 }
63}
64
65template<typename VariableType>
67 auto itr = monotonicityResult.find(var);
68 if (itr != monotonicityResult.end()) {
69 return itr->second;
70 }
71 return Monotonicity::Unknown;
72}
73
74template<typename VariableType>
75std::map<VariableType, typename MonotonicityResult<VariableType>::Monotonicity> const& MonotonicityResult<VariableType>::getMonotonicityResult() const {
76 return monotonicityResult;
77}
78
79template<typename VariableType>
80std::pair<std::set<VariableType>, std::set<VariableType>> MonotonicityResult<VariableType>::splitVariables(
81 std::set<VariableType> const& consideredVariables) const {
82 std::set<VariableType> nonMonotoneVariables;
83 std::set<VariableType> monotoneVariables;
84 for (auto var : consideredVariables) {
85 if (isDoneForVar(var)) {
86 auto res = getMonotonicity(var);
87 if (res == Monotonicity::Not || res == Monotonicity::Unknown) {
88 nonMonotoneVariables.insert(var);
89 } else {
90 monotoneVariables.insert(var);
91 }
92 } else {
93 nonMonotoneVariables.insert(var);
94 }
95 }
96 return std::make_pair(std::move(monotoneVariables), std::move(nonMonotoneVariables));
97}
98
99template<typename VariableType>
101 std::stringstream stream;
102 auto countIncr = 0;
103 auto countDecr = 0;
104 for (auto res : getMonotonicityResult()) {
105 stream << res.first.name() << " " << res.second << "; ";
106 countIncr += (res.second == Monotonicity::Incr) ? 1 : 0;
107 countDecr += (res.second == Monotonicity::Decr) ? 1 : 0;
108 }
109 return "#Incr: " + std::to_string(countIncr) + " #Decr: " + std::to_string(countDecr) + "\n" + stream.str();
110}
111
112template<typename VariableType>
114 this->done = done;
115}
116
117template<typename VariableType>
119 doneVariables.insert(variable);
120}
121
122template<typename VariableType>
124 return done;
125}
126
127template<typename VariableType>
129 return doneVariables.find(var) != doneVariables.end();
130}
131
132template<typename VariableType>
134 this->somewhereMonotonicity = somewhereMonotonicity;
135}
136
137template<typename VariableType>
139 if (!somewhereMonotonicity) {
140 for (auto itr : monotonicityResult) {
144 break;
145 }
146 }
147 }
148 return monotonicityResult.size() > 0 && somewhereMonotonicity;
149}
150
151template<typename VariableType>
153 this->allMonotonicity = allMonotonicity;
154}
155
156template<typename VariableType>
158 return allMonotonicity;
159}
160
161template<typename VariableType>
162std::shared_ptr<MonotonicityResult<VariableType>> MonotonicityResult<VariableType>::copy() const {
163 std::shared_ptr<MonotonicityResult<VariableType>> copy = std::make_shared<MonotonicityResult<VariableType>>();
164 copy->monotonicityResult = std::map<VariableType, Monotonicity>(monotonicityResult);
165 copy->setAllMonotonicity(allMonotonicity);
166 copy->setSomewhereMonotonicity(somewhereMonotonicity);
167 copy->setDone(done);
168 copy->setDoneVariables(doneVariables);
169 return copy;
170}
171
172template<typename VariableType>
173void MonotonicityResult<VariableType>::setDoneVariables(std::set<VariableType> doneVariables) {
174 this->doneVariables = doneVariables;
175}
176
177template<typename VariableType>
178void MonotonicityResult<VariableType>::splitBasedOnMonotonicity(const std::set<VariableType>& consideredVariables, std::set<VariableType>& monotoneIncr,
179 std::set<VariableType>& monotoneDecr, std::set<VariableType>& notMonotone) const {
180 for (auto& var : consideredVariables) {
181 if (!isDoneForVar(var)) {
182 notMonotone.insert(var);
183 } else {
184 auto mon = getMonotonicity(var);
185 if (mon == Monotonicity::Unknown || mon == Monotonicity::Not) {
186 notMonotone.insert(var);
187 } else if (mon == Monotonicity::Incr) {
188 monotoneIncr.insert(var);
189 } else {
190 monotoneDecr.insert(var);
191 }
192 }
193 }
194}
195
196template<typename VariableType>
198 if (monotonicityResult.find(var) == monotonicityResult.end()) {
199 return false;
200 } else {
201 auto monRes = monotonicityResult.at(var);
202 return isDoneForVar(var) && (monRes == Monotonicity::Incr || monRes == Monotonicity::Decr || monRes == Monotonicity::Constant);
203 }
204}
205
207} // namespace analysis
208} // 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.
storm::analysis::MonotonicityKind 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_ASSERT(cond, message)
Definition macros.h:9