#pragma once #include "storm/parser/AutoParser.h" #include "storm/parser/DirectEncodingParser.h" #include "storm/parser/ImcaMarkovAutomatonParser.h" #include "storm/storage/SymbolicModelDescription.h" #include "storm/storage/sparse/ModelComponents.h" #include "storm/models/sparse/Dtmc.h" #include "storm/models/sparse/Ctmc.h" #include "storm/models/sparse/Mdp.h" #include "storm/models/sparse/MarkovAutomaton.h" #include "storm/models/sparse/StochasticTwoPlayerGame.h" #include "storm/models/sparse/StandardRewardModel.h" #include "storm/builder/DdPrismModelBuilder.h" #include "storm/builder/DdJaniModelBuilder.h" #include "storm/generator/PrismNextStateGenerator.h" #include "storm/generator/JaniNextStateGenerator.h" #include "storm/builder/ExplicitModelBuilder.h" #include "storm/builder/jit/ExplicitJitJaniModelBuilder.h" #include "storm/settings/SettingsManager.h" #include "storm/settings/modules/IOSettings.h" #include "storm/settings/modules/JitBuilderSettings.h" #include "storm/utility/macros.h" #include "storm/exceptions/NotSupportedException.h" namespace storm { namespace api { template std::shared_ptr> buildSymbolicModel(storm::storage::SymbolicModelDescription const& model, std::vector> const& formulas) { if (model.isPrismProgram()) { typename storm::builder::DdPrismModelBuilder::Options options; options = typename storm::builder::DdPrismModelBuilder::Options(formulas); storm::builder::DdPrismModelBuilder builder; return builder.build(model.asPrismProgram(), options); } else { STORM_LOG_THROW(model.isJaniModel(), storm::exceptions::NotSupportedException, "Building symbolic model from this model description is unsupported."); typename storm::builder::DdJaniModelBuilder::Options options; options = typename storm::builder::DdJaniModelBuilder::Options(formulas); storm::builder::DdJaniModelBuilder builder; return builder.build(model.asJaniModel(), options); } } template<> inline std::shared_ptr> buildSymbolicModel(storm::storage::SymbolicModelDescription const& model, std::vector> const& formulas) { STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "CUDD does not support rational numbers."); } template<> inline std::shared_ptr> buildSymbolicModel(storm::storage::SymbolicModelDescription const& model, std::vector> const& formulas) { STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "CUDD does not support rational functions."); } template std::shared_ptr> buildSparseModel(storm::storage::SymbolicModelDescription const& model, std::vector> const& formulas, bool buildChoiceLabels = false, bool buildChoiceOrigins = false, bool buildStateValuations = false) { storm::builder::BuilderOptions options(formulas); if (storm::settings::getModule().isBuildFullModelSet()) { options.setBuildAllLabels(); options.setBuildAllRewardModels(); options.clearTerminalStates(); } options.setBuildChoiceLabels(buildChoiceLabels); options.setBuildChoiceOrigins(buildChoiceOrigins); options.setBuildStateValuations(buildStateValuations); if (storm::settings::getModule().isJitSet()) { STORM_LOG_THROW(model.isJaniModel(), storm::exceptions::NotSupportedException, "Cannot use JIT-based model builder for non-JANI model."); storm::builder::jit::ExplicitJitJaniModelBuilder builder(model.asJaniModel(), options); if (storm::settings::getModule().isDoctorSet()) { bool result = builder.doctor(); STORM_LOG_THROW(result, storm::exceptions::NotSupportedException, "The JIT-based model builder cannot be used on your system."); STORM_LOG_INFO("The JIT-based model builder seems to be working."); } return builder.build(); } else { std::shared_ptr> generator; if (model.isPrismProgram()) { generator = std::make_shared>(model.asPrismProgram(), options); } else if (model.isJaniModel()) { generator = std::make_shared>(model.asJaniModel(), options); } else { STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Cannot build sparse model from this symbolic model description."); } storm::builder::ExplicitModelBuilder builder(generator); return builder.build(); } } template> std::shared_ptr> buildSparseModel(storm::models::ModelType modelType, storm::storage::sparse::ModelComponents&& components) { switch (modelType) { case storm::models::ModelType::Dtmc: return std::make_shared>(std::move(components)); case storm::models::ModelType::Ctmc: return std::make_shared>(std::move(components)); case storm::models::ModelType::Mdp: return std::make_shared>(std::move(components)); case storm::models::ModelType::MarkovAutomaton: return std::make_shared>(std::move(components)); case storm::models::ModelType::S2pg: return std::make_shared>(std::move(components)); } } template std::shared_ptr> buildExplicitModel(std::string const& transitionsFile, std::string const& labelingFile, boost::optional const& stateRewardsFile = boost::none, boost::optional const& transitionRewardsFile = boost::none, boost::optional const& choiceLabelingFile = boost::none) { STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Exact or parametric models with explicit input are not supported."); } template<> inline std::shared_ptr> buildExplicitModel(std::string const& transitionsFile, std::string const& labelingFile, boost::optional const& stateRewardsFile, boost::optional const& transitionRewardsFile, boost::optional const& choiceLabelingFile) { return storm::parser::AutoParser::parseModel(transitionsFile, labelingFile, stateRewardsFile ? stateRewardsFile.get() : "", transitionRewardsFile ? transitionRewardsFile.get() : "", choiceLabelingFile ? choiceLabelingFile.get() : "" ); } template std::shared_ptr> buildExplicitDRNModel(std::string const& drnFile) { return storm::parser::DirectEncodingParser::parseModel(drnFile); } template<> inline std::shared_ptr> buildExplicitDRNModel(std::string const&) { STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Exact models with direct encoding are not supported."); } template std::shared_ptr> buildExplicitIMCAModel(std::string const&) { STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Exact models with direct encoding are not supported."); } template<> inline std::shared_ptr> buildExplicitIMCAModel(std::string const& imcaFile) { return storm::parser::ImcaMarkovAutomatonParser::parseImcaFile(imcaFile); } } }