Storm 1.13.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
StateValuationTransformer.cpp
Go to the documentation of this file.
8
10
11StateValuationTransformer::StateValuationTransformer(StateValuations const& oldStateValuations) : oldStateValuations(oldStateValuations) {
12 // Intentionally left empty.
13}
14
16 STORM_LOG_THROW(var.getType().isBooleanType(), storm::exceptions::InvalidArgumentException, "Variable must have type `Boolean`.");
17 STORM_LOG_THROW(expr.getType().isBooleanType(), storm::exceptions::InvalidArgumentException, "Expression must have type `Boolean`.");
18 STORM_LOG_THROW(var.getManager() == oldStateValuations.getManager(), storm::exceptions::InvalidArgumentException,
19 "All variables must refer to same manager.");
20 booleanVariables.push_back(var);
21 booleanExpressions.push_back(expr);
22}
23
25 STORM_LOG_THROW(var.getType().isIntegerType(), storm::exceptions::InvalidArgumentException, "Variable must have type `Integer`.");
26 STORM_LOG_THROW(expr.getType().isIntegerType(), storm::exceptions::InvalidArgumentException, "Expression must have type `Integer`.");
27 STORM_LOG_THROW(var.getManager() == oldStateValuations.getManager(), storm::exceptions::InvalidArgumentException,
28 "All variables must refer to same manager.");
29 integerVariables.push_back(var);
30 integerExpressions.push_back(expr);
31}
32
35 if (extend) {
36 STORM_LOG_ASSERT(oldStateValuations.getNumberOfStates() > 0, "Code assumes that there are states in the state valuations.");
37 // This assumption can of course be avoided, but 0state statevaluations are a corner case anyway. Probably better to fix once we have updated state
38 // valuations.
39 for (auto it = oldStateValuations.at(0).begin(); it != oldStateValuations.at(0).end(); ++it) {
40 builder.addVariable(it.getVariable());
41 }
42 }
43 for (auto const& v : booleanVariables) {
44 builder.addVariable(v);
45 }
46 for (auto const& v : integerVariables) {
47 builder.addVariable(v);
48 }
49
50 storm::expressions::ExpressionEvaluator<storm::RationalNumber> evaluator(oldStateValuations.getManager());
51 for (uint64_t state = 0; state < oldStateValuations.getNumberOfStates(); ++state) {
52 std::vector<bool> booleanValues{};
53 std::vector<int64_t> integerValues{};
54 // Copy variables into the new state valuations and setup the expression evaluator for the current state.
55 for (auto sv = oldStateValuations.at(state).begin(); sv != oldStateValuations.at(state).end(); ++sv) {
56 if (sv.isVariableAssignment()) {
57 auto const& var = sv.getVariable();
58 if (sv.isBoolean()) {
59 evaluator.setBooleanValue(var, sv.getBooleanValue());
60 if (extend) {
61 booleanValues.push_back(sv.getBooleanValue());
62 }
63 } else if (sv.isInteger()) {
64 evaluator.setIntegerValue(var, sv.getIntegerValue());
65 if (extend) {
66 integerValues.push_back(sv.getIntegerValue());
67 }
68 } else {
69 STORM_LOG_ASSERT(sv.isRational(), "Must be RationalVariable");
70 evaluator.setRationalValue(var, sv.getRationalValue());
71 STORM_LOG_THROW(!extend, storm::exceptions::NotSupportedException,
72 "Extending state valuations with rational values is currently not supported.");
73 }
74 } else {
75 STORM_LOG_THROW(!extend, storm::exceptions::NotSupportedException, "Extending state valuations with label values is currently not supported.");
76 // Label assignments can be safely skipped.
77 }
78 }
79 for (auto const& expr : booleanExpressions) {
80 booleanValues.push_back(evaluator.asBool(expr));
81 }
82 for (auto const& expr : integerExpressions) {
83 integerValues.push_back(evaluator.asInt(expr));
84 }
85 builder.addState(state, std::move(booleanValues), std::move(integerValues));
86 }
87 return builder.build();
88}
89} // namespace storm::storage::sparse
Type const & getType() const
Retrieves the type of the expression.
bool isBooleanType() const
Checks whether this type is a boolean type.
Definition Type.cpp:194
bool isIntegerType() const
Checks whether this type is an integral type.
Definition Type.cpp:198
ExpressionManager const & getManager() const
Retrieves the manager responsible for this variable.
Definition Variable.cpp:54
Type const & getType() const
Retrieves the type of the variable.
Definition Variable.cpp:50
void addBooleanExpression(storm::expressions::Variable const &var, storm::expressions::Expression const &expr)
Add a Boolean variable defined by the given expression.
StateValuationTransformer(StateValuations const &oldStateValuations)
void addIntegerExpression(storm::expressions::Variable const &var, storm::expressions::Expression const &expr)
Add a Integer variable defined by the given expression.
StateValuations build(bool extend)
Build and export the state valuations.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30