Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
LocalMonotonicityResult.cpp
Go to the documentation of this file.
2
5
6namespace storm {
7namespace analysis {
8
9template<typename VariableType>
11 stateMonRes = std::vector<std::shared_ptr<MonotonicityResult<VariableType>>>(numberOfStates, nullptr);
12 globalMonotonicityResult = std::make_shared<MonotonicityResult<VariableType>>();
13 statesMonotone = storm::storage::BitVector(numberOfStates, false);
14 dummyPointer = std::make_shared<MonotonicityResult<VariableType>>();
15 done = false;
16}
17
18template<typename VariableType>
20 stateMonRes = std::vector<std::shared_ptr<MonotonicityResult<VariableType>>>(numberOfStates);
21 globalMonotonicityResult = globalResult;
22 statesMonotone = storm::storage::BitVector(numberOfStates, false);
23 dummyPointer = std::make_shared<MonotonicityResult<VariableType>>();
24 done = globalResult->isDone();
25}
26
27template<typename VariableType>
29 VariableType var) const {
30 if (stateMonRes[state] == dummyPointer) {
31 return Monotonicity::Constant;
32 } else if (stateMonRes[state] != nullptr) {
33 auto res = stateMonRes[state]->getMonotonicity(var);
34 if (res == Monotonicity::Unknown && globalMonotonicityResult->isDoneForVar(var)) {
35 return globalMonotonicityResult->getMonotonicity(var);
36 }
37 return res;
38 } else {
39 return globalMonotonicityResult->isDoneForVar(var) ? globalMonotonicityResult->getMonotonicity(var) : Monotonicity::Unknown;
40 }
41}
42
43template<typename VariableType>
44std::shared_ptr<MonotonicityResult<VariableType>> LocalMonotonicityResult<VariableType>::getGlobalMonotonicityResult() const {
45 return globalMonotonicityResult;
46}
47
48template<typename VariableType>
49void LocalMonotonicityResult<VariableType>::setMonotonicity(uint_fast64_t state, VariableType var,
51 STORM_LOG_ASSERT(stateMonRes[state] != dummyPointer, "State monotonicity result is dummy pointer.");
52 if (stateMonRes[state] == nullptr) {
53 stateMonRes[state] = std::make_shared<MonotonicityResult<VariableType>>();
54 }
55 stateMonRes[state]->addMonotonicityResult(var, mon);
56 globalMonotonicityResult->updateMonotonicityResult(var, mon);
57 if (mon == Monotonicity::Unknown || mon == Monotonicity::Not) {
58 statesMonotone.set(state, false);
59 } else {
60 bool stateMonotone = stateMonRes[state]->isAllMonotonicity();
61 if (stateMonotone) {
62 statesMonotone.set(state);
63 done |= statesMonotone.full();
64 }
65 if (isDone()) {
66 globalMonotonicityResult->setDone();
67 }
68 }
69}
70
71template<typename VariableType>
72std::shared_ptr<LocalMonotonicityResult<VariableType>> LocalMonotonicityResult<VariableType>::copy() {
73 std::shared_ptr<LocalMonotonicityResult<VariableType>> copy = std::make_shared<LocalMonotonicityResult<VariableType>>(stateMonRes.size());
74 for (uint_fast64_t state = 0; state < stateMonRes.size(); state++) {
75 if (stateMonRes[state] != nullptr) {
76 copy->setMonotonicityResult(state, stateMonRes[state]->copy());
77 }
78 }
79 copy->setGlobalMonotonicityResult(this->getGlobalMonotonicityResult()->copy());
80 copy->setStatesMonotone(statesMonotone);
81 return copy;
82}
83
84template<typename VariableType>
86 return done;
87}
88
89template<typename VariableType>
91 STORM_LOG_ASSERT(indexMinimize == -1, "Index minimize already set.");
92 this->indexMinimize = i;
93}
94
95template<typename VariableType>
97 this->indexMaximize = i;
98}
99
100template<typename VariableType>
102 return indexMinimize;
103}
104
105template<typename VariableType>
107 return indexMaximize;
108}
109
110template<typename VariableType>
112 return statesMonotone.empty();
113}
114
115template<typename VariableType>
116void LocalMonotonicityResult<VariableType>::setMonotonicityResult(uint_fast64_t state, std::shared_ptr<MonotonicityResult<VariableType>> monRes) {
117 this->stateMonRes[state] = monRes;
118}
119
120template<typename VariableType>
121void LocalMonotonicityResult<VariableType>::setGlobalMonotonicityResult(std::shared_ptr<MonotonicityResult<VariableType>> monRes) {
122 this->globalMonotonicityResult = monRes;
123}
124
125template<typename VariableType>
126void LocalMonotonicityResult<VariableType>::setStatesMonotone(storm::storage::BitVector statesMonotone) {
127 this->statesMonotone = statesMonotone;
128}
129
130template<typename VariableType>
132 if (stateMonRes[state] == nullptr) {
133 stateMonRes[state] = dummyPointer;
134 }
135 this->statesMonotone.set(state);
136}
137
138template<typename VariableType>
140 globalMonotonicityResult->updateMonotonicityResult(var, Monotonicity::Incr);
141 globalMonotonicityResult->setDoneForVar(var);
142 setFixedParameters = true;
143}
144
145template<typename VariableType>
147 globalMonotonicityResult->updateMonotonicityResult(var, Monotonicity::Decr);
148 globalMonotonicityResult->setDoneForVar(var);
149 setFixedParameters = true;
150}
151
152template<typename VariableType>
154 std::string result = "Local Monotonicity Result: \n";
155 for (uint_fast64_t i = 0; i < stateMonRes.size(); ++i) {
156 result += "state ";
157 result += std::to_string(i);
158 if (stateMonRes[i] != nullptr) {
159 result += stateMonRes[i]->toString();
160 } else if (statesMonotone[i]) {
161 result += "constant";
162 } else {
163 result += "not analyzed";
164 }
165 result += "\n";
166 }
167 return result;
168}
169
170template<typename VariableType>
172 return setFixedParameters;
173}
174
175template<typename VariableType>
177 this->done = done;
178 globalMonotonicityResult->setDone(done);
179}
180
181template<typename VariableType>
182std::shared_ptr<MonotonicityResult<VariableType>> LocalMonotonicityResult<VariableType>::getMonotonicity(uint_fast64_t state) const {
183 return stateMonRes[state];
184}
185
187} // namespace analysis
188} // namespace storm
void setMonotonicity(uint_fast64_t state, VariableType var, Monotonicity mon)
Sets the local Monotonicity of a parameter at a given state.
LocalMonotonicityResult(uint_fast64_t numberOfStates)
Constructs a new LocalMonotonicityResult object.
MonotonicityResult< VariableType >::Monotonicity Monotonicity
std::shared_ptr< LocalMonotonicityResult< VariableType > > copy()
Constructs a new LocalMonotonicityResult object that is a copy of the current one.
bool isDone() const
Checks if the LocalMonotonicity is done yet.
std::shared_ptr< MonotonicityResult< VariableType > > getGlobalMonotonicityResult() const
Returns the Global MonotonicityResult object that corresponds to this object.
std::string toString() const
Constructs a string output of all variables and their corresponding Monotonicity.
Monotonicity getMonotonicity(uint_fast64_t state, VariableType var) const
Returns the local Monotonicity of a parameter at a given state.
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
void set(uint64_t index, bool value=true)
Sets the given truth value at the given index.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9