From a53b7ca0050856e73617c06944febee0c33bcae3 Mon Sep 17 00:00:00 2001 From: Sebastian Junges Date: Fri, 24 Jan 2020 18:21:57 +0100 Subject: [PATCH] permute actions in reward models --- src/storm/models/sparse/StandardRewardModel.cpp | 14 ++++++++++++++ src/storm/models/sparse/StandardRewardModel.h | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/src/storm/models/sparse/StandardRewardModel.cpp b/src/storm/models/sparse/StandardRewardModel.cpp index 190449ea6..159c39446 100644 --- a/src/storm/models/sparse/StandardRewardModel.cpp +++ b/src/storm/models/sparse/StandardRewardModel.cpp @@ -138,6 +138,20 @@ namespace storm { } return StandardRewardModel(std::move(newStateRewardVector), std::move(newStateActionRewardVector), std::move(newTransitionRewardMatrix)); } + + template + StandardRewardModel StandardRewardModel::permuteActions(std::vector const& inversePermutation) const { + boost::optional> newStateRewardVector(this->getOptionalStateRewardVector()); + boost::optional> newStateActionRewardVector; + if (this->hasStateActionRewards()) { + newStateActionRewardVector = storm::utility::vector::applyInversePermutation(inversePermutation, this->getStateActionRewardVector()); + } + boost::optional> newTransitionRewardMatrix; + if (this->hasTransitionRewards()) { + newTransitionRewardMatrix = this->getTransitionRewardMatrix().permuteRows(inversePermutation); + } + return StandardRewardModel(std::move(newStateRewardVector), std::move(newStateActionRewardVector), std::move(newTransitionRewardMatrix)); + } template template diff --git a/src/storm/models/sparse/StandardRewardModel.h b/src/storm/models/sparse/StandardRewardModel.h index ac725d06c..2bfed8143 100644 --- a/src/storm/models/sparse/StandardRewardModel.h +++ b/src/storm/models/sparse/StandardRewardModel.h @@ -187,6 +187,13 @@ namespace storm { * @return The restricted reward model. */ StandardRewardModel restrictActions(storm::storage::BitVector const& enabledActions) const; + + /*! + * Creates a new reward model by permuting the actions. + * That is, in row i, write the action reward of row inversePermutation[i]. + * + */ + StandardRewardModel permuteActions(std::vector const& inversePermutation) const; /*! * Reduces the transition-based rewards to state-action rewards by taking the average of each row. If