14template<storm::dd::DdType Type,
typename ValueType>
18 : optionalStateRewardVector(stateRewardVector),
19 optionalStateActionRewardVector(stateActionRewardVector),
20 optionalTransitionRewardMatrix(transitionRewardMatrix) {
24template<storm::dd::DdType Type,
typename ValueType>
26 return !(this->hasStateRewards() || this->hasStateActionRewards() || this->hasTransitionRewards());
29template<storm::dd::DdType Type,
typename ValueType>
31 return static_cast<bool>(this->optionalStateRewardVector);
34template<storm::dd::DdType Type,
typename ValueType>
36 return this->hasStateRewards() && !this->hasStateActionRewards() && !this->hasTransitionRewards();
39template<storm::dd::DdType Type,
typename ValueType>
41 return this->optionalStateRewardVector.get();
44template<storm::dd::DdType Type,
typename ValueType>
46 return this->optionalStateRewardVector.get();
49template<storm::dd::DdType Type,
typename ValueType>
51 return this->optionalStateRewardVector;
54template<storm::dd::DdType Type,
typename ValueType>
56 return static_cast<bool>(this->optionalStateActionRewardVector);
59template<storm::dd::DdType Type,
typename ValueType>
61 return this->optionalStateActionRewardVector.get();
64template<storm::dd::DdType Type,
typename ValueType>
66 return this->optionalStateActionRewardVector.get();
69template<storm::dd::DdType Type,
typename ValueType>
71 return this->optionalStateActionRewardVector;
74template<storm::dd::DdType Type,
typename ValueType>
76 return static_cast<bool>(this->optionalTransitionRewardMatrix);
79template<storm::dd::DdType Type,
typename ValueType>
81 return this->optionalTransitionRewardMatrix.get();
84template<storm::dd::DdType Type,
typename ValueType>
86 return this->optionalTransitionRewardMatrix.get();
89template<storm::dd::DdType Type,
typename ValueType>
91 return this->optionalTransitionRewardMatrix;
94template<storm::dd::DdType Type,
typename ValueType>
97 std::set<storm::expressions::Variable>
const& columnVariables)
const {
99 if (this->hasStateRewards()) {
100 result += filterAdd * optionalStateRewardVector.get();
102 if (this->hasStateActionRewards()) {
103 result += filterAdd * optionalStateActionRewardVector.get();
105 if (this->hasTransitionRewards()) {
106 result += (transitionMatrix * this->getTransitionRewardMatrix()).sumAbstract(columnVariables);
111template<storm::dd::DdType Type,
typename ValueType>
116 if (this->hasStateRewards()) {
117 result += stateFilterAdd * choiceFilterAdd * optionalStateRewardVector.get();
119 if (this->hasStateActionRewards()) {
120 result += choiceFilterAdd * optionalStateActionRewardVector.get();
122 if (this->hasTransitionRewards()) {
123 result += (transitionMatrix * this->getTransitionRewardMatrix()).sumAbstract(columnVariables);
128template<storm::dd::DdType Type,
typename ValueType>
132 if (this->hasStateRewards()) {
133 result += optionalStateRewardVector.get();
135 if (this->hasStateActionRewards()) {
136 result += optionalStateActionRewardVector.get();
138 if (this->hasTransitionRewards()) {
139 result += (transitionMatrix * this->getTransitionRewardMatrix()).sumAbstract(columnVariables);
144template<storm::dd::DdType Type,
typename ValueType>
146 std::set<storm::expressions::Variable>
const& columnVariables,
148 bool scaleTransAndActions)
const {
150 if (this->hasStateRewards()) {
151 result += optionalStateRewardVector.get();
153 if (this->hasStateActionRewards()) {
154 result += optionalStateActionRewardVector.get() * weights;
156 if (this->hasTransitionRewards()) {
157 if (scaleTransAndActions) {
158 result += weights * (transitionMatrix * this->getTransitionRewardMatrix()).sumAbstract(columnVariables);
160 result += (transitionMatrix * this->getTransitionRewardMatrix()).sumAbstract(columnVariables);
166template<storm::dd::DdType Type,
typename ValueType>
168 if (this->hasStateRewards()) {
169 this->optionalStateRewardVector.get() *= filter;
171 if (this->hasStateActionRewards()) {
172 this->optionalStateActionRewardVector.
get() *= filter;
174 if (this->hasTransitionRewards()) {
175 this->optionalTransitionRewardMatrix.
get() *= filter;
181template<storm::dd::DdType Type,
typename ValueType>
183 boost::optional<storm::dd::Add<Type, ValueType>> modifiedStateRewardVector;
184 if (this->hasStateRewards()) {
185 modifiedStateRewardVector = this->optionalStateRewardVector.get() / divisor;
190template<storm::dd::DdType Type,
typename ValueType>
192 std::set<storm::expressions::Variable>
const& rowVariables,
193 std::set<storm::expressions::Variable>
const& columnVariables,
bool reduceToStateRewards) {
194 if (this->hasTransitionRewards()) {
195 if (this->hasStateActionRewards()) {
196 this->optionalStateActionRewardVector.get() += transitionMatrix.
multiplyMatrix(this->getTransitionRewardMatrix(), columnVariables);
197 this->optionalTransitionRewardMatrix = boost::none;
199 this->optionalStateActionRewardVector = transitionMatrix.
multiplyMatrix(this->getTransitionRewardMatrix(), columnVariables);
203 if (reduceToStateRewards && this->hasStateActionRewards()) {
204 STORM_LOG_THROW(this->getStateActionRewardVector().getContainedMetaVariables() == rowVariables, storm::exceptions::InvalidOperationException,
205 "The reduction to state rewards is only possible if the state-action rewards do not depend on nondeterminism variables.");
206 if (this->hasStateRewards()) {
207 this->optionalStateRewardVector = this->optionalStateRewardVector.get() + this->getStateActionRewardVector();
209 this->optionalStateRewardVector = this->getStateActionRewardVector();
211 this->optionalStateActionRewardVector = boost::none;
215template<storm::dd::DdType Type,
typename ValueType>
216template<
typename NewValueType>
219 this->hasStateRewards() ? boost::make_optional(this->getStateRewardVector().
template toValueType<NewValueType>()) : boost::none,
220 this->hasStateActionRewards() ? boost::make_optional(this->getStateActionRewardVector().
template toValueType<NewValueType>()) : boost::none,
221 this->hasTransitionRewards() ? boost::make_optional(this->getTransitionRewardMatrix().
template toValueType<NewValueType>()) : boost::none);
Add< LibraryType, ValueType > multiplyMatrix(Add< LibraryType, ValueType > const &otherMatrix, std::set< storm::expressions::Variable > const &summationMetaVariables) const
Multiplies the current ADD (representing a matrix) with the given matrix by summing over the given me...
DdManager< LibraryType > & getDdManager() const
Retrieves the manager that is responsible for this DD.
boost::optional< storm::dd::Add< Type, ValueType > > const & getOptionalStateRewardVector() const
Retrieves an optional value that contains the state reward vector if there is one.
storm::dd::Add< Type, ValueType > const & getStateActionRewardVector() const
Retrieves the state-action rewards of the reward model.
boost::optional< storm::dd::Add< Type, ValueType > > const & getOptionalStateActionRewardVector() const
Retrieves an optional value that contains the state-action reward vector if there is one.
bool hasOnlyStateRewards() const
Retrieves whether the reward model only has state rewards (and hence no other rewards).
void reduceToStateBasedRewards(storm::dd::Add< Type, ValueType > const &transitionMatrix, std::set< storm::expressions::Variable > const &rowVariables, std::set< storm::expressions::Variable > const &columnVariables, bool reduceToStateRewards)
Reduces the transition-based rewards to state-action rewards by taking the average of each row.
bool hasStateRewards() const
Retrieves whether the reward model has state rewards.
storm::dd::Add< Type, ValueType > getTotalRewardVector(storm::dd::Add< Type, ValueType > const &transitionMatrix, std::set< storm::expressions::Variable > const &columnVariables) const
Creates a vector representing the complete reward vector based on the state-, state-action- and trans...
storm::dd::Add< Type, ValueType > const & getTransitionRewardMatrix() const
Retrieves the transition rewards of the reward model.
bool empty() const
Retrieves whether the reward model is empty.
storm::dd::Add< Type, ValueType > const & getStateRewardVector() const
Retrieves the state rewards of the reward model.
bool hasStateActionRewards() const
Retrieves whether the reward model has state-action rewards.
boost::optional< storm::dd::Add< Type, ValueType > > const & getOptionalTransitionRewardMatrix() const
Retrieves an optional value that contains the transition reward matrix if there is one.
StandardRewardModel< Type, ValueType > & operator*=(storm::dd::Add< Type, ValueType > const &filter)
Multiplies all components of the reward model with the given DD.
bool hasTransitionRewards() const
Retrieves whether the reward model has transition rewards.
StandardRewardModel< Type, ValueType > divideStateRewardVector(storm::dd::Add< Type, ValueType > const &divisor) const
Divides the state reward vector of the reward model by the given divisor.
StandardRewardModel< Type, NewValueType > toValueType() const
StandardRewardModel(boost::optional< storm::dd::Add< Type, ValueType > > const &stateRewardVector, boost::optional< storm::dd::Add< Type, ValueType > > const &stateActionRewardVector, boost::optional< storm::dd::Add< Type, ValueType > > const &transitionRewardMatrix)
Builds a reward model by copying with the given reward structures.
bool get(uint_fast64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
#define STORM_LOG_THROW(cond, exception, message)