Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Edge.cpp
Go to the documentation of this file.
2
5
8
10
11namespace storm {
12namespace jani {
13
14Edge::Edge(uint64_t sourceLocationIndex, uint64_t actionIndex, boost::optional<storm::expressions::Expression> const& rate,
15 std::shared_ptr<TemplateEdge> const& templateEdge,
16 std::vector<std::pair<uint64_t, storm::expressions::Expression>> const& destinationTargetLocationsAndProbabilities)
17 : sourceLocationIndex(sourceLocationIndex), actionIndex(actionIndex), rate(rate), templateEdge(templateEdge) {
18 // Create the concrete destinations from the template edge.
19 STORM_LOG_THROW(templateEdge->getNumberOfDestinations() == destinationTargetLocationsAndProbabilities.size(), storm::exceptions::InvalidArgumentException,
20 "Sizes of template edge destinations and target locations mismatch.");
21 for (uint64_t i = 0; i < templateEdge->getNumberOfDestinations(); ++i) {
22 auto const& templateDestination = templateEdge->getDestination(i);
23 destinations.emplace_back(destinationTargetLocationsAndProbabilities[i].first, destinationTargetLocationsAndProbabilities[i].second,
24 templateDestination);
25 }
26}
27
28Edge::Edge(uint64_t sourceLocationIndex, uint64_t actionIndex, boost::optional<storm::expressions::Expression> const& rate,
29 std::shared_ptr<TemplateEdge> const& templateEdge, std::vector<uint64_t> const& destinationLocations,
30 std::vector<storm::expressions::Expression> const& destinationProbabilities)
31 : sourceLocationIndex(sourceLocationIndex), actionIndex(actionIndex), rate(rate), templateEdge(templateEdge) {
32 // Create the concrete destinations from the template edge.
33 STORM_LOG_THROW(templateEdge->getNumberOfDestinations() == destinationLocations.size() && destinationLocations.size() == destinationProbabilities.size(),
34 storm::exceptions::InvalidArgumentException, "Sizes of template edge destinations and target locations mismatch.");
35 for (uint64_t i = 0; i < templateEdge->getNumberOfDestinations(); ++i) {
36 auto const& templateDestination = templateEdge->getDestination(i);
37 destinations.emplace_back(destinationLocations[i], destinationProbabilities[i], templateDestination);
38 }
39}
40
42 return sourceLocationIndex;
43}
44
45uint64_t Edge::getActionIndex() const {
46 return actionIndex;
47}
48
49bool Edge::hasRate() const {
50 return static_cast<bool>(rate);
51}
52
54 return rate.get();
55}
56
57boost::optional<storm::expressions::Expression> const& Edge::getOptionalRate() const {
58 return rate;
59}
60
62 this->rate = rate;
63}
64
66 return templateEdge->getGuard();
67}
68
70 templateEdge->setGuard(guard);
71}
72
73EdgeDestination const& Edge::getDestination(uint64_t index) const {
74 return destinations[index];
75}
76
77std::vector<EdgeDestination> const& Edge::getDestinations() const {
78 return destinations;
79}
80
81std::vector<EdgeDestination>& Edge::getDestinations() {
82 return destinations;
83}
84
85std::size_t Edge::getNumberOfDestinations() const {
86 return destinations.size();
87}
88
90 return templateEdge->getAssignments();
91}
92
93void Edge::substitute(std::map<storm::expressions::Variable, storm::expressions::Expression> const& substitution, bool const substituteTranscendentalNumbers) {
94 if (this->hasRate()) {
95 this->setRate(substituteJaniExpression(this->getRate(), substitution, substituteTranscendentalNumbers));
96 }
97 for (auto& destination : destinations) {
98 destination.substitute(substitution, substituteTranscendentalNumbers);
99 }
100}
101
103 return actionIndex == Model::SILENT_ACTION_INDEX;
104}
105
106uint64_t Edge::getColor() const {
107 return this->color;
108}
109
110void Edge::setColor(uint64_t newColor) {
111 this->color = newColor;
112}
113
115 return templateEdge->getWrittenGlobalVariables();
116}
117
118bool Edge::usesVariablesInNonTransientAssignments(std::set<storm::expressions::Variable> const& variables) const {
119 return templateEdge->usesVariablesInNonTransientAssignments(variables);
120}
121
123 return templateEdge->hasTransientEdgeDestinationAssignments();
124}
125
126bool Edge::usesAssignmentLevels(bool onlyTransient) const {
127 return templateEdge->usesAssignmentLevels(onlyTransient);
128}
129
131 if (usesAssignmentLevels()) {
132 templateEdge = std::make_shared<TemplateEdge>(templateEdge->simplifyIndexedAssignments(!hasSilentAction(), localVars));
133 std::vector<EdgeDestination> newdestinations;
134 assert(templateEdge->getNumberOfDestinations() == destinations.size());
135 for (uint64_t i = 0; i < templateEdge->getNumberOfDestinations(); ++i) {
136 auto const& templateDestination = templateEdge->getDestination(i);
137 newdestinations.emplace_back(destinations[i].getLocationIndex(), destinations[i].getProbability(), templateDestination);
138 }
139 destinations = newdestinations;
140 }
141}
142
143int64_t const& Edge::getLowestAssignmentLevel() const {
144 return templateEdge->getLowestAssignmentLevel();
145}
146
147int64_t const& Edge::getHighestAssignmentLevel() const {
148 return templateEdge->getHighestAssignmentLevel();
149}
150
151void Edge::setTemplateEdge(std::shared_ptr<TemplateEdge> const& newTe) {
152 templateEdge = newTe;
153 uint64_t i = 0;
154 std::vector<EdgeDestination> newdestinations;
155
156 assert(destinations.size() == newTe->getNumberOfDestinations());
157 for (auto& destination : destinations) {
158 newdestinations.emplace_back(destination.getLocationIndex(), destination.getProbability(), newTe->getDestination(i));
159 // destination.updateTemplateEdgeDestination(newTe->getDestination(i));
160 ++i;
161 }
162 destinations = newdestinations;
163}
164
165std::string Edge::toString() const {
166 std::stringstream ss;
167 ss << *this;
168 return ss.str();
169}
170
171std::shared_ptr<TemplateEdge> const& Edge::getTemplateEdge() {
172 return templateEdge;
173}
174
175std::ostream& operator<<(std::ostream& stream, Edge const& edge) {
176 stream << "[" << (edge.hasSilentAction() ? "" : ("action_id: " + std::to_string(edge.getActionIndex()))) << "]";
177 stream << "guard: '" << edge.getGuard() << "'\t from_location_id: " << edge.getSourceLocationIndex();
178 if (edge.hasRate()) {
179 stream << " with rate '" << edge.getRate() << "'";
180 }
181 if (edge.getDestinations().empty()) {
182 stream << "without any destination";
183 } else {
184 stream << " to ... [\n";
185 for (auto const& dest : edge.getDestinations()) {
186 stream << "\tlocation_id: " << dest.getLocationIndex() << " with probability '" << dest.getProbability() << "' and updates: ";
187 if (dest.getOrderedAssignments().empty()) {
188 stream << "none\n";
189 }
190 bool first = true;
191 for (auto const& a : dest.getOrderedAssignments()) {
192 if (first) {
193 first = false;
194 stream << a;
195 }
196 stream << ", " << a;
197 }
198 }
199 stream << "]";
200 }
201 if (edge.getColor() != 0) {
202 stream << " color: " << edge.getColor();
203 }
204 return stream;
205}
206} // namespace jani
207} // namespace storm
bool hasSilentAction() const
Returns whether it contains the silent action.
Definition Edge.cpp:102
void setTemplateEdge(std::shared_ptr< TemplateEdge > const &newTe)
Definition Edge.cpp:151
void setRate(storm::expressions::Expression const &rate)
Sets a new rate for this edge.
Definition Edge.cpp:61
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.
Definition Edge.cpp:118
std::string toString() const
Definition Edge.cpp:165
bool usesAssignmentLevels(bool onlyTransient=false) const
Retrieves whether the edge uses an assignment level other than zero.
Definition Edge.cpp:126
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.
Definition Edge.cpp:114
std::shared_ptr< TemplateEdge > const & getTemplateEdge()
Definition Edge.cpp:171
uint64_t getActionIndex() const
Retrieves the id of the action with which this edge is labeled.
Definition Edge.cpp:45
void simplifyIndexedAssignments(VariableSet const &localVars)
Definition Edge.cpp:130
std::vector< EdgeDestination > const & getDestinations() const
Retrieves the destinations of this edge.
Definition Edge.cpp:77
bool hasRate() const
Retrieves whether this edge has an associated rate.
Definition Edge.cpp:49
uint64_t getSourceLocationIndex() const
Retrieves the index of the source location.
Definition Edge.cpp:41
bool hasTransientEdgeDestinationAssignments() const
Retrieves whether there is any transient edge destination assignment in the edge.
Definition Edge.cpp:122
OrderedAssignments const & getAssignments() const
Retrieves the assignments of this edge.
Definition Edge.cpp:89
storm::expressions::Expression const & getRate() const
Retrieves the rate of this edge.
Definition Edge.cpp:53
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.
Definition Edge.cpp:93
int64_t const & getHighestAssignmentLevel() const
Retrieves the highest assignment level occurring in a destination assignment If no assignment exists,...
Definition Edge.cpp:147
std::size_t getNumberOfDestinations() const
Retrieves the number of destinations of this edge.
Definition Edge.cpp:85
boost::optional< storm::expressions::Expression > const & getOptionalRate() const
Retrieves an optional that stores the rate if there is any and none otherwise.
Definition Edge.cpp:57
uint64_t getColor() const
Retrieves the color of the edge.
Definition Edge.cpp:106
int64_t const & getLowestAssignmentLevel() const
Retrieves the lowest assignment level occurring in a destination assignment.
Definition Edge.cpp:143
void setGuard(storm::expressions::Expression const &guard)
Sets a new guard for this edge.
Definition Edge.cpp:69
storm::expressions::Expression const & getGuard() const
Retrieves the guard of this edge.
Definition Edge.cpp:65
EdgeDestination const & getDestination(uint64_t index) const
Retrieves the destination with the given index.
Definition Edge.cpp:73
void setColor(uint64_t newColor)
Sets the color of the edge.
Definition Edge.cpp:110
static const uint64_t SILENT_ACTION_INDEX
The index of the silent action.
Definition Model.h:642
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
storm::expressions::Expression substituteJaniExpression(storm::expressions::Expression const &expression, std::map< storm::expressions::Variable, storm::expressions::Expression > const &identifierToExpressionMap, bool const substituteTranscendentalNumbers)
std::ostream & operator<<(std::ostream &stream, Assignment const &assignment)
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