Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Property.cpp
Go to the documentation of this file.
1#include "Property.h"
2
3namespace storm {
4namespace jani {
5
6std::ostream& operator<<(std::ostream& os, FilterExpression const& fe) {
7 return os << "Obtain " << toString(fe.getFilterType()) << " of the '" << *fe.getStatesFormula() << "'-states with values described by '" << *fe.getFormula()
8 << "'";
9}
10
11Property::Property(std::string const& name, std::shared_ptr<storm::logic::Formula const> const& formula,
12 std::set<storm::expressions::Variable> const& undefinedConstants, std::string const& comment)
13 : name(name), comment(comment), filterExpression(FilterExpression(formula)), undefinedConstants(undefinedConstants) {
14 // Intentionally left empty.
15}
16
17Property::Property(std::string const& name, FilterExpression const& fe, std::set<storm::expressions::Variable> const& undefinedConstants,
18 std::string const& comment)
19 : name(name), comment(comment), filterExpression(fe), undefinedConstants(undefinedConstants) {
20 // Intentionally left empty.
21}
22
23std::string const& Property::getName() const {
24 return this->name;
25}
26
27std::string const& Property::getComment() const {
28 return this->comment;
29}
30
31std::string Property::asPrismSyntax() const {
32 std::stringstream stream;
33 if (!this->getName().empty()) {
34 stream << "\"" << this->getName() << "\": ";
35 }
36 auto fe = this->getFilter();
37 if (fe.isDefault()) {
38 stream << *fe.getFormula();
39 } else {
40 stream << "filter(" << storm::modelchecker::toString(fe.getFilterType()) << ", " << *fe.getFormula();
41 if (fe.getStatesFormula() && !fe.getStatesFormula()->isInitialFormula()) {
42 stream << ", " << *fe.getFormula();
43 }
44 stream << ")";
45 }
46 stream << ";";
47
48 if (!this->getComment().empty()) {
49 stream << " // " << this->getComment();
50 }
51 return stream.str();
52}
53
54Property Property::substitute(std::map<storm::expressions::Variable, storm::expressions::Expression> const& substitution) const {
55 std::set<storm::expressions::Variable> remainingUndefinedConstants;
56 for (auto const& constant : undefinedConstants) {
57 if (substitution.find(constant) == substitution.end()) {
58 remainingUndefinedConstants.insert(constant);
59 }
60 }
61 return Property(name, filterExpression.substitute(substitution), remainingUndefinedConstants, comment);
62}
63
64Property Property::substitute(std::function<storm::expressions::Expression(storm::expressions::Expression const&)> const& substitutionFunction) const {
65 std::set<storm::expressions::Variable> remainingUndefinedConstants;
66 for (auto const& constant : undefinedConstants) {
67 substitutionFunction(constant.getExpression()).getBaseExpression().gatherVariables(remainingUndefinedConstants);
68 }
69 return Property(name, filterExpression.substitute(substitutionFunction), remainingUndefinedConstants, comment);
70}
71
72Property Property::substituteLabels(std::map<std::string, std::string> const& substitution) const {
73 return Property(name, filterExpression.substituteLabels(substitution), undefinedConstants, comment);
74}
75
76Property Property::substituteRewardModelNames(std::map<std::string, std::string> const& rewardModelNameSubstitution) const {
77 return Property(name, filterExpression.substituteRewardModelNames(rewardModelNameSubstitution), undefinedConstants, comment);
78}
79
81 return Property(name, filterExpression.substituteTranscendentalNumbers(), undefinedConstants, comment);
82}
83
85 return Property(name, filterExpression.clone(), undefinedConstants, comment);
86}
87
89 return this->filterExpression;
90}
91
92std::shared_ptr<storm::logic::Formula const> Property::getRawFormula() const {
93 return this->filterExpression.getFormula();
94}
95
96std::set<storm::expressions::Variable> const& Property::getUndefinedConstants() const {
97 return undefinedConstants;
98}
99
101 return !undefinedConstants.empty();
102}
103
104std::set<storm::expressions::Variable> Property::getUsedVariablesAndConstants() const {
105 auto res = getUndefinedConstants();
106 getFilter().getFormula()->gatherUsedVariables(res);
107 getFilter().getStatesFormula()->gatherUsedVariables(res);
108 return res;
109}
110
111std::set<std::string> Property::getUsedLabels() const {
112 std::set<std::string> res;
113 auto labFormSet = getFilter().getFormula()->getAtomicLabelFormulas();
114 for (auto const& f : labFormSet) {
115 res.insert(f->getLabel());
116 }
117 labFormSet = getFilter().getStatesFormula()->getAtomicLabelFormulas();
118 for (auto const& f : labFormSet) {
119 res.insert(f->getLabel());
120 }
121 return res;
122}
123
124void Property::gatherReferencedRewardModels(std::set<std::string>& rewardModelNames) const {
125 getFilter().getFormula()->gatherReferencedRewardModels(rewardModelNames);
126 getFilter().getStatesFormula()->gatherReferencedRewardModels(rewardModelNames);
127}
128
129std::ostream& operator<<(std::ostream& os, Property const& p) {
130 return os << "(" << p.getName() << "): " << p.getFilter();
131}
132
133} // namespace jani
134} // namespace storm
FilterExpression substitute(std::map< storm::expressions::Variable, storm::expressions::Expression > const &substitution) const
Definition Property.h:64
std::shared_ptr< storm::logic::Formula const > const & getFormula() const
Definition Property.h:48
FilterExpression substituteRewardModelNames(std::map< std::string, std::string > const &rewardModelNameSubstitution) const
Definition Property.h:76
FilterExpression substituteTranscendentalNumbers() const
Definition Property.h:81
FilterExpression substituteLabels(std::map< std::string, std::string > const &labelSubstitution) const
Definition Property.h:72
std::shared_ptr< storm::logic::Formula const > const & getStatesFormula() const
Definition Property.h:52
storm::modelchecker::FilterType getFilterType() const
Definition Property.h:56
FilterExpression clone() const
Definition Property.h:85
std::shared_ptr< storm::logic::Formula const > getRawFormula() const
Definition Property.cpp:92
std::set< storm::expressions::Variable > const & getUndefinedConstants() const
Definition Property.cpp:96
bool containsUndefinedConstants() const
Definition Property.cpp:100
std::set< storm::expressions::Variable > getUsedVariablesAndConstants() const
Definition Property.cpp:104
void gatherReferencedRewardModels(std::set< std::string > &rewardModelNames) const
Definition Property.cpp:124
std::string const & getName() const
Get the provided name.
Definition Property.cpp:23
Property substituteTranscendentalNumbers() const
Definition Property.cpp:80
std::string const & getComment() const
Get the provided comment, if any.
Definition Property.cpp:27
Property substitute(std::map< storm::expressions::Variable, storm::expressions::Expression > const &substitution) const
Definition Property.cpp:54
Property substituteRewardModelNames(std::map< std::string, std::string > const &rewardModelNameSubstitution) const
Definition Property.cpp:76
FilterExpression const & getFilter() const
Definition Property.cpp:88
std::string asPrismSyntax() const
Definition Property.cpp:31
std::set< std::string > getUsedLabels() const
Definition Property.cpp:111
Property substituteLabels(std::map< std::string, std::string > const &labelSubstitution) const
Definition Property.cpp:72
Property clone() const
Definition Property.cpp:84
std::string toString(ModelFeature const &modelFeature)
std::ostream & operator<<(std::ostream &stream, Assignment const &assignment)
std::string toString(FilterType ft)
Definition FilterType.cpp:9
LabParser.cpp.
Definition cli.cpp:18