#pragma once #include #include #include #include "storm/storage/expressions/Variable.h" #include "storm/storage/expressions/Expression.h" #include "storm/storage/expressions/ExpressionEvaluator.h" #include "storm/utility/macros.h" #include "storm/exceptions/OutOfRangeException.h" namespace storm { namespace jani { class Model; class Automaton; class ArrayEliminatorData; class VariableSet; } namespace expressions { template class ExpressionEvaluator; } namespace generator { // A structure storing information about a transient variable template struct TransientVariableData { TransientVariableData(storm::expressions::Variable const& variable, boost::optional const& lowerBound, boost::optional const& upperBound, VariableType const& defaultValue, bool global = false); TransientVariableData(storm::expressions::Variable const& variable, VariableType const& defaultValue, bool global = false); // The integer variable. storm::expressions::Variable variable; // The lower bound of its range. boost::optional lowerBound; // The upper bound of its range. boost::optional upperBound; // Its default value VariableType defaultValue; // A flag indicating whether the variable is a global one. bool global; }; template struct TransientVariableValuation { std::vector const*, bool>> booleanValues; std::vector const*, int64_t>> integerValues; std::vector const*, ValueType>> rationalValues; void clear() { booleanValues.clear(); integerValues.clear(); rationalValues.clear(); } bool empty() const { return booleanValues.empty() && integerValues.empty() && rationalValues.empty(); } void setInEvaluator(storm::expressions::ExpressionEvaluator& evaluator, bool explorationChecks) const { for (auto const& varValue : booleanValues) { evaluator.setBooleanValue(varValue.first->variable, varValue.second); } for (auto const& varValue : integerValues) { if (explorationChecks) { STORM_LOG_THROW(!varValue.first->lowerBound.is_initialized() || varValue.first->lowerBound.get() <= varValue.second, storm::exceptions::OutOfRangeException, "The assigned value for transient variable " << varValue.first->variable.getName() << " is smaller than its lower bound."); STORM_LOG_THROW(varValue.first->upperBound.is_initialized() || varValue.second <= varValue.first->upperBound.get(), storm::exceptions::OutOfRangeException, "The assigned value for transient variable " << varValue.first->variable.getName() << " is higher than its upper bound."); } evaluator.setIntegerValue(varValue.first->variable, varValue.second); } for (auto const& varValue : rationalValues) { evaluator.setRationalValue(varValue.first->variable, varValue.second); } } }; // A structure storing information about the used variables of the program. template struct TransientVariableInformation { TransientVariableInformation(storm::jani::Model const& model, std::vector> const& parallelAutomata); TransientVariableInformation() = default; void registerArrayVariableReplacements(storm::jani::ArrayEliminatorData const& arrayEliminatorData); TransientVariableData const& getBooleanArrayVariableReplacement(storm::expressions::Variable const& arrayVariable, uint64_t index); TransientVariableData const& getIntegerArrayVariableReplacement(storm::expressions::Variable const& arrayVariable, uint64_t index); TransientVariableData const& getRationalArrayVariableReplacement(storm::expressions::Variable const& arrayVariable, uint64_t index); void setDefaultValuesInEvaluator(storm::expressions::ExpressionEvaluator& evaluator) const; std::vector> booleanVariableInformation; std::vector> integerVariableInformation; std::vector> rationalVariableInformation; /// Replacements for each array variable std::unordered_map> arrayVariableToElementInformations; private: /*! * Sorts the variables to establish a known ordering. */ void sortVariables(); /*! * Creates all necessary variables for a JANI automaton. */ void createVariablesForAutomaton(storm::jani::Automaton const& automaton); /*! * Creates all non-transient variables from the given set */ void createVariablesForVariableSet(storm::jani::VariableSet const& variableSet, bool global); }; } }