Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
storm-gspn.cpp
Go to the documentation of this file.
1#include "storm-gspn.h"
2
3#include <boost/algorithm/string.hpp>
4
8#include "storm/io/file.h"
10
11namespace storm {
12namespace api {
13
18
19void exportGspnToDot(storm::gspn::GSPN const& gspn, std::string const& filename) {
20 std::ofstream fs;
21 storm::io::openFile(filename, fs);
22 gspn.writeDotToStream(fs);
24}
25
26void exportGspnToPnpro(storm::gspn::GSPN const& gspn, std::string const& filename) {
27 std::ofstream fs;
28 storm::io::openFile(filename, fs);
29 gspn.toPnpro(fs);
31}
32
33void exportGspnToPnml(storm::gspn::GSPN const& gspn, std::string const& filename) {
34 std::ofstream fs;
35 storm::io::openFile(filename, fs);
36 gspn.toPnml(fs);
38}
39
40void exportGspnToJson(storm::gspn::GSPN const& gspn, std::string const& filename) {
41 std::ofstream fs;
42 storm::io::openFile(filename, fs);
43 gspn.toJson(fs);
45}
46
47void printGspnStatsToStream(storm::gspn::GSPN const& gspn, std::ostream& out) {
48 gspn.writeStatsToStream(out);
49}
50
51void exportGspnStatsToFile(storm::gspn::GSPN const& gspn, std::string const& filename) {
52 std::ofstream fs;
53 storm::io::openFile(filename, fs);
54 gspn.writeStatsToStream(fs);
56}
57
58void exportGspnToJani(storm::gspn::GSPN const& gspn, std::string const& filename, GspnJaniExportOptions const& options,
59 std::function<std::vector<storm::jani::Property>(storm::builder::JaniGSPNBuilder const&)> const& janiPropertyGetter) {
61 storm::jani::Model* model = builder.build("gspn_automaton");
62
63 auto properties = janiPropertyGetter(builder);
64 if (options.addDeadlockProperties) {
65 auto deadlockProperties = builder.getDeadlockProperties(model);
66 properties.insert(properties.end(), deadlockProperties.begin(), deadlockProperties.end());
67 }
68
69 storm::api::transformJani(*model, properties, options.janiConversionOptions, options.smtSolverFactory);
70
71 storm::api::exportJaniToFile(*model, properties, filename, options.compactJson);
72 delete model;
73}
74
75std::unordered_map<std::string, uint64_t> parseCapacitiesList(std::string const& filename, storm::gspn::GSPN const& gspn) {
76 storm::parser::ExpressionParser expressionParser(*gspn.getExpressionManager());
77 std::unordered_map<std::string, storm::expressions::Expression> identifierMapping;
78 for (auto const& var : gspn.getExpressionManager()->getVariables()) {
79 identifierMapping.emplace(var.getName(), var.getExpression());
80 }
81 expressionParser.setIdentifierMapping(identifierMapping);
82 expressionParser.setAcceptDoubleLiterals(false);
83
84 std::unordered_map<std::string, uint64_t> map;
85
86 std::ifstream stream;
87 storm::io::openFile(filename, stream);
88
89 std::string line;
90 while (storm::io::getline(stream, line)) {
91 std::vector<std::string> strs;
92 boost::split(strs, line, boost::is_any_of("\t "));
93 STORM_LOG_THROW(strs.size() == 2, storm::exceptions::WrongFormatException, "Expect key value pairs.");
94 storm::expressions::Expression expr = expressionParser.parseFromString(strs[1]);
95 if (!gspn.getConstantsSubstitution().empty()) {
96 expr = expr.substitute(gspn.getConstantsSubstitution());
97 }
98 STORM_LOG_THROW(!expr.containsVariables(), storm::exceptions::WrongFormatException,
99 "The capacity expression '" << strs[1] << "' still contains undefined constants.");
100 map[strs[0]] = expr.evaluateAsInt();
101 }
102 storm::io::closeFile(stream);
103 return map;
104}
105} // namespace api
106} // namespace storm
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.
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.
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
void exportGspnToJani(storm::gspn::GSPN const &gspn, std::string const &filename, GspnJaniExportOptions const &options, std::function< std::vector< storm::jani::Property >(storm::builder::JaniGSPNBuilder const &)> const &janiPropertyGetter)
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 exportJaniToFile(storm::jani::Model const &model, std::vector< storm::jani::Property > const &properties, std::string const &filename, bool compact)
void exportGspnToPnpro(storm::gspn::GSPN const &gspn, std::string const &filename)
void exportGspnToPnml(storm::gspn::GSPN const &gspn, std::string const &filename)
storm::jani::Model * buildJani(storm::gspn::GSPN const &gspn)
Builds JANI model from GSPN.
void exportGspnToJson(storm::gspn::GSPN const &gspn, std::string const &filename)
void exportGspnToDot(storm::gspn::GSPN const &gspn, std::string const &filename)
std::unordered_map< std::string, uint64_t > parseCapacitiesList(std::string const &filename, storm::gspn::GSPN const &gspn)
void exportGspnStatsToFile(storm::gspn::GSPN const &gspn, std::string const &filename)
void printGspnStatsToStream(storm::gspn::GSPN const &gspn, std::ostream &out)
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
Options for exporting a GSPN as a JANI model.
Definition storm-gspn.h:30
storm::converter::JaniConversionOptions janiConversionOptions
Definition storm-gspn.h:34
std::shared_ptr< storm::utility::solver::SmtSolverFactory > smtSolverFactory
Definition storm-gspn.h:36