diff --git a/src/models/sparse/StandardRewardModel.cpp b/src/models/sparse/StandardRewardModel.cpp index 3bd624d3d..c8fd2aa8f 100644 --- a/src/models/sparse/StandardRewardModel.cpp +++ b/src/models/sparse/StandardRewardModel.cpp @@ -145,15 +145,15 @@ namespace storm { if (this->hasTransitionRewards()) { if (this->hasStateActionRewards()) { storm::utility::vector::addVectors(this->getStateActionRewardVector(), transitionMatrix.getPointwiseProductRowSumVector(this->getTransitionRewardMatrix()), this->getStateActionRewardVector()); - this->optionalStateActionRewardVector = boost::none; + this->optionalTransitionRewardMatrix = boost::none; } else { this->optionalStateActionRewardVector = transitionMatrix.getPointwiseProductRowSumVector(this->getTransitionRewardMatrix()); } } if (reduceToStateRewards && this->hasStateActionRewards()) { + STORM_LOG_THROW(transitionMatrix.getRowGroupCount() == this->getStateActionRewardVector().size(), storm::exceptions::InvalidOperationException, "The reduction to state rewards is only possible if the size of the action reward vector equals the number of states."); if (this->hasStateRewards()) { - STORM_LOG_THROW(this->getStateRewardVector().size() == this->getStateActionRewardVector().size(), storm::exceptions::InvalidOperationException, "The reduction to state rewards is only possible of both the state and the state-action rewards have the same dimension."); storm::utility::vector::addVectors(this->getStateActionRewardVector(), this->getStateRewardVector(), this->getStateRewardVector()); } else { this->optionalStateRewardVector = std::move(this->optionalStateActionRewardVector); @@ -242,6 +242,14 @@ namespace storm { bool StandardRewardModel::empty() const { return !(static_cast(this->optionalStateRewardVector) || static_cast(this->optionalStateActionRewardVector) || static_cast(this->optionalTransitionRewardMatrix)); } + + template + bool StandardRewardModel::isAllZero() const { + if(hasStateRewards() && !std::all_of(getStateRewardVector().begin(), getStateRewardVector().end(), storm::utility::isZero)) { + return false; + } + return !(static_cast(this->optionalStateRewardVector) || static_cast(this->optionalStateActionRewardVector) || static_cast(this->optionalTransitionRewardMatrix)); + } @@ -335,4 +343,4 @@ namespace storm { } } -} \ No newline at end of file +} diff --git a/src/models/sparse/StandardRewardModel.h b/src/models/sparse/StandardRewardModel.h index 6e153fa07..985f4189c 100644 --- a/src/models/sparse/StandardRewardModel.h +++ b/src/models/sparse/StandardRewardModel.h @@ -253,6 +253,13 @@ namespace storm { * @return True iff the reward model is empty. */ bool empty() const; + + /*! + * Retrieves whether every reward defined by this reward model is zero + * + * @return True iff every reward defined by this reward model is zero. + */ + bool isAllZero() const; /*! * Checks whether the reward model is compatible with key model characteristics. @@ -293,4 +300,4 @@ namespace storm { } } -#endif /* STORM_MODELS_SPARSE_STANDARDREWARDMODEL_H_ */ \ No newline at end of file +#endif /* STORM_MODELS_SPARSE_STANDARDREWARDMODEL_H_ */