4#include <boost/algorithm/string/join.hpp>
14 std::string
const& filename, uint_fast64_t lineNumber)
15 :
Update(globalIndex,
std::make_pair(likelihoodExpression,
storm::
expressions::Expression()), assignments, filename, lineNumber) {
30 auto simplified = expression.
simplify();
34Update::Update(uint_fast64_t globalIndex,
ExpressionPair const& likelihoodExpressionInterval, std::vector<storm::prism::Assignment>
const& assignments,
35 std::string
const& filename, uint_fast64_t lineNumber)
37 likelihoodExpressions(likelihoodExpressionInterval),
38 assignments(assignments),
39 variableToAssignmentIndexMap(),
40 globalIndex(globalIndex) {
41 STORM_LOG_ASSERT(likelihoodExpressions.first.isInitialized(),
"likelihoodExpression must be initialized");
44 "Negative likelihood expressions are not allowed. Got " << likelihoodExpressions.first <<
".");
46 "Negative likelihood expressions are not allowed. Got " << likelihoodExpressions.second <<
".");
48 bool smaller = assignment1.getVariable().getType().isBooleanType() && !assignment2.getVariable().getType().isBooleanType();
50 smaller = assignment1.getVariable() < assignment2.getVariable();
54 this->createAssignmentMapping();
58 return likelihoodExpressions.second.isInitialized();
63 return likelihoodExpressions.first;
68 return likelihoodExpressions;
72 return this->assignments.size();
76 return this->assignments;
80 return this->assignments;
84 auto const& variableIndexPair = this->variableToAssignmentIndexMap.find(variableName);
85 STORM_LOG_THROW(variableIndexPair != this->variableToAssignmentIndexMap.end(), storm::exceptions::OutOfRangeException,
86 "Variable '" << variableName <<
"' is not assigned in update.");
91 std::map<storm::expressions::Variable, storm::expressions::Expression> result;
94 result.emplace(assignment.getVariable(), assignment.getExpression());
101 return this->globalIndex;
104void Update::createAssignmentMapping() {
105 this->variableToAssignmentIndexMap.clear();
106 for (uint_fast64_t assignmentIndex = 0; assignmentIndex < this->getAssignments().size(); ++assignmentIndex) {
107 this->variableToAssignmentIndexMap[this->getAssignments()[assignmentIndex].getVariableName()] = assignmentIndex;
112 std::vector<Assignment> newAssignments;
115 newAssignments.emplace_back(assignment.substitute(substitution));
118 auto res = expr.substitute(substitution).simplify();
120 "Substitution yielding negative probabilities in '" << expr <<
"' are not allowed.");
134 std::vector<Assignment> newAssignments;
137 newAssignments.emplace_back(assignment.substituteNonStandardPredicates());
140 auto res = expr.substituteNonStandardPredicates().simplify();
142 "Predicate substitution yielding negative probabilities in '" << expr <<
"' are not allowed.");
156 std::vector<Assignment> newAssignments;
158 for (
auto const& ass : this->assignments) {
159 if (!ass.isIdentity()) {
160 newAssignments.push_back(ass);
167 std::vector<Assignment> newAssignments;
169 for (
auto const& ass : this->assignments) {
170 Assignment newAssignment(ass.getVariable(), ass.getExpression().simplify().reduceNesting(), ass.getFilename(), ass.getLineNumber());
172 newAssignments.push_back(std::move(newAssignment));
193 std::vector<std::string> assignmentsAsStrings;
195 std::stringstream sstream;
196 sstream << assignment;
197 assignmentsAsStrings.push_back(sstream.str());
199 stream << boost::algorithm::join(assignmentsAsStrings,
" & ");
Expression simplify() const
Simplifies the expression according to some basic rules.
storm::RationalNumber evaluateAsRational() const
Evaluates the expression and returns the resulting rational number.
bool isLiteral() const
Retrieves whether the expression is a literal.
bool isInitialized() const
Checks whether the object encapsulates a base-expression.
bool isIdentity() const
Checks whether the assignment is an identity (lhs equals rhs).
Update substituteNonStandardPredicates() const
std::size_t getNumberOfAssignments() const
Retrieves the number of assignments associated with this update.
bool isLikelihoodInterval() const
Update substitute(std::map< storm::expressions::Variable, storm::expressions::Expression > const &substitution) const
Substitutes all identifiers in the update according to the given map.
Update simplify() const
Simplifies the update in various ways (also removes identity assignments).
std::pair< storm::expressions::Expression, storm::expressions::Expression > ExpressionPair
Update(uint_fast64_t globalIndex, storm::expressions::Expression const &likelihoodExpression, std::vector< storm::prism::Assignment > const &assignments, std::string const &filename="", uint_fast64_t lineNumber=0)
Creates an update with the given expression specifying the likelihood and assignments.
std::map< storm::expressions::Variable, storm::expressions::Expression > getAsVariableToExpressionMap() const
Creates a mapping representation of this update.
storm::prism::Assignment const & getAssignment(std::string const &variableName) const
Retrieves a reference to the assignment for the variable with the given name.
uint_fast64_t getGlobalIndex() const
Retrieves the global index of the update, that is, a unique index over all modules.
Update removeIdentityAssignments() const
Removes all assignments which do not change the variable.
ExpressionPair const & getLikelihoodExpressionInterval() const
Retrieves the two expression for the interval likelihood of this update.
std::vector< storm::prism::Assignment > const & getAssignments() const
Retrieves a reference to the map of variable names to their respective assignments.
storm::expressions::Expression const & getLikelihoodExpression() const
Retrieves the expression for the likelihood of this update.
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
bool isValidLikelihood(storm::expressions::Expression const &expression)
bool isValidLikelihoodSimpl(storm::expressions::Expression const &simplifiedExpression)
helper to assert valid likelihood expressions
std::ostream & operator<<(std::ostream &stream, ConditionalAlgorithmSetting const &algorithm)