Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SymbolicModelDescription.cpp
Go to the documentation of this file.
2
3#include "storm/utility/cli.h"
6
10
14
15namespace storm {
16namespace storage {
17
19 // Intentionally left empty.
20}
21
23 // Intentionally left empty.
24}
25
27 this->modelDescription = model;
28 return *this;
29}
30
32 this->modelDescription = program;
33 return *this;
34}
35
37 return static_cast<bool>(modelDescription);
38}
39
41 return modelDescription.get().which() == 0;
42}
43
45 return modelDescription.get().which() == 1;
46}
47
49 if (this->isJaniModel()) {
50 storm::jani::Model const& janiModel = this->asJaniModel();
51 switch (janiModel.getModelType()) {
60 default:
61 STORM_LOG_THROW(false, storm::exceptions::InvalidTypeException, "Expected other JANI model type.");
62 }
63 } else {
64 storm::prism::Program const& prismProgram = this->asPrismProgram();
65 switch (prismProgram.getModelType()) {
78 default:
79 STORM_LOG_THROW(false, storm::exceptions::InvalidTypeException, "Expected other PRISM model type.");
80 }
81 }
82}
83
85 if (this->isPrismProgram()) {
86 return this->asPrismProgram().getManager();
87 } else {
88 return this->asJaniModel().getManager();
89 }
90}
91
93 modelDescription = model;
94}
95
97 modelDescription = program;
98}
99
101 STORM_LOG_THROW(isJaniModel(), storm::exceptions::InvalidOperationException,
102 "Cannot retrieve JANI model, because the symbolic description has a different type.");
103 return boost::get<storm::jani::Model>(modelDescription.get());
104}
105
107 STORM_LOG_THROW(isJaniModel(), storm::exceptions::InvalidOperationException,
108 "Cannot retrieve JANI model, because the symbolic description has a different type.");
109 return boost::get<storm::jani::Model>(modelDescription.get());
110}
111
113 STORM_LOG_THROW(isPrismProgram(), storm::exceptions::InvalidOperationException,
114 "Cannot retrieve JANI model, because the symbolic description has a different type.");
115 return boost::get<storm::prism::Program>(modelDescription.get());
116}
117
119 STORM_LOG_THROW(isPrismProgram(), storm::exceptions::InvalidOperationException,
120 "Cannot retrieve JANI model, because the symbolic description has a different type.");
121 return boost::get<storm::prism::Program>(modelDescription.get());
122}
123
124std::vector<std::string> SymbolicModelDescription::getParameterNames() const {
125 std::vector<std::string> result;
126 if (isJaniModel()) {
127 for (auto const& c : asJaniModel().getUndefinedConstants()) {
128 result.push_back(c.get().getName());
129 }
130 } else {
131 for (auto const& c : asPrismProgram().getUndefinedConstants()) {
132 result.push_back(c.get().getName());
133 }
134 }
135 return result;
136}
137
139 if (this->isJaniModel()) {
140 return *this;
141 }
142 if (this->isPrismProgram()) {
143 return SymbolicModelDescription(this->asPrismProgram().toJani(makeVariablesGlobal, ""));
144 } else {
145 STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Cannot transform model description to the JANI format.");
146 }
147}
148
149std::pair<SymbolicModelDescription, std::vector<storm::jani::Property>> SymbolicModelDescription::toJani(std::vector<storm::jani::Property> const& properties,
150 bool makeVariablesGlobal) const {
151 if (this->isJaniModel()) {
152 return std::make_pair(*this, std::vector<storm::jani::Property>());
153 }
154 if (this->isPrismProgram()) {
155 auto modelProperties = this->asPrismProgram().toJani(properties, makeVariablesGlobal, "");
156 return std::make_pair(SymbolicModelDescription(modelProperties.first), modelProperties.second);
157 } else {
158 STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Cannot transform model description to the JANI format.");
159 }
160}
161
162SymbolicModelDescription SymbolicModelDescription::preprocess(std::string const& constantDefinitionString) const {
163 std::map<storm::expressions::Variable, storm::expressions::Expression> substitution = parseConstantDefinitions(constantDefinitionString);
164 return preprocess(substitution);
165}
166
168 std::map<storm::expressions::Variable, storm::expressions::Expression> const& constantDefinitions) const {
169 if (this->isJaniModel()) {
170 storm::jani::Model preparedModel = this->asJaniModel().defineUndefinedConstants(constantDefinitions).substituteConstants();
171 // We intentionally do not eliminate function expressions in jani models at this point because that would also remove the function
172 // declarations from the model. However, those might still be needed to, e.g., process properties that refer to functions.
173 return SymbolicModelDescription(preparedModel);
174 } else if (this->isPrismProgram()) {
176 this->asPrismProgram().defineUndefinedConstants(constantDefinitions).substituteConstantsFormulas().substituteNonStandardPredicates());
177 }
178 return *this;
179}
180
181std::map<storm::expressions::Variable, storm::expressions::Expression> SymbolicModelDescription::parseConstantDefinitions(
182 std::string const& constantDefinitionString) const {
183 if (this->isJaniModel()) {
184 return storm::utility::cli::parseConstantDefinitionString(this->asJaniModel().getManager(), constantDefinitionString);
185 } else {
186 return storm::utility::cli::parseConstantDefinitionString(this->asPrismProgram().getManager(), constantDefinitionString);
187 }
188}
189
197
199 if (this->isPrismProgram()) {
200 return this->asPrismProgram().hasUndefinedConstants();
201 } else {
202 return this->asJaniModel().hasUndefinedConstants();
203 }
204}
205
206std::vector<storm::expressions::Variable> SymbolicModelDescription::getUndefinedConstants() const {
207 std::vector<storm::expressions::Variable> result;
208 if (this->isPrismProgram()) {
209 std::vector<std::reference_wrapper<storm::prism::Constant const>> constants = this->asPrismProgram().getUndefinedConstants();
210 for (auto const& constant : constants) {
211 result.emplace_back(constant.get().getExpressionVariable());
212 }
213 } else {
214 std::vector<std::reference_wrapper<storm::jani::Constant const>> constants = this->asJaniModel().getUndefinedConstants();
215 for (auto const& constant : constants) {
216 result.emplace_back(constant.get().getExpressionVariable());
217 }
218 }
219 return result;
220}
221
222std::ostream& operator<<(std::ostream& out, SymbolicModelDescription const& model) {
223 if (model.isPrismProgram()) {
224 out << model.asPrismProgram();
225 } else if (model.isJaniModel()) {
226 out << model.asJaniModel();
227 } else {
228 out << "unkown symbolic model description";
229 }
230 return out;
231}
232
233std::ostream& operator<<(std::ostream& out, SymbolicModelDescription::ModelType const& type) {
234 switch (type) {
236 out << "dtmc";
237 break;
239 out << "ctmc";
240 break;
242 out << "mdp";
243 break;
245 out << "ma";
246 break;
248 out << "pomdp";
249 break;
251 out << "smg";
252 break;
253 }
254 return out;
255}
256} // namespace storage
257} // namespace storm
This class is responsible for managing a set of typed variables and all expressions using these varia...
bool hasUndefinedConstants() const
Retrieves whether the model still has undefined constants.
Definition Model.cpp:1083
storm::expressions::ExpressionManager & getManager() const
Retrieves the expression manager responsible for the expressions in the model.
Definition Model.cpp:113
ModelType const & getModelType() const
Retrieves the type of the model.
Definition Model.cpp:121
Model substituteConstants() const
Substitutes all constants in all expressions of the model.
Definition Model.cpp:1144
Model defineUndefinedConstants(std::map< storm::expressions::Variable, storm::expressions::Expression > const &constantDefinitions) const
Defines the undefined constants of the model by the given expressions.
Definition Model.cpp:1046
std::vector< std::reference_wrapper< Constant const > > getUndefinedConstants() const
Retrieves all undefined constants of the model.
Definition Model.cpp:1092
ModelType getModelType() const
Retrieves the model type of the model.
Definition Program.cpp:247
std::vector< std::reference_wrapper< Constant const > > getUndefinedConstants() const
Retrieves the undefined constants in the program.
Definition Program.cpp:368
storm::expressions::ExpressionManager & getManager() const
Retrieves the manager responsible for the expressions of this program.
Definition Program.cpp:2359
bool hasUndefinedConstants() const
Retrieves whether there are undefined constants of any type in the program.
Definition Program.cpp:285
storm::jani::Model toJani(bool allVariablesGlobal=true, std::string suffix="") const
Converts the PRISM model into an equivalent JANI model.
Definition Program.cpp:2321
std::map< storm::expressions::Variable, storm::expressions::Expression > parseConstantDefinitions(std::string const &constantDefinitionString) const
SymbolicModelDescription & operator=(storm::jani::Model const &model)
storm::prism::Program const & asPrismProgram() const
std::vector< storm::expressions::Variable > getUndefinedConstants() const
storm::expressions::ExpressionManager & getManager() const
std::vector< std::string > getParameterNames() const
SymbolicModelDescription toJani(bool makeVariablesGlobal=true) const
void setModel(storm::jani::Model const &model)
storm::jani::Model const & asJaniModel() const
SymbolicModelDescription preprocess(std::string const &constantDefinitionString="") const
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
std::ostream & operator<<(std::ostream &out, ParameterRegion< ParametricType > const &region)
std::map< storm::expressions::Variable, storm::expressions::Expression > parseConstantDefinitionString(storm::expressions::ExpressionManager const &manager, std::string const &constantDefinitionString)
Definition cli.cpp:18
void requireNoUndefinedConstants(storm::jani::Model const &model)
Definition jani.cpp:15
void requireNoUndefinedConstants(storm::prism::Program const &program)
Definition prism.cpp:30
LabParser.cpp.
Definition cli.cpp:18