Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
LocalMonotonicityResult.cpp
Go to the documentation of this file.
2
4
5namespace storm {
6namespace analysis {
7
8template<typename VariableType>
10 stateMonRes = std::vector<std::shared_ptr<MonotonicityResult<VariableType>>>(numberOfStates, nullptr);
11 globalMonotonicityResult = std::make_shared<MonotonicityResult<VariableType>>();
12 statesMonotone = storm::storage::BitVector(numberOfStates, false);
13 dummyPointer = std::make_shared<MonotonicityResult<VariableType>>();
14 done = false;
15}
16
17template<typename VariableType>
19 stateMonRes = std::vector<std::shared_ptr<MonotonicityResult<VariableType>>>(numberOfStates);
20 globalMonotonicityResult = globalResult;
21 statesMonotone = storm::storage::BitVector(numberOfStates, false);
22 dummyPointer = std::make_shared<MonotonicityResult<VariableType>>();
23 done = globalResult->isDone();
24}
25
26template<typename VariableType>
28 VariableType var) const {
29 if (stateMonRes[state] == dummyPointer) {
30 return Monotonicity::Constant;
31 } else if (stateMonRes[state] != nullptr) {
32 auto res = stateMonRes[state]->getMonotonicity(var);
33 if (res == Monotonicity::Unknown && globalMonotonicityResult->isDoneForVar(var)) {
34 return globalMonotonicityResult->getMonotonicity(var);
35 }
36 return res;
37 } else {
38 return globalMonotonicityResult->isDoneForVar(var) ? globalMonotonicityResult->getMonotonicity(var) : Monotonicity::Unknown;
39 }
40}
41
42template<typename VariableType>
43std::shared_ptr<MonotonicityResult<VariableType>> LocalMonotonicityResult<VariableType>::getGlobalMonotonicityResult() const {
44 return globalMonotonicityResult;
45}
46
47template<typename VariableType>
48void LocalMonotonicityResult<VariableType>::setMonotonicity(uint_fast64_t state, VariableType var,
50 assert(stateMonRes[state] != dummyPointer);
51 if (stateMonRes[state] == nullptr) {
52 stateMonRes[state] = std::make_shared<MonotonicityResult<VariableType>>();
53 }
54 stateMonRes[state]->addMonotonicityResult(var, mon);
55 globalMonotonicityResult->updateMonotonicityResult(var, mon);
56 if (mon == Monotonicity::Unknown || mon == Monotonicity::Not) {
57 statesMonotone.set(state, false);
58 } else {
59 bool stateMonotone = stateMonRes[state]->isAllMonotonicity();
60 if (stateMonotone) {
61 statesMonotone.set(state);
62 done |= statesMonotone.full();
63 }
64 if (isDone()) {
65 globalMonotonicityResult->setDone();
66 }
67 }
68}
69
70template<typename VariableType>
71std::shared_ptr<LocalMonotonicityResult<VariableType>> LocalMonotonicityResult<VariableType>::copy() {
72 std::shared_ptr<LocalMonotonicityResult<VariableType>> copy = std::make_shared<LocalMonotonicityResult<VariableType>>(stateMonRes.size());
73 for (uint_fast64_t state = 0; state < stateMonRes.size(); state++) {
74 if (stateMonRes[state] != nullptr) {
75 copy->setMonotonicityResult(state, stateMonRes[state]->copy());
76 }
77 }
78 copy->setGlobalMonotonicityResult(this->getGlobalMonotonicityResult()->copy());
79 copy->setStatesMonotone(statesMonotone);
80 return copy;
81}
82
83template<typename VariableType>
85 return done;
86}
87
88template<typename VariableType>
90 assert(indexMinimize == -1);
91 this->indexMinimize = i;
92}
93
94template<typename VariableType>
96 this->indexMaximize = i;
97}
98
99template<typename VariableType>
101 return indexMinimize;
102}
103
104template<typename VariableType>
106 return indexMaximize;
107}
108
109template<typename VariableType>
111 return statesMonotone.empty();
112}
113
114template<typename VariableType>
116 this->stateMonRes[state] = monRes;
117}
118
119template<typename VariableType>
120void LocalMonotonicityResult<VariableType>::setGlobalMonotonicityResult(std::shared_ptr<MonotonicityResult<VariableType>> monRes) {
121 this->globalMonotonicityResult = monRes;
122}
123
124template<typename VariableType>
125void LocalMonotonicityResult<VariableType>::setStatesMonotone(storm::storage::BitVector statesMonotone) {
126 this->statesMonotone = statesMonotone;
127}
128
129template<typename VariableType>
131 if (stateMonRes[state] == nullptr) {
132 stateMonRes[state] = dummyPointer;
133 }
134 this->statesMonotone.set(state);
135}
136
137template<typename VariableType>
139 globalMonotonicityResult->updateMonotonicityResult(var, Monotonicity::Incr);
140 globalMonotonicityResult->setDoneForVar(var);
141 setFixedParameters = true;
142}
143
144template<typename VariableType>
146 globalMonotonicityResult->updateMonotonicityResult(var, Monotonicity::Decr);
147 globalMonotonicityResult->setDoneForVar(var);
148 setFixedParameters = true;
149}
150
151template<typename VariableType>
153 std::string result = "Local Monotonicity Result: \n";
154 for (uint_fast64_t i = 0; i < stateMonRes.size(); ++i) {
155 result += "state ";
156 result += std::to_string(i);
157 if (stateMonRes[i] != nullptr) {
158 result += stateMonRes[i]->toString();
159 } else if (statesMonotone[i]) {
160 result += "constant";
161 } else {
162 result += "not analyzed";
163 }
164 result += "\n";
165 }
166 return result;
167}
168
169template<typename VariableType>
171 return setFixedParameters;
172}
173
174template<typename VariableType>
176 this->done = done;
177 globalMonotonicityResult->setDone(done);
178}
179
180template<typename VariableType>
181std::shared_ptr<MonotonicityResult<VariableType>> LocalMonotonicityResult<VariableType>::getMonotonicity(uint_fast64_t state) const {
182 return stateMonRes[state];
183}
184
186} // namespace analysis
187} // 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.
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.
MonotonicityKind
The results of monotonicity checking for a single Parameter Region.