Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Command.cpp
Go to the documentation of this file.
1#include "Command.h"
2
3namespace storm {
4namespace prism {
5Command::Command(uint_fast64_t globalIndex, bool markovian, uint_fast64_t actionIndex, std::string const& actionName,
6 storm::expressions::Expression const& guardExpression, std::vector<storm::prism::Update> const& updates, std::string const& filename,
7 uint_fast64_t lineNumber)
8 : LocatedInformation(filename, lineNumber),
9 actionIndex(actionIndex),
10 markovian(markovian),
11 actionName(actionName),
12 guardExpression(guardExpression),
13 updates(updates),
14 globalIndex(globalIndex),
15 labeled(actionName != "") {
16 // Nothing to do here.
17}
18
19uint_fast64_t Command::getActionIndex() const {
20 return this->actionIndex;
21}
22
24 return this->markovian;
25}
26
27void Command::setMarkovian(bool value) {
28 this->markovian = value;
29}
30
31std::string const& Command::getActionName() const {
32 return this->actionName;
33}
34
36 return guardExpression;
37}
38
39std::size_t Command::getNumberOfUpdates() const {
40 return this->updates.size();
41}
42
43storm::prism::Update const& Command::getUpdate(uint_fast64_t index) const {
44 STORM_LOG_ASSERT(index < getNumberOfUpdates(), "Invalid index.");
45 return this->updates[index];
46}
47
48std::vector<storm::prism::Update> const& Command::getUpdates() const {
49 return this->updates;
50}
51
52std::vector<storm::prism::Update>& Command::getUpdates() {
53 return this->updates;
54}
55
56uint_fast64_t Command::getGlobalIndex() const {
57 return this->globalIndex;
58}
59
60Command Command::substitute(std::map<storm::expressions::Variable, storm::expressions::Expression> const& substitution) const {
61 std::vector<Update> newUpdates;
62 newUpdates.reserve(this->getNumberOfUpdates());
63 for (auto const& update : this->getUpdates()) {
64 newUpdates.emplace_back(update.substitute(substitution));
65 }
66
67 return Command(this->getGlobalIndex(), this->isMarkovian(), this->getActionIndex(), this->getActionName(),
68 this->getGuardExpression().substitute(substitution).simplify(), newUpdates, this->getFilename(), this->getLineNumber());
69}
70
72 std::vector<Update> newUpdates;
73 newUpdates.reserve(this->getNumberOfUpdates());
74 for (auto const& update : this->getUpdates()) {
75 newUpdates.emplace_back(update.substituteNonStandardPredicates());
76 }
77
78 return Command(this->getGlobalIndex(), this->isMarkovian(), this->getActionIndex(), this->getActionName(),
80}
81
82bool Command::isLabeled() const {
83 return labeled;
84}
85
86bool Command::containsVariablesOnlyInUpdateProbabilities(std::set<storm::expressions::Variable> const& undefinedConstantVariables) const {
87 if (this->getGuardExpression().containsVariable(undefinedConstantVariables)) {
88 return false;
89 }
90 for (auto const& update : this->getUpdates()) {
91 for (auto const& assignment : update.getAssignments()) {
92 if (assignment.getExpression().containsVariable(undefinedConstantVariables)) {
93 return false;
94 }
95 }
96
97 // check likelihood, undefined constants may not occur in 'if' part of IfThenElseExpression
98 if (update.getLikelihoodExpression().containsVariableInITEGuard(undefinedConstantVariables)) {
99 return false;
100 }
101 }
102
103 return true;
104}
105
107 std::vector<Update> newUpdates;
108 newUpdates.reserve(this->getNumberOfUpdates());
109 for (auto const& update : this->getUpdates()) {
110 newUpdates.emplace_back(update.simplify());
111 }
112 auto simpleGuard = guardExpression.simplify().reduceNesting();
113 return Command(this->globalIndex, this->markovian, this->getActionIndex(), this->getActionName(), simpleGuard, newUpdates, this->getFilename(),
114 this->getLineNumber());
115}
116
117Command Command::copyWithNewUpdates(std::vector<Update>&& newUpdates) const {
118 return Command(this->globalIndex, this->markovian, this->getActionIndex(), this->getActionName(), guardExpression, newUpdates, this->getFilename(),
119 this->getLineNumber());
120}
121
122std::ostream& operator<<(std::ostream& stream, Command const& command) {
123 if (command.isMarkovian()) {
124 stream << "<" << command.getActionName() << "> ";
125 } else {
126 stream << "[" << command.getActionName() << "] ";
127 }
128 stream << command.getGuardExpression() << " -> ";
129 for (uint_fast64_t i = 0; i < command.getUpdates().size(); ++i) {
130 stream << command.getUpdate(i);
131 if (i < command.getUpdates().size() - 1) {
132 stream << " + ";
133 }
134 }
135 stream << ";";
136 return stream;
137}
138} // namespace prism
139} // namespace storm
Expression simplify() const
Simplifies the expression according to some basic rules.
Expression reduceNesting() const
Tries to flatten the syntax tree of the expression, e.g., 1 + (2 + (3 + 4)) becomes (1 + 2) + (3 + 4)
std::vector< storm::prism::Update > const & getUpdates() const
Retrieves a vector of all updates associated with this command.
Definition Command.cpp:48
bool isLabeled() const
Retrieves whether the command possesses a synchronization label.
Definition Command.cpp:82
std::size_t getNumberOfUpdates() const
Retrieves the number of updates associated with this command.
Definition Command.cpp:39
bool containsVariablesOnlyInUpdateProbabilities(std::set< storm::expressions::Variable > const &undefinedConstantVariables) const
Checks whether the given set of variables only appears in the update probabilities of the command.
Definition Command.cpp:86
std::string const & getActionName() const
Retrieves the action name of this command.
Definition Command.cpp:31
storm::prism::Update const & getUpdate(uint_fast64_t index) const
Retrieves a reference to the update with the given index.
Definition Command.cpp:43
Command substitute(std::map< storm::expressions::Variable, storm::expressions::Expression > const &substitution) const
Substitutes all identifiers in the command according to the given map.
Definition Command.cpp:60
void setMarkovian(bool value)
Sets whether this command is a Markovian command, i.e.
Definition Command.cpp:27
storm::expressions::Expression const & getGuardExpression() const
Retrieves a reference to the guard of the command.
Definition Command.cpp:35
Command simplify() const
Simplifies this command.
Definition Command.cpp:106
uint_fast64_t getActionIndex() const
Retrieves the action index of this command.
Definition Command.cpp:19
bool isMarkovian() const
Retrieves whether the command is a Markovian command, i.e.
Definition Command.cpp:23
Command substituteNonStandardPredicates() const
Definition Command.cpp:71
uint_fast64_t getGlobalIndex() const
Retrieves the global index of the command, that is, a unique index over all modules.
Definition Command.cpp:56
uint_fast64_t getLineNumber() const
Retrieves the line number in which the information was found.
std::string const & getFilename() const
Retrieves the name of the file in which the information was found.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
std::ostream & operator<<(std::ostream &stream, Assignment const &assignment)
LabParser.cpp.
Definition cli.cpp:18