Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
export.h
Go to the documentation of this file.
1#pragma once
2
7#include "storm/io/file.h"
13
14namespace storm {
15
16namespace jani {
17class Model;
18}
19
20namespace api {
21
22void exportJaniModelAsDot(storm::jani::Model const& model, std::string const& filename);
23
24template<typename ValueType>
25void exportSparseModelAsDrn(std::shared_ptr<storm::models::sparse::Model<ValueType>> const& model, std::string const& filename,
26 std::vector<std::string> const& parameterNames = {}, bool allowPlaceholders = true) {
27 std::ofstream stream;
28 storm::io::openFile(filename, stream);
30 options.allowPlaceholders = allowPlaceholders;
31 storm::io::explicitExportSparseModel(stream, model, parameterNames, options);
33}
34
35template<storm::dd::DdType Type, typename ValueType>
36void exportSymbolicModelAsDrdd(std::shared_ptr<storm::models::symbolic::Model<Type, ValueType>> const& model, std::string const& filename) {
38}
39
40template<typename ValueType>
41void exportSparseModelAsDot(std::shared_ptr<storm::models::sparse::Model<ValueType>> const& model, std::string const& filename, size_t maxWidth = 30) {
42 std::ofstream stream;
43 storm::io::openFile(filename, stream);
44 model->writeDotToStream(stream, maxWidth);
46}
47
48template<typename ValueType>
49void exportSparseModelAsJson(std::shared_ptr<storm::models::sparse::Model<ValueType>> const& model, std::string const& filename) {
50 std::ofstream stream;
51 storm::io::openFile(filename, stream);
52 model->writeJsonToStream(stream);
54}
55
56template<storm::dd::DdType Type, typename ValueType>
57void exportSymbolicModelAsDot(std::shared_ptr<storm::models::symbolic::Model<Type, ValueType>> const& model, std::string const& filename) {
58 model->writeDotToFile(filename);
59}
60
61template<typename ValueType>
63 std::string const& filename) {
64 std::ofstream stream;
65 storm::io::openFile(filename, stream);
66 std::string jsonFileExtension = ".json";
67 if (filename.size() > 4 && std::equal(jsonFileExtension.rbegin(), jsonFileExtension.rend(), filename.rbegin())) {
68 scheduler.printJsonToStream(stream, model, false, true);
69 } else {
70 scheduler.printToStream(stream, model, false, true);
71 }
73}
74
75template<typename ValueType>
76inline void exportCheckResultToJson(std::shared_ptr<storm::models::sparse::Model<ValueType>> const& model,
77 std::unique_ptr<storm::modelchecker::CheckResult> const& checkResult, std::string const& filename) {
78 std::ofstream stream;
79 storm::io::openFile(filename, stream);
80 if (checkResult->isExplicitQualitativeCheckResult()) {
81 auto j = checkResult->asExplicitQualitativeCheckResult().toJson<storm::RationalNumber>(model->getOptionalStateValuations(), model->getStateLabeling());
82 stream << storm::dumpJson(j);
83 } else {
84 STORM_LOG_THROW(checkResult->isExplicitQuantitativeCheckResult(), storm::exceptions::NotSupportedException,
85 "Export of check results is only supported for explicit check results (e.g. in the sparse engine)");
86 auto j = checkResult->template asExplicitQuantitativeCheckResult<ValueType>().toJson(model->getOptionalStateValuations(), model->getStateLabeling());
87 stream << storm::dumpJson(j);
88 }
90}
91
92template<>
94 std::unique_ptr<storm::modelchecker::CheckResult> const&, std::string const&) {
95 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Export of check results is not supported for rational functions. ");
96}
97
98} // namespace api
99} // namespace storm
Base class for all sparse models.
Definition Model.h:33
Base class for all symbolic models.
Definition Model.h:46
This class defines which action is chosen in a particular state of a non-deterministic model.
Definition Scheduler.h:18
void printJsonToStream(std::ostream &out, std::shared_ptr< storm::models::sparse::Model< ValueType > > model=nullptr, bool skipUniqueChoices=false, bool skipDontCareStates=false) const
Prints the scheduler in json format to the given output stream.
void printToStream(std::ostream &out, std::shared_ptr< storm::models::sparse::Model< ValueType > > model=nullptr, bool skipUniqueChoices=false, bool skipDontCareStates=false) const
Prints the scheduler to the given output stream.
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
void exportScheduler(std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, storm::storage::Scheduler< ValueType > const &scheduler, std::string const &filename)
Definition export.h:62
void exportSymbolicModelAsDot(std::shared_ptr< storm::models::symbolic::Model< Type, ValueType > > const &model, std::string const &filename)
Definition export.h:57
void exportCheckResultToJson< storm::RationalFunction >(std::shared_ptr< storm::models::sparse::Model< storm::RationalFunction > > const &, std::unique_ptr< storm::modelchecker::CheckResult > const &, std::string const &)
Definition export.h:93
void exportJaniModelAsDot(storm::jani::Model const &model, std::string const &filename)
Definition export.cpp:7
void exportSymbolicModelAsDrdd(std::shared_ptr< storm::models::symbolic::Model< Type, ValueType > > const &model, std::string const &filename)
Definition export.h:36
void exportSparseModelAsDrn(std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, std::string const &filename, std::vector< std::string > const &parameterNames={}, bool allowPlaceholders=true)
Definition export.h:25
void exportCheckResultToJson(std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, std::unique_ptr< storm::modelchecker::CheckResult > const &checkResult, std::string const &filename)
Definition export.h:76
void exportSparseModelAsJson(std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, std::string const &filename)
Definition export.h:49
void exportSparseModelAsDot(std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, std::string const &filename, size_t maxWidth=30)
Definition export.h:41
void explicitExportSparseModel(std::ostream &os, std::shared_ptr< storm::models::sparse::Model< ValueType > > sparseModel, std::vector< std::string > const &parameters, DirectEncodingOptions const &options)
Exports a sparse model into the explicit DRN format.
void explicitExportSymbolicModel(std::string const &filename, std::shared_ptr< storm::models::symbolic::Model< Type, ValueType > > symbolicModel)
Exports a sparse model into the explicit drdd format.
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
LabParser.cpp.
Definition cli.cpp:18
std::string dumpJson(storm::json< ValueType > const &j, bool compact)
Dumps the given json object, producing a String.