Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
TemplateEdge.cpp
Go to the documentation of this file.
2
5
8
9namespace storm {
10namespace jani {
11
13 : guard(guard), lowestAssignmentLevel(std::numeric_limits<int64_t>::max()), highestAssignmentLevel(std::numeric_limits<int64_t>::min()) {
14 // Intentionally left empty.
15}
16
18 std::vector<TemplateEdgeDestination> const& destinations)
19 : guard(guard),
20 destinations(destinations),
21 assignments(assignments),
22 lowestAssignmentLevel(std::numeric_limits<int64_t>::max()),
23 highestAssignmentLevel(std::numeric_limits<int64_t>::min()) {
24 // Intentionally left empty.
25}
26
28 destinations.emplace_back(destination);
29}
30
31bool TemplateEdge::addTransientAssignment(Assignment const& assignment, bool addToExisting) {
32 return assignments.add(assignment, addToExisting);
33}
34
35void TemplateEdge::finalize(Model const& containingModel) {
36 lowestAssignmentLevel = std::numeric_limits<int64_t>::max();
37 highestAssignmentLevel = std::numeric_limits<int64_t>::min();
38 for (auto const& destination : getDestinations()) {
39 if (!destination.getOrderedAssignments().empty()) {
40 lowestAssignmentLevel = std::min(lowestAssignmentLevel, destination.getOrderedAssignments().getLowestLevel());
41 highestAssignmentLevel = std::max(highestAssignmentLevel, destination.getOrderedAssignments().getHighestLevel());
42 }
43 for (auto const& assignment : destination.getOrderedAssignments().getAllAssignments()) {
44 Variable const& var = assignment.getVariable();
45 if (containingModel.getGlobalVariables().hasVariable(var.getExpressionVariable())) {
46 writtenGlobalVariables.insert(var.getExpressionVariable());
47 }
48 }
49 }
50}
51
55
57 return guard;
58}
59
61 guard = newGuard;
62}
63
65 return destinations.size();
66}
67
68std::vector<TemplateEdgeDestination> const& TemplateEdge::getDestinations() const {
69 return destinations;
70}
71
72std::vector<TemplateEdgeDestination>& TemplateEdge::getDestinations() {
73 return destinations;
74}
75
77 return destinations[index];
78}
79
81 return assignments;
82}
83
85 return assignments;
86}
87
88void TemplateEdge::substitute(std::map<storm::expressions::Variable, storm::expressions::Expression> const& substitution,
89 bool const substituteTranscendentalNumbers) {
90 guard = substituteJaniExpression(guard, substitution, substituteTranscendentalNumbers);
91
92 for (auto& assignment : assignments) {
93 assignment.substitute(substitution, substituteTranscendentalNumbers);
94 }
95
96 for (auto& destination : destinations) {
97 destination.substitute(substitution, substituteTranscendentalNumbers);
98 }
99}
100
101void TemplateEdge::changeAssignmentVariables(std::map<Variable const*, std::reference_wrapper<Variable const>> const& remapping) {
102 for (auto& destination : destinations) {
103 destination.changeAssignmentVariables(remapping);
104 }
105 assignments.changeAssignmentVariables(remapping);
106}
107
109 if (!destinations.empty()) {
110 auto const& destination = *destinations.begin();
111
112 std::vector<std::shared_ptr<Assignment>> assignmentsToLift;
113
114 for (auto const& assignment : destination.getOrderedAssignments().getTransientAssignments()) {
115 // Check if we can lift the assignment to the edge.
116 bool canBeLifted = assignment.getLevel() <= maxLevel;
117 if (canBeLifted) {
118 for (auto const& destination : destinations) {
119 if (!destination.hasAssignment(assignment)) {
120 canBeLifted = false;
121 break;
122 }
123 }
124 }
125
126 if (canBeLifted) {
127 // Do not remove the assignment now, as we currently iterate over them.
128 // Also we need to make a copy of the assignment since we are about to delete it
129 assignmentsToLift.push_back(std::make_shared<Assignment>(assignment));
130 }
131 }
132
133 // now actually lift the assignments
134 for (auto const& assignment : assignmentsToLift) {
135 this->addTransientAssignment(*assignment);
136 for (auto& destination : destinations) {
137 destination.removeAssignment(*assignment);
138 }
139 }
140 }
141}
142
144 STORM_LOG_ASSERT(!destinations.empty(), "Need non-empty destinations for this transformation.");
145 for (auto const& assignment : this->getAssignments()) {
146 for (auto& destination : destinations) {
147 destination.addAssignment(assignment, true);
148 }
149 }
150 this->assignments.clear();
151}
152
153bool TemplateEdge::usesVariablesInNonTransientAssignments(std::set<storm::expressions::Variable> const& variables) const {
154 for (auto const& destination : destinations) {
155 for (auto const& assignment : destination.getOrderedAssignments().getNonTransientAssignments()) {
156 if (assignment.getAssignedExpression().containsVariable(variables)) {
157 return true;
158 }
159 }
160 }
161 return false;
162}
163
165 for (auto const& destination : this->getDestinations()) {
166 if (destination.hasTransientAssignment()) {
167 return true;
168 }
169 }
170 return false;
171}
172
173bool TemplateEdge::usesAssignmentLevels(bool onlyTransient) const {
174 if (assignments.hasMultipleLevels(onlyTransient)) {
175 return true;
176 }
177 for (auto const& destination : this->getDestinations()) {
178 if (destination.usesAssignmentLevels(onlyTransient)) {
179 return true;
180 }
181 }
182 return false;
183}
184
186 return lowestAssignmentLevel;
187}
188
190 return highestAssignmentLevel;
191}
192
194 for (auto const& destination : destinations) {
195 if (destination.hasAssignments()) {
196 return true;
197 }
198 }
199 return false;
200}
201
204
205 bool result = linearityChecker.check(this->getGuard(), true);
206 for (auto const& destination : destinations) {
207 result &= destination.isLinear();
208 }
209 return result;
210}
211
212TemplateEdge TemplateEdge::simplifyIndexedAssignments(bool syncronized, VariableSet const& localVars) const {
213 // We currently only support cases where we have EITHER edge assignments or destination assignments.
214 if (assignments.empty()) {
215 // Only edge destination assignments:
216 TemplateEdge simplifiedTemplateEdge(guard);
217 for (auto const& dest : destinations) {
218 simplifiedTemplateEdge.addDestination(dest.simplifyIndexedAssignments(syncronized, localVars));
219 }
220 return simplifiedTemplateEdge;
221 } else if (!hasEdgeDestinationAssignments()) {
222 return TemplateEdge(guard, assignments.simplifyLevels(syncronized, localVars), destinations);
223 } else {
224 return TemplateEdge(*this);
225 }
226}
227} // namespace jani
228} // namespace storm
bool check(Expression const &expression, bool booleanIsLinear=false)
Checks that the given expression is linear.
VariableSet & getGlobalVariables()
Retrieves the variables of this automaton.
Definition Model.cpp:721
bool hasMultipleLevels(bool onlyTransient=false) const
Checks whether the assignments have several levels.
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.
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 hasTransientEdgeDestinationAssignments() const
Retrieves whether there is any transient edge destination assignment in the edge.
void finalize(Model const &containingModel)
Finalizes the building of this edge.
storm::expressions::Expression const & getGuard() const
bool usesVariablesInNonTransientAssignments(std::set< storm::expressions::Variable > const &variables) const
Checks whether the provided variables appear on the right-hand side of non-transient assignments.
std::vector< TemplateEdgeDestination > const & getDestinations() const
int64_t const & getLowestAssignmentLevel() const
Retrieves the lowest assignment level occurring in a destination assignment.
bool isLinear() const
Checks the template edge for linearity.
bool usesAssignmentLevels(bool onlyTransient=false) const
Retrieves whether the edge uses an assignment level other than zero.
void setGuard(storm::expressions::Expression const &newGuard)
void liftTransientDestinationAssignments(int64_t maxLevel=0)
Finds the transient assignments common to all destinations and lifts them to the edge.
OrderedAssignments const & getAssignments() const
std::size_t getNumberOfDestinations() const
int64_t const & getHighestAssignmentLevel() const
Retrieves the highest assignment level occurring in a destination assignment If no assignment exists,...
void pushAssignmentsToDestinations()
Shifts the assingments from the edges to the destinations.
bool hasEdgeDestinationAssignments() const
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.
bool addTransientAssignment(Assignment const &assignment, bool addToExisting=false)
Adds a transient assignment to this edge.
void changeAssignmentVariables(std::map< Variable const *, std::reference_wrapper< Variable const > > const &remapping)
Changes all variables in assignments based on the given mapping.
TemplateEdge simplifyIndexedAssignments(bool syncronized, VariableSet const &localVars) const
Simplify Indexed Assignments.
TemplateEdgeDestination const & getDestination(uint64_t index) const
storm::storage::FlatSet< storm::expressions::Variable > const & getWrittenGlobalVariables() const
Retrieves a set of (global) variables that are written by at least one of the edge's destinations.
void addDestination(TemplateEdgeDestination const &destination)
storm::expressions::Variable const & getExpressionVariable() const
Retrieves the associated expression variable.
Definition Variable.cpp:26
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)
Definition macros.h:11
storm::expressions::Expression substituteJaniExpression(storm::expressions::Expression const &expression, std::map< storm::expressions::Variable, storm::expressions::Expression > const &identifierToExpressionMap, bool const substituteTranscendentalNumbers)
boost::container::flat_set< Key, std::less< Key >, boost::container::new_allocator< Key > > FlatSet
Redefinition of flat_set was needed, because from Boost 1.70 on the default allocator is set to void.
Definition BoostTypes.h:13
LabParser.cpp.
Definition cli.cpp:18