Browse Source

Merge branch 'master' of https://sselab.de/lab9/private/git/storm

Former-commit-id: 5691793f9a
tempestpy_adaptions
sjunges 9 years ago
parent
commit
85e15c035f
  1. 18
      src/models/sparse/NondeterministicModel.cpp
  2. 9
      src/models/sparse/NondeterministicModel.h
  3. 5
      src/models/sparse/StandardRewardModel.cpp
  4. 13
      src/models/sparse/StandardRewardModel.h

18
src/models/sparse/NondeterministicModel.cpp

@ -4,6 +4,8 @@
#include "src/adapters/CarlAdapter.h" #include "src/adapters/CarlAdapter.h"
#include "src/exceptions/InvalidOperationException.h"
namespace storm { namespace storm {
namespace models { namespace models {
namespace sparse { namespace sparse {
@ -45,6 +47,22 @@ namespace storm {
return indices[state+1] - indices[state]; return indices[state+1] - indices[state];
} }
template<typename ValueType, typename RewardModelType>
void NondeterministicModel<ValueType, RewardModelType>::modifyStateActionRewards(RewardModelType& rewardModel, std::map<std::pair<uint_fast64_t, LabelSet>, typename RewardModelType::ValueType> const& modifications) const {
STORM_LOG_THROW(rewardModel.hasStateActionRewards(), storm::exceptions::InvalidOperationException, "Cannot modify state-action rewards, because the reward model does not have state-action rewards.");
STORM_LOG_THROW(this->hasChoiceLabeling(), storm::exceptions::InvalidOperationException, "Cannot modify state-action rewards, because the model does not have an action labeling.");
std::vector<LabelSet> const& choiceLabels = this->getChoiceLabeling();
for (auto const& modification : modifications) {
uint_fast64_t stateIndex = modification.first.first;
for (uint_fast64_t row = this->getNondeterministicChoiceIndices()[stateIndex]; row < this->getNondeterministicChoiceIndices()[stateIndex + 1]; ++row) {
// If the action label of the row matches the requested one, we set the reward value accordingly.
if (choiceLabels[row] == modification.first.second) {
rewardModel.setStateActionRewardValue(row, modification.second);
}
}
}
}
template<typename ValueType, typename RewardModelType> template<typename ValueType, typename RewardModelType>
void NondeterministicModel<ValueType, RewardModelType>::reduceToStateBasedRewards() { void NondeterministicModel<ValueType, RewardModelType>::reduceToStateBasedRewards() {
for (auto& rewardModel : this->getRewardModels()) { for (auto& rewardModel : this->getRewardModels()) {

9
src/models/sparse/NondeterministicModel.h

@ -73,6 +73,15 @@ namespace storm {
*/ */
uint_fast64_t getNumberOfChoices(uint_fast64_t state) const; uint_fast64_t getNumberOfChoices(uint_fast64_t state) const;
/*!
* Modifies the state-action reward vector of the given reward model by setting the value specified in
* the map for the corresponding state-action pairs.
*
* @param rewardModel The reward model whose state-action rewards to modify.
* @param modifications A mapping from state-action pairs to the their new reward values.
*/
void modifyStateActionRewards(RewardModelType& rewardModel, std::map<std::pair<uint_fast64_t, LabelSet>, typename RewardModelType::ValueType> const& modifications) const;
virtual void reduceToStateBasedRewards() override; virtual void reduceToStateBasedRewards() override;
virtual void printModelInformationToStream(std::ostream& out) const override; virtual void printModelInformationToStream(std::ostream& out) const override;

5
src/models/sparse/StandardRewardModel.cpp

@ -197,6 +197,11 @@ namespace storm {
return result; return result;
} }
template<typename ValueType>
void StandardRewardModel<ValueType>::setStateActionRewardValue(uint_fast64_t row, ValueType const& value) {
this->optionalStateActionRewardVector.get()[row] = value;
}
template<typename ValueType> template<typename ValueType>
bool StandardRewardModel<ValueType>::empty() const { bool StandardRewardModel<ValueType>::empty() const {
return !(static_cast<bool>(this->optionalStateRewardVector) || static_cast<bool>(this->optionalStateActionRewardVector) || static_cast<bool>(this->optionalTransitionRewardMatrix)); return !(static_cast<bool>(this->optionalStateRewardVector) || static_cast<bool>(this->optionalStateActionRewardVector) || static_cast<bool>(this->optionalTransitionRewardMatrix));

13
src/models/sparse/StandardRewardModel.h

@ -10,9 +10,11 @@
namespace storm { namespace storm {
namespace models { namespace models {
namespace sparse { namespace sparse {
template <typename ValueType>
template <typename CValueType>
class StandardRewardModel { class StandardRewardModel {
public: public:
typedef CValueType ValueType;
/*! /*!
* Constructs a reward model by copying the given data. * Constructs a reward model by copying the given data.
* *
@ -213,6 +215,15 @@ namespace storm {
*/ */
std::vector<ValueType> getTotalStateActionRewardVector(uint_fast64_t numberOfRows, std::vector<uint_fast64_t> const& rowGroupIndices, storm::storage::BitVector const& filter) const; std::vector<ValueType> getTotalStateActionRewardVector(uint_fast64_t numberOfRows, std::vector<uint_fast64_t> const& rowGroupIndices, storm::storage::BitVector const& filter) const;
/*!
* Sets the given value in the state-action reward vector at the given row. This assumes that the reward
* model has state-action rewards.
*
* @param row The row at which to set the given value.
* @param value The value to set.
*/
void setStateActionRewardValue(uint_fast64_t row, ValueType const& value);
/*! /*!
* Retrieves whether the reward model is empty, i.e. contains no state-, state-action- or transition-based * Retrieves whether the reward model is empty, i.e. contains no state-, state-action- or transition-based
* rewards. * rewards.

Loading…
Cancel
Save