3#include <unordered_map>
28 typedef std::shared_ptr<storm::expressions::BaseExpression const>
BaseExprPtr;
31 std::unordered_map<std::string, FunctionDefinition>
const* localFunctions =
nullptr)
32 : globalFunctions(globalFunctions), localFunctions(localFunctions) {}
42 return res.simplify();
55 return std::const_pointer_cast<storm::expressions::BaseExpression const>(
57 expression.
getManager(), thenExpression->getType(), conditionExpression, thenExpression, elseExpression)));
69 return std::const_pointer_cast<storm::expressions::BaseExpression const>(
83 return std::const_pointer_cast<storm::expressions::BaseExpression const>(
97 return std::const_pointer_cast<storm::expressions::BaseExpression const>(
108 BaseExprPtr operandExpression = boost::any_cast<BaseExprPtr>(expression.
getOperand()->accept(*
this, data));
111 if (operandExpression.get() == expression.
getOperand().get()) {
114 return std::const_pointer_cast<storm::expressions::BaseExpression const>(
121 BaseExprPtr operandExpression = boost::any_cast<BaseExprPtr>(expression.
getOperand()->accept(*
this, data));
124 if (operandExpression.get() == expression.
getOperand().get()) {
127 return std::const_pointer_cast<storm::expressions::BaseExpression const>(
147 "unexpected kind of size expression of ValueArrayExpression (" << expression.
size()->toExpression() <<
").");
148 uint64_t size = expression.
size()->evaluateAsInt();
149 std::vector<BaseExprPtr> elements;
150 bool changed =
false;
151 for (uint64_t i = 0; i < size; ++i) {
152 BaseExprPtr element = boost::any_cast<BaseExprPtr>(expression.
at(i)->accept(*
this, data));
153 if (element.get() != expression.
at(i).get()) {
156 elements.push_back(element);
159 return std::const_pointer_cast<storm::expressions::BaseExpression const>(std::shared_ptr<storm::expressions::BaseExpression>(
167 BaseExprPtr sizeExpression = boost::any_cast<BaseExprPtr>(expression.
size()->accept(*
this, data));
171 if (sizeExpression.get() == expression.
size().get() && elementExpression.get() == expression.
getElementExpression().get()) {
174 return std::const_pointer_cast<storm::expressions::BaseExpression const>(
188 return std::const_pointer_cast<storm::expressions::BaseExpression const>(std::shared_ptr<storm::expressions::BaseExpression>(
196 if (localFunctions !=
nullptr) {
198 if (funDefIt != localFunctions->end()) {
199 funDef = &(funDefIt->second);
202 if (globalFunctions !=
nullptr) {
204 if (funDefIt != globalFunctions->end()) {
205 funDef = &(funDefIt->second);
209 STORM_LOG_THROW(funDef !=
nullptr, storm::exceptions::UnexpectedException,
210 "Unable to find function definition for function call " << expression <<
".");
220 std::unordered_map<std::string, FunctionDefinition>
const* globalFunctions;
221 std::unordered_map<std::string, FunctionDefinition>
const* localFunctions;
239 for (
auto& property : properties) {
247 automaton.getFunctionDefinitions().clear();
260 std::unordered_map<std::string, FunctionDefinition>& functions,
261 std::unordered_map<std::string, FunctionDefinitionStatus>& status, std::string
const& current) {
265 for (
auto const& calledFunction : calledFunctions) {
266 STORM_LOG_THROW(calledFunction != current, storm::exceptions::NotSupportedException,
267 "Function '" << calledFunction <<
"' calls itself. This is not supported.");
268 auto calledStatus = status.find(calledFunction);
270 if (calledStatus != status.end()) {
272 "Found cyclic dependencies between functions '" << calledFunction <<
"' and '" << current <<
"'. This is not supported.");
283 std::unordered_map<std::string, FunctionDefinition>& functions) {
284 std::unordered_map<std::string, FunctionDefinitionStatus> status;
285 for (
auto const& f : functions) {
288 for (
auto const& f : functions) {
302 traverse(c, &globalFunctionEliminationVisitor);
306 traverse(aut, &globalFunctionEliminationVisitor);
312 nonTrivRew.second = globalFunctionEliminationVisitor.
eliminate(nonTrivRew.second);
318 auto functionEliminationVisitor = boost::any_cast<FunctionEliminationExpressionVisitor*>(data)->setLocalFunctions(&automaton.
getFunctionDefinitions());
324 traverse(loc, &functionEliminationVisitor);
359 if (bndType.hasLowerBound()) {
362 if (bndType.hasUpperBound()) {
363 bndType.setUpperBound(functionEliminationVisitor->
eliminate(bndType.getUpperBound()));
403 std::vector<storm::expressions::Expression> arrayIndex;
405 arrayIndex.push_back(functionEliminationVisitor->
eliminate(indexExpr));
413 "Did not translate functions in expression " << expression);
Represents an access to an array.
virtual boost::any accept(ExpressionVisitor &visitor, boost::any const &data) const =0
Accepts the given visitor by calling its visit method.
ExpressionManager const & getManager() const
Retrieves the manager responsible for this expression.
Type const & getType() const
Retrieves the type of the expression.
std::shared_ptr< BaseExpression const > getSharedPointer() const
Retrieves a shared pointer to this expression.
OperatorType getOperatorType() const
Retrieves the operator associated with the expression.
std::shared_ptr< BaseExpression const > const & getSecondOperand() const
Retrieves the second operand of the expression.
std::shared_ptr< BaseExpression const > const & getFirstOperand() const
Retrieves the first operand of the expression.
OperatorType getOperatorType() const
Retrieves the operator associated with the expression.
RelationType getRelationType() const
Retrieves the relation associated with the expression.
Represents an array of the given size, where the i'th entry is determined by the elementExpression,...
virtual std::shared_ptr< BaseExpression const > size() const override
std::shared_ptr< BaseExpression const > const & getElementExpression() const
storm::expressions::Variable const & getIndexVar() const
boost::any accept(ExpressionVisitor &visitor, boost::any const &data) const
Accepts the given visitor.
BaseExpression const & getBaseExpression() const
Retrieves the base expression underlying this expression object.
virtual boost::any visit(IfThenElseExpression const &expression, boost::any const &data)=0
Represents an array with a given list of elements.
std::vector< std::shared_ptr< BaseExpression const > > const & getArguments() const
std::string const & getFunctionIdentifier() const
std::shared_ptr< BaseExpression const > getElseExpression() const
Retrieves the else expression of the if-then-else expression.
std::shared_ptr< BaseExpression const > getCondition() const
Retrieves the condition expression of the if-then-else expression.
std::shared_ptr< BaseExpression const > getThenExpression() const
Retrieves the then expression of the if-then-else expression.
OperatorType getOperatorType() const
Retrieves the operator associated with this expression.
virtual std::shared_ptr< BaseExpression const > getOperand(uint_fast64_t operandIndex) const override
Retrieves the given operand from the expression.
OperatorType getOperatorType() const
Retrieves the operator associated with this expression.
Represents an array with a given list of elements.
virtual std::shared_ptr< BaseExpression const > size() const override
virtual std::shared_ptr< BaseExpression const > at(uint64_t i) const override
storm::expressions::Expression const & getAssignedExpression() const
Retrieves the expression whose value is assigned to the target variable.
storm::jani::LValue const & getLValue() const
Retrieves the lValue that is written in this assignment.
void setAssignedExpression(storm::expressions::Expression const &expression)
Sets a new expression that is assigned to the target LValue.
VariableSet & getVariables()
Retrieves the variables of this automaton.
storm::expressions::Expression const & getInitialStatesRestriction() const
Gets the expression restricting the legal initial values of the automaton's variables.
void setInitialStatesRestriction(storm::expressions::Expression const &initialStatesRestriction)
Sets the expression restricting the legal initial values of the automaton's variables.
std::vector< Location > const & getLocations() const
Retrieves the locations of the automaton.
bool hasInitialStatesRestriction() const
Retrieves whether this automaton has an initial states restriction.
std::unordered_map< std::string, FunctionDefinition > const & getFunctionDefinitions() const
Retrieves all function definitions of this automaton.
EdgeContainer const & getEdgeContainer() const
Retrieves the container of all edges of this automaton.
void setLowerBound(storm::expressions::Expression const &expression)
void define(storm::expressions::Expression const &expression)
Defines the constant with the given expression.
bool isDefined() const
Retrieves whether the constant is defined in the sense that it has a defining expression.
storm::expressions::Expression const & getExpression() const
Retrieves the expression that defines this constant (if any).
storm::expressions::Expression const & getProbability() const
Retrieves the probability of choosing this destination.
void setProbability(storm::expressions::Expression const &probability)
Sets a new probability for this edge destination.
void setRate(storm::expressions::Expression const &rate)
Sets a new rate for this edge.
std::vector< EdgeDestination > const & getDestinations() const
Retrieves the destinations of this edge.
bool hasRate() const
Retrieves whether this edge has an associated rate.
storm::expressions::Expression const & getRate() const
Retrieves the rate of this edge.
storm::expressions::Expression const & getFunctionBody() const
Retrieves the expression that defines the function.
storm::expressions::Expression call(std::vector< std::shared_ptr< storm::expressions::BaseExpression const > > const &arguments) const
Calls the function with the given arguments.
void setFunctionBody(storm::expressions::Expression const &body)
sets the expression that defines the function
virtual void traverse(Model &model, boost::any const &data)
ArrayType const & asArrayType() const
virtual bool isArrayType() const
virtual bool isBoundedType() const
BoundedType const & asBoundedType() const
void setArrayIndex(std::vector< storm::expressions::Expression > const &newIndex)
std::vector< storm::expressions::Expression > & getArrayIndexVector()
Returns the referred variable. In case of an array access, this is the referred array variable.
bool isArrayAccess() const
Returns true if the lValue refers either to an array variable or to an array access.
OrderedAssignments const & getAssignments() const
Retrieves the assignments of this location.
void setTimeProgressInvariant(storm::expressions::Expression const &expression)
Sets the time progress invariant of this location.
storm::expressions::Expression const & getTimeProgressInvariant() const
Retrieves the time progress invariant.
bool hasTimeProgressInvariant() const
Retrieves whether a time progress invariant is attached to this location.
bool hasFunctions() const
void remove(ModelFeature const &modelFeature)
void setInitialStatesRestriction(storm::expressions::Expression const &initialStatesRestriction)
Sets the expression restricting the legal initial values of the global variables.
VariableSet & getGlobalVariables()
Retrieves the variables of this automaton.
std::unordered_map< std::string, storm::expressions::Expression > const & getNonTrivialRewardExpressions() const
Retrieves all available non-trivial reward model names and expressions of the model.
bool hasInitialStatesRestriction() const
Retrieves whether there is an expression restricting the legal initial values of the global variables...
storm::expressions::Expression const & getInitialStatesRestriction() const
Gets the expression restricting the legal initial values of the global variables.
std::vector< Automaton > & getAutomata()
Retrieves the automata of the model.
std::vector< Constant > const & getConstants() const
Retrieves the constants of the model.
ModelFeatures const & getModelFeatures() const
Retrieves the enabled model features.
void finalize()
After adding all components to the model, this method has to be called.
std::unordered_map< std::string, FunctionDefinition > const & getGlobalFunctionDefinitions() const
Retrieves all global function definitions.
storm::expressions::Expression const & getGuard() const
std::vector< TemplateEdgeDestination > const & getDestinations() const
void setGuard(storm::expressions::Expression const &newGuard)
OrderedAssignments const & getAssignments() const
bool hasInitExpression() const
Retrieves whether an initial expression is set.
storm::expressions::Expression const & getInitExpression() const
Retrieves the initial expression Should only be called if an initial expression is set for this varia...
void setInitExpression(storm::expressions::Expression const &initialExpression)
Sets the initial expression for this variable.
virtual boost::any visit(storm::expressions::BinaryRelationExpression const &expression, boost::any const &data) override
virtual boost::any visit(storm::expressions::BinaryNumericalFunctionExpression const &expression, boost::any const &data) override
virtual boost::any visit(storm::expressions::ValueArrayExpression const &expression, boost::any const &data) override
virtual ~FunctionEliminationExpressionVisitor()=default
virtual boost::any visit(storm::expressions::RationalLiteralExpression const &expression, boost::any const &) override
virtual boost::any visit(storm::expressions::ConstructorArrayExpression const &expression, boost::any const &data) override
virtual boost::any visit(storm::expressions::TranscendentalNumberLiteralExpression const &expression, boost::any const &) override
FunctionEliminationExpressionVisitor(std::unordered_map< std::string, FunctionDefinition > const *globalFunctions, std::unordered_map< std::string, FunctionDefinition > const *localFunctions=nullptr)
virtual boost::any visit(storm::expressions::IfThenElseExpression const &expression, boost::any const &data) override
virtual boost::any visit(storm::expressions::UnaryNumericalFunctionExpression const &expression, boost::any const &data) override
virtual boost::any visit(storm::expressions::IntegerLiteralExpression const &expression, boost::any const &) override
virtual boost::any visit(storm::expressions::BooleanLiteralExpression const &expression, boost::any const &) override
virtual boost::any visit(storm::expressions::BinaryBooleanFunctionExpression const &expression, boost::any const &data) override
storm::expressions::Expression eliminate(storm::expressions::Expression const &expression)
virtual boost::any visit(storm::expressions::UnaryBooleanFunctionExpression const &expression, boost::any const &data) override
virtual boost::any visit(storm::expressions::ArrayAccessExpression const &expression, boost::any const &data) override
FunctionEliminationExpressionVisitor setLocalFunctions(std::unordered_map< std::string, FunctionDefinition > const *localFunctions)
virtual boost::any visit(storm::expressions::VariableExpression const &expression, boost::any const &) override
std::shared_ptr< storm::expressions::BaseExpression const > BaseExprPtr
virtual boost::any visit(storm::expressions::FunctionCallExpression const &expression, boost::any const &data) override
void eliminateFunctionsInFunctionBodies(FunctionEliminationExpressionVisitor &eliminationVisitor, std::unordered_map< std::string, FunctionDefinition > &functions)
void traverse(LValue &lValue, boost::any const &data) override
void traverse(storm::expressions::Expression const &expression, boost::any const &) override
void traverse(Location &location, boost::any const &data) override
void traverse(TemplateEdge &templateEdge, boost::any const &data) override
void traverse(Variable &variable, boost::any const &data) override
void eliminate(Model &model, std::vector< Property > &properties)
void traverse(Constant &constant, boost::any const &data) override
void eliminateFunctionsInFunctionBodies(FunctionEliminationExpressionVisitor &eliminationVisitor, std::unordered_map< std::string, FunctionDefinition > &functions, std::unordered_map< std::string, FunctionDefinitionStatus > &status, std::string const ¤t)
void traverse(JaniType &type, boost::any const &data) override
void traverse(EdgeDestination &edgeDestination, boost::any const &data) override
void traverse(Edge &edge, boost::any const &data) override
void traverse(Automaton &automaton, boost::any const &data) override
FunctionEliminatorTraverser()=default
virtual ~FunctionEliminatorTraverser()=default
virtual void traverse(Model &model, boost::any const &) override
void traverse(Assignment &assignment, boost::any const &data) override
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
void eliminateFunctions(Model &model, std::vector< Property > &properties)
Eliminates all function references in the given model and the given properties by replacing them with...
storm::expressions::Expression eliminateFunctionCallsInExpression(storm::expressions::Expression const &expression, Model const &model)
Eliminates all function calls in the given expression by replacing them with their corresponding defi...
std::unordered_set< std::string > getOccurringFunctionCalls(storm::expressions::Expression const &expression)
bool containsFunctionCallExpression(Model const &model)