Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
properties.cpp
Go to the documentation of this file.
2
6#include "storm/io/file.h"
13#include "storm/utility/cli.h"
14
15namespace storm {
16namespace api {
17
18boost::optional<std::set<std::string>> parsePropertyFilter(std::string const& propertyFilter) {
19 if (propertyFilter == "all") {
20 return boost::none;
21 }
22 std::vector<std::string> propertyNames = storm::utility::cli::parseCommaSeparatedStrings(propertyFilter);
23 std::set<std::string> propertyNameSet(propertyNames.begin(), propertyNames.end());
24 return propertyNameSet;
25}
26
27std::vector<storm::jani::Property> parseProperties(storm::parser::FormulaParser& formulaParser, std::string const& inputString,
28 boost::optional<std::set<std::string>> const& propertyFilter) {
29 // If the given property is a file, we parse it as a file, otherwise we assume it's a property.
30 std::vector<storm::jani::Property> properties;
31 if (storm::io::fileExistsAndIsReadable(inputString)) {
32 STORM_LOG_INFO("Loading properties from file: " << inputString << '\n');
33 properties = formulaParser.parseFromFile(inputString);
34 } else {
35 // File does not exists -> parse as property string
36 // Provide warning if string could potentially be a property file
37 if (inputString.find(".prop") != std::string::npos || inputString.find(".pctl") != std::string::npos ||
38 inputString.find(".prctl") != std::string::npos || inputString.find(".csl") != std::string::npos) {
39 STORM_LOG_WARN("File with name '" << inputString << "' does not exist. Trying to parse as property string.");
40 }
41 properties = formulaParser.parseFromString(inputString);
42 }
43
44 return filterProperties(properties, propertyFilter);
45}
46
47std::vector<storm::jani::Property> parseProperties(std::string const& inputString, boost::optional<std::set<std::string>> const& propertyFilter) {
48 auto exprManager = std::make_shared<storm::expressions::ExpressionManager>();
49 storm::parser::FormulaParser formulaParser(exprManager);
50 try {
51 return parseProperties(formulaParser, inputString, propertyFilter);
52 } catch (storm::exceptions::WrongFormatException const& e) {
53 STORM_LOG_THROW(false, storm::exceptions::WrongFormatException,
54 e.what() << "Note that the used API function does not have access to model variables. If the property you tried to parse contains "
55 "model variables, it will not be parsed correctly.");
56 }
57}
58
59std::vector<storm::jani::Property> parsePropertiesForJaniModel(std::string const& inputString, storm::jani::Model const& model,
60 boost::optional<std::set<std::string>> const& propertyFilter) {
62 auto formulas = parseProperties(formulaParser, inputString, propertyFilter);
63 // Eliminate reward accumulations if possible
67}
68
69std::vector<storm::jani::Property> parsePropertiesForPrismProgram(std::string const& inputString, storm::prism::Program const& program,
70 boost::optional<std::set<std::string>> const& propertyFilter) {
71 storm::parser::FormulaParser formulaParser(program);
72 auto formulas = parseProperties(formulaParser, inputString, propertyFilter);
74}
75
76std::vector<storm::jani::Property> parsePropertiesForSymbolicModelDescription(std::string const& inputString,
77 storm::storage::SymbolicModelDescription const& modelDescription,
78 boost::optional<std::set<std::string>> const& propertyFilter) {
79 std::vector<storm::jani::Property> result;
80 if (modelDescription.isPrismProgram()) {
81 result = storm::api::parsePropertiesForPrismProgram(inputString, modelDescription.asPrismProgram(), propertyFilter);
82 } else {
83 STORM_LOG_ASSERT(modelDescription.isJaniModel(), "Unknown model description type.");
84 result = storm::api::parsePropertiesForJaniModel(inputString, modelDescription.asJaniModel(), propertyFilter);
85 }
86 return result;
87}
88} // namespace api
89} // namespace storm
std::shared_ptr< ExpressionManager > getSharedPointer()
Retrieves a shared pointer to the expression manager.
storm::expressions::ExpressionManager & getManager() const
Retrieves the expression manager responsible for the expressions in the model.
Definition Model.cpp:113
std::map< storm::expressions::Variable, storm::expressions::Expression > getConstantsSubstitution() const
Retrieves a mapping from expression variables associated with defined constants of the model to their...
Definition Model.cpp:1159
std::shared_ptr< Formula > eliminateRewardAccumulations(Formula const &f) const
Eliminates any reward accumulations of the formula, where the presence of the reward accumulation doe...
std::vector< storm::jani::Property > parseFromString(std::string const &propertyString) const
Parses the property given by the provided string.
std::vector< storm::jani::Property > parseFromFile(std::string const &filename) const
Parses the properties in the given file.
std::map< storm::expressions::Variable, storm::expressions::Expression > getConstantsFormulasSubstitution(bool getConstantsSubstitution=true, bool getFormulasSubstitution=true) const
Retrieves a mapping of all defined constants and formula variables to their defining expressions.
Definition Program.cpp:414
storm::prism::Program const & asPrismProgram() const
storm::jani::Model const & asJaniModel() const
#define STORM_LOG_INFO(message)
Definition logging.h:29
#define STORM_LOG_WARN(message)
Definition logging.h:30
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
std::vector< storm::jani::Property > parsePropertiesForPrismProgram(std::string const &inputString, storm::prism::Program const &program, boost::optional< std::set< std::string > > const &propertyFilter)
std::pair< storm::jani::Model, std::vector< storm::jani::Property > > filterProperties(std::pair< storm::jani::Model, std::vector< storm::jani::Property > > &modelAndFormulae, boost::optional< std::vector< std::string > > const &propertyFilter)
std::vector< storm::jani::Property > parseProperties(storm::parser::FormulaParser &formulaParser, std::string const &inputString, boost::optional< std::set< std::string > > const &propertyFilter)
std::vector< storm::jani::Property > parsePropertiesForJaniModel(std::string const &inputString, storm::jani::Model const &model, boost::optional< std::set< std::string > > const &propertyFilter)
std::vector< storm::jani::Property > parsePropertiesForSymbolicModelDescription(std::string const &inputString, storm::storage::SymbolicModelDescription const &modelDescription, boost::optional< std::set< std::string > > const &propertyFilter)
boost::optional< std::set< std::string > > parsePropertyFilter(std::string const &propertyFilter)
std::vector< storm::jani::Property > substituteConstantsInProperties(std::vector< storm::jani::Property > const &properties, std::map< storm::expressions::Variable, storm::expressions::Expression > const &substitution)
bool fileExistsAndIsReadable(std::string const &filename)
Tests whether the given file exists and is readable.
Definition file.h:66
std::vector< std::string > parseCommaSeparatedStrings(std::string const &input)
Definition cli.cpp:86
LabParser.cpp.
Definition cli.cpp:18