diff --git a/src/storm-pars-cli/storm-pars.cpp b/src/storm-pars-cli/storm-pars.cpp index f40d27f2f..b124538b7 100644 --- a/src/storm-pars-cli/storm-pars.cpp +++ b/src/storm-pars-cli/storm-pars.cpp @@ -543,14 +543,21 @@ namespace storm { storm::utility::Stopwatch latticeWatch(true); storm::analysis::LatticeExtender *extender = new storm::analysis::LatticeExtender(sparseModel); std::tuple criticalPair = extender->toLattice(formulas); - // TODO check not mdp - auto dtmcModel = model->as>(); - // TODO check formula type - auto assumptionChecker = storm::analysis::AssumptionChecker(formulas[0], dtmcModel, 3); - auto assumptionMaker = storm::analysis::AssumptionMaker(extender, &assumptionChecker, sparseModel->getNumberOfStates(), parSettings.isValidateAssumptionsSet()); - - std::map>> result = assumptionMaker.makeAssumptions( - std::get<0>(criticalPair), std::get<1>(criticalPair), std::get<2>(criticalPair)); + std::map>> result; + if (model->isOfType(storm::models::ModelType::Dtmc)) { + auto dtmcModel = model->as>(); + auto assumptionChecker = storm::analysis::AssumptionChecker(formulas[0], dtmcModel, 3); + auto assumptionMaker = storm::analysis::AssumptionMaker(extender, &assumptionChecker, sparseModel->getNumberOfStates(), parSettings.isValidateAssumptionsSet()); + result = assumptionMaker.makeAssumptions(std::get<0>(criticalPair), std::get<1>(criticalPair), std::get<2>(criticalPair)); + } else if (model->isOfType(storm::models::ModelType::Dtmc)) { + auto mdpModel = model->as>(); + auto assumptionChecker = storm::analysis::AssumptionChecker(formulas[0], mdpModel, 3); + auto assumptionMaker = storm::analysis::AssumptionMaker(extender, &assumptionChecker, sparseModel->getNumberOfStates(), parSettings.isValidateAssumptionsSet()); + result = assumptionMaker.makeAssumptions(std::get<0>(criticalPair), std::get<1>(criticalPair), std::get<2>(criticalPair)); + } else { + STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Unable to perform monotonicity analysis on the provided model type."); + } + latticeWatch.stop(); STORM_PRINT(std::endl << "Time for lattice creation: " << latticeWatch << "." << std::endl << std::endl); diff --git a/src/storm-pars/analysis/AssumptionChecker.cpp b/src/storm-pars/analysis/AssumptionChecker.cpp index 1ed16f149..359dc1a86 100644 --- a/src/storm-pars/analysis/AssumptionChecker.cpp +++ b/src/storm-pars/analysis/AssumptionChecker.cpp @@ -9,6 +9,7 @@ #include "storm/exceptions/NotSupportedException.h" #include "storm/modelchecker/CheckTask.h" #include "storm/modelchecker/prctl/SparseDtmcPrctlModelChecker.h" +#include "storm/modelchecker/prctl/SparseMdpPrctlModelChecker.h" #include "storm/modelchecker/results/CheckResult.h" #include "storm/modelchecker/results/ExplicitQuantitativeCheckResult.h" #include "storm/storage/expressions/SimpleValuation.h" @@ -56,6 +57,45 @@ namespace storm { } } + template + AssumptionChecker::AssumptionChecker(std::shared_ptr formula, std::shared_ptr> model, uint_fast64_t numberOfSamples) { + this->formula = formula; + this->matrix = model->getTransitionMatrix(); + + // Create sample points + auto instantiator = storm::utility::ModelInstantiator, storm::models::sparse::Mdp>(*model); + auto matrix = model->getTransitionMatrix(); + std::set variables = storm::models::sparse::getProbabilityParameters(*model); + for (auto i = 0; i < numberOfSamples; ++i) { + auto valuation = storm::utility::parametric::Valuation(); + for (auto itr = variables.begin(); itr != variables.end(); ++itr) { + // TODO: Type + auto val = std::pair((*itr), storm::utility::convertNumber(boost::lexical_cast((i+1)/(double (numberOfSamples + 1))))); + valuation.insert(val); + } + storm::models::sparse::Mdp sampleModel = instantiator.instantiate(valuation); + auto checker = storm::modelchecker::SparseMdpPrctlModelChecker>(sampleModel); + std::unique_ptr checkResult; + if (formula->isProbabilityOperatorFormula() && + formula->asProbabilityOperatorFormula().getSubformula().isUntilFormula()) { + const storm::modelchecker::CheckTask checkTask = storm::modelchecker::CheckTask( + (*formula).asProbabilityOperatorFormula().getSubformula().asUntilFormula()); + checkResult = checker.computeUntilProbabilities(Environment(), checkTask); + } else if (formula->isProbabilityOperatorFormula() && + formula->asProbabilityOperatorFormula().getSubformula().isEventuallyFormula()) { + const storm::modelchecker::CheckTask checkTask = storm::modelchecker::CheckTask( + (*formula).asProbabilityOperatorFormula().getSubformula().asEventuallyFormula()); + checkResult = checker.computeReachabilityProbabilities(Environment(), checkTask); + } else { + STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, + "Expecting until or eventually formula"); + } + auto quantitativeResult = checkResult->asExplicitQuantitativeCheckResult(); + std::vector values = quantitativeResult.getValueVector(); + results.push_back(values); + } + } + template bool AssumptionChecker::checkOnSamples(std::shared_ptr assumption) { bool result = true; diff --git a/src/storm-pars/analysis/AssumptionChecker.h b/src/storm-pars/analysis/AssumptionChecker.h index 8d434e561..deb75cd87 100644 --- a/src/storm-pars/analysis/AssumptionChecker.h +++ b/src/storm-pars/analysis/AssumptionChecker.h @@ -7,6 +7,7 @@ #include "storm/logic/Formula.h" #include "storm/models/sparse/Dtmc.h" +#include "storm/models/sparse/Mdp.h" #include "storm/environment/Environment.h" #include "storm/storage/expressions/BinaryRelationExpression.h" #include "Lattice.h" @@ -20,11 +21,20 @@ namespace storm { * Constructs an AssumptionChecker based on the number of samples, for the given formula and model. * * @param formula The formula to check. - * @param model The model to check the formula on. + * @param model The dtmc model to check the formula on. * @param numberOfSamples Number of sample points. */ AssumptionChecker(std::shared_ptr formula, std::shared_ptr> model, uint_fast64_t numberOfSamples); + /*! + * Constructs an AssumptionChecker based on the number of samples, for the given formula and model. + * + * @param formula The formula to check. + * @param model The mdp model to check the formula on. + * @param numberOfSamples Number of sample points. + */ + AssumptionChecker(std::shared_ptr formula, std::shared_ptr> model, uint_fast64_t numberOfSamples); + /*! * Checks if the assumption holds at the sample points of the AssumptionChecker. *