Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
StandardRewardModel.cpp
Go to the documentation of this file.
2
7
9
10namespace storm {
11namespace models {
12namespace sparse {
13template<typename ValueType>
14StandardRewardModel<ValueType>::StandardRewardModel(std::optional<std::vector<ValueType>> const& optionalStateRewardVector,
15 std::optional<std::vector<ValueType>> const& optionalStateActionRewardVector,
16 std::optional<storm::storage::SparseMatrix<ValueType>> const& optionalTransitionRewardMatrix)
17 : optionalStateRewardVector(optionalStateRewardVector),
18 optionalStateActionRewardVector(optionalStateActionRewardVector),
19 optionalTransitionRewardMatrix(optionalTransitionRewardMatrix) {
20 // Intentionally left empty.
21}
22
23template<typename ValueType>
24StandardRewardModel<ValueType>::StandardRewardModel(std::optional<std::vector<ValueType>>&& optionalStateRewardVector,
25 std::optional<std::vector<ValueType>>&& optionalStateActionRewardVector,
26 std::optional<storm::storage::SparseMatrix<ValueType>>&& optionalTransitionRewardMatrix)
27 : optionalStateRewardVector(std::move(optionalStateRewardVector)),
28 optionalStateActionRewardVector(std::move(optionalStateActionRewardVector)),
29 optionalTransitionRewardMatrix(std::move(optionalTransitionRewardMatrix)) {
30 // Intentionally left empty.
31}
32
33template<typename ValueType>
35 return static_cast<bool>(this->optionalStateRewardVector);
36}
37
38template<typename ValueType>
40 return static_cast<bool>(this->optionalStateRewardVector) && !static_cast<bool>(this->optionalStateActionRewardVector) &&
41 !static_cast<bool>(this->optionalTransitionRewardMatrix);
42}
43
44template<typename ValueType>
45std::vector<ValueType> const& StandardRewardModel<ValueType>::getStateRewardVector() const {
46 STORM_LOG_ASSERT(this->hasStateRewards(), "No state rewards available.");
47 return this->optionalStateRewardVector.value();
48}
49
50template<typename ValueType>
52 STORM_LOG_ASSERT(this->hasStateRewards(), "No state rewards available.");
53 return this->optionalStateRewardVector.value();
54}
55
56template<typename ValueType>
57std::optional<std::vector<ValueType>> const& StandardRewardModel<ValueType>::getOptionalStateRewardVector() const {
58 return this->optionalStateRewardVector;
59}
60
61template<typename ValueType>
63 STORM_LOG_ASSERT(this->hasStateRewards(), "No state rewards available.");
64 STORM_LOG_ASSERT(state < this->optionalStateRewardVector.value().size(), "Invalid state.");
65 return this->optionalStateRewardVector.value()[state];
66}
67
68template<typename ValueType>
69template<typename T>
70void StandardRewardModel<ValueType>::setStateReward(uint_fast64_t state, T const& newReward) {
71 STORM_LOG_ASSERT(this->hasStateRewards(), "No state rewards available.");
72 STORM_LOG_ASSERT(state < this->optionalStateRewardVector.value().size(), "Invalid state.");
73 this->optionalStateRewardVector.value()[state] = newReward;
74}
75
76template<typename ValueType>
78 return static_cast<bool>(this->optionalStateActionRewardVector);
79}
80
81template<typename ValueType>
83 STORM_LOG_ASSERT(this->hasStateActionRewards(), "No state action rewards available.");
84 return this->optionalStateActionRewardVector.value();
85}
86
87template<typename ValueType>
89 STORM_LOG_ASSERT(this->hasStateActionRewards(), "No state action rewards available.");
90 return this->optionalStateActionRewardVector.value();
91}
92
93template<typename ValueType>
94ValueType const& StandardRewardModel<ValueType>::getStateActionReward(uint_fast64_t choiceIndex) const {
95 STORM_LOG_ASSERT(this->hasStateActionRewards(), "No state action rewards available.");
96 STORM_LOG_ASSERT(choiceIndex < this->optionalStateActionRewardVector.value().size(), "Invalid choiceIndex.");
97 return this->optionalStateActionRewardVector.value()[choiceIndex];
98}
99
100template<typename ValueType>
101template<typename T>
102void StandardRewardModel<ValueType>::setStateActionReward(uint_fast64_t choiceIndex, T const& newValue) {
103 STORM_LOG_ASSERT(this->hasStateActionRewards(), "No state action rewards available.");
104 STORM_LOG_ASSERT(choiceIndex < this->optionalStateActionRewardVector.value().size(), "Invalid choiceIndex.");
105 this->optionalStateActionRewardVector.value()[choiceIndex] = newValue;
106}
107
108template<typename ValueType>
109std::optional<std::vector<ValueType>> const& StandardRewardModel<ValueType>::getOptionalStateActionRewardVector() const {
110 return this->optionalStateActionRewardVector;
111}
112
113template<typename ValueType>
115 return static_cast<bool>(this->optionalTransitionRewardMatrix);
116}
117
118template<typename ValueType>
120 return this->optionalTransitionRewardMatrix.value();
121}
122
123template<typename ValueType>
125 return this->optionalTransitionRewardMatrix.value();
126}
127
128template<typename ValueType>
129std::optional<storm::storage::SparseMatrix<ValueType>> const& StandardRewardModel<ValueType>::getOptionalTransitionRewardMatrix() const {
130 return this->optionalTransitionRewardMatrix;
131}
132
133template<typename ValueType>
135 std::optional<std::vector<ValueType>> newStateRewardVector(this->getOptionalStateRewardVector());
136 std::optional<std::vector<ValueType>> newStateActionRewardVector;
137 if (this->hasStateActionRewards()) {
138 newStateActionRewardVector = std::vector<ValueType>(enabledActions.getNumberOfSetBits());
139 storm::utility::vector::selectVectorValues(newStateActionRewardVector.value(), enabledActions, this->getStateActionRewardVector());
140 }
141 std::optional<storm::storage::SparseMatrix<ValueType>> newTransitionRewardMatrix;
142 if (this->hasTransitionRewards()) {
143 newTransitionRewardMatrix = this->getTransitionRewardMatrix().restrictRows(enabledActions);
144 }
145 return StandardRewardModel(std::move(newStateRewardVector), std::move(newStateActionRewardVector), std::move(newTransitionRewardMatrix));
146}
147
148template<typename ValueType>
149StandardRewardModel<ValueType> StandardRewardModel<ValueType>::permuteActions(std::vector<uint64_t> const& inversePermutation) const {
150 std::optional<std::vector<ValueType>> newStateRewardVector(this->getOptionalStateRewardVector());
151 std::optional<std::vector<ValueType>> newStateActionRewardVector;
152 if (this->hasStateActionRewards()) {
153 newStateActionRewardVector = storm::utility::vector::applyInversePermutation(inversePermutation, this->getStateActionRewardVector());
154 }
155 std::optional<storm::storage::SparseMatrix<ValueType>> newTransitionRewardMatrix;
156 if (this->hasTransitionRewards()) {
157 newTransitionRewardMatrix = this->getTransitionRewardMatrix().permuteRows(inversePermutation);
158 }
159 return StandardRewardModel(std::move(newStateRewardVector), std::move(newStateActionRewardVector), std::move(newTransitionRewardMatrix));
160}
161
162template<typename ValueType>
164 storm::OptionalRef<std::vector<uint64_t> const> rowGroupIndices,
165 storm::OptionalRef<std::vector<uint64_t> const> permutation) const {
166 std::optional<std::vector<ValueType>> newStateRewardVector;
167 if (hasStateRewards()) {
168 newStateRewardVector = storm::utility::vector::applyInversePermutation(inversePermutation, getStateRewardVector());
169 }
170 std::optional<std::vector<ValueType>> newStateActionRewardVector;
171 if (this->hasStateActionRewards()) {
172 if (rowGroupIndices) {
173 newStateActionRewardVector =
174 storm::utility::vector::applyInversePermutationToGroupedVector(inversePermutation, this->getStateActionRewardVector(), rowGroupIndices.value());
175 } else {
176 STORM_LOG_ASSERT(inversePermutation.size() == this->getStateActionRewardVector().size(), "Invalid permutation size.");
177 newStateActionRewardVector = storm::utility::vector::applyInversePermutation(inversePermutation, this->getStateActionRewardVector());
178 }
179 }
180 std::optional<storm::storage::SparseMatrix<ValueType>> newTransitionRewardMatrix;
181 if (this->hasTransitionRewards()) {
182 STORM_LOG_ASSERT(permutation, "Permutation required for transition rewards.");
183 STORM_LOG_ASSERT(rowGroupIndices.has_value() != getTransitionRewardMatrix().hasTrivialRowGrouping(),
184 "Row group indices required for transition rewards.");
185 this->getTransitionRewardMatrix().permuteRowGroupsAndColumns(inversePermutation, permutation.value());
186 }
187
188 return StandardRewardModel(std::move(newStateRewardVector), std::move(newStateActionRewardVector), std::move(newTransitionRewardMatrix));
189}
190
191template<typename ValueType>
192template<typename MatrixValueType>
194 storm::storage::SparseMatrix<MatrixValueType> const& transitionMatrix) const {
195 ValueType result = this->hasStateActionRewards() ? this->getStateActionReward(choiceIndex) : storm::utility::zero<ValueType>();
196 if (this->hasTransitionRewards()) {
197 result += transitionMatrix.getPointwiseProductRowSum(getTransitionRewardMatrix(), choiceIndex);
198 }
199 return result;
200}
201
202template<typename ValueType>
203template<typename MatrixValueType>
204ValueType StandardRewardModel<ValueType>::getTotalStateActionReward(uint_fast64_t stateIndex, uint_fast64_t choiceIndex,
205 storm::storage::SparseMatrix<MatrixValueType> const& transitionMatrix,
206 MatrixValueType const& stateRewardWeight, MatrixValueType const& actionRewardWeight) const {
207 ValueType result = actionRewardWeight * getStateActionAndTransitionReward(choiceIndex, transitionMatrix);
208 if (this->hasStateRewards()) {
209 result += stateRewardWeight * this->getStateReward(stateIndex);
210 }
211 return result;
212}
213
214template<typename ValueType>
215template<typename MatrixValueType>
217 std::vector<MatrixValueType> const* weights) {
218 if (this->hasTransitionRewards()) {
219 if (this->hasStateActionRewards()) {
220 storm::utility::vector::addVectors<ValueType>(this->getStateActionRewardVector(),
221 transitionMatrix.getPointwiseProductRowSumVector(this->getTransitionRewardMatrix()),
222 this->getStateActionRewardVector());
223 this->optionalTransitionRewardMatrix = std::nullopt;
224 } else {
225 this->optionalStateActionRewardVector = transitionMatrix.getPointwiseProductRowSumVector(this->getTransitionRewardMatrix());
226 }
227 }
228
229 if (reduceToStateRewards && this->hasStateActionRewards()) {
230 STORM_LOG_THROW(transitionMatrix.getRowGroupCount() == this->getStateActionRewardVector().size(), storm::exceptions::InvalidOperationException,
231 "The reduction to state rewards is only possible if the size of the action reward vector equals the number of states.");
232 if (weights) {
233 if (this->hasStateRewards()) {
234 storm::utility::vector::applyPointwiseTernary<ValueType, MatrixValueType, ValueType>(
235 this->getStateActionRewardVector(), *weights, this->getStateRewardVector(),
236 [](ValueType const& sar, MatrixValueType const& w, ValueType const& sr) -> ValueType { return sr + w * sar; });
237 } else {
238 this->optionalStateRewardVector = std::move(this->optionalStateActionRewardVector);
239 storm::utility::vector::applyPointwise<ValueType, MatrixValueType, ValueType, std::multiplies<>>(
240 this->optionalStateRewardVector.value(), *weights, this->optionalStateRewardVector.value());
241 }
242 } else {
243 if (this->hasStateRewards()) {
244 storm::utility::vector::addVectors<ValueType>(this->getStateActionRewardVector(), this->getStateRewardVector(), this->getStateRewardVector());
245 } else {
246 this->optionalStateRewardVector = std::move(this->optionalStateActionRewardVector);
247 }
248 }
249 this->optionalStateActionRewardVector = std::nullopt;
250 }
251}
252
253template<typename ValueType>
254template<typename MatrixValueType>
256 std::vector<ValueType> result = this->hasTransitionRewards() ? transitionMatrix.getPointwiseProductRowSumVector(this->getTransitionRewardMatrix())
257 : (this->hasStateActionRewards() ? this->getStateActionRewardVector()
258 : std::vector<ValueType>(transitionMatrix.getRowCount()));
259 if (this->hasStateActionRewards() && this->hasTransitionRewards()) {
260 storm::utility::vector::addVectors(result, this->getStateActionRewardVector(), result);
261 }
262 if (this->hasStateRewards()) {
263 storm::utility::vector::addVectorToGroupedVector(result, this->getStateRewardVector(), transitionMatrix.getRowGroupIndices());
264 }
265 return result;
266}
267
268template<typename ValueType>
269template<typename MatrixValueType>
271 std::vector<MatrixValueType> const& weights) const {
272 std::vector<ValueType> result;
273 if (this->hasTransitionRewards()) {
274 result = transitionMatrix.getPointwiseProductRowSumVector(this->getTransitionRewardMatrix());
275 storm::utility::vector::applyPointwiseTernary<MatrixValueType, ValueType, ValueType>(
276 weights, this->getStateActionRewardVector(), result,
277 [](MatrixValueType const& weight, ValueType const& rewardElement, ValueType const& resultElement) {
278 return weight * (resultElement + rewardElement);
279 });
280 } else {
281 result = std::vector<ValueType>(transitionMatrix.getRowCount());
282 if (this->hasStateActionRewards()) {
283 storm::utility::vector::applyPointwise<MatrixValueType, ValueType, ValueType>(
284 weights, this->getStateActionRewardVector(), result,
285 [](MatrixValueType const& weight, ValueType const& rewardElement) { return weight * rewardElement; });
286 }
287 }
288 if (this->hasStateRewards()) {
289 storm::utility::vector::addVectorToGroupedVector(result, this->getStateRewardVector(), transitionMatrix.getRowGroupIndices());
290 }
291 return result;
292}
293
294template<typename ValueType>
295template<typename MatrixValueType>
296std::vector<ValueType> StandardRewardModel<ValueType>::getTotalRewardVector(uint_fast64_t numberOfRows,
297 storm::storage::SparseMatrix<MatrixValueType> const& transitionMatrix,
298 storm::storage::BitVector const& filter) const {
299 std::vector<ValueType> result(numberOfRows);
300 if (this->hasTransitionRewards()) {
301 std::vector<ValueType> pointwiseProductRowSumVector = transitionMatrix.getPointwiseProductRowSumVector(this->getTransitionRewardMatrix());
302 storm::utility::vector::selectVectorValues(result, filter, transitionMatrix.getRowGroupIndices(), pointwiseProductRowSumVector);
303 }
304
305 if (this->hasStateActionRewards()) {
306 storm::utility::vector::addFilteredVectorGroupsToGroupedVector(result, this->getStateActionRewardVector(), filter,
307 transitionMatrix.getRowGroupIndices());
308 }
309 if (this->hasStateRewards()) {
310 storm::utility::vector::addFilteredVectorToGroupedVector(result, this->getStateRewardVector(), filter, transitionMatrix.getRowGroupIndices());
311 }
312 return result;
313}
314
315template<typename ValueType>
316template<typename MatrixValueType>
318 std::vector<MatrixValueType> const& stateRewardWeights) const {
319 std::vector<ValueType> result;
320 if (this->hasTransitionRewards()) {
321 result = transitionMatrix.getPointwiseProductRowSumVector(this->getTransitionRewardMatrix());
322 } else {
323 result = std::vector<ValueType>(transitionMatrix.getRowCount());
324 }
325 if (this->hasStateActionRewards()) {
326 storm::utility::vector::addVectors(result, this->getStateActionRewardVector(), result);
327 }
328 if (this->hasStateRewards()) {
329 std::vector<ValueType> scaledStateRewardVector(transitionMatrix.getRowGroupCount());
330 storm::utility::vector::multiplyVectorsPointwise(this->getStateRewardVector(), stateRewardWeights, scaledStateRewardVector);
331 storm::utility::vector::addVectorToGroupedVector(result, scaledStateRewardVector, transitionMatrix.getRowGroupIndices());
332 }
333 return result;
334}
335
336template<typename ValueType>
337template<typename MatrixValueType>
339 return getStatesWithFilter(transitionMatrix, storm::utility::isZero<ValueType>);
340}
341
342template<typename ValueType>
343template<typename MatrixValueType>
345 std::function<bool(ValueType const&)> const& filter) const {
346 storm::storage::BitVector result = this->hasStateRewards() ? storm::utility::vector::filter(this->getStateRewardVector(), filter)
347 : storm::storage::BitVector(transitionMatrix.getRowGroupCount(), true);
348 if (this->hasStateActionRewards()) {
349 for (uint_fast64_t state = 0; state < transitionMatrix.getRowGroupCount(); ++state) {
350 for (uint_fast64_t row = transitionMatrix.getRowGroupIndices()[state]; row < transitionMatrix.getRowGroupIndices()[state + 1]; ++row) {
351 if (!filter(this->getStateActionRewardVector()[row])) {
352 result.set(state, false);
353 break;
354 }
355 }
356 }
357 }
358 if (this->hasTransitionRewards()) {
359 for (uint_fast64_t state = 0; state < transitionMatrix.getRowGroupCount(); ++state) {
360 for (auto const& rewardMatrixEntry : this->getTransitionRewardMatrix().getRowGroup(state)) {
361 if (!filter(rewardMatrixEntry.getValue())) {
362 result.set(state, false);
363 break;
364 }
365 }
366 }
367 }
368 return result;
369}
370
371template<typename ValueType>
372template<typename MatrixValueType>
374 storm::storage::SparseMatrix<MatrixValueType> const& transitionMatrix) const {
375 return getChoicesWithFilter(transitionMatrix, storm::utility::isZero<ValueType>);
376}
377
378template<typename ValueType>
379template<typename MatrixValueType>
381 std::function<bool(ValueType const&)> const& filter) const {
383 if (this->hasStateActionRewards()) {
384 result = storm::utility::vector::filter(this->getStateActionRewardVector(), filter);
385 if (this->hasStateRewards()) {
386 result &= transitionMatrix.getRowFilter(storm::utility::vector::filter(this->getStateRewardVector(), filter));
387 }
388 } else {
389 if (this->hasStateRewards()) {
390 result = transitionMatrix.getRowFilter(storm::utility::vector::filter(this->getStateRewardVector(), filter));
391 } else {
392 result = storm::storage::BitVector(transitionMatrix.getRowCount(), true);
393 }
394 }
395 if (this->hasTransitionRewards()) {
396 for (uint_fast64_t row = 0; row < transitionMatrix.getRowCount(); ++row) {
397 for (auto const& rewardMatrixEntry : this->getTransitionRewardMatrix().getRow(row)) {
398 if (!filter(rewardMatrixEntry.getValue())) {
399 result.set(row, false);
400 break;
401 }
402 }
403 }
404 }
405 return result;
406}
407
408template<typename ValueType>
409template<typename MatrixValueType>
411 if (hasStateRewards()) {
412 getStateRewardVector()[state] = storm::utility::zero<ValueType>();
413 }
414 if (hasStateActionRewards()) {
415 for (uint_fast64_t choice = transitions.getRowGroupIndices()[state]; choice < transitions.getRowGroupIndices()[state + 1]; ++choice) {
416 getStateActionRewardVector()[choice] = storm::utility::zero<ValueType>();
417 }
418 }
419 if (hasTransitionRewards()) {
420 for (auto& entry : getTransitionRewardMatrix().getRowGroup(state)) {
421 entry.setValue(storm::utility::zero<ValueType>());
422 }
423 }
424}
425
426template<typename ValueType>
428 return !(static_cast<bool>(this->optionalStateRewardVector) || static_cast<bool>(this->optionalStateActionRewardVector) ||
429 static_cast<bool>(this->optionalTransitionRewardMatrix));
430}
431
432template<typename ValueType>
434 if (hasStateRewards() && !std::all_of(getStateRewardVector().begin(), getStateRewardVector().end(), storm::utility::isZero<ValueType>)) {
435 return false;
436 }
437 if (hasStateActionRewards() && !std::all_of(getStateActionRewardVector().begin(), getStateActionRewardVector().end(), storm::utility::isZero<ValueType>)) {
438 return false;
439 }
440 if (hasTransitionRewards() && !std::all_of(getTransitionRewardMatrix().begin(), getTransitionRewardMatrix().end(),
442 return storm::utility::isZero(entry.getValue());
443 })) {
444 return false;
445 }
446 return true;
447}
448
449template<typename ValueType>
450bool StandardRewardModel<ValueType>::isCompatible(uint_fast64_t nrStates, uint_fast64_t nrChoices) const {
451 if (hasStateRewards()) {
452 if (optionalStateRewardVector.value().size() != nrStates)
453 return false;
454 }
455 if (hasStateActionRewards()) {
456 if (optionalStateActionRewardVector.value().size() != nrChoices)
457 return false;
458 }
459 return true;
460}
461
462template<typename ValueType>
464 size_t seed = 0;
465 if (hasStateRewards()) {
466 boost::hash_combine(seed, boost::hash_range(optionalStateRewardVector->begin(), optionalStateRewardVector->end()));
467 }
468 if (hasStateActionRewards()) {
469 boost::hash_combine(seed, boost::hash_range(optionalStateActionRewardVector->begin(), optionalStateActionRewardVector->end()));
470 }
471 if (hasTransitionRewards()) {
472 boost::hash_combine(seed, optionalTransitionRewardMatrix->hash());
473 }
474 return seed;
475}
476
477template<typename ValueType>
478std::ostream& operator<<(std::ostream& out, StandardRewardModel<ValueType> const& rewardModel) {
479 out << std::boolalpha << "reward model [state reward: " << rewardModel.hasStateRewards()
480 << ", state-action rewards: " << rewardModel.hasStateActionRewards() << ", transition rewards: " << rewardModel.hasTransitionRewards() << "]"
481 << std::noboolalpha;
482 return out;
483}
484
485std::set<storm::RationalFunctionVariable> getRewardModelParameters(StandardRewardModel<storm::RationalFunction> const& rewModel) {
486 std::set<storm::RationalFunctionVariable> vars;
487 if (rewModel.hasTransitionRewards()) {
488 vars = storm::storage::getVariables(rewModel.getTransitionRewardMatrix());
489 }
490 if (rewModel.hasStateActionRewards()) {
491 std::set<storm::RationalFunctionVariable> tmp = storm::utility::vector::getVariables(rewModel.getStateActionRewardVector());
492 vars.insert(tmp.begin(), tmp.end());
493 }
494 if (rewModel.hasStateRewards()) {
495 std::set<storm::RationalFunctionVariable> tmp = storm::utility::vector::getVariables(rewModel.getStateRewardVector());
496 vars.insert(tmp.begin(), tmp.end());
497 }
498 return vars;
499}
500
501// Explicitly instantiate the class.
502template std::vector<double> StandardRewardModel<double>::getTotalRewardVector(storm::storage::SparseMatrix<double> const& transitionMatrix) const;
503template std::vector<double> StandardRewardModel<double>::getTotalRewardVector(uint_fast64_t numberOfRows,
504 storm::storage::SparseMatrix<double> const& transitionMatrix,
505 storm::storage::BitVector const& filter) const;
506template std::vector<double> StandardRewardModel<double>::getTotalRewardVector(storm::storage::SparseMatrix<double> const& transitionMatrix,
507 std::vector<double> const& weights) const;
509 std::vector<double> const& stateRewardWeights) const;
512 std::function<bool(double const&)> const& filter) const;
515 std::function<bool(double const&)> const& filter) const;
516template double StandardRewardModel<double>::getStateActionAndTransitionReward(uint_fast64_t stateIndex,
517 storm::storage::SparseMatrix<double> const& transitionMatrix) const;
518template double StandardRewardModel<double>::getTotalStateActionReward(uint_fast64_t stateIndex, uint_fast64_t choiceIndex,
519 storm::storage::SparseMatrix<double> const& transitionMatrix,
520 double const& stateRewardWeight, double const& actionRewardWeight) const;
521template void StandardRewardModel<double>::clearRewardAtState(uint_fast64_t state, storm::storage::SparseMatrix<double> const& transitionMatrix);
522template void StandardRewardModel<double>::reduceToStateBasedRewards(storm::storage::SparseMatrix<double> const& transitionMatrix, bool reduceToStateRewards,
523 std::vector<double> const* weights);
524template void StandardRewardModel<double>::setStateActionReward(uint_fast64_t choiceIndex, double const& newValue);
525template void StandardRewardModel<double>::setStateReward(uint_fast64_t state, double const& newValue);
526template class StandardRewardModel<double>;
527template std::ostream& operator<< <double>(std::ostream& out, StandardRewardModel<double> const& rewardModel);
528
529#ifdef STORM_HAVE_CARL
530template std::vector<storm::RationalNumber> StandardRewardModel<storm::RationalNumber>::getTotalRewardVector(
531 uint_fast64_t numberOfRows, storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix, storm::storage::BitVector const& filter) const;
532template std::vector<storm::RationalNumber> StandardRewardModel<storm::RationalNumber>::getTotalRewardVector(
533 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix) const;
534template std::vector<storm::RationalNumber> StandardRewardModel<storm::RationalNumber>::getTotalRewardVector(
535 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix, std::vector<storm::RationalNumber> const& weights) const;
536template std::vector<storm::RationalNumber> StandardRewardModel<storm::RationalNumber>::getTotalActionRewardVector(
537 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix, std::vector<storm::RationalNumber> const& stateRewardWeights) const;
539 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix) const;
541 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix, std::function<bool(storm::RationalNumber const&)> const& filter) const;
543 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix) const;
545 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix, std::function<bool(storm::RationalNumber const&)> const& filter) const;
547 uint_fast64_t stateIndex, storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix) const;
549 uint_fast64_t stateIndex, uint_fast64_t choiceIndex, storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix,
550 storm::RationalNumber const& stateRewardWeight, storm::RationalNumber const& actionRewardWeight) const;
552 bool reduceToStateRewards,
553 std::vector<storm::RationalNumber> const* weights);
556template void StandardRewardModel<storm::RationalNumber>::setStateActionReward(uint_fast64_t choiceIndex, storm::RationalNumber const& newValue);
557template void StandardRewardModel<storm::RationalNumber>::setStateReward(uint_fast64_t state, storm::RationalNumber const& newValue);
559template std::ostream& operator<< <storm::RationalNumber>(std::ostream& out, StandardRewardModel<storm::RationalNumber> const& rewardModel);
560
561template std::vector<storm::RationalFunction> StandardRewardModel<storm::RationalFunction>::getTotalRewardVector(
562 uint_fast64_t numberOfRows, storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix, storm::storage::BitVector const& filter) const;
563template std::vector<storm::RationalFunction> StandardRewardModel<storm::RationalFunction>::getTotalRewardVector(
564 storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix) const;
565template std::vector<storm::RationalFunction> StandardRewardModel<storm::RationalFunction>::getTotalRewardVector(
566 storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix, std::vector<storm::RationalFunction> const& weights) const;
568 storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix) const;
570 storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix, std::function<bool(storm::RationalFunction const&)> const& filter) const;
572 storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix) const;
574 storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix, std::function<bool(storm::RationalFunction const&)> const& filter) const;
577template std::vector<storm::RationalFunction> StandardRewardModel<storm::RationalFunction>::getTotalActionRewardVector(
578 storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix, std::vector<storm::RationalFunction> const& stateRewardWeights) const;
580 uint_fast64_t stateIndex, storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix) const;
582 uint_fast64_t stateIndex, uint_fast64_t choiceIndex, storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix,
583 storm::RationalFunction const& stateRewardWeight, storm::RationalFunction const& actionRewardWeight) const;
585 storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix, bool reduceToStateRewards,
586 std::vector<storm::RationalFunction> const* weights);
587template void StandardRewardModel<storm::RationalFunction>::setStateActionReward(uint_fast64_t choiceIndex, storm::RationalFunction const& newValue);
588template void StandardRewardModel<storm::RationalFunction>::setStateReward(uint_fast64_t state, storm::RationalFunction const& newValue);
590template std::ostream& operator<< <storm::RationalFunction>(std::ostream& out, StandardRewardModel<storm::RationalFunction> const& rewardModel);
591
592template std::vector<storm::Interval> StandardRewardModel<storm::Interval>::getTotalRewardVector(uint_fast64_t numberOfRows,
593 storm::storage::SparseMatrix<double> const& transitionMatrix,
594 storm::storage::BitVector const& filter) const;
595template std::vector<storm::Interval> StandardRewardModel<storm::Interval>::getTotalRewardVector(
596 storm::storage::SparseMatrix<double> const& transitionMatrix) const;
597template std::vector<storm::Interval> StandardRewardModel<storm::Interval>::getTotalRewardVector(storm::storage::SparseMatrix<double> const& transitionMatrix,
598 std::vector<double> const& weights) const;
599template std::vector<storm::Interval> StandardRewardModel<storm::Interval>::getTotalRewardVector(
600 uint_fast64_t numberOfRows, storm::storage::SparseMatrix<storm::Interval> const& transitionMatrix, storm::storage::BitVector const& filter) const;
601template std::vector<storm::Interval> StandardRewardModel<storm::Interval>::getTotalRewardVector(
602 storm::storage::SparseMatrix<storm::Interval> const& transitionMatrix) const;
603template std::vector<storm::Interval> StandardRewardModel<storm::Interval>::getTotalRewardVector(
604 storm::storage::SparseMatrix<storm::Interval> const& transitionMatrix, std::vector<storm::Interval> const& weights) const;
605template std::vector<storm::Interval> StandardRewardModel<storm::Interval>::getTotalActionRewardVector(
606 storm::storage::SparseMatrix<double> const& transitionMatrix, std::vector<double> const& stateRewardWeights) const;
608 std::function<bool(storm::Interval const&)> const& filter) const;
610 storm::storage::SparseMatrix<storm::Interval> const& transitionMatrix, std::function<bool(storm::Interval const&)> const& filter) const;
612 std::function<bool(storm::Interval const&)> const& filter) const;
614 storm::storage::SparseMatrix<storm::Interval> const& transitionMatrix, std::function<bool(storm::Interval const&)> const& filter) const;
615template void StandardRewardModel<storm::Interval>::setStateActionReward(uint_fast64_t choiceIndex, double const& newValue);
616template void StandardRewardModel<storm::Interval>::setStateActionReward(uint_fast64_t choiceIndex, storm::Interval const& newValue);
617template void StandardRewardModel<storm::Interval>::setStateReward(uint_fast64_t state, double const& newValue);
618template void StandardRewardModel<storm::Interval>::setStateReward(uint_fast64_t state, storm::Interval const& newValue);
619template void StandardRewardModel<storm::Interval>::clearRewardAtState(uint_fast64_t state, storm::storage::SparseMatrix<double> const& transitionMatrix);
620template void StandardRewardModel<storm::Interval>::clearRewardAtState(uint_fast64_t state,
621 storm::storage::SparseMatrix<storm::Interval> const& transitionMatrix);
623 bool reduceToStateRewards, std::vector<double> const* weights);
625 bool reduceToStateRewards, std::vector<storm::Interval> const* weights);
627 storm::storage::SparseMatrix<storm::Interval> const& transitionMatrix) const;
629 storm::storage::SparseMatrix<storm::Interval> const& transitionMatrix) const;
631template std::ostream& operator<< <storm::Interval>(std::ostream& out, StandardRewardModel<storm::Interval> const& rewardModel);
632#endif
633} // namespace sparse
634
635} // namespace models
636} // namespace storm
Helper class that optionally holds a reference to an object of type T.
Definition OptionalRef.h:48
storm::storage::SparseMatrix< ValueType > const & getTransitionRewardMatrix() const
Retrieves the transition rewards of the reward model.
bool hasTransitionRewards() const
Retrieves whether the reward model has transition rewards.
StandardRewardModel< ValueType > restrictActions(storm::storage::BitVector const &enabledActions) const
Creates a new reward model by restricting the actions of the action-based rewards.
std::optional< storm::storage::SparseMatrix< ValueType > > const & getOptionalTransitionRewardMatrix() const
Retrieves an optional value that contains the transition reward matrix if there is one.
void setStateReward(uint_fast64_t state, T const &newReward)
bool hasOnlyStateRewards() const
Retrieves whether the reward model only has state rewards (and hence no other rewards).
std::vector< ValueType > getTotalActionRewardVector(storm::storage::SparseMatrix< MatrixValueType > const &transitionMatrix, std::vector< MatrixValueType > const &stateRewardWeights) const
Creates a vector representing the complete action-based rewards, i.e., state-action- and transition-b...
ValueType const & getStateReward(uint_fast64_t state) const
std::optional< std::vector< ValueType > > const & getOptionalStateRewardVector() const
Retrieves an optional value that contains the state reward vector if there is one.
std::vector< ValueType > const & getStateActionRewardVector() const
Retrieves the state-action rewards of the reward model.
std::vector< ValueType > const & getStateRewardVector() const
Retrieves the state rewards of the reward model.
storm::storage::BitVector getStatesWithZeroReward(storm::storage::SparseMatrix< MatrixValueType > const &transitionMatrix) const
Returns the set of states at which a all rewards (state-, action- and transition-rewards) are zero.
void clearRewardAtState(uint_fast64_t state, storm::storage::SparseMatrix< MatrixValueType > const &transitions)
Sets all available rewards at this state to zero.
ValueType const & getStateActionReward(uint_fast64_t choiceIndex) const
Retrieves the state-action reward for the given choice.
bool empty() const
Retrieves whether the reward model is empty, i.e.
ValueType getStateActionAndTransitionReward(uint_fast64_t choiceIndex, storm::storage::SparseMatrix< MatrixValueType > const &transitionMatrix) const
bool isCompatible(uint_fast64_t nrStates, uint_fast64_t nrChoices) const
Checks whether the reward model is compatible with key model characteristics.
std::vector< ValueType > getTotalRewardVector(storm::storage::SparseMatrix< MatrixValueType > const &transitionMatrix) const
Creates a vector representing the complete reward vector based on the state-, state-action- and trans...
void reduceToStateBasedRewards(storm::storage::SparseMatrix< MatrixValueType > const &transitionMatrix, bool reduceToStateRewards=false, std::vector< MatrixValueType > const *weights=nullptr)
Reduces the transition-based rewards to state-action rewards by taking the average of each row.
ValueType getTotalStateActionReward(uint_fast64_t stateIndex, uint_fast64_t choiceIndex, storm::storage::SparseMatrix< MatrixValueType > const &transitionMatrix, MatrixValueType const &stateRewardWeight=storm::utility::one< MatrixValueType >(), MatrixValueType const &actionRewardWeight=storm::utility::one< MatrixValueType >()) const
Retrieves the total reward for the given state action pair (including (scaled) state rewards,...
StandardRewardModel(std::optional< std::vector< ValueType > > const &optionalStateRewardVector=std::nullopt, std::optional< std::vector< ValueType > > const &optionalStateActionRewardVector=std::nullopt, std::optional< storm::storage::SparseMatrix< ValueType > > const &optionalTransitionRewardMatrix=std::nullopt)
Constructs a reward model by copying the given data.
bool hasStateRewards() const
Retrieves whether the reward model has state rewards.
bool hasStateActionRewards() const
Retrieves whether the reward model has state-action rewards.
storm::storage::BitVector getChoicesWithZeroReward(storm::storage::SparseMatrix< MatrixValueType > const &transitionMatrix) const
Returns the set of choices at which all rewards (state-, action- and transition-rewards) are zero.
bool isAllZero() const
Retrieves whether every reward defined by this reward model is zero.
storm::storage::BitVector getChoicesWithFilter(storm::storage::SparseMatrix< MatrixValueType > const &transitionMatrix, std::function< bool(ValueType const &)> const &filter) const
Returns the set of choices for which all associated rewards (state, action or transition rewards) sat...
void setStateActionReward(uint_fast64_t choiceIndex, T const &newValue)
Sets the state-action reward for the given choice.
storm::storage::BitVector getStatesWithFilter(storm::storage::SparseMatrix< MatrixValueType > const &transitionMatrix, std::function< bool(ValueType const &)> const &filter) const
Returns the set of states for which all associated rewards (state, action or transition rewards) sati...
StandardRewardModel< ValueType > permuteActions(std::vector< uint64_t > const &inversePermutation) const
Creates a new reward model by permuting the actions.
StandardRewardModel< ValueType > permuteStates(std::vector< uint64_t > const &inversePermutation, storm::OptionalRef< std::vector< uint64_t > const > rowGroupIndices=storm::NullRef, storm::OptionalRef< std::vector< uint64_t > const > permutation=storm::NullRef) const
Creates a new reward model by permuting the states.
std::optional< std::vector< ValueType > > const & getOptionalStateActionRewardVector() const
Retrieves an optional value that contains the state-action reward vector if there is one.
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
void set(uint_fast64_t index, bool value=true)
Sets the given truth value at the given index.
uint_fast64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
value_type const & getValue() const
Retrieves the value of the matrix entry.
A class that holds a possibly non-square matrix in the compressed row storage format.
std::vector< ResultValueType > getPointwiseProductRowSumVector(storm::storage::SparseMatrix< OtherValueType > const &otherMatrix) const
Performs a pointwise matrix multiplication of the matrix with the given matrix and returns a vector c...
index_type getRowGroupCount() const
Returns the number of row groups in the matrix.
ResultValueType getPointwiseProductRowSum(storm::storage::SparseMatrix< OtherValueType > const &otherMatrix, index_type const &row) const
Performs a pointwise multiplication of the entries in the given row of this matrix and the entries of...
std::vector< index_type > const & getRowGroupIndices() const
Returns the grouping of rows of this matrix.
index_type getRowCount() const
Returns the number of rows of the matrix.
storm::storage::BitVector getRowFilter(storm::storage::BitVector const &groupConstraint) const
Returns a bitvector representing the set of rows, with all indices set that correspond to one of the ...
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
std::set< storm::RationalFunctionVariable > getRewardModelParameters(StandardRewardModel< storm::RationalFunction > const &rewModel)
template std::ostream & operator<<< double >(std::ostream &out, StandardRewardModel< double > const &rewardModel)
std::ostream & operator<<(std::ostream &out, ChoiceLabeling const &labeling)
storm::storage::BitVector filter(std::vector< T > const &values, std::function< bool(T const &value)> const &function)
Retrieves a bit vector containing all the indices for which the value at this position makes the give...
Definition vector.h:530
void addVectors(std::vector< InValueType1 > const &firstOperand, std::vector< InValueType2 > const &secondOperand, std::vector< OutValueType > &target)
Adds the two given vectors and writes the result to the target vector.
Definition vector.h:443
void addVectorToGroupedVector(std::vector< T > &target, std::vector< T > const &source, std::vector< uint_fast64_t > const &rowGroupIndices)
Adds the source vector to the target vector in a way such that the i-th entry is added to all element...
Definition vector.h:310
void addFilteredVectorGroupsToGroupedVector(std::vector< T > &target, std::vector< T > const &source, storm::storage::BitVector const &filter, std::vector< uint_fast64_t > const &rowGroupIndices)
Definition vector.h:289
void selectVectorValues(std::vector< T > &vector, storm::storage::BitVector const &positions, std::vector< T > const &values)
Selects the elements from a vector at the specified positions and writes them consecutively into anot...
Definition vector.h:189
void multiplyVectorsPointwise(std::vector< InValueType1 > const &firstOperand, std::vector< InValueType2 > const &secondOperand, std::vector< OutValueType > &target)
Multiplies the two given vectors (pointwise) and writes the result to the target vector.
Definition vector.h:467
void addFilteredVectorToGroupedVector(std::vector< T > &target, std::vector< T > const &source, storm::storage::BitVector const &filter, std::vector< uint_fast64_t > const &rowGroupIndices)
Adds the source vector to the target vector in a way such that the i-th selected entry is added to al...
Definition vector.h:335
std::vector< T > applyInversePermutation(std::vector< uint64_t > const &inversePermutation, std::vector< T > const &source)
Definition vector.h:1267
std::set< storm::RationalFunctionVariable > getVariables(std::vector< storm::RationalFunction > const &vector)
std::vector< T > applyInversePermutationToGroupedVector(std::vector< uint64_t > const &inversePermutation, std::vector< T > const &source, std::vector< uint64_t > const &rowGroupIndices)
Definition vector.h:1277
bool isZero(ValueType const &a)
Definition constants.cpp:41
LabParser.cpp.
Definition cli.cpp:18