Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
StandardRewardModel.cpp
Go to the documentation of this file.
2
8
9namespace storm {
10namespace models {
11namespace symbolic {
12template<storm::dd::DdType Type, typename ValueType>
14 boost::optional<storm::dd::Add<Type, ValueType>> const& stateActionRewardVector,
15 boost::optional<storm::dd::Add<Type, ValueType>> const& transitionRewardMatrix)
16 : optionalStateRewardVector(stateRewardVector),
17 optionalStateActionRewardVector(stateActionRewardVector),
18 optionalTransitionRewardMatrix(transitionRewardMatrix) {
19 // Intentionally left empty.
20}
21
22template<storm::dd::DdType Type, typename ValueType>
24 return !(this->hasStateRewards() || this->hasStateActionRewards() || this->hasTransitionRewards());
25}
26
27template<storm::dd::DdType Type, typename ValueType>
29 return static_cast<bool>(this->optionalStateRewardVector);
30}
31
32template<storm::dd::DdType Type, typename ValueType>
34 return this->hasStateRewards() && !this->hasStateActionRewards() && !this->hasTransitionRewards();
35}
36
37template<storm::dd::DdType Type, typename ValueType>
39 return this->optionalStateRewardVector.get();
40}
41
42template<storm::dd::DdType Type, typename ValueType>
46
47template<storm::dd::DdType Type, typename ValueType>
48boost::optional<storm::dd::Add<Type, ValueType>> const& StandardRewardModel<Type, ValueType>::getOptionalStateRewardVector() const {
49 return this->optionalStateRewardVector;
50}
51
52template<storm::dd::DdType Type, typename ValueType>
54 return static_cast<bool>(this->optionalStateActionRewardVector);
55}
56
57template<storm::dd::DdType Type, typename ValueType>
59 return this->optionalStateActionRewardVector.get();
60}
61
62template<storm::dd::DdType Type, typename ValueType>
64 return this->optionalStateActionRewardVector.get();
65}
66
67template<storm::dd::DdType Type, typename ValueType>
68boost::optional<storm::dd::Add<Type, ValueType>> const& StandardRewardModel<Type, ValueType>::getOptionalStateActionRewardVector() const {
69 return this->optionalStateActionRewardVector;
70}
71
72template<storm::dd::DdType Type, typename ValueType>
74 return static_cast<bool>(this->optionalTransitionRewardMatrix);
75}
76
77template<storm::dd::DdType Type, typename ValueType>
79 return this->optionalTransitionRewardMatrix.get();
80}
81
82template<storm::dd::DdType Type, typename ValueType>
84 return this->optionalTransitionRewardMatrix.get();
85}
86
87template<storm::dd::DdType Type, typename ValueType>
88boost::optional<storm::dd::Add<Type, ValueType>> const& StandardRewardModel<Type, ValueType>::getOptionalTransitionRewardMatrix() const {
89 return this->optionalTransitionRewardMatrix;
90}
91
92template<storm::dd::DdType Type, typename ValueType>
94 storm::dd::Add<Type, ValueType> const& filterAdd, storm::dd::Add<Type, ValueType> const& transitionMatrix,
95 std::set<storm::expressions::Variable> const& columnVariables) const {
96 storm::dd::Add<Type, ValueType> result = transitionMatrix.getDdManager().template getAddZero<ValueType>();
97 if (this->hasStateRewards()) {
98 result += filterAdd * optionalStateRewardVector.get();
99 }
100 if (this->hasStateActionRewards()) {
101 result += filterAdd * optionalStateActionRewardVector.get();
102 }
103 if (this->hasTransitionRewards()) {
104 result += (transitionMatrix * this->getTransitionRewardMatrix()).sumAbstract(columnVariables);
105 }
106 return result;
107}
108
109template<storm::dd::DdType Type, typename ValueType>
111 storm::dd::Add<Type, ValueType> const& stateFilterAdd, storm::dd::Add<Type, ValueType> const& choiceFilterAdd,
112 storm::dd::Add<Type, ValueType> const& transitionMatrix, std::set<storm::expressions::Variable> const& columnVariables) const {
113 storm::dd::Add<Type, ValueType> result = transitionMatrix.getDdManager().template getAddZero<ValueType>();
114 if (this->hasStateRewards()) {
115 result += stateFilterAdd * choiceFilterAdd * optionalStateRewardVector.get();
116 }
117 if (this->hasStateActionRewards()) {
118 result += choiceFilterAdd * optionalStateActionRewardVector.get();
119 }
120 if (this->hasTransitionRewards()) {
121 result += (transitionMatrix * this->getTransitionRewardMatrix()).sumAbstract(columnVariables);
122 }
123 return result;
124}
125
126template<storm::dd::DdType Type, typename ValueType>
128 storm::dd::Add<Type, ValueType> const& transitionMatrix, std::set<storm::expressions::Variable> const& columnVariables) const {
129 storm::dd::Add<Type, ValueType> result = transitionMatrix.getDdManager().template getAddZero<ValueType>();
130 if (this->hasStateRewards()) {
131 result += optionalStateRewardVector.get();
132 }
133 if (this->hasStateActionRewards()) {
134 result += optionalStateActionRewardVector.get();
135 }
136 if (this->hasTransitionRewards()) {
137 result += (transitionMatrix * this->getTransitionRewardMatrix()).sumAbstract(columnVariables);
138 }
139 return result;
140}
141
142template<storm::dd::DdType Type, typename ValueType>
144 std::set<storm::expressions::Variable> const& columnVariables,
145 storm::dd::Add<Type, ValueType> const& weights,
146 bool scaleTransAndActions) const {
147 storm::dd::Add<Type, ValueType> result = transitionMatrix.getDdManager().template getAddZero<ValueType>();
148 if (this->hasStateRewards()) {
149 result += optionalStateRewardVector.get();
150 }
151 if (this->hasStateActionRewards()) {
152 result += optionalStateActionRewardVector.get() * weights;
153 }
154 if (this->hasTransitionRewards()) {
155 if (scaleTransAndActions) {
156 result += weights * (transitionMatrix * this->getTransitionRewardMatrix()).sumAbstract(columnVariables);
157 } else {
158 result += (transitionMatrix * this->getTransitionRewardMatrix()).sumAbstract(columnVariables);
159 }
160 }
161 return result;
162}
163
164template<storm::dd::DdType Type, typename ValueType>
166 if (this->hasStateRewards()) {
167 this->optionalStateRewardVector.get() *= filter;
168 }
169 if (this->hasStateActionRewards()) {
170 this->optionalStateActionRewardVector.get() *= filter;
171 }
172 if (this->hasTransitionRewards()) {
173 this->optionalTransitionRewardMatrix.get() *= filter;
174 }
175
176 return *this;
177}
178
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;
184 }
185 return StandardRewardModel<Type, ValueType>(modifiedStateRewardVector, this->optionalStateActionRewardVector, this->optionalTransitionRewardMatrix);
186}
187
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;
196 } else {
197 this->optionalStateActionRewardVector = transitionMatrix.multiplyMatrix(this->getTransitionRewardMatrix(), columnVariables);
198 }
199 }
200
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();
206 } else {
207 this->optionalStateRewardVector = this->getStateActionRewardVector();
208 }
209 this->optionalStateActionRewardVector = boost::none;
210 }
211}
212
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);
220}
221
223
228
229} // namespace symbolic
230} // namespace models
231} // namespace storm
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...
Definition Add.cpp:368
DdManager< LibraryType > & getDdManager() const
Retrieves the manager that is responsible for this DD.
Definition Dd.cpp:38
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)
Definition macros.h:30