Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
export.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4#include <fstream>
5#include <iterator>
6#include <vector>
7
9#include "storm/io/file.h"
10
11namespace storm::pars {
12namespace api {
13
14namespace {
15
16void writeConstraints(std::ostream& filestream, storm::analysis::ConstraintCollector::ConstraintSet const& constraints) {
17 std::vector<std::string> stringConstraints;
18 stringConstraints.reserve(constraints.size());
19 std::transform(constraints.begin(), constraints.end(), std::back_inserter(stringConstraints),
20 [](storm::expressions::Expression const& c) -> std::string { return c.toString(); });
21 std::copy(stringConstraints.begin(), stringConstraints.end(), std::ostream_iterator<std::string>(filestream, "\n"));
22}
23
24} // namespace
25
26template<>
27void exportParametricResultToFile(std::optional<storm::RationalFunction> result,
28 storm::OptionalRef<storm::analysis::ConstraintCollector const> const& constraintCollector, std::string const& path) {
29 std::ofstream filestream;
30 storm::io::openFile(path, filestream);
31 if (constraintCollector.has_value()) {
32 filestream << "$Parameters: ";
33 auto const& vars = constraintCollector->getVariables();
34 std::copy(vars.begin(), vars.end(), std::ostream_iterator<storm::RationalFunctionVariable>(filestream, "; "));
35 filestream << '\n';
36 } else {
37 if (result) {
38 filestream << "$Parameters: ";
39 auto const& vars = result->gatherVariables();
40 std::copy(vars.begin(), vars.end(), std::ostream_iterator<storm::RationalFunctionVariable>(filestream, "; "));
41 filestream << '\n';
42 }
43 }
44 if (result) {
45 filestream << "$Result: " << result->toString(false, true) << '\n';
46 }
47 if (constraintCollector.has_value()) {
48 filestream << "$Well-formed Constraints: \n";
49 writeConstraints(filestream, constraintCollector->getWellformedConstraints());
50 filestream << "$Graph-preserving Constraints: \n";
51 writeConstraints(filestream, constraintCollector->getGraphPreservingConstraints());
52 }
53 storm::io::closeFile(filestream);
54}
55
56} // namespace api
57} // namespace storm::pars
Helper class that optionally holds a reference to an object of type T.
Definition OptionalRef.h:48
bool has_value() const
Yields true iff this contains a reference.
std::vector< storm::expressions::Expression > ConstraintSet
The type of the collected constraints.
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
void exportParametricResultToFile(std::optional< storm::RationalFunction > result, storm::OptionalRef< storm::analysis::ConstraintCollector const > const &constraintCollector, std::string const &path)
Definition export.cpp:27