#ifndef STORM_ENTRYPOINTS_H_H #define STORM_ENTRYPOINTS_H_H #include "src/utility/storm.h" #include "src/storage/SymbolicModelDescription.h" #include "src/exceptions/NotImplementedException.h" #include "src/exceptions/InvalidSettingsException.h" #include "src/exceptions/UnexpectedException.h" namespace storm { namespace cli { template void verifySparseModel(std::shared_ptr> model, std::vector> const& formulas, bool onlyInitialStatesRelevant = false) { for (auto const& formula : formulas) { std::cout << std::endl << "Model checking property: " << *formula << " ..."; std::unique_ptr result(storm::verifySparseModel(model, formula, onlyInitialStatesRelevant)); if (result) { std::cout << " done." << std::endl; std::cout << "Result (initial states): "; result->filter(storm::modelchecker::ExplicitQualitativeCheckResult(model->getInitialStates())); std::cout << *result << std::endl; } else { std::cout << " skipped, because the modelling formalism is currently unsupported." << std::endl; } } } #ifdef STORM_HAVE_CARL template<> inline void verifySparseModel(std::shared_ptr> model, std::vector> const& formulas, bool onlyInitialStatesRelevant) { for (auto const& formula : formulas) { STORM_LOG_THROW(model->getType() == storm::models::ModelType::Dtmc || model->getType() == storm::models::ModelType::Ctmc, storm::exceptions::InvalidSettingsException, "Currently parametric verification is only available for DTMCs and CTMCs."); std::cout << std::endl << "Model checking property: " << *formula << " ..."; std::unique_ptr result(storm::verifySparseModel(model, formula, onlyInitialStatesRelevant)); if (result) { std::cout << " done." << std::endl; std::cout << "Result (initial states): "; result->filter(storm::modelchecker::ExplicitQualitativeCheckResult(model->getInitialStates())); std::cout << *result << std::endl; } else { std::cout << " skipped, because the modelling formalism is currently unsupported." << std::endl; } if (storm::settings::getModule().exportResultToFile()) { exportParametricResultToFile(result->asExplicitQuantitativeCheckResult()[*model->getInitialStates().begin()], storm::models::sparse::Dtmc::ConstraintCollector(*(model->template as>())), storm::settings::getModule().exportResultPath()); } } } #endif template void verifySymbolicModelWithAbstractionRefinementEngine(storm::storage::SymbolicModelDescription const& model, std::vector> const& formulas, bool onlyInitialStatesRelevant = false) { STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Abstraction Refinement is not yet implemented."); } template void verifySymbolicModelWithExplorationEngine(storm::storage::SymbolicModelDescription const& model, std::vector> const& formulas, bool onlyInitialStatesRelevant = false) { STORM_LOG_THROW(model.isPrismProgram(), storm::exceptions::InvalidSettingsException, "Exploration engine is currently only applicable to PRISM models."); storm::prism::Program const& program = model.asPrismProgram(); STORM_LOG_THROW(program.getModelType() == storm::prism::Program::ModelType::DTMC || program.getModelType() == storm::prism::Program::ModelType::MDP, storm::exceptions::InvalidSettingsException, "Currently exploration-based verification is only available for DTMCs and MDPs."); for (auto const& formula : formulas) { std::cout << std::endl << "Model checking property: " << *formula << " ..."; bool supportFormula; std::unique_ptr result; if(program.getModelType() == storm::prism::Program::ModelType::DTMC) { storm::modelchecker::SparseExplorationModelChecker> checker(program); storm::modelchecker::CheckTask task(*formula, onlyInitialStatesRelevant); supportFormula = checker.canHandle(task); if (supportFormula) { result = checker.check(task); } } else if(program.getModelType() == storm::prism::Program::ModelType::MDP) { storm::modelchecker::SparseExplorationModelChecker> checker(program); storm::modelchecker::CheckTask task(*formula, onlyInitialStatesRelevant); supportFormula = checker.canHandle(task); if (supportFormula) { result = checker.check(task); } } else { // Should be catched before. assert(false); } if(!supportFormula) { std::cout << " skipped, because the formula cannot be handled by the selected engine/method." << std::endl; } if (result) { std::cout << " done." << std::endl; std::cout << "Result (initial states): "; std::cout << *result << std::endl; } else { std::cout << " skipped, because the modelling formalism is currently unsupported." << std::endl; } } } #ifdef STORM_HAVE_CARL template<> void verifySymbolicModelWithExplorationEngine(storm::storage::SymbolicModelDescription const& model, std::vector> const& formulas, bool onlyInitialStatesRelevant) { STORM_LOG_THROW(false, storm::exceptions::InvalidSettingsException, "Exploration-based verification does currently not support parametric models."); } #endif template void verifySymbolicModelWithHybridEngine(std::shared_ptr> model, std::vector> const& formulas, bool onlyInitialStatesRelevant = false) { for (auto const& formula : formulas) { std::cout << std::endl << "Model checking property: " << *formula << " ..."; std::unique_ptr result(storm::verifySymbolicModelWithHybridEngine(model, formula, onlyInitialStatesRelevant)); if (result) { std::cout << " done." << std::endl; std::cout << "Result (initial states): "; result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); std::cout << *result << std::endl; } else { std::cout << " skipped, because the modelling formalism is currently unsupported." << std::endl; } } } template void verifySymbolicModelWithDdEngine(std::shared_ptr> model, std::vector> const& formulas, bool onlyInitialStatesRelevant = false) { for (auto const& formula : formulas) { std::cout << std::endl << "Model checking property: " << *formula << " ..."; std::unique_ptr result(storm::verifySymbolicModelWithDdEngine(model, formula, onlyInitialStatesRelevant)); if (result) { std::cout << " done." << std::endl; std::cout << "Result (initial states): "; result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); std::cout << *result << std::endl; } else { std::cout << " skipped, because the modelling formalism is currently unsupported." << std::endl; } } } #define BRANCH_ON_MODELTYPE(result, model, value_type, dd_type, function, ...) \ if (model->isSymbolicModel()) { \ if (model->isOfType(storm::models::ModelType::Dtmc)) { \ result = function>(model->as>(), __VA_ARGS__); \ } else if (model->isOfType(storm::models::ModelType::Ctmc)) { \ result = function>(model->as>(), __VA_ARGS__); \ } else if (model->isOfType(storm::models::ModelType::Mdp)) { \ result = function>(model->as>(), __VA_ARGS__); \ } else { \ STORM_LOG_ASSERT(false, "Unknown model type."); \ } \ } else { \ STORM_LOG_ASSERT(model->isSparseModel(), "Unknown model type."); \ if (model->isOfType(storm::models::ModelType::Dtmc)) { \ result = function>(model->as>(), __VA_ARGS__); \ } else if (model->isOfType(storm::models::ModelType::Ctmc)) { \ result = function>(model->as>(), __VA_ARGS__); \ } else if (model->isOfType(storm::models::ModelType::Mdp)) { \ result = function>(model->as>(), __VA_ARGS__); \ } else if (model->isOfType(storm::models::ModelType::MarkovAutomaton)) { \ result = function>(model->as>(), __VA_ARGS__); \ } else { \ STORM_LOG_ASSERT(false, "Unknown model type."); \ } \ } #define BRANCH_ON_SPARSE_MODELTYPE(result, model, value_type, function, ...) \ STORM_LOG_ASSERT(model->isSparseModel(), "Illegal model type."); \ if (model->isOfType(storm::models::ModelType::Dtmc)) { \ result = function>(model->template as>(), __VA_ARGS__); \ } else if (model->isOfType(storm::models::ModelType::Ctmc)) { \ result = function>(model->template as>(), __VA_ARGS__); \ } else if (model->isOfType(storm::models::ModelType::Mdp)) { \ result = function>(model->template as>(), __VA_ARGS__); \ } else if (model->isOfType(storm::models::ModelType::MarkovAutomaton)) { \ result = function>(model->template as>(), __VA_ARGS__); \ } else { \ STORM_LOG_ASSERT(false, "Unknown model type."); \ } template void buildAndCheckSymbolicModelWithSymbolicEngine(bool hybrid, storm::storage::SymbolicModelDescription const& model, std::vector> const& formulas, bool onlyInitialStatesRelevant = false) { // Start by building the model. auto markovModel = buildSymbolicModel(model, formulas); // Print some information about the model. markovModel->printModelInformationToStream(std::cout); // Then select the correct engine. if (hybrid) { verifySymbolicModelWithHybridEngine(markovModel, formulas, onlyInitialStatesRelevant); } else { verifySymbolicModelWithDdEngine(markovModel, formulas, onlyInitialStatesRelevant); } } template void buildAndCheckSymbolicModelWithSparseEngine(storm::storage::SymbolicModelDescription const& model, std::vector> const& formulas, bool onlyInitialStatesRelevant = false) { // Start by building the model. std::shared_ptr markovModel = buildSparseModel(model, formulas); STORM_LOG_THROW(markovModel, storm::exceptions::UnexpectedException, "The model was not successfully built."); // Print some information about the model. markovModel->printModelInformationToStream(std::cout); // Preprocess the model. BRANCH_ON_SPARSE_MODELTYPE(markovModel, markovModel, ValueType, preprocessModel, formulas); std::shared_ptr> sparseModel = markovModel->template as>(); // Finally, treat the formulas. if (storm::settings::getModule().isCounterexampleSet()) { generateCounterexamples(model, sparseModel, formulas); } else { verifySparseModel(sparseModel, formulas, onlyInitialStatesRelevant); } } template void buildAndCheckSymbolicModel(storm::storage::SymbolicModelDescription const& model, std::vector> const& formulas, bool onlyInitialStatesRelevant = false) { if (storm::settings::getModule().getEngine() == storm::settings::modules::CoreSettings::Engine::AbstractionRefinement) { auto ddlib = storm::settings::getModule().getDdLibraryType(); if (ddlib == storm::dd::DdType::CUDD) { verifySymbolicModelWithAbstractionRefinementEngine(model, formulas, onlyInitialStatesRelevant); } else { verifySymbolicModelWithAbstractionRefinementEngine(model, formulas, onlyInitialStatesRelevant); } } else if (storm::settings::getModule().getEngine() == storm::settings::modules::CoreSettings::Engine::Exploration) { verifySymbolicModelWithExplorationEngine(model, formulas, onlyInitialStatesRelevant); } else { auto engine = storm::settings::getModule().getEngine(); if (engine == storm::settings::modules::CoreSettings::Engine::Dd || engine == storm::settings::modules::CoreSettings::Engine::Hybrid) { auto ddlib = storm::settings::getModule().getDdLibraryType(); if (ddlib == storm::dd::DdType::CUDD) { buildAndCheckSymbolicModelWithSymbolicEngine(engine == storm::settings::modules::CoreSettings::Engine::Hybrid, model, formulas, onlyInitialStatesRelevant); } else { buildAndCheckSymbolicModelWithSymbolicEngine(engine == storm::settings::modules::CoreSettings::Engine::Hybrid, model, formulas, onlyInitialStatesRelevant); } } else { STORM_LOG_THROW(engine == storm::settings::modules::CoreSettings::Engine::Sparse, storm::exceptions::InvalidSettingsException, "Illegal engine."); buildAndCheckSymbolicModelWithSparseEngine(model, formulas, onlyInitialStatesRelevant); } } } #ifdef STORM_HAVE_CARL template<> void buildAndCheckSymbolicModel(storm::storage::SymbolicModelDescription const& model, std::vector> const& formulas, bool onlyInitialStatesRelevant) { STORM_LOG_THROW(storm::settings::getModule().getEngine() == storm::settings::modules::CoreSettings::Engine::Sparse, storm::exceptions::InvalidSettingsException, "Cannot use this data type with an engine different than the sparse one."); buildAndCheckSymbolicModelWithSparseEngine(model, formulas, onlyInitialStatesRelevant); } template<> void buildAndCheckSymbolicModel(storm::storage::SymbolicModelDescription const& model, std::vector> const& formulas, bool onlyInitialStatesRelevant) { STORM_LOG_THROW(storm::settings::getModule().getEngine() == storm::settings::modules::CoreSettings::Engine::Sparse, storm::exceptions::InvalidSettingsException, "Cannot use this data type with an engine different than the sparse one."); buildAndCheckSymbolicModelWithSparseEngine(model, formulas, onlyInitialStatesRelevant); } #endif template void buildAndCheckExplicitModel(std::vector> const& formulas, bool onlyInitialStatesRelevant = false) { storm::settings::modules::IOSettings const& settings = storm::settings::getModule(); STORM_LOG_THROW(settings.isExplicitSet(), storm::exceptions::InvalidStateException, "Unable to build explicit model without model files."); std::shared_ptr model = buildExplicitModel(settings.getTransitionFilename(), settings.getLabelingFilename(), settings.isStateRewardsSet() ? boost::optional(settings.getStateRewardsFilename()) : boost::none, settings.isTransitionRewardsSet() ? boost::optional(settings.getTransitionRewardsFilename()) : boost::none, settings.isChoiceLabelingSet() ? boost::optional(settings.getChoiceLabelingFilename()) : boost::none); // Preprocess the model if needed. BRANCH_ON_MODELTYPE(model, model, ValueType, storm::dd::DdType::CUDD, preprocessModel, formulas); // Print some information about the model. model->printModelInformationToStream(std::cout); // Verify the model, if a formula was given. if (!formulas.empty()) { STORM_LOG_THROW(model->isSparseModel(), storm::exceptions::InvalidStateException, "Expected sparse model."); verifySparseModel(model->as>(), formulas, onlyInitialStatesRelevant); } } } } #endif //STORM_ENTRYPOINTS_H_H