12template<storm::dd::DdType Type,
typename ValueType>
16 : optionalStateRewardVector(stateRewardVector),
17 optionalStateActionRewardVector(stateActionRewardVector),
18 optionalTransitionRewardMatrix(transitionRewardMatrix) {
22template<storm::dd::DdType Type,
typename ValueType>
24 return !(this->hasStateRewards() || this->hasStateActionRewards() || this->hasTransitionRewards());
27template<storm::dd::DdType Type,
typename ValueType>
29 return static_cast<bool>(this->optionalStateRewardVector);
32template<storm::dd::DdType Type,
typename ValueType>
34 return this->hasStateRewards() && !this->hasStateActionRewards() && !this->hasTransitionRewards();
37template<storm::dd::DdType Type,
typename ValueType>
39 return this->optionalStateRewardVector.get();
42template<storm::dd::DdType Type,
typename ValueType>
44 return this->optionalStateRewardVector.get();
47template<storm::dd::DdType Type,
typename ValueType>
49 return this->optionalStateRewardVector;
52template<storm::dd::DdType Type,
typename ValueType>
54 return static_cast<bool>(this->optionalStateActionRewardVector);
57template<storm::dd::DdType Type,
typename ValueType>
59 return this->optionalStateActionRewardVector.get();
62template<storm::dd::DdType Type,
typename ValueType>
64 return this->optionalStateActionRewardVector.get();
67template<storm::dd::DdType Type,
typename ValueType>
69 return this->optionalStateActionRewardVector;
72template<storm::dd::DdType Type,
typename ValueType>
74 return static_cast<bool>(this->optionalTransitionRewardMatrix);
77template<storm::dd::DdType Type,
typename ValueType>
79 return this->optionalTransitionRewardMatrix.get();
82template<storm::dd::DdType Type,
typename ValueType>
84 return this->optionalTransitionRewardMatrix.get();
87template<storm::dd::DdType Type,
typename ValueType>
89 return this->optionalTransitionRewardMatrix;
92template<storm::dd::DdType Type,
typename ValueType>
95 std::set<storm::expressions::Variable>
const& columnVariables)
const {
97 if (this->hasStateRewards()) {
98 result += filterAdd * optionalStateRewardVector.get();
100 if (this->hasStateActionRewards()) {
101 result += filterAdd * optionalStateActionRewardVector.get();
103 if (this->hasTransitionRewards()) {
104 result += (transitionMatrix * this->getTransitionRewardMatrix()).sumAbstract(columnVariables);
109template<storm::dd::DdType Type,
typename ValueType>
114 if (this->hasStateRewards()) {
115 result += stateFilterAdd * choiceFilterAdd * optionalStateRewardVector.get();
117 if (this->hasStateActionRewards()) {
118 result += choiceFilterAdd * optionalStateActionRewardVector.get();
120 if (this->hasTransitionRewards()) {
121 result += (transitionMatrix * this->getTransitionRewardMatrix()).sumAbstract(columnVariables);
126template<storm::dd::DdType Type,
typename ValueType>
130 if (this->hasStateRewards()) {
131 result += optionalStateRewardVector.get();
133 if (this->hasStateActionRewards()) {
134 result += optionalStateActionRewardVector.get();
136 if (this->hasTransitionRewards()) {
137 result += (transitionMatrix * this->getTransitionRewardMatrix()).sumAbstract(columnVariables);
142template<storm::dd::DdType Type,
typename ValueType>
144 std::set<storm::expressions::Variable>
const& columnVariables,
146 bool scaleTransAndActions)
const {
148 if (this->hasStateRewards()) {
149 result += optionalStateRewardVector.get();
151 if (this->hasStateActionRewards()) {
152 result += optionalStateActionRewardVector.get() * weights;
154 if (this->hasTransitionRewards()) {
155 if (scaleTransAndActions) {
156 result += weights * (transitionMatrix * this->getTransitionRewardMatrix()).sumAbstract(columnVariables);
158 result += (transitionMatrix * this->getTransitionRewardMatrix()).sumAbstract(columnVariables);
164template<storm::dd::DdType Type,
typename ValueType>
166 if (this->hasStateRewards()) {
167 this->optionalStateRewardVector.get() *= filter;
169 if (this->hasStateActionRewards()) {
170 this->optionalStateActionRewardVector.
get() *= filter;
172 if (this->hasTransitionRewards()) {
173 this->optionalTransitionRewardMatrix.
get() *= filter;
179template<storm::dd::DdType Type,
typename ValueType>
181 boost::optional<storm::dd::Add<Type, ValueType>> modifiedStateRewardVector;
182 if (this->hasStateRewards()) {
183 modifiedStateRewardVector = this->optionalStateRewardVector.get() / divisor;
188template<storm::dd::DdType Type,
typename ValueType>
190 std::set<storm::expressions::Variable>
const& rowVariables,
191 std::set<storm::expressions::Variable>
const& columnVariables,
bool reduceToStateRewards) {
192 if (this->hasTransitionRewards()) {
193 if (this->hasStateActionRewards()) {
194 this->optionalStateActionRewardVector.get() += transitionMatrix.
multiplyMatrix(this->getTransitionRewardMatrix(), columnVariables);
195 this->optionalTransitionRewardMatrix = boost::none;
197 this->optionalStateActionRewardVector = transitionMatrix.
multiplyMatrix(this->getTransitionRewardMatrix(), columnVariables);
201 if (reduceToStateRewards && this->hasStateActionRewards()) {
202 STORM_LOG_THROW(this->getStateActionRewardVector().getContainedMetaVariables() == rowVariables, storm::exceptions::InvalidOperationException,
203 "The reduction to state rewards is only possible if the state-action rewards do not depend on nondeterminism variables.");
204 if (this->hasStateRewards()) {
205 this->optionalStateRewardVector = this->optionalStateRewardVector.get() + this->getStateActionRewardVector();
207 this->optionalStateRewardVector = this->getStateActionRewardVector();
209 this->optionalStateActionRewardVector = boost::none;
213template<storm::dd::DdType Type,
typename ValueType>
214template<
typename NewValueType>
217 this->hasStateRewards() ? boost::make_optional(this->getStateRewardVector().
template toValueType<NewValueType>()) : boost::none,
218 this->hasStateActionRewards() ? boost::make_optional(this->getStateActionRewardVector().
template toValueType<NewValueType>()) : boost::none,
219 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(uint64_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)