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