11 for (
auto const& assignment : assignments) {
22 for (
auto const& assignment : allAssignments) {
30 if (!addToExisting && this->
contains(assignment)) {
35 auto it = lowerBound(assignment, allAssignments);
38 if (it != allAssignments.end() && assignment.
getLValue() == (*it)->getLValue()) {
40 storm::exceptions::InvalidArgumentException,
41 "Cannot add assignment ('" << assignment.
getAssignedExpression() <<
"') as an assignment ('" << (*it)->getAssignedExpression()
42 <<
"') to LValue '" << (*it)->getLValue() <<
"' already exists.");
46 auto elementToInsert = std::make_shared<Assignment>(assignment);
47 allAssignments.emplace(it, elementToInsert);
49 auto transientIt = lowerBound(assignment, transientAssignments);
50 transientAssignments.emplace(transientIt, elementToInsert);
52 auto nonTransientIt = lowerBound(assignment, nonTransientAssignments);
53 nonTransientAssignments.emplace(nonTransientIt, elementToInsert);
67 auto it = lowerBound(assignment, allAssignments);
68 STORM_LOG_ASSERT(it != allAssignments.end(),
"Invalid iterator, expected existing element.");
70 allAssignments.erase(it);
73 auto transientIt = lowerBound(assignment, transientAssignments);
74 STORM_LOG_ASSERT(transientIt != transientAssignments.end(),
"Invalid iterator, expected existing element.");
76 transientAssignments.erase(transientIt);
78 auto nonTransientIt = lowerBound(assignment, nonTransientAssignments);
79 STORM_LOG_ASSERT(nonTransientIt != nonTransientAssignments.end(),
"Invalid iterator, expected existing element.");
80 STORM_LOG_ASSERT(assignment == **nonTransientIt,
"Wrong iterator position.");
81 nonTransientAssignments.erase(nonTransientIt);
87 if ((onlyTransient ? transientAssignments : allAssignments).
empty()) {
95 return transientAssignments.empty();
97 return allAssignments.empty();
101 allAssignments.clear();
102 transientAssignments.clear();
103 nonTransientAssignments.clear();
107 return allAssignments.size();
111 auto const& as = onlyTransient ? transientAssignments : allAssignments;
113 return as.front()->getLevel();
117 auto const& as = onlyTransient ? transientAssignments : allAssignments;
119 return as.back()->getLevel();
123 auto it = lowerBound(assignment, allAssignments);
124 if (it != allAssignments.end() && assignment == **it) {
132 bool changed =
false;
134 std::vector<Assignment> newAssignments;
135 for (uint64_t i = 0; i < allAssignments.size(); ++i) {
136 auto const& iLValue = allAssignments.at(i)->getLValue();
137 if (synchronous && !localVars.
hasVariable(iLValue.getVariable())) {
138 newAssignments.push_back(*(allAssignments.at(i)));
141 bool readBeforeWrite =
true;
142 for (uint64_t j = i + 1; j < allAssignments.size(); ++j) {
143 if (allAssignments.at(j)->getAssignedExpression().containsVariable({iLValue.getVariable().getExpressionVariable()})) {
147 if (iLValue == allAssignments.at(j)->getLValue()) {
149 readBeforeWrite =
false;
153 if (readBeforeWrite) {
154 newAssignments.push_back(*(allAssignments.at(i)));
164 std::vector<Assignment> newAssignments;
165 for (
auto const& assignment : allAssignments) {
166 newAssignments.push_back(*assignment);
167 if (synchronous && !localVars.
hasVariable(assignment->getLValue().getVariable())) {
170 if (assignment->getLevel() == 0) {
173 uint64_t assNr = upperBound(assignment->getLevel() - 1);
174 if (assNr == isWrittenBeforeAssignment(assignment->getLValue(), assNr)) {
175 if (assNr == isReadBeforeAssignment(assignment->getLValue(), assNr)) {
176 newAssignments.back().setLevel(0);
201 bool operator()(std::shared_ptr<Assignment>
const& left, int64_t
const& right)
const {
202 return left->getLevel() < right;
204 bool operator()(int64_t
const& left, std::shared_ptr<Assignment>
const& right)
const {
205 return left < right->getLevel();
222 return !transientAssignments.empty();
242 bool const substituteTranscendentalNumbers) {
243 for (
auto& assignment : allAssignments) {
244 assignment->substitute(substitution, substituteTranscendentalNumbers);
249 std::vector<Assignment> newAssignments;
250 for (
auto& assignment : allAssignments) {
251 newAssignments.emplace_back(assignment->getLValue().changeAssignmentVariables(remapping), assignment->getAssignedExpression(), assignment->getLevel());
256std::vector<std::shared_ptr<Assignment>>::const_iterator OrderedAssignments::lowerBound(
Assignment const& assignment,
257 std::vector<std::shared_ptr<Assignment>>
const& assignments) {
261uint64_t OrderedAssignments::isReadBeforeAssignment(LValue
const& lValue, uint64_t assignmentNumber, uint64_t start)
const {
262 Variable
const& var = lValue.getVariable();
264 STORM_LOG_WARN_COND(lValue.isVariable(),
"Called a method that is not optimized for arrays.");
265 for (uint64_t i = start; i < assignmentNumber; i++) {
266 if (allAssignments.at(i)->getAssignedExpression().containsVariable({var.getExpressionVariable()})) {
270 return assignmentNumber;
273uint64_t OrderedAssignments::isWrittenBeforeAssignment(LValue
const& lValue, uint64_t assignmentNumber, uint64_t start)
const {
274 for (uint64_t i = start;
i < assignmentNumber;
i++) {
275 if (allAssignments.at(i)->getLValue() == lValue) {
279 return assignmentNumber;
282uint64_t OrderedAssignments::upperBound(int64_t index)
const {
284 for (
auto const& assignment : allAssignments) {
285 if (assignment->getLevel() > index) {
296 result &= assignment.isLinear();
302 for (std::vector<std::shared_ptr<Assignment>>::const_iterator it = allAssignments.cbegin(); it != allAssignments.cend(); ++it) {
303 if (it != lowerBound(**it, allAssignments)) {
312 for (
auto const& e : assignments.allAssignments) {
313 stream <<
"\t" << *e <<
'\n';
static iterator make_iterator(input_iterator it)
boost::transform_iterator< Dereferencer< value_type >, input_iterator > iterator
bool hasNumericalType() const
Checks whether the variable is of numerical type.
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.
storm::expressions::Variable const & getExpressionVariable() const
Retrieves the expression variable that is written in this assignment.
bool isTransient() const
Retrieves whether the assignment assigns to a transient variable.
bool hasMultipleLevels(bool onlyTransient=false) const
Checks whether the assignments have several levels.
void substitute(std::map< storm::expressions::Variable, storm::expressions::Expression > const &substitution, bool const substituteTranscendentalNumbers)
Substitutes all variables in all expressions according to the given substitution.
void changeAssignmentVariables(std::map< Variable const *, std::reference_wrapper< Variable const > > const &remapping)
Changes all variables in assignments based on the given mapping.
bool empty(bool onlyTransient=false) const
Retrieves whether this set of assignments is empty.
OrderedAssignments simplifyLevels(bool synchronous, VariableSet const &localVars, bool first=true) const
Produces a new OrderedAssignments object with simplified leveling.
std::size_t getNumberOfAssignments() const
Retrieves the total number of assignments.
detail::Assignments::iterator begin()
Returns an iterator to the assignments.
int64_t getLowestLevel(bool onlyTransient=false) const
Retrieves the lowest level among all assignments.
detail::ConstAssignments getNonTransientAssignments() const
Returns all non-transient assignments in this set of assignments.
detail::ConstAssignments getTransientAssignments() const
Returns all transient assignments in this set of assignments.
bool checkOrder() const
Checks whether this ordered assignment is in the correct order.
int64_t getHighestLevel(bool onlyTransient=false) const
Retrieves the highest level among all assignments.
bool areLinear() const
Checks the assignments for linearity.
bool hasTransientAssignment() const
Retrieves whether the set of assignments has at least one transient assignment.
bool remove(Assignment const &assignment)
Removes the given assignment from this set of assignments.
detail::ConstAssignments getAllAssignments() const
Returns all assignments in this set of assignments.
OrderedAssignments clone() const
OrderedAssignments(std::vector< Assignment > const &assignments=std::vector< Assignment >())
Creates an ordered set of assignments.
detail::Assignments::iterator end()
Returns an iterator past the end of the assignments.
void clear()
Removes all assignments from this set.
bool add(Assignment const &assignment, bool addToExisting=false)
Adds the given assignment to the set of assignments.
bool contains(Assignment const &assignment) const
Retrieves whether the given assignment is contained in this set of assignments.
bool hasVariable(std::string const &name) const
Retrieves whether this variable set contains a variable with the given name.
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_WARN_COND(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
storm::adapters::DereferenceIteratorAdapter< std::vector< std::shared_ptr< Assignment > > const > ConstAssignments
std::ostream & operator<<(std::ostream &stream, Assignment const &assignment)
bool operator()(int64_t const &left, std::shared_ptr< Assignment > const &right) const
bool operator()(std::shared_ptr< Assignment > const &left, int64_t const &right) const
This functor enables ordering the assignments first by the assignment level and then by lValue.