Browse Source

further operators on models and reward models

Former-commit-id: 0146278302
tempestpy_adaptions
sjunges 9 years ago
parent
commit
57dffbcd4f
  1. 19
      src/models/sparse/Model.cpp
  2. 13
      src/models/sparse/Model.h
  3. 15
      src/models/sparse/StandardRewardModel.cpp
  4. 13
      src/models/sparse/StandardRewardModel.h

19
src/models/sparse/Model.cpp

@ -112,6 +112,25 @@ namespace storm {
return it->second;
}
template<typename ValueType, typename RewardModelType>
void Model<ValueType, RewardModelType>::addRewardModel(std::string const& rewardModelName, RewardModelType const& newRewardModel) {
if(this->hasRewardModel(rewardModelName)) {
STORM_LOG_THROW(!(this->hasRewardModel(rewardModelName)), storm::exceptions::IllegalArgumentException, "A reward model with the given name '" << rewardModelName << "' already exists.");
}
assert(newRewardModel.isCompatible(this->getNumberOfStates(), this->getTransitionMatrix().getRowCount()));
this->rewardModels.emplace(rewardModelName, newRewardModel);
}
template<typename ValueType, typename RewardModelType>
bool Model<ValueType, RewardModelType>::removeRewardModel(std::string const& rewardModelName) {
auto it = this->rewardModels.find(rewardModelName);
bool res = (it != this->rewardModels.end());
if(res) {
this->rewardModels.erase(it->first);
}
return res;
}
template<typename ValueType, typename RewardModelType>
bool Model<ValueType, RewardModelType>::hasUniqueRewardModel() const {
return this->getNumberOfRewardModels() == 1;

13
src/models/sparse/Model.h

@ -183,6 +183,19 @@ namespace storm {
*/
uint_fast64_t getNumberOfRewardModels() const;
/*!
* Adds a reward model to the model. Notice that this operation is only valid if the reward model matches the number of
* states and/or choices of the model.
* Moreover, it is required that no reward model with the same name exists in the model.
*/
void addRewardModel(std::string const& rewardModelName, RewardModelType const& rewModel);
/*!
* Removes the reward model with the given name from the model.
* @return true, iff such a reward model existed
*/
bool removeRewardModel(std::string const& rewardModelName);
/*!
* Retrieves the labels for the choices of the model. Note that calling this method is only valid if the
* model has a choice labeling.

15
src/models/sparse/StandardRewardModel.cpp

@ -126,6 +126,7 @@ namespace storm {
// return max;
// }
template<typename ValueType>
boost::optional<std::vector<ValueType>> const& StandardRewardModel<ValueType>::getOptionalStateActionRewardVector() const {
return this->optionalStateActionRewardVector;
@ -268,6 +269,20 @@ namespace storm {
return !(static_cast<bool>(this->optionalStateRewardVector) || static_cast<bool>(this->optionalStateActionRewardVector) || static_cast<bool>(this->optionalTransitionRewardMatrix));
}
template<typename ValueType>
bool StandardRewardModel<ValueType>::isCompatible(uint_fast64_t nrStates, uint_fast64_t nrChoices) const {
if(hasStateRewards()) {
if(optionalStateRewardVector.get().size() != nrStates) return false;
}
if(hasStateActionRewards()) {
if(optionalStateActionRewardVector.get().size() != nrChoices) return false;
}
return true;
}
template<typename ValueType>
std::size_t StandardRewardModel<ValueType>::getSizeInBytes() const {
std::size_t result = 0;

13
src/models/sparse/StandardRewardModel.h

@ -59,6 +59,7 @@ namespace storm {
*/
bool hasOnlyStateRewards() const;
/*!
* Retrieves the state rewards of the reward model. Note that it is illegal to call this function if the
* reward model does not have state rewards.
@ -253,6 +254,18 @@ namespace storm {
*/
bool empty() const;
/*!
* Checks whether the reward model is compatible with key model characteristics.
*
* In detail, the method checks
* - if the state-rewards exist, whether the given number of states corresponds to the size of the vector.
* - if the state-action-rewards exist, whether the given number of choices corresponds to the size of the vector.
*
* @param nrStates The number of states in the model
* @param nrChoices The number of choices in the model
*/
bool isCompatible(uint_fast64_t nrStates, uint_fast64_t nrChoices) const;
/*!
* Retrieves (an approximation of) the size of the model in bytes.
*

Loading…
Cancel
Save