Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
ValuationTransformer.cpp
Go to the documentation of this file.
2
11
12namespace storm::storage::sparse {
13
14ValuationTransformer::ValuationTransformer(Valuations const& oldValuations) : oldValuations(oldValuations) {
15 // Intentionally left empty.
16}
17
19 STORM_LOG_THROW(var.getType() == expr.getType(), storm::exceptions::InvalidArgumentException,
20 "Variable " << var.getName() << " and expression " << expr << " must have the same type.");
21 STORM_LOG_THROW(var.getManager() == expr.getManager(), storm::exceptions::InvalidArgumentException,
22 "Variable " << var.getName() << " and expression " << expr << " must have the same manager.");
23 STORM_LOG_THROW(var.getManager() == oldValuations.getManager(), storm::exceptions::InvalidArgumentException,
24 "Variable " << var.getName() << " and old state valuations must have the same manager.");
25 STORM_LOG_THROW(var.hasBooleanType() || var.hasIntegerType() || var.hasRationalType(), storm::exceptions::InvalidArgumentException,
26 "Unsupported variable type " << var.getType() << " for variable " << var.getName() << ".");
27 variables.push_back(var);
28 expressions.push_back(expr);
29}
30
32 STORM_LOG_THROW(oldValuations.getStorage().numClasses() == 1, storm::exceptions::NotSupportedException,
33 "Valuation transformation is only supported for valuations with a single class.");
34 ValuationsStorage result = [&]() {
35 ValuationDescriptionBuilder descriptionBuilder(oldValuations.getManager().shared_from_this());
36 if (extend) {
37 descriptionBuilder.addVariables(oldValuations.getStorage().getClassDescription());
38 }
39 for (auto const& v : variables) {
40 if (v.hasBooleanType()) {
41 descriptionBuilder.addBooleanVariable(v);
42 } else if (v.hasIntegerType()) {
43 descriptionBuilder.addIntegerVariable(v, std::numeric_limits<int64_t>::min(), std::numeric_limits<int64_t>::max());
44 } else if (v.hasRationalType()) {
45 descriptionBuilder.addRationalVariable(v, 128);
46 } else {
47 STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException,
48 "Variable " << v.getName() << " has unsupported type " << v.getType() << ".");
49 }
50 }
51 return ValuationsStorage(descriptionBuilder.buildClassDescription(), oldValuations.getManager().shared_from_this());
52 }();
53 result.resize(oldValuations.getNumberOfEntities());
54
55 storm::expressions::ExpressionEvaluator<storm::RationalNumber> evaluator(oldValuations.getManager());
56 for (uint64_t entity = 0; entity < oldValuations.getNumberOfEntities(); ++entity) {
57 if (extend) {
58 // If requested, we copy variables into the new valuations
59 oldValuations.getStorage().readCallback(entity, [&result](auto const e, auto const& var, auto const& value) { result.writeValue(e, var, value); });
60 }
61
62 // Setup the expression evaluator
63 oldValuations.setValuesInEvaluator(entity, evaluator);
64 // Evaluate expressions and write results into the new valuations
65 for (uint64_t i = 0; i < variables.size(); ++i) {
66 auto const& var = variables[i];
67 auto const& expr = expressions[i];
68 if (var.hasBooleanType()) {
69 result.writeValue(entity, var, evaluator.asBool(expr));
70 } else if (var.hasIntegerType()) {
71 result.writeValue(entity, var, evaluator.asInt(expr));
72 } else if (var.hasRationalType()) {
73 result.writeValue(entity, var, evaluator.asRational(expr));
74 } else {
75 STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException,
76 "Variable " << var.getName() << " has unsupported type " << var.getType() << ".");
77 }
78 }
79 }
80 return Valuations(std::move(result));
81}
82} // namespace storm::storage::sparse
Type const & getType() const
Retrieves the type of the expression.
ExpressionManager const & getManager() const
Retrieves the manager responsible for this expression.
bool hasBooleanType() const
Checks whether the variable is of boolean type.
Definition Variable.cpp:59
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
bool hasIntegerType() const
Checks whether the variable is of integral type.
Definition Variable.cpp:63
bool hasRationalType() const
Checks whether the variable is of rational type.
Definition Variable.cpp:71
std::string const & getName() const
Retrieves the name of the variable.
Definition Variable.cpp:46
Helper to incrementally build a ValuationClassDescription, i.e.
ValuationClassDescription buildClassDescription()
Creates the finalized state valuations object.
void addBooleanVariable(storm::expressions::Variable const &variable, bool optional=false)
Adds a new boolean variable to the builder.
void addRationalVariable(storm::expressions::Variable const &variable, uint64_t bitSize, bool optional=false)
Adds a new rational variable to the builder.
void addIntegerVariable(storm::expressions::Variable const &variable, int64_t const lowerBound, int64_t const upperBound, bool optional=false)
Adds a new integer variable to the builder.
void addVariables(ValuationClassDescription const &description, bool addPadding=false)
Adds all variables from the given description.
ValuationTransformer(Valuations const &oldValuations)
Valuations build(bool extend)
Build and export the state valuations.
void addExpression(storm::expressions::Variable const &var, storm::expressions::Expression const &expr)
Add a variable defined by the given expression.
Provides access to valuations of variables for a set of entities (e.g.
Definition Valuations.h:28
Stores valuations of variables for a set of entities (e.g.
void resize(uint64_t newEntityCount, uint64_t classIndex=0)
Resizes the entity count to newEntityCount.
void writeValue(uint64_t entity, storm::expressions::Variable const &variable, ValueType const &value)
Directly writes value to the given variable of entity.
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28