Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
storm-gspn.cpp
Go to the documentation of this file.
2
3#include <boost/algorithm/string.hpp>
9#include "storm/io/file.h"
11
12namespace storm {
13namespace api {
14
17 return builder.build();
18}
19
21 std::function<std::vector<storm::jani::Property>(storm::builder::JaniGSPNBuilder const&)> const& janiProperyGetter) {
23 if (exportSettings.isWriteToDotSet()) {
24 std::ofstream fs;
25 storm::io::openFile(exportSettings.getWriteToDotFilename(), fs);
26 gspn.writeDotToStream(fs);
28 }
29
30 if (exportSettings.isWriteToPnproSet()) {
31 std::ofstream fs;
32 storm::io::openFile(exportSettings.getWriteToPnproFilename(), fs);
33 gspn.toPnpro(fs);
35 }
36
37 if (exportSettings.isWriteToPnmlSet()) {
38 std::ofstream fs;
39 storm::io::openFile(exportSettings.getWriteToPnmlFilename(), fs);
40 gspn.toPnml(fs);
42 }
43
44 if (exportSettings.isWriteToJsonSet()) {
45 std::ofstream fs;
46 storm::io::openFile(exportSettings.getWriteToJsonFilename(), fs);
47 gspn.toJson(fs);
49 }
50
51 if (exportSettings.isDisplayStatsSet()) {
52 std::cout << "============GSPN Statistics==============\n";
53 gspn.writeStatsToStream(std::cout);
54 std::cout << "=========================================\n";
55 }
56
57 if (exportSettings.isWriteStatsToFileSet()) {
58 std::ofstream fs;
59 storm::io::openFile(exportSettings.getWriteStatsFilename(), fs);
60 gspn.writeStatsToStream(fs);
62 }
63
64 if (exportSettings.isWriteToJaniSet()) {
67
69 storm::jani::Model* model = builder.build("gspn_automaton");
70
71 auto properties = janiProperyGetter(builder);
72 if (exportSettings.isAddJaniPropertiesSet()) {
73 auto deadlockProperties = builder.getDeadlockProperties(model);
74 properties.insert(properties.end(), deadlockProperties.begin(), deadlockProperties.end());
75 }
76
77 storm::api::transformJani(*model, properties, options);
78
79 storm::api::exportJaniToFile(*model, properties, exportSettings.getWriteToJaniFilename(), jani.isCompactJsonSet());
80 delete model;
81 }
82}
83
84std::unordered_map<std::string, uint64_t> parseCapacitiesList(std::string const& filename, storm::gspn::GSPN const& gspn) {
86 std::unordered_map<std::string, storm::expressions::Expression> identifierMapping;
87 for (auto const& var : gspn.getExpressionManager()->getVariables()) {
88 identifierMapping.emplace(var.getName(), var.getExpression());
89 }
90 expressionParser.setIdentifierMapping(identifierMapping);
91 expressionParser.setAcceptDoubleLiterals(false);
92
93 std::unordered_map<std::string, uint64_t> map;
94
95 std::ifstream stream;
96 storm::io::openFile(filename, stream);
97
98 std::string line;
99 while (storm::io::getline(stream, line)) {
100 std::vector<std::string> strs;
101 boost::split(strs, line, boost::is_any_of("\t "));
102 STORM_LOG_THROW(strs.size() == 2, storm::exceptions::WrongFormatException, "Expect key value pairs");
103 storm::expressions::Expression expr = expressionParser.parseFromString(strs[1]);
104 if (!gspn.getConstantsSubstitution().empty()) {
105 expr = expr.substitute(gspn.getConstantsSubstitution());
106 }
107 STORM_LOG_THROW(!expr.containsVariables(), storm::exceptions::WrongFormatException,
108 "The capacity expression '" << strs[1] << "' still contains undefined constants.");
109 map[strs[0]] = expr.evaluateAsInt();
110 }
111 storm::io::closeFile(stream);
112 return map;
113}
114} // namespace api
115} // namespace storm
storm::jani::Model * build(std::string const &automatonName="gspn_automaton")
std::vector< storm::jani::Property > getDeadlockProperties(storm::jani::Model *model)
Get standard properties (reachability, time bounded reachability, expected time) for deadlocks.
int_fast64_t evaluateAsInt(Valuation const *valuation=nullptr) const
Evaluates the expression under the valuation of variables given by the valuation and returns the resu...
bool containsVariables() const
Retrieves whether the expression contains a variable.
Expression substitute(std::map< Variable, Expression > const &variableToExpressionMap) const
Substitutes all occurrences of the variables according to the given map.
void toPnml(std::ostream &stream) const
Definition GSPN.cpp:536
void toJson(std::ostream &stream) const
Export GSPN in Json format.
Definition GSPN.cpp:697
std::map< storm::expressions::Variable, storm::expressions::Expression > const & getConstantsSubstitution() const
Gets an assignment of occurring constants of the GSPN to their value.
Definition GSPN.cpp:142
void writeStatsToStream(std::ostream &stream) const
Definition GSPN.cpp:701
void toPnpro(std::ostream &stream) const
Definition GSPN.cpp:418
std::shared_ptr< storm::expressions::ExpressionManager > const & getExpressionManager() const
Obtain the expression manager used for expressions over GSPNs.
Definition GSPN.cpp:138
void writeDotToStream(std::ostream &outStream) const
Write the gspn in a dot(graphviz) configuration.
Definition GSPN.cpp:154
storm::expressions::Expression parseFromString(std::string const &expressionString, bool ignoreError=false) const
Parses an expression from the given string.
void setIdentifierMapping(qi::symbols< char, storm::expressions::Expression > const *identifiers_)
Sets an identifier mapping that is used to determine valid variables in the expression.
void setAcceptDoubleLiterals(bool flag)
Sets whether double literals are to be accepted or not.
bool isAddJaniPropertiesSet() const
Returns whether a set of standard properties is to be added when exporting to jani.
std::string getWriteToDotFilename() const
Retrieves the dot file name.
bool isWriteToDotSet() const
Retrieve whether the to dot option was set.
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
void exportJaniToFile(storm::jani::Model const &model, std::vector< storm::jani::Property > const &properties, std::string const &filename, bool compact)
void handleGSPNExportSettings(storm::gspn::GSPN const &gspn, std::function< std::vector< storm::jani::Property >(storm::builder::JaniGSPNBuilder const &)> const &janiProperyGetter)
void transformJani(storm::jani::Model &janiModel, std::vector< storm::jani::Property > &properties, storm::converter::JaniConversionOptions const &options)
storm::jani::Model * buildJani(storm::gspn::GSPN const &gspn)
Builds JANI model from GSPN.
std::unordered_map< std::string, uint64_t > parseCapacitiesList(std::string const &filename, storm::gspn::GSPN const &gspn)
std::basic_istream< CharT, Traits > & getline(std::basic_istream< CharT, Traits > &input, std::basic_string< CharT, Traits, Allocator > &str)
Overloaded getline function which handles different types of newline ( and \r).
Definition file.h:80
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
SettingsType const & getModule()
Get module.
LabParser.cpp.
Definition cli.cpp:18