#include "gtest/gtest.h" #include "storm-config.h" #include "src/logic/Formulas.h" #include "src/utility/solver.h" #include "src/modelchecker/prctl/SymbolicMdpPrctlModelChecker.h" #include "src/modelchecker/results/SymbolicQualitativeCheckResult.h" #include "src/modelchecker/results/SymbolicQuantitativeCheckResult.h" #include "src/parser/FormulaParser.h" #include "src/parser/PrismParser.h" #include "src/builder/DdPrismModelBuilder.h" #include "src/models/symbolic/Dtmc.h" #include "src/models/symbolic/StandardRewardModel.h" #include "src/settings/SettingsManager.h" #include "src/settings/modules/NativeEquationSolverSettings.h" #include "src/settings/modules/GeneralSettings.h" TEST(SymbolicMdpPrctlModelCheckerTest, AsynchronousLeader_Cudd) { storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/performance/builder/leader5.nm"); // A parser that we use for conveniently constructing the formulas. storm::parser::FormulaParser formulaParser; // Build the die model with its reward model. #ifdef WINDOWS storm::builder::DdPrismModelBuilder::Options options; #else typename storm::builder::DdPrismModelBuilder::Options options; #endif options.buildAllRewardModels = false; options.rewardModelsToBuild.insert("rounds"); std::shared_ptr> model = storm::builder::DdPrismModelBuilder().build(program, options); EXPECT_EQ(27299ul, model->getNumberOfStates()); EXPECT_EQ(74365ul, model->getNumberOfTransitions()); ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp); std::shared_ptr> mdp = model->as>(); storm::modelchecker::SymbolicMdpPrctlModelChecker checker(*mdp, std::unique_ptr>(new storm::utility::solver::SymbolicMinMaxLinearEquationSolverFactory())); std::shared_ptr formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"elected\"]"); std::unique_ptr result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult1 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(1, quantitativeResult1.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(1, quantitativeResult1.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F<=25 \"elected\"]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult3 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(0, quantitativeResult3.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(0, quantitativeResult3.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("Rmin=? [F \"elected\"]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult5 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(5.0348834996352601, quantitativeResult5.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(5.0348834996352601, quantitativeResult5.getMax(), storm::settings::getModule().getPrecision()); } TEST(SymbolicMdpPrctlModelCheckerTest, AsynchronousLeader_Sylvan) { storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/performance/builder/leader5.nm"); // A parser that we use for conveniently constructing the formulas. storm::parser::FormulaParser formulaParser; // Build the die model with its reward model. #ifdef WINDOWS storm::builder::DdPrismModelBuilder::Options options; #else typename storm::builder::DdPrismModelBuilder::Options options; #endif options.buildAllRewardModels = false; options.rewardModelsToBuild.insert("rounds"); std::shared_ptr> model = storm::builder::DdPrismModelBuilder().build(program, options); EXPECT_EQ(27299ul, model->getNumberOfStates()); EXPECT_EQ(74365ul, model->getNumberOfTransitions()); ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp); std::shared_ptr> mdp = model->as>(); storm::modelchecker::SymbolicMdpPrctlModelChecker checker(*mdp, std::unique_ptr>(new storm::utility::solver::SymbolicMinMaxLinearEquationSolverFactory())); std::shared_ptr formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"elected\"]"); std::unique_ptr result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult1 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(1, quantitativeResult1.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(1, quantitativeResult1.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F<=25 \"elected\"]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult3 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(0, quantitativeResult3.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(0, quantitativeResult3.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("Rmin=? [F \"elected\"]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult5 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(5.034920501133386, quantitativeResult5.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(5.034920501133386, quantitativeResult5.getMax(), storm::settings::getModule().getPrecision()); } TEST(SymbolicMdpPrctlModelCheckerTest, CSMA_Cudd) { storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/performance/builder/csma3_2.nm"); // A parser that we use for conveniently constructing the formulas. storm::parser::FormulaParser formulaParser(program); // Build the die model with its reward model. #ifdef WINDOWS storm::builder::DdPrismModelBuilder::Options options; #else typename storm::builder::DdPrismModelBuilder::Options options; #endif options.buildAllRewardModels = false; options.rewardModelsToBuild.insert("time"); storm::builder::DdPrismModelBuilder builder; std::shared_ptr> model = builder.build(program, options); storm::prism::Program translatedProgram = builder.getTranslatedProgram(); EXPECT_EQ(36850ul, model->getNumberOfStates()); EXPECT_EQ(55862ul, model->getNumberOfTransitions()); ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp); std::shared_ptr> mdp = model->as>(); storm::modelchecker::SymbolicMdpPrctlModelChecker checker(*mdp, std::unique_ptr>(new storm::utility::solver::SymbolicMinMaxLinearEquationSolverFactory())); std::shared_ptr formula = formulaParser.parseSingleFormulaFromString("Pmin=? [ !\"collision_max_backoff\" U \"all_delivered\" ]"); std::unique_ptr result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult1 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(0.4349662650631545, quantitativeResult1.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(0.4349662650631545, quantitativeResult1.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("Pmin=? [ F (min_backoff_after_success < 4) ]"); formula = formula->substitute(translatedProgram.getConstantsSubstitution()); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult3 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(1, quantitativeResult3.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(1, quantitativeResult3.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("Rmin=? [ F \"all_delivered\" ]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult5 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(93.624085091252454, quantitativeResult5.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(93.624085091252454, quantitativeResult5.getMax(), storm::settings::getModule().getPrecision()); } TEST(SymbolicMdpPrctlModelCheckerTest, CSMA_Sylvan) { storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/performance/builder/csma3_2.nm"); // A parser that we use for conveniently constructing the formulas. storm::parser::FormulaParser formulaParser(program); // Build the die model with its reward model. #ifdef WINDOWS storm::builder::DdPrismModelBuilder::Options options; #else typename storm::builder::DdPrismModelBuilder::Options options; #endif options.buildAllRewardModels = false; options.rewardModelsToBuild.insert("time"); storm::builder::DdPrismModelBuilder builder; std::shared_ptr> model = builder.build(program, options); storm::prism::Program translatedProgram = builder.getTranslatedProgram(); EXPECT_EQ(36850ul, model->getNumberOfStates()); EXPECT_EQ(55862ul, model->getNumberOfTransitions()); ASSERT_EQ(model->getType(), storm::models::ModelType::Mdp); std::shared_ptr> mdp = model->as>(); storm::modelchecker::SymbolicMdpPrctlModelChecker checker(*mdp, std::unique_ptr>(new storm::utility::solver::SymbolicMinMaxLinearEquationSolverFactory())); std::shared_ptr formula = formulaParser.parseSingleFormulaFromString("Pmin=? [ !\"collision_max_backoff\" U \"all_delivered\" ]"); std::unique_ptr result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult1 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(0.4349666248753522, quantitativeResult1.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(0.4349666248753522, quantitativeResult1.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("Pmin=? [ F (min_backoff_after_success < 4) ]"); formula = formula->substitute(translatedProgram.getConstantsSubstitution()); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult3 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(1, quantitativeResult3.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(1, quantitativeResult3.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("Rmin=? [ F \"all_delivered\" ]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult5 = result->asSymbolicQuantitativeCheckResult(); // FIXME: not optimal precision. EXPECT_NEAR(93.624117712294478, quantitativeResult5.getMin(), 100 * storm::settings::getModule().getPrecision()); EXPECT_NEAR(93.624117712294478, quantitativeResult5.getMax(), 100 * storm::settings::getModule().getPrecision()); }