Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
RewardModelInformation.cpp
Go to the documentation of this file.
2
8
9namespace storm {
10namespace jani {
11
16
17RewardModelInformation::RewardModelInformation(Model const& model, std::string const& rewardModelNameIdentifier)
18 : RewardModelInformation(model, model.getRewardModelExpression(rewardModelNameIdentifier)) {
19 // Intentionally left empty
20}
21
23 : stateRewards(false), actionRewards(false), transitionRewards(false) {
24 auto variablesInRewardExpression = rewardModelExpression.getVariables();
25 std::map<storm::expressions::Variable, storm::expressions::Expression> initialSubstitution;
26 bool containsNonTransientVariable = false;
27 for (auto const& v : variablesInRewardExpression) {
28 if (model.hasConstant(v.getName())) {
29 auto const& janiConst = model.getConstant(v.getName());
30 if (janiConst.isDefined()) {
31 initialSubstitution.emplace(v, janiConst.getExpression());
32 }
33 } else {
34 STORM_LOG_ASSERT(model.hasGlobalVariable(v.getName()), "Unable to find global variable " << v.getName() << " occurring in a reward expression.");
35 auto const& janiVar = model.getGlobalVariable(v.getName());
36 if (janiVar.hasInitExpression()) {
37 initialSubstitution.emplace(v, janiVar.getInitExpression());
38 }
39 if (!janiVar.isTransient()) {
40 containsNonTransientVariable = true;
41 }
42 }
43 }
44 auto initExpr = storm::jani::substituteJaniExpression(rewardModelExpression, initialSubstitution, true).simplify();
45 if (containsNonTransientVariable || initExpr.containsVariables() || !storm::utility::isZero(initExpr.evaluateAsRational())) {
46 stateRewards = true;
47 actionRewards = true;
48 transitionRewards = true;
49 }
50 traverse(model, &variablesInRewardExpression);
51}
52
53void RewardModelInformation::traverse(Location const& location, boost::any const& data) {
54 auto const& vars = *boost::any_cast<std::set<storm::expressions::Variable>*>(data);
55 if (!hasStateRewards()) {
56 for (auto const& assignment : location.getAssignments().getTransientAssignments()) {
57 storm::jani::Variable const& assignedVariable = assignment.getVariable();
58 if (vars.count(assignedVariable.getExpressionVariable()) > 0) {
59 stateRewards = true;
60 break;
61 }
62 }
63 }
64}
65
66void RewardModelInformation::traverse(TemplateEdge const& templateEdge, boost::any const& data) {
67 auto const& vars = *boost::any_cast<std::set<storm::expressions::Variable>*>(data);
68 if (!hasActionRewards()) {
69 for (auto const& assignment : templateEdge.getAssignments().getTransientAssignments()) {
70 storm::jani::Variable const& assignedVariable = assignment.getVariable();
71 if (vars.count(assignedVariable.getExpressionVariable()) > 0) {
72 actionRewards = true;
73 break;
74 }
75 }
76 }
77 for (auto const& dest : templateEdge.getDestinations()) {
78 traverse(dest, data);
79 }
80}
81
82void RewardModelInformation::traverse(TemplateEdgeDestination const& templateEdgeDestination, boost::any const& data) {
83 auto const& vars = *boost::any_cast<std::set<storm::expressions::Variable>*>(data);
84 if (!hasTransitionRewards()) {
85 for (auto const& assignment : templateEdgeDestination.getOrderedAssignments().getTransientAssignments()) {
86 storm::jani::Variable const& assignedVariable = assignment.getVariable();
87 if (vars.count(assignedVariable.getExpressionVariable()) > 0) {
88 transitionRewards = true;
89 break;
90 }
91 }
92 }
93}
94
96 return RewardModelInformation(this->hasStateRewards() || other.hasStateRewards(), this->hasActionRewards() || other.hasActionRewards(),
97 this->hasTransitionRewards() || other.hasTransitionRewards());
98}
99
103
107
111
112} // namespace jani
113} // namespace storm
Expression simplify() const
Simplifies the expression according to some basic rules.
std::set< storm::expressions::Variable > getVariables() const
Retrieves the set of all variables that appear in the expression.
Jani Location:
Definition Location.h:15
OrderedAssignments const & getAssignments() const
Retrieves the assignments of this location.
Definition Location.cpp:23
Variable const & getGlobalVariable(std::string const &name) const
Retrieves the global variable with the given name if one exists.
Definition Model.cpp:757
bool hasConstant(std::string const &name) const
Retrieves whether the model has a constant with the given name.
Definition Model.cpp:659
Constant const & getConstant(std::string const &name) const
Retrieves the constant with the given name (if any).
Definition Model.cpp:679
bool hasGlobalVariable(std::string const &name) const
Retrieves whether this model has a global variable with the given name.
Definition Model.cpp:753
detail::ConstAssignments getTransientAssignments() const
Returns all transient assignments in this set of assignments.
bool hasTransitionRewards() const
Returns true iff the given reward model has transition rewards.
virtual void traverse(Location const &location, boost::any const &data) override
bool hasActionRewards() const
Returns true iff the given reward model has action rewards.
RewardModelInformation(bool hasStateRewards, bool hasActionRewards, bool hasTransitionRewards)
bool hasStateRewards() const
Returns true iff the given reward model has state rewards.
RewardModelInformation join(RewardModelInformation const &other) const
Returns the resulting information when joining the two reward models.
OrderedAssignments const & getOrderedAssignments() const
std::vector< TemplateEdgeDestination > const & getDestinations() const
OrderedAssignments const & getAssignments() const
storm::expressions::Variable const & getExpressionVariable() const
Retrieves the associated expression variable.
Definition Variable.cpp:26
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
storm::expressions::Expression substituteJaniExpression(storm::expressions::Expression const &expression, std::map< storm::expressions::Variable, storm::expressions::Expression > const &identifierToExpressionMap, bool const substituteTranscendentalNumbers)
bool isZero(ValueType const &a)
Definition constants.cpp:44
The contract of a DD backend.