#pragma once #include "storm/settings/SettingsManager.h" #include "storm/io/DirectEncodingExporter.h" #include "storm/io/DDEncodingExporter.h" #include "storm/io/file.h" #include "storm/utility/macros.h" #include "storm/storage/Scheduler.h" #include "storm/modelchecker/results/CheckResult.h" #include "storm/modelchecker/results/ExplicitQuantitativeCheckResult.h" #include "storm/modelchecker/results/ExplicitQualitativeCheckResult.h" #include "storm/exceptions/NotSupportedException.h" #include "storm/shields/AbstractShield.h" namespace storm { namespace jani { class Model; } namespace api { void exportJaniModelAsDot(storm::jani::Model const& model, std::string const& filename); template void exportSparseModelAsDrn(std::shared_ptr> const& model, std::string const& filename, std::vector const& parameterNames = {}, bool allowPlaceholders=true) { std::ofstream stream; storm::utility::openFile(filename, stream); storm::exporter::DirectEncodingOptions options; options.allowPlaceholders = allowPlaceholders; storm::exporter::explicitExportSparseModel(stream, model, parameterNames, options); storm::utility::closeFile(stream); } template void exportSparseModelAsDrdd(std::shared_ptr> const& model, std::string const& filename) { storm::exporter::explicitExportSymbolicModel(filename, model); } template void exportSparseModelAsDot(std::shared_ptr> const& model, std::string const& filename, size_t maxWidth = 30) { std::ofstream stream; storm::utility::openFile(filename, stream); model->writeDotToStream(stream, maxWidth); storm::utility::closeFile(stream); } template void exportSymbolicModelAsDot(std::shared_ptr> const& model, std::string const& filename) { model->writeDotToFile(filename); } template void exportScheduler(std::shared_ptr> const& model, storm::storage::Scheduler const& scheduler, std::string const& filename) { std::ofstream stream; storm::utility::openFile(filename, stream); std::string jsonFileExtension = ".json"; if (filename.size() > 4 && std::equal(jsonFileExtension.rbegin(), jsonFileExtension.rend(), filename.rbegin())) { scheduler.printJsonToStream(stream, model, false, true); } else { scheduler.printToStream(stream, model, false, true); } storm::utility::closeFile(stream); } template void exportShield(std::shared_ptr> const& model, std::shared_ptr> const& shield, std::string const& filename) { std::ofstream stream; storm::utility::openFile(filename, stream); std::string jsonFileExtension = ".json"; if (filename.size() > 4 && std::equal(jsonFileExtension.rbegin(), jsonFileExtension.rend(), filename.rbegin())) { shield->printJsonToStream(stream, model); } else { shield->printToStream(stream, model); } storm::utility::closeFile(stream); } template inline void exportCheckResultToJson(std::shared_ptr> const& model, std::unique_ptr const& checkResult, std::string const& filename) { std::ofstream stream; storm::utility::openFile(filename, stream); if (checkResult->isExplicitQualitativeCheckResult()) { stream << checkResult->asExplicitQualitativeCheckResult().toJson(model->getOptionalStateValuations()).dump(4); } else { STORM_LOG_THROW(checkResult->isExplicitQuantitativeCheckResult(), storm::exceptions::NotSupportedException, "Export of check results is only supported for explicit check results (e.g. in the sparse engine)"); stream << checkResult->template asExplicitQuantitativeCheckResult().toJson(model->getOptionalStateValuations()).dump(4); } storm::utility::closeFile(stream); } template <> inline void exportCheckResultToJson(std::shared_ptr> const&, std::unique_ptr const&, std::string const&) { STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Export of check results is not supported for rational functions. "); } } }