#ifndef STORM_ENTRYPOINTS_H_H #define STORM_ENTRYPOINTS_H_H #include "src/utility/storm.h" namespace storm { namespace cli { template void verifySparseModel(std::shared_ptr> model, std::vector> const& formulas) { for (auto const& formula : formulas) { std::cout << std::endl << "Model checking property: " << *formula << " ..."; std::unique_ptr result(storm::verifySparseModel(model, formula)); 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) { if (storm::settings::generalSettings().isParametricRegionSet()){ auto regions=storm::modelchecker::region::ParameterRegion::getRegionsFromSettings(); std::shared_ptr, double>> modelchecker; if(model->isOfType(storm::models::ModelType::Dtmc)){ modelchecker = std::make_shared, double>>(model); } else if (model->isOfType(storm::models::ModelType::Mdp)){ modelchecker = std::make_shared, double>>(model); } else { STORM_LOG_THROW(false, storm::exceptions::InvalidSettingsException, "Currently parametric region verification is only available for DTMCs and Mdps."); } for (auto const& formula : formulas) { std::cout << std::endl << "Model checking property: " << *formula << " for all parameters in the given region(s)." << std::endl; STORM_LOG_THROW(modelchecker->canHandle(*formula.get()), storm::exceptions::InvalidSettingsException, "The parametric region check engine does not support this property."); modelchecker->specifyFormula(formula); if(storm::settings::regionSettings().doRefinement()){ modelchecker->refineAndCheckRegion(regions, storm::settings::regionSettings().getRefinementThreshold()); } else { modelchecker->checkRegions(regions); } modelchecker->printStatisticsToStream(std::cout); std::cout << std::endl; } } else { for (auto const& formula : formulas) { STORM_LOG_THROW(model->getType() == storm::models::ModelType::Dtmc, storm::exceptions::InvalidSettingsException, "Currently parametric verification is only available for DTMCs."); std::cout << std::endl << "Model checking property: " << *formula << " ..."; std::unique_ptr result(storm::verifySparseModel(model, formula)); 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; } storm::settings::modules::ParametricSettings const& parametricSettings = storm::settings::parametricSettings(); if (parametricSettings.exportResultToFile()) { exportParametricResultToFile(result->asExplicitQuantitativeCheckResult()[*model->getInitialStates().begin()], storm::models::sparse::Dtmc::ConstraintCollector(*(model->template as>())), parametricSettings.exportResultPath()); } } } } #endif template void verifySymbolicModelWithHybridEngine(std::shared_ptr> model, std::vector> const& formulas) { for (auto const& formula : formulas) { std::cout << std::endl << "Model checking property: " << *formula << " ..."; std::unique_ptr result(storm::verifySymbolicModelWithHybridEngine(model, formula)); 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 verifySymbolicModelWithSymbolicEngine(std::shared_ptr> model, std::vector> const& formulas) { for (auto const& formula : formulas) { std::cout << std::endl << "Model checking property: " << *formula << " ..."; std::unique_ptr result(storm::verifySymbolicModelWithDdEngine(model, formula)); 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."); \ } \ } template void buildAndCheckSymbolicModel(storm::prism::Program const& program, std::vector> const& formulas) { storm::storage::ModelProgramPair modelProgramPair = buildSymbolicModel(program, formulas); STORM_LOG_THROW(modelProgramPair.model != nullptr, storm::exceptions::InvalidStateException, "Model could not be constructed for an unknown reason."); std::cout << "PrintingInfo;Filename;Constants;NumStates;NumTransitions" << std::endl; std::cout << "INPUTMODEL_INFO;" << storm::settings::generalSettings().getSymbolicModelFilename() << ";" << storm::settings::generalSettings().getConstantDefinitionString() << ";" << modelProgramPair.model->getNumberOfStates() << ";" << modelProgramPair.model->getNumberOfTransitions() << ";" << std::endl; // Preprocess the model if needed. BRANCH_ON_MODELTYPE(modelProgramPair.model, modelProgramPair.model, ValueType, LibraryType, preprocessModel, formulas); // Print some information about the model. modelProgramPair.model->printModelInformationToStream(std::cout); // Verify the model, if a formula was given. if (!formulas.empty()) { // There may be constants of the model appearing in the formulas, so we replace all their occurrences // by their definitions in the translated program. // Start by building a mapping from constants of the (translated) model to their defining expressions. std::map constantSubstitution; for (auto const& constant : modelProgramPair.program.getConstants()) { if (constant.isDefined()) { constantSubstitution.emplace(constant.getExpressionVariable(), constant.getExpression()); } } std::vector> preparedFormulas; for (auto const& formula : formulas) { preparedFormulas.emplace_back(formula->substitute(constantSubstitution)); } if (modelProgramPair.model->isSparseModel()) { if(storm::settings::generalSettings().isCounterexampleSet()) { // If we were requested to generate a counterexample, we now do so for each formula. for(auto const& formula : preparedFormulas) { generateCounterexample(program, modelProgramPair.model->as>(), formula); } } else { verifySparseModel(modelProgramPair.model->as>(), preparedFormulas); } } else if (modelProgramPair.model->isSymbolicModel()) { if (storm::settings::generalSettings().getEngine() == storm::settings::modules::GeneralSettings::Engine::Hybrid) { verifySymbolicModelWithHybridEngine(modelProgramPair.model->as>(), preparedFormulas); } else { verifySymbolicModelWithSymbolicEngine(modelProgramPair.model->as>(), preparedFormulas); } } else { STORM_LOG_THROW(false, storm::exceptions::InvalidSettingsException, "Invalid input model type."); } } std::cout << "PrintingInfo;Filename;Constants;NumStates;NumTransitions" << std::endl; std::cout << "DONE_MODEL_INFO;" << storm::settings::generalSettings().getSymbolicModelFilename() << ";" << storm::settings::generalSettings().getConstantDefinitionString() << ";" << modelProgramPair.model->getNumberOfStates() << ";" << modelProgramPair.model->getNumberOfTransitions() << ";" << std::endl; } template void buildAndCheckSymbolicModel(storm::prism::Program const& program, std::vector> const& formulas) { if (storm::settings::generalSettings().getDdLibraryType() == storm::dd::DdType::CUDD) { buildAndCheckSymbolicModel(program, formulas); } else if (storm::settings::generalSettings().getDdLibraryType() == storm::dd::DdType::Sylvan) { buildAndCheckSymbolicModel(program, formulas); } } template void buildAndCheckExplicitModel(std::vector> const& formulas) { storm::settings::modules::GeneralSettings const& settings = storm::settings::generalSettings(); 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() ? settings.getStateRewardsFilename() : boost::optional(), settings.isTransitionRewardsSet() ? settings.getTransitionRewardsFilename() : boost::optional(), settings.isChoiceLabelingSet() ? settings.getChoiceLabelingFilename() : boost::optional()); // 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); } } } } #endif //STORM_ENTRYPOINTS_H_H