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