Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
StandardRewardModel.cpp
Go to the documentation of this file.
2
10
11namespace storm {
12namespace models {
13namespace sparse {
14template<typename ValueType>
15StandardRewardModel<ValueType>::StandardRewardModel(std::optional<std::vector<ValueType>> const& optionalStateRewardVector,
16 std::optional<std::vector<ValueType>> const& optionalStateActionRewardVector,
17 std::optional<storm::storage::SparseMatrix<ValueType>> const& optionalTransitionRewardMatrix)
18 : optionalStateRewardVector(optionalStateRewardVector),
19 optionalStateActionRewardVector(optionalStateActionRewardVector),
20 optionalTransitionRewardMatrix(optionalTransitionRewardMatrix) {
21 // Intentionally left empty.
22}
23
24template<typename ValueType>
25StandardRewardModel<ValueType>::StandardRewardModel(std::optional<std::vector<ValueType>>&& optionalStateRewardVector,
26 std::optional<std::vector<ValueType>>&& optionalStateActionRewardVector,
27 std::optional<storm::storage::SparseMatrix<ValueType>>&& optionalTransitionRewardMatrix)
28 : optionalStateRewardVector(std::move(optionalStateRewardVector)),
29 optionalStateActionRewardVector(std::move(optionalStateActionRewardVector)),
30 optionalTransitionRewardMatrix(std::move(optionalTransitionRewardMatrix)) {
31 // Intentionally left empty.
32}
33
34template<typename ValueType>
36 return static_cast<bool>(this->optionalStateRewardVector);
37}
38
39template<typename ValueType>
41 return static_cast<bool>(this->optionalStateRewardVector) && !static_cast<bool>(this->optionalStateActionRewardVector) &&
42 !static_cast<bool>(this->optionalTransitionRewardMatrix);
43}
44
45template<typename ValueType>
46std::vector<ValueType> const& StandardRewardModel<ValueType>::getStateRewardVector() const {
47 STORM_LOG_ASSERT(this->hasStateRewards(), "No state rewards available.");
48 return this->optionalStateRewardVector.value();
49}
50
51template<typename ValueType>
53 STORM_LOG_ASSERT(this->hasStateRewards(), "No state rewards available.");
54 return this->optionalStateRewardVector.value();
55}
56
57template<typename ValueType>
58std::optional<std::vector<ValueType>> const& StandardRewardModel<ValueType>::getOptionalStateRewardVector() const {
59 return this->optionalStateRewardVector;
61
62template<typename ValueType>
64 STORM_LOG_ASSERT(this->hasStateRewards(), "No state rewards available.");
65 STORM_LOG_ASSERT(state < this->optionalStateRewardVector.value().size(), "Invalid state.");
66 return this->optionalStateRewardVector.value()[state];
67}
69template<typename ValueType>
70template<typename T>
71void StandardRewardModel<ValueType>::setStateReward(uint_fast64_t state, T const& newReward) {
72 STORM_LOG_ASSERT(this->hasStateRewards(), "No state rewards available.");
73 STORM_LOG_ASSERT(state < this->optionalStateRewardVector.value().size(), "Invalid state.");
74 this->optionalStateRewardVector.value()[state] = newReward;
75}
76
77template<typename ValueType>
79 return static_cast<bool>(this->optionalStateActionRewardVector);
80}
82template<typename ValueType>
84 STORM_LOG_ASSERT(this->hasStateActionRewards(), "No state action rewards available.");
85 return this->optionalStateActionRewardVector.value();
86}
87
88template<typename ValueType>
90 STORM_LOG_ASSERT(this->hasStateActionRewards(), "No state action rewards available.");
91 return this->optionalStateActionRewardVector.value();
92}
93
94template<typename ValueType>
95ValueType const& StandardRewardModel<ValueType>::getStateActionReward(uint_fast64_t choiceIndex) const {
96 STORM_LOG_ASSERT(this->hasStateActionRewards(), "No state action rewards available.");
97 STORM_LOG_ASSERT(choiceIndex < this->optionalStateActionRewardVector.value().size(), "Invalid choiceIndex.");
98 return this->optionalStateActionRewardVector.value()[choiceIndex];
99}
100
101template<typename ValueType>
102template<typename T>
103void StandardRewardModel<ValueType>::setStateActionReward(uint_fast64_t choiceIndex, T const& newValue) {
104 STORM_LOG_ASSERT(this->hasStateActionRewards(), "No state action rewards available.");
105 STORM_LOG_ASSERT(choiceIndex < this->optionalStateActionRewardVector.value().size(), "Invalid choiceIndex.");
106 this->optionalStateActionRewardVector.value()[choiceIndex] = newValue;
107}
108
109template<typename ValueType>
110std::optional<std::vector<ValueType>> const& StandardRewardModel<ValueType>::getOptionalStateActionRewardVector() const {
111 return this->optionalStateActionRewardVector;
112}
113
114template<typename ValueType>
116 return static_cast<bool>(this->optionalTransitionRewardMatrix);
117}
118
119template<typename ValueType>
121 return this->optionalTransitionRewardMatrix.value();
122}
123
124template<typename ValueType>
126 return this->optionalTransitionRewardMatrix.value();
127}
128
129template<typename ValueType>
130std::optional<storm::storage::SparseMatrix<ValueType>> const& StandardRewardModel<ValueType>::getOptionalTransitionRewardMatrix() const {
131 return this->optionalTransitionRewardMatrix;
132}
133
134template<typename ValueType>
136 std::optional<std::vector<ValueType>> newStateRewardVector(this->getOptionalStateRewardVector());
137 std::optional<std::vector<ValueType>> newStateActionRewardVector;
139 newStateActionRewardVector = std::vector<ValueType>(enabledActions.getNumberOfSetBits());
140 storm::utility::vector::selectVectorValues(newStateActionRewardVector.value(), enabledActions, this->getStateActionRewardVector());
141 }
142 std::optional<storm::storage::SparseMatrix<ValueType>> newTransitionRewardMatrix;
143 if (this->hasTransitionRewards()) {
144 newTransitionRewardMatrix = this->getTransitionRewardMatrix().restrictRows(enabledActions);
146 return StandardRewardModel(std::move(newStateRewardVector), std::move(newStateActionRewardVector), std::move(newTransitionRewardMatrix));
147}
148
149template<typename ValueType>
150StandardRewardModel<ValueType> StandardRewardModel<ValueType>::permuteActions(std::vector<uint64_t> const& inversePermutation) const {
151 std::optional<std::vector<ValueType>> newStateRewardVector(this->getOptionalStateRewardVector());
152 std::optional<std::vector<ValueType>> newStateActionRewardVector;
154 newStateActionRewardVector = storm::utility::vector::applyInversePermutation(inversePermutation, this->getStateActionRewardVector());
155 }
156 std::optional<storm::storage::SparseMatrix<ValueType>> newTransitionRewardMatrix;
157 if (this->hasTransitionRewards()) {
158 newTransitionRewardMatrix = this->getTransitionRewardMatrix().permuteRows(inversePermutation);
159 }
160 return StandardRewardModel(std::move(newStateRewardVector), std::move(newStateActionRewardVector), std::move(newTransitionRewardMatrix));
161}
162
163template<typename ValueType>
165 storm::OptionalRef<std::vector<uint64_t> const> rowGroupIndices,
166 storm::OptionalRef<std::vector<uint64_t> const> permutation) const {
167 std::optional<std::vector<ValueType>> newStateRewardVector;
169 newStateRewardVector = storm::utility::vector::applyInversePermutation(inversePermutation, getStateRewardVector());
170 }
171 std::optional<std::vector<ValueType>> newStateActionRewardVector;
172 if (this->hasStateActionRewards()) {
173 if (rowGroupIndices) {
174 newStateActionRewardVector =
175 storm::utility::vector::applyInversePermutationToGroupedVector(inversePermutation, this->getStateActionRewardVector(), rowGroupIndices.value());
176 } else {
177 STORM_LOG_ASSERT(inversePermutation.size() == this->getStateActionRewardVector().size(), "Invalid permutation size.");
178 newStateActionRewardVector = storm::utility::vector::applyInversePermutation(inversePermutation, this->getStateActionRewardVector());
179 }
180 }
181 std::optional<storm::storage::SparseMatrix<ValueType>> newTransitionRewardMatrix;
182 if (this->hasTransitionRewards()) {
183 STORM_LOG_ASSERT(permutation, "Permutation required for transition rewards.");
184 STORM_LOG_ASSERT(rowGroupIndices.has_value() != getTransitionRewardMatrix().hasTrivialRowGrouping(),
185 "Row group indices required for transition rewards.");
186 this->getTransitionRewardMatrix().permuteRowGroupsAndColumns(inversePermutation, permutation.value());
187 }
188
189 return StandardRewardModel(std::move(newStateRewardVector), std::move(newStateActionRewardVector), std::move(newTransitionRewardMatrix));
191
192template<typename ValueType>
193template<typename MatrixValueType>
195 storm::storage::SparseMatrix<MatrixValueType> const& transitionMatrix) const {
197 if (this->hasTransitionRewards()) {
198 result += transitionMatrix.getPointwiseProductRowSum(getTransitionRewardMatrix(), choiceIndex);
199 }
200 return result;
202
203template<typename ValueType>
204template<typename MatrixValueType>
205ValueType StandardRewardModel<ValueType>::getTotalStateActionReward(uint_fast64_t stateIndex, uint_fast64_t choiceIndex,
206 storm::storage::SparseMatrix<MatrixValueType> const& transitionMatrix,
207 MatrixValueType const& stateRewardWeight, MatrixValueType const& actionRewardWeight) const {
208 ValueType result = actionRewardWeight * getStateActionAndTransitionReward(choiceIndex, transitionMatrix);
209 if (this->hasStateRewards()) {
210 result += stateRewardWeight * this->getStateReward(stateIndex);
211 }
212 return result;
213}
214
215template<typename ValueType>
216template<typename MatrixValueType>
218 std::vector<MatrixValueType> const* weights) {
219 if (this->hasTransitionRewards()) {
220 STORM_LOG_ASSERT(this->getTransitionRewardMatrix().isSubmatrixOf(transitionMatrix),
221 "Transition reward matrix is not a submatrix of the transition matrix.");
222 if (this->hasStateActionRewards()) {
224 transitionMatrix.getPointwiseProductRowSumVector(this->getTransitionRewardMatrix()),
225 this->getStateActionRewardVector());
226 } else {
227 this->optionalStateActionRewardVector = transitionMatrix.getPointwiseProductRowSumVector(this->getTransitionRewardMatrix());
228 }
229 this->optionalTransitionRewardMatrix = std::nullopt;
230 }
231
232 if (reduceToStateRewards && this->hasStateActionRewards()) {
233 STORM_LOG_THROW(transitionMatrix.getRowGroupCount() == this->getStateActionRewardVector().size(), storm::exceptions::InvalidOperationException,
234 "The reduction to state rewards is only possible if the size of the action reward vector equals the number of states.");
235 if (weights) {
236 if (this->hasStateRewards()) {
238 this->getStateActionRewardVector(), *weights, this->getStateRewardVector(),
239 [](ValueType const& sar, MatrixValueType const& w, ValueType const& sr) -> ValueType { return sr + w * sar; });
240 } else {
241 this->optionalStateRewardVector = std::move(this->optionalStateActionRewardVector);
243 this->optionalStateRewardVector.value(), *weights, this->optionalStateRewardVector.value());
244 }
245 } else {
246 if (this->hasStateRewards()) {
247 storm::utility::vector::addVectors<ValueType>(this->getStateActionRewardVector(), this->getStateRewardVector(), this->getStateRewardVector());
248 } else {
249 this->optionalStateRewardVector = std::move(this->optionalStateActionRewardVector);
250 }
251 }
252 this->optionalStateActionRewardVector = std::nullopt;
253 }
254}
255
256template<typename ValueType>
257template<typename MatrixValueType>
259 std::vector<ValueType> result =
263 : std::vector<ValueType>(transitionMatrix.getRowCount(), storm::utility::zero<ValueType>()));
264 if (this->hasStateActionRewards() && this->hasTransitionRewards()) {
266 }
267 if (this->hasStateRewards()) {
269 }
270 return result;
271}
272
273template<typename ValueType>
274template<typename MatrixValueType>
276 std::vector<MatrixValueType> const& weights) const {
277 std::vector<ValueType> result;
278 if (this->hasTransitionRewards()) {
279 result = transitionMatrix.getPointwiseProductRowSumVector(this->getTransitionRewardMatrix());
281 weights, this->getStateActionRewardVector(), result,
282 [](MatrixValueType const& weight, ValueType const& rewardElement, ValueType const& resultElement) {
283 return weight * (resultElement + rewardElement);
284 });
285 } else {
286 result = std::vector<ValueType>(transitionMatrix.getRowCount(), storm::utility::zero<ValueType>());
287 if (this->hasStateActionRewards()) {
289 weights, this->getStateActionRewardVector(), result,
290 [](MatrixValueType const& weight, ValueType const& rewardElement) { return weight * rewardElement; });
291 }
293 if (this->hasStateRewards()) {
294 storm::utility::vector::addVectorToGroupedVector(result, this->getStateRewardVector(), transitionMatrix.getRowGroupIndices());
295 }
296 return result;
297}
298
299template<typename ValueType>
300template<typename MatrixValueType>
301std::vector<ValueType> StandardRewardModel<ValueType>::getTotalRewardVector(uint_fast64_t numberOfRows,
302 storm::storage::SparseMatrix<MatrixValueType> const& transitionMatrix,
303 storm::storage::BitVector const& filter) const {
304 std::vector<ValueType> result(numberOfRows, storm::utility::zero<ValueType>());
305 if (this->hasTransitionRewards()) {
306 std::vector<ValueType> pointwiseProductRowSumVector = transitionMatrix.getPointwiseProductRowSumVector(this->getTransitionRewardMatrix());
307 storm::utility::vector::selectVectorValues(result, filter, transitionMatrix.getRowGroupIndices(), pointwiseProductRowSumVector);
308 }
310 if (this->hasStateActionRewards()) {
312 transitionMatrix.getRowGroupIndices());
313 }
314 if (this->hasStateRewards()) {
315 storm::utility::vector::addFilteredVectorToGroupedVector(result, this->getStateRewardVector(), filter, transitionMatrix.getRowGroupIndices());
317 return result;
318}
319
320template<typename ValueType>
321template<typename MatrixValueType>
323 std::vector<MatrixValueType> const& stateRewardWeights) const {
324 std::vector<ValueType> result;
325 if (this->hasTransitionRewards()) {
326 result = transitionMatrix.getPointwiseProductRowSumVector(this->getTransitionRewardMatrix());
327 } else {
328 result = std::vector<ValueType>(transitionMatrix.getRowCount(), storm::utility::zero<ValueType>());
329 }
330 if (this->hasStateActionRewards()) {
331 storm::utility::vector::addVectors(result, this->getStateActionRewardVector(), result);
333 if (this->hasStateRewards()) {
334 std::vector<ValueType> scaledStateRewardVector(transitionMatrix.getRowGroupCount());
335 storm::utility::vector::multiplyVectorsPointwise(this->getStateRewardVector(), stateRewardWeights, scaledStateRewardVector);
336 storm::utility::vector::addVectorToGroupedVector(result, scaledStateRewardVector, transitionMatrix.getRowGroupIndices());
338 return result;
339}
340
341template<typename ValueType>
342template<typename MatrixValueType>
346
347template<typename ValueType>
348template<typename MatrixValueType>
350 std::function<bool(ValueType const&)> const& filter) const {
352 : storm::storage::BitVector(transitionMatrix.getRowGroupCount(), true);
353 if (this->hasStateActionRewards()) {
354 for (uint_fast64_t state = 0; state < transitionMatrix.getRowGroupCount(); ++state) {
355 for (uint_fast64_t row = transitionMatrix.getRowGroupIndices()[state]; row < transitionMatrix.getRowGroupIndices()[state + 1]; ++row) {
356 if (!filter(this->getStateActionRewardVector()[row])) {
357 result.set(state, false);
358 break;
359 }
360 }
361 }
362 }
363 if (this->hasTransitionRewards()) {
364 for (uint_fast64_t state = 0; state < transitionMatrix.getRowGroupCount(); ++state) {
365 for (auto const& rewardMatrixEntry : this->getTransitionRewardMatrix().getRowGroup(state)) {
366 if (!filter(rewardMatrixEntry.getValue())) {
367 result.set(state, false);
368 break;
369 }
370 }
371 }
372 }
373 return result;
374}
375
376template<typename ValueType>
377template<typename MatrixValueType>
382
383template<typename ValueType>
384template<typename MatrixValueType>
386 std::function<bool(ValueType const&)> const& filter) const {
388 if (this->hasStateActionRewards()) {
390 if (this->hasStateRewards()) {
391 result &= transitionMatrix.getRowFilter(storm::utility::vector::filter(this->getStateRewardVector(), filter));
392 }
393 } else {
394 if (this->hasStateRewards()) {
395 result = transitionMatrix.getRowFilter(storm::utility::vector::filter(this->getStateRewardVector(), filter));
396 } else {
397 result = storm::storage::BitVector(transitionMatrix.getRowCount(), true);
398 }
399 }
400 if (this->hasTransitionRewards()) {
401 for (uint_fast64_t row = 0; row < transitionMatrix.getRowCount(); ++row) {
402 for (auto const& rewardMatrixEntry : this->getTransitionRewardMatrix().getRow(row)) {
403 if (!filter(rewardMatrixEntry.getValue())) {
404 result.set(row, false);
405 break;
406 }
407 }
408 }
409 }
410 return result;
411}
412
413template<typename ValueType>
414template<typename MatrixValueType>
416 if (hasStateRewards()) {
418 }
419 if (hasStateActionRewards()) {
420 for (uint_fast64_t choice = transitions.getRowGroupIndices()[state]; choice < transitions.getRowGroupIndices()[state + 1]; ++choice) {
422 }
423 }
424 if (hasTransitionRewards()) {
425 for (auto& entry : getTransitionRewardMatrix().getRowGroup(state)) {
426 entry.setValue(storm::utility::zero<ValueType>());
427 }
428 }
429}
430
431template<typename ValueType>
433 return !(static_cast<bool>(this->optionalStateRewardVector) || static_cast<bool>(this->optionalStateActionRewardVector) ||
434 static_cast<bool>(this->optionalTransitionRewardMatrix));
435}
436
440template<typename ValueType>
441bool anyOfRewardValues(StandardRewardModel<ValueType> const& rewardModel, auto const& predicate) {
442 if (rewardModel.hasStateRewards() && std::any_of(rewardModel.getStateRewardVector().begin(), rewardModel.getStateRewardVector().end(), predicate)) {
443 return true;
444 }
445 if (rewardModel.hasStateActionRewards() &&
446 std::any_of(rewardModel.getStateActionRewardVector().begin(), rewardModel.getStateActionRewardVector().end(), predicate)) {
447 return true;
448 }
449 if (rewardModel.hasTransitionRewards()) {
450 for (auto const& entry : rewardModel.getTransitionRewardMatrix()) {
451 if (predicate(entry.getValue())) {
452 return true;
453 }
454 }
455 }
456 return false;
457}
458
459template<typename ValueType>
461 bool const hasNonZeroReward = anyOfRewardValues(*this, [](auto&& value) { return !storm::utility::isZero<ValueType>(value); });
462 return !hasNonZeroReward;
463}
464
465template<typename ValueType>
467 if constexpr (std::is_same_v<ValueType, storm::RationalFunction>) {
468 // Rational functions can never be negative.
469 STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Checking Rational functions for negativity is not possible.");
470 return false;
471 } else {
472 return anyOfRewardValues(*this, [](auto&& value) { return value < storm::utility::zero<ValueType>(); });
473 }
474}
475
476template<typename ValueType>
478 if constexpr (std::is_same_v<ValueType, storm::RationalFunction>) {
479 // Rational functions can never be negative.
480 STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Checking Rational functions for negativity is not possible.");
481 return false;
482 } else {
483 return anyOfRewardValues(*this, [](auto&& value) { return value > storm::utility::zero<ValueType>(); });
484 }
485}
486
487template<typename ValueType>
488bool StandardRewardModel<ValueType>::isCompatible(uint_fast64_t nrStates, uint_fast64_t nrChoices) const {
489 if (hasStateRewards()) {
490 if (optionalStateRewardVector.value().size() != nrStates) {
491 return false;
492 }
493 }
494 if (hasStateActionRewards()) {
495 if (optionalStateActionRewardVector.value().size() != nrChoices) {
496 return false;
497 }
498 }
499 return true;
500}
501
502template<typename ValueType>
504 size_t seed = 0;
505 if (hasStateRewards()) {
506 boost::hash_combine(seed, boost::hash_range(optionalStateRewardVector->begin(), optionalStateRewardVector->end()));
507 }
508 if (hasStateActionRewards()) {
509 boost::hash_combine(seed, boost::hash_range(optionalStateActionRewardVector->begin(), optionalStateActionRewardVector->end()));
510 }
511 if (hasTransitionRewards()) {
512 boost::hash_combine(seed, optionalTransitionRewardMatrix->hash());
513 }
514 return seed;
515}
516
517template<typename ValueType>
518std::ostream& operator<<(std::ostream& out, StandardRewardModel<ValueType> const& rewardModel) {
519 out << std::boolalpha << "reward model [state reward: " << rewardModel.hasStateRewards()
520 << ", state-action rewards: " << rewardModel.hasStateActionRewards() << ", transition rewards: " << rewardModel.hasTransitionRewards() << "]"
521 << std::noboolalpha;
522 return out;
523}
524
525std::set<storm::RationalFunctionVariable> getRewardModelParameters(StandardRewardModel<storm::RationalFunction> const& rewModel) {
526 std::set<storm::RationalFunctionVariable> vars;
527 if (rewModel.hasTransitionRewards()) {
529 }
530 if (rewModel.hasStateActionRewards()) {
531 std::set<storm::RationalFunctionVariable> tmp = storm::utility::vector::getVariables(rewModel.getStateActionRewardVector());
532 vars.insert(tmp.begin(), tmp.end());
533 }
534 if (rewModel.hasStateRewards()) {
535 std::set<storm::RationalFunctionVariable> tmp = storm::utility::vector::getVariables(rewModel.getStateRewardVector());
536 vars.insert(tmp.begin(), tmp.end());
537 }
538 return vars;
539}
540
541// Explicitly instantiate the class.
542template std::vector<double> StandardRewardModel<double>::getTotalRewardVector(storm::storage::SparseMatrix<double> const& transitionMatrix) const;
543template std::vector<double> StandardRewardModel<double>::getTotalRewardVector(uint_fast64_t numberOfRows,
544 storm::storage::SparseMatrix<double> const& transitionMatrix,
545 storm::storage::BitVector const& filter) const;
546template std::vector<double> StandardRewardModel<double>::getTotalRewardVector(storm::storage::SparseMatrix<double> const& transitionMatrix,
547 std::vector<double> const& weights) const;
549 std::vector<double> const& stateRewardWeights) const;
552 std::function<bool(double const&)> const& filter) const;
555 std::function<bool(double const&)> const& filter) const;
556template double StandardRewardModel<double>::getStateActionAndTransitionReward(uint_fast64_t stateIndex,
557 storm::storage::SparseMatrix<double> const& transitionMatrix) const;
558template double StandardRewardModel<double>::getTotalStateActionReward(uint_fast64_t stateIndex, uint_fast64_t choiceIndex,
559 storm::storage::SparseMatrix<double> const& transitionMatrix,
560 double const& stateRewardWeight, double const& actionRewardWeight) const;
561template void StandardRewardModel<double>::clearRewardAtState(uint_fast64_t state, storm::storage::SparseMatrix<double> const& transitionMatrix);
562template void StandardRewardModel<double>::reduceToStateBasedRewards(storm::storage::SparseMatrix<double> const& transitionMatrix, bool reduceToStateRewards,
563 std::vector<double> const* weights);
564template void StandardRewardModel<double>::setStateActionReward(uint_fast64_t choiceIndex, double const& newValue);
565template void StandardRewardModel<double>::setStateReward(uint_fast64_t state, double const& newValue);
566template class StandardRewardModel<double>;
567template std::ostream& operator<< <double>(std::ostream& out, StandardRewardModel<double> const& rewardModel);
568
569template std::vector<storm::RationalNumber> StandardRewardModel<storm::RationalNumber>::getTotalRewardVector(
570 uint_fast64_t numberOfRows, storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix, storm::storage::BitVector const& filter) const;
571template std::vector<storm::RationalNumber> StandardRewardModel<storm::RationalNumber>::getTotalRewardVector(
572 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix) const;
573template std::vector<storm::RationalNumber> StandardRewardModel<storm::RationalNumber>::getTotalRewardVector(
574 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix, std::vector<storm::RationalNumber> const& weights) const;
575template std::vector<storm::RationalNumber> StandardRewardModel<storm::RationalNumber>::getTotalActionRewardVector(
576 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix, std::vector<storm::RationalNumber> const& stateRewardWeights) const;
578 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix) const;
580 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix, std::function<bool(storm::RationalNumber const&)> const& filter) const;
582 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix) const;
584 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix, std::function<bool(storm::RationalNumber const&)> const& filter) const;
586 uint_fast64_t stateIndex, storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix) const;
588 uint_fast64_t stateIndex, uint_fast64_t choiceIndex, storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix,
589 storm::RationalNumber const& stateRewardWeight, storm::RationalNumber const& actionRewardWeight) const;
591 bool reduceToStateRewards,
592 std::vector<storm::RationalNumber> const* weights);
595template void StandardRewardModel<storm::RationalNumber>::setStateActionReward(uint_fast64_t choiceIndex, storm::RationalNumber const& newValue);
596template void StandardRewardModel<storm::RationalNumber>::setStateReward(uint_fast64_t state, storm::RationalNumber const& newValue);
598template std::ostream& operator<< <storm::RationalNumber>(std::ostream& out, StandardRewardModel<storm::RationalNumber> const& rewardModel);
599
600template std::vector<storm::RationalFunction> StandardRewardModel<storm::RationalFunction>::getTotalRewardVector(
601 uint_fast64_t numberOfRows, storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix, storm::storage::BitVector const& filter) const;
602template std::vector<storm::RationalFunction> StandardRewardModel<storm::RationalFunction>::getTotalRewardVector(
603 storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix) const;
604template std::vector<storm::RationalFunction> StandardRewardModel<storm::RationalFunction>::getTotalRewardVector(
605 storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix, std::vector<storm::RationalFunction> const& weights) const;
607 storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix) const;
609 storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix, std::function<bool(storm::RationalFunction const&)> const& filter) const;
611 storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix) const;
613 storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix, std::function<bool(storm::RationalFunction const&)> const& filter) const;
616template std::vector<storm::RationalFunction> StandardRewardModel<storm::RationalFunction>::getTotalActionRewardVector(
617 storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix, std::vector<storm::RationalFunction> const& stateRewardWeights) const;
619 uint_fast64_t stateIndex, storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix) const;
621 uint_fast64_t stateIndex, uint_fast64_t choiceIndex, storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix,
622 storm::RationalFunction const& stateRewardWeight, storm::RationalFunction const& actionRewardWeight) const;
624 storm::storage::SparseMatrix<storm::RationalFunction> const& transitionMatrix, bool reduceToStateRewards,
625 std::vector<storm::RationalFunction> const* weights);
626template void StandardRewardModel<storm::RationalFunction>::setStateActionReward(uint_fast64_t choiceIndex, storm::RationalFunction const& newValue);
627template void StandardRewardModel<storm::RationalFunction>::setStateReward(uint_fast64_t state, storm::RationalFunction const& newValue);
629template std::ostream& operator<< <storm::RationalFunction>(std::ostream& out, StandardRewardModel<storm::RationalFunction> const& rewardModel);
630
631template std::vector<storm::Interval> StandardRewardModel<storm::Interval>::getTotalRewardVector(uint_fast64_t numberOfRows,
632 storm::storage::SparseMatrix<double> const& transitionMatrix,
633 storm::storage::BitVector const& filter) const;
634template std::vector<storm::Interval> StandardRewardModel<storm::Interval>::getTotalRewardVector(
635 storm::storage::SparseMatrix<double> const& transitionMatrix) const;
636template std::vector<storm::Interval> StandardRewardModel<storm::Interval>::getTotalRewardVector(storm::storage::SparseMatrix<double> const& transitionMatrix,
637 std::vector<double> const& weights) const;
638template std::vector<storm::Interval> StandardRewardModel<storm::Interval>::getTotalRewardVector(
639 uint_fast64_t numberOfRows, storm::storage::SparseMatrix<storm::Interval> const& transitionMatrix, storm::storage::BitVector const& filter) const;
640template std::vector<storm::Interval> StandardRewardModel<storm::Interval>::getTotalRewardVector(
641 storm::storage::SparseMatrix<storm::Interval> const& transitionMatrix) const;
642template std::vector<storm::Interval> StandardRewardModel<storm::Interval>::getTotalRewardVector(
643 storm::storage::SparseMatrix<storm::Interval> const& transitionMatrix, std::vector<storm::Interval> const& weights) const;
644template std::vector<storm::Interval> StandardRewardModel<storm::Interval>::getTotalActionRewardVector(
645 storm::storage::SparseMatrix<double> const& transitionMatrix, std::vector<double> const& stateRewardWeights) const;
647 std::function<bool(storm::Interval const&)> const& filter) const;
649 storm::storage::SparseMatrix<storm::Interval> const& transitionMatrix, std::function<bool(storm::Interval const&)> const& filter) const;
651 std::function<bool(storm::Interval const&)> const& filter) const;
653 storm::storage::SparseMatrix<storm::Interval> const& transitionMatrix, std::function<bool(storm::Interval const&)> const& filter) const;
654template void StandardRewardModel<storm::Interval>::setStateActionReward(uint_fast64_t choiceIndex, double const& newValue);
655template void StandardRewardModel<storm::Interval>::setStateActionReward(uint_fast64_t choiceIndex, storm::Interval const& newValue);
656template void StandardRewardModel<storm::Interval>::setStateReward(uint_fast64_t state, double const& newValue);
657template void StandardRewardModel<storm::Interval>::setStateReward(uint_fast64_t state, storm::Interval const& newValue);
658template void StandardRewardModel<storm::Interval>::clearRewardAtState(uint_fast64_t state, storm::storage::SparseMatrix<double> const& transitionMatrix);
659template void StandardRewardModel<storm::Interval>::clearRewardAtState(uint_fast64_t state,
660 storm::storage::SparseMatrix<storm::Interval> const& transitionMatrix);
662 bool reduceToStateRewards, std::vector<double> const* weights);
664 bool reduceToStateRewards, std::vector<storm::Interval> const* weights);
666 storm::storage::SparseMatrix<storm::Interval> const& transitionMatrix) const;
668 storm::storage::SparseMatrix<storm::Interval> const& transitionMatrix) const;
670template std::ostream& operator<< <storm::Interval>(std::ostream& out, StandardRewardModel<storm::Interval> const& rewardModel);
671
672template std::vector<storm::RationalInterval> StandardRewardModel<storm::RationalInterval>::getTotalRewardVector(
673 uint_fast64_t numberOfRows, storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix, storm::storage::BitVector const& filter) const;
674template std::vector<storm::RationalInterval> StandardRewardModel<storm::RationalInterval>::getTotalRewardVector(
675 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix) const;
676template std::vector<storm::RationalInterval> StandardRewardModel<storm::RationalInterval>::getTotalRewardVector(
677 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix, std::vector<storm::RationalNumber> const& weights) const;
678template std::vector<storm::RationalInterval> StandardRewardModel<storm::RationalInterval>::getTotalRewardVector(
679 uint_fast64_t numberOfRows, storm::storage::SparseMatrix<storm::RationalInterval> const& transitionMatrix, storm::storage::BitVector const& filter) const;
680template std::vector<storm::RationalInterval> StandardRewardModel<storm::RationalInterval>::getTotalRewardVector(
681 storm::storage::SparseMatrix<storm::RationalInterval> const& transitionMatrix) const;
682template std::vector<storm::RationalInterval> StandardRewardModel<storm::RationalInterval>::getTotalRewardVector(
683 storm::storage::SparseMatrix<storm::RationalInterval> const& transitionMatrix, std::vector<storm::RationalInterval> const& weights) const;
684template std::vector<storm::RationalInterval> StandardRewardModel<storm::RationalInterval>::getTotalActionRewardVector(
685 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix, std::vector<storm::RationalNumber> const& stateRewardWeights) const;
687 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix, std::function<bool(storm::RationalInterval const&)> const& filter) const;
689 storm::storage::SparseMatrix<storm::RationalInterval> const& transitionMatrix, std::function<bool(storm::RationalInterval const&)> const& filter) const;
691 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix, std::function<bool(storm::RationalInterval const&)> const& filter) const;
693 storm::storage::SparseMatrix<storm::RationalInterval> const& transitionMatrix, std::function<bool(storm::RationalInterval const&)> const& filter) const;
694template void StandardRewardModel<storm::RationalInterval>::setStateActionReward(uint_fast64_t choiceIndex, storm::RationalNumber const& newValue);
695template void StandardRewardModel<storm::RationalInterval>::setStateActionReward(uint_fast64_t choiceIndex, storm::RationalInterval const& newValue);
696template void StandardRewardModel<storm::RationalInterval>::setStateReward(uint_fast64_t state, storm::RationalNumber const& newValue);
697template void StandardRewardModel<storm::RationalInterval>::setStateReward(uint_fast64_t state, storm::RationalInterval const& newValue);
703 storm::storage::SparseMatrix<storm::RationalNumber> const& transitionMatrix, bool reduceToStateRewards, std::vector<storm::RationalNumber> const* weights);
705 storm::storage::SparseMatrix<storm::RationalInterval> const& transitionMatrix, bool reduceToStateRewards,
706 std::vector<storm::RationalInterval> const* weights);
708 storm::storage::SparseMatrix<storm::RationalInterval> const& transitionMatrix) const;
710 storm::storage::SparseMatrix<storm::RationalInterval> const& transitionMatrix) const;
712template std::ostream& operator<< <storm::RationalInterval>(std::ostream& out, StandardRewardModel<storm::RationalInterval> const& rewardModel);
713} // namespace sparse
714
715} // namespace models
716} // 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.
ValueType getStateActionAndTransitionReward(uint_fast64_t choiceIndex, storm::storage::SparseMatrix< MatrixValueType > const &transitionMatrix) const
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).
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,...
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.
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.
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.
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...
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:16
uint64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
void set(uint64_t index, bool value=true)
Sets the given truth value at the given index.
A class that holds a possibly non-square matrix in the compressed row storage format.
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...
index_type getRowGroupCount() const
Returns the number of row groups in the matrix.
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...
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:9
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
template std::ostream & operator<<< storm::RationalInterval >(std::ostream &out, StandardRewardModel< storm::RationalInterval > const &rewardModel)
std::set< storm::RationalFunctionVariable > getRewardModelParameters(StandardRewardModel< storm::RationalFunction > const &rewModel)
template std::ostream & operator<<< storm::RationalFunction >(std::ostream &out, StandardRewardModel< storm::RationalFunction > const &rewardModel)
template std::ostream & operator<<< double >(std::ostream &out, StandardRewardModel< double > const &rewardModel)
template std::ostream & operator<<< storm::Interval >(std::ostream &out, StandardRewardModel< storm::Interval > const &rewardModel)
std::ostream & operator<<(std::ostream &out, ChoiceLabeling const &labeling)
bool anyOfRewardValues(StandardRewardModel< ValueType > const &rewardModel, auto const &predicate)
Auxiliary function to check if the given predicate is true for any of the reward values in the given ...
template std::ostream & operator<<< storm::RationalNumber >(std::ostream &out, StandardRewardModel< storm::RationalNumber > const &rewardModel)
std::set< storm::RationalFunctionVariable > getVariables(SparseMatrix< storm::RationalFunction > const &matrix)
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:487
void applyPointwiseTernary(std::vector< InValueType1 > const &firstOperand, std::vector< InValueType2 > const &secondOperand, std::vector< OutValueType > &target, Operation f=Operation())
Applies the given operation pointwise on the two given vectors and writes the result to the third vec...
Definition vector.h:352
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:400
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:306
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:285
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:185
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:424
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:331
void applyPointwise(std::vector< InValueType1 > const &firstOperand, std::vector< InValueType2 > const &secondOperand, std::vector< OutValueType > &target, Operation f=Operation())
Applies the given operation pointwise on the two given vectors and writes the result to the third vec...
Definition vector.h:375
std::vector< T > applyInversePermutation(std::vector< uint64_t > const &inversePermutation, std::vector< T > const &source)
Definition vector.h:1157
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:1167
bool isZero(ValueType const &a)
Definition constants.cpp:44
ValueType zero()
Definition constants.cpp:26
carl::Interval< storm::RationalNumber > RationalInterval
carl::Interval< double > Interval
Interval type.
carl::RationalFunction< Polynomial, true > RationalFunction