Browse Source

sparse/StandardRewardModel: Added a method that only yields the action-based rewards (excl. state rewards)

tempestpy_adaptions
Tim Quatmann 4 years ago
parent
commit
31dd1d8f49
  1. 30
      src/storm/models/sparse/StandardRewardModel.cpp
  2. 9
      src/storm/models/sparse/StandardRewardModel.h

30
src/storm/models/sparse/StandardRewardModel.cpp

@ -155,24 +155,20 @@ namespace storm {
template<typename ValueType>
template<typename MatrixValueType>
ValueType StandardRewardModel<ValueType>::getTotalStateActionReward(uint_fast64_t stateIndex, uint_fast64_t choiceIndex, storm::storage::SparseMatrix<MatrixValueType> const& transitionMatrix, MatrixValueType const& stateRewardWeight, MatrixValueType const& actionRewardWeight) const {
ValueType result = this->hasStateRewards() ? (this->hasStateActionRewards() ? (ValueType) (this->getStateReward(stateIndex) * stateRewardWeight + this->getStateActionReward(choiceIndex) * actionRewardWeight)
: (ValueType) (this->getStateReward(stateIndex) * stateRewardWeight))
: (this->hasStateActionRewards() ? (ValueType) (this->getStateActionReward(choiceIndex) * actionRewardWeight)
: storm::utility::zero<ValueType>());
ValueType StandardRewardModel<ValueType>::getStateActionAndTransitionReward(uint_fast64_t choiceIndex, storm::storage::SparseMatrix<MatrixValueType> const& transitionMatrix) const {
ValueType result = this->hasStateActionRewards() ? this->getStateActionReward(choiceIndex) : storm::utility::zero<ValueType>();
if (this->hasTransitionRewards()) {
auto rewMatrixEntryIt = this->getTransitionRewardMatrix().begin(choiceIndex);
for (auto const& transitionEntry : transitionMatrix.getRow(choiceIndex)) {
assert(rewMatrixEntryIt != this->getTransitionRewardMatrix().end(choiceIndex));
if (transitionEntry.getColumn() < rewMatrixEntryIt->getColumn()) {
continue;
} else {
// We assume that the transition reward matrix is a submatrix of the given transition matrix. Hence, the following must hold
assert(transitionEntry.getColumn() == rewMatrixEntryIt->getColumn());
result += actionRewardWeight * rewMatrixEntryIt->getValue() * storm::utility::convertNumber<ValueType>(transitionEntry.getValue());
++rewMatrixEntryIt;
}
}
result += transitionMatrix.getPointwiseProductRowSum(getTransitionRewardMatrix(), choiceIndex);
}
return result;
}
template<typename ValueType>
template<typename MatrixValueType>
ValueType StandardRewardModel<ValueType>::getTotalStateActionReward(uint_fast64_t stateIndex, uint_fast64_t choiceIndex, storm::storage::SparseMatrix<MatrixValueType> const& transitionMatrix, MatrixValueType const& stateRewardWeight, MatrixValueType const& actionRewardWeight) const {
ValueType result = actionRewardWeight * getStateActionAndTransitionReward(choiceIndex, transitionMatrix);
if (this->hasStateRewards()) {
result += stateRewardWeight * this->getStateReward(stateIndex);
}
return result;
}

9
src/storm/models/sparse/StandardRewardModel.h

@ -167,6 +167,15 @@ namespace storm {
*/
boost::optional<storm::storage::SparseMatrix<ValueType>> const& getOptionalTransitionRewardMatrix() const;
/*!
* @param choiceIndex The index of the considered choice
* @param transitionMatrix The matrix that is used to weight the values of the transition reward matrix.
* @return the sum of the action reward and the weighted transition rewards for the given choice, excluding potential state rewards
* @note returns zero if there is neither action nor transition reward.
*/
template<typename MatrixValueType>
ValueType getStateActionAndTransitionReward(uint_fast64_t choiceIndex, storm::storage::SparseMatrix<MatrixValueType> const& transitionMatrix) const;
/*!
* Retrieves the total reward for the given state action pair (including (scaled) state rewards, action rewards and transition rewards
*

Loading…
Cancel
Save