Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
storm-conv.cpp
Go to the documentation of this file.
2
4#include "storm/io/file.h"
13
14namespace storm {
15namespace api {
16
17void transformJani(storm::jani::Model& janiModel, std::vector<storm::jani::Property>& properties, storm::converter::JaniConversionOptions const& options,
18 std::shared_ptr<storm::utility::solver::SmtSolverFactory> smtSolverFactory) {
21 }
22
23 if (options.substituteConstants) {
24 janiModel.substituteConstantsInPlace(false);
25 }
26
27 if (options.localVars) {
28 STORM_LOG_WARN_COND(!options.globalVars, "Ignoring 'globalvars' option, since 'localvars' is also set.");
30 } else if (options.globalVars) {
32 }
33
34 if (!options.locationVariables.empty()) {
35 // Make variables local if necessary/possible
36 for (auto const& pair : options.locationVariables) {
37 if (janiModel.hasGlobalVariable(pair.second)) {
38 auto var = janiModel.getGlobalVariable(pair.second).getExpressionVariable();
39 if (storm::jani::JaniScopeChanger().canMakeVariableLocal(var, janiModel, properties, janiModel.getAutomatonIndex(pair.first)).first) {
40 storm::jani::JaniScopeChanger().makeVariableLocal(var, janiModel, janiModel.getAutomatonIndex(pair.first));
41 } else {
42 STORM_LOG_ERROR("Can not transform variable " << pair.second << " into locations since it can not be made local to automaton " << pair.first
43 << ".");
44 }
45 }
46 }
47
48 for (auto const& pair : options.locationVariables) {
49 storm::jani::JaniLocationExpander expander(janiModel);
50 janiModel = expander.transform(pair.first, pair.second).newModel;
51 }
52 }
53
54 if (options.simplifyComposition) {
55 janiModel.simplifyComposition();
56 }
57
58 if (options.locationElimination) {
59 auto locationHeuristic = options.locationEliminationLocationHeuristic;
60 auto edgesHeuristic = options.locationEliminationEdgeHeuristic;
61 janiModel = storm::jani::JaniLocalEliminator::eliminateAutomatically(janiModel, properties, locationHeuristic, edgesHeuristic);
62 }
63
64 if (options.flatten) {
65 janiModel = smtSolverFactory ? janiModel.flattenComposition(smtSolverFactory) : janiModel.flattenComposition();
66 }
67
68 if (!options.edgeAssignments) {
70 }
71
72 auto uneliminatedFeatures = janiModel.restrictToFeatures(options.allowedModelFeatures, properties);
73 STORM_LOG_WARN_COND(uneliminatedFeatures.empty(), "The following model features could not be eliminated: " << uneliminatedFeatures.toString());
74
75 if (options.modelName) {
76 janiModel.setName(options.modelName.get());
77 }
78
79 if (options.addPropertyConstants) {
80 for (auto& f : properties) {
81 for (auto const& constant : f.getUndefinedConstants()) {
82 if (!janiModel.hasConstant(constant.getName())) {
83 janiModel.addConstant(storm::jani::Constant(constant.getName(), constant));
84 }
85 }
86 }
87 }
88}
89
90void transformPrism(storm::prism::Program& prismProgram, std::vector<storm::jani::Property>& properties, bool simplify, bool flatten) {
91 if (simplify) {
92 prismProgram = prismProgram.simplify().simplify();
94 }
95 if (flatten) {
96 prismProgram = prismProgram.flattenModules();
97 if (simplify) {
98 // Let's simplify the flattened program again ... just to be sure ... twice ...
99 prismProgram = prismProgram.simplify().simplify();
100 }
101 }
102}
103
104std::pair<storm::jani::Model, std::vector<storm::jani::Property>> convertPrismToJani(storm::prism::Program const& program,
106 return convertPrismToJani(program, {}, options);
107}
108
109std::pair<storm::jani::Model, std::vector<storm::jani::Property>> convertPrismToJani(storm::prism::Program const& program,
110 std::vector<storm::jani::Property> const& properties,
112 // Perform conversion
113 auto res = program.toJani(properties, options.allVariablesGlobal);
114 if (res.second.empty()) {
115 std::vector<storm::jani::Property> clonedProperties;
116 for (auto const& p : properties) {
117 clonedProperties.push_back(p.clone());
118 }
119 res.second = std::move(clonedProperties);
120 }
121
122 // Postprocess Jani model based on the options
123 transformJani(res.first, res.second, options.janiOptions);
124
125 return res;
126}
127
128void exportJaniToFile(storm::jani::Model const& model, std::vector<storm::jani::Property> const& properties, std::string const& filename, bool compact) {
129 storm::jani::JsonExporter::toFile(model, properties, filename, true, compact);
130}
131
132void printJaniToStream(storm::jani::Model const& model, std::vector<storm::jani::Property> const& properties, std::ostream& ostream, bool compact) {
133 storm::jani::JsonExporter::toStream(model, properties, ostream, true, compact);
134}
135
136void exportPrismToFile(storm::prism::Program const& program, std::vector<storm::jani::Property> const& properties, std::string const& filename) {
137 std::ofstream stream;
138 storm::io::openFile(filename, stream);
139 stream << program << '\n';
140 storm::io::closeFile(stream);
141
142 if (!properties.empty()) {
143 storm::io::openFile(filename + ".props", stream);
144 for (auto const& prop : properties) {
145 prop.asPrismSyntax(stream);
146 if (!prop.getComment().empty()) {
147 stream << " // " << prop.getComment();
148 }
149 stream << '\n';
150 STORM_LOG_WARN_COND(!prop.containsUndefinedConstants(), "A property contains undefined constants. These might not be exported correctly.");
151 }
152 storm::io::closeFile(stream);
153 }
154}
155void printPrismToStream(storm::prism::Program const& program, std::vector<storm::jani::Property> const& properties, std::ostream& ostream) {
156 ostream << program << '\n';
157 for (auto const& prop : properties) {
158 STORM_LOG_WARN_COND(!prop.containsUndefinedConstants(), "A property contains undefined constants. These might not be exported correctly.");
159 prop.asPrismSyntax(ostream);
160 if (!prop.getComment().empty()) {
161 ostream << " // " << prop.getComment();
162 }
163 ostream << '\n';
164 }
165}
166
167} // namespace api
168} // namespace storm
static Model eliminateAutomatically(const Model &model, std::vector< jani::Property > properties, uint64_t locationHeuristic, uint64_t edgesHeuristic)
ReturnType transform(std::string const &automatonName, std::string const &variableName)
void makeVariablesGlobal(Model &model) const
Moves as many variables to the global scope as possible.
void makeVariablesLocal(Model &model, storm::OptionalRef< std::vector< Property > const > properties=storm::NullRef) const
Moves as many variables to a local scope as possible.
void makeVariableLocal(storm::expressions::Variable const &variable, Model &model, uint64_t automatonIndex) const
Moves the given variable into the local scope of the automaton with the given index.
static void toFile(storm::jani::Model const &janiModel, std::vector< storm::jani::Property > const &formulas, std::string const &filepath, bool checkValid=true, bool compact=false)
static void toStream(storm::jani::Model const &janiModel, std::vector< storm::jani::Property > const &formulas, std::ostream &ostream, bool checkValid=false, bool compact=false)
Model & replaceUnassignedVariablesWithConstants()
Replaces each variable to which we never assign a value with a constant.
Definition Model.cpp:1100
Variable const & getGlobalVariable(std::string const &name) const
Retrieves the global variable with the given name if one exists.
Definition Model.cpp:757
Model & substituteConstantsInPlace(bool const substituteTranscendentalNumbers)
Substitutes all constants in all expressions of the model.
Definition Model.cpp:1105
void pushEdgeAssignmentsToDestinations()
Definition Model.cpp:1550
void addConstant(Constant const &constant)
Adds the given constant to the model.
Definition Model.cpp:650
bool hasConstant(std::string const &name) const
Retrieves whether the model has a constant with the given name.
Definition Model.cpp:659
void simplifyComposition()
Attempts to simplify the composition.
Definition Model.cpp:981
Model flattenComposition(std::shared_ptr< storm::utility::solver::SmtSolverFactory > const &smtSolverFactory=std::make_shared< storm::utility::solver::SmtSolverFactory >()) const
Flatten the composition to obtain an equivalent model that contains exactly one automaton that has th...
Definition Model.cpp:438
bool hasGlobalVariable(std::string const &name) const
Retrieves whether this model has a global variable with the given name.
Definition Model.cpp:753
void setName(std::string const &newName)
Sets the name of the model.
Definition Model.cpp:137
uint64_t getAutomatonIndex(std::string const &name) const
Retrieves the index of the given automaton.
Definition Model.cpp:904
ModelFeatures restrictToFeatures(ModelFeatures const &modelFeatures)
Attempts to eliminate all features of this model that are not in the given set of features.
Definition Model.cpp:1249
storm::expressions::Variable const & getExpressionVariable() const
Retrieves the associated expression variable.
Definition Variable.cpp:26
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:410
Program flattenModules(std::shared_ptr< storm::utility::solver::SmtSolverFactory > const &smtSolverFactory=std::shared_ptr< storm::utility::solver::SmtSolverFactory >(new storm::utility::solver::SmtSolverFactory())) const
Creates an equivalent program that contains exactly one module.
Definition Program.cpp:1980
Program simplify()
Entry point for static analysis for simplify.
Definition Program.cpp:1832
storm::jani::Model toJani(bool allVariablesGlobal=true, std::string suffix="") const
Converts the PRISM model into an equivalent JANI model.
Definition Program.cpp:2350
#define STORM_LOG_ERROR(message)
Definition logging.h:36
#define STORM_LOG_WARN_COND(cond, message)
Definition macros.h:54
void transformJani(storm::jani::Model &janiModel, std::vector< storm::jani::Property > &properties, storm::converter::JaniConversionOptions const &options, std::shared_ptr< storm::utility::solver::SmtSolverFactory > smtSolverFactory)
void transformPrism(storm::prism::Program &prismProgram, std::vector< storm::jani::Property > &properties, bool simplify, bool flatten)
void exportJaniToFile(storm::jani::Model const &model, std::vector< storm::jani::Property > const &properties, std::string const &filename, bool compact)
void printPrismToStream(storm::prism::Program const &program, std::vector< storm::jani::Property > const &properties, std::ostream &ostream)
std::pair< storm::jani::Model, std::vector< storm::jani::Property > > convertPrismToJani(storm::prism::Program const &program, storm::converter::PrismToJaniConverterOptions options)
void exportPrismToFile(storm::prism::Program const &program, std::vector< storm::jani::Property > const &properties, std::string const &filename)
std::vector< storm::jani::Property > substituteConstantsInProperties(std::vector< storm::jani::Property > const &properties, std::map< storm::expressions::Variable, storm::expressions::Expression > const &substitution)
void printJaniToStream(storm::jani::Model const &model, std::vector< storm::jani::Property > const &properties, std::ostream &ostream, bool compact)
void closeFile(std::ofstream &stream)
Close the given file after writing.
Definition file.h:47
void openFile(std::string const &filepath, std::ofstream &filestream, bool append=false, bool silent=false)
Open the given file for writing.
Definition file.h:18
The contract of a DD backend.
uint64_t locationEliminationLocationHeuristic
Controls which locations are eliminated if location elimination is enabled.
boost::optional< std::string > modelName
If given, the model will get this name.
bool globalVars
If set, variables will be made global wherever possible.
bool replaceUnassignedVariablesWithConstants
If set, local and global variables that are (a) not assigned to some value and (b) have a known initi...
bool addPropertyConstants
Add constants that are defined in the properties to the model.
bool localVars
If set, variables will be made local wherever possible.
bool locationElimination
If set, attempts to perform location elimination of states to reduce the state space of the final mod...
storm::jani::ModelFeatures allowedModelFeatures
Only these model features are allowed in the output.
bool substituteConstants
If set, constants in expressions are substituted with their definition.
std::vector< std::pair< std::string, std::string > > locationVariables
(Automaton,Variable)-pairs that will be transformed to location variables of the respective automaton...
bool simplifyComposition
If set, attempts to simplify the system composition.
bool flatten
If set, the model is transformed into a single automaton.
bool edgeAssignments
If set, the model might have transient assignments to the edges.