#include "gtest/gtest.h" #include "storm-config.h" #include "src/parser/FormulaParser.h" #include "src/logic/Formulas.h" #include "src/utility/solver.h" #include "src/storage/SymbolicModelDescription.h" #include "src/modelchecker/prctl/SymbolicDtmcPrctlModelChecker.h" #include "src/modelchecker/results/SymbolicQualitativeCheckResult.h" #include "src/modelchecker/results/SymbolicQuantitativeCheckResult.h" #include "src/parser/PrismParser.h" #include "src/builder/DdPrismModelBuilder.h" #include "src/models/symbolic/StandardRewardModel.h" #include "src/models/symbolic/Dtmc.h" #include "src/settings/SettingsManager.h" #include "src/settings/modules/NativeEquationSolverSettings.h" #include "src/settings/modules/GeneralSettings.h" TEST(SymbolicDtmcPrctlModelCheckerTest, Die_Cudd) { storm::storage::SymbolicModelDescription modelDescription = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/die.pm"); storm::prism::Program program = modelDescription.preprocess().asPrismProgram(); // 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("coin_flips"); std::shared_ptr> model = storm::builder::DdPrismModelBuilder().build(program, options); EXPECT_EQ(13ul, model->getNumberOfStates()); EXPECT_EQ(20ul, model->getNumberOfTransitions()); ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc); std::shared_ptr> dtmc = model->as>(); storm::modelchecker::SymbolicDtmcPrctlModelChecker> checker(*dtmc, std::unique_ptr>(new storm::utility::solver::SymbolicLinearEquationSolverFactory())); std::shared_ptr formula = formulaParser.parseSingleFormulaFromString("P=? [F \"one\"]"); 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.0/6.0, quantitativeResult1.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(1.0/6.0, quantitativeResult1.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("P=? [F \"two\"]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult2 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(1.0/6.0, quantitativeResult2.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(1.0/6.0, quantitativeResult2.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("P=? [F \"three\"]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult3 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(1.0/6.0, quantitativeResult3.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(1.0/6.0, quantitativeResult3.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("R=? [F \"done\"]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult4 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(3.6666622161865234, quantitativeResult4.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(3.6666622161865234, quantitativeResult4.getMax(), storm::settings::getModule().getPrecision()); } TEST(SymbolicDtmcPrctlModelCheckerTest, Die_Sylvan) { storm::storage::SymbolicModelDescription modelDescription = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/die.pm"); storm::prism::Program program = modelDescription.preprocess().asPrismProgram(); // 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("coin_flips"); std::shared_ptr> model = storm::builder::DdPrismModelBuilder().build(program, options); EXPECT_EQ(13ul, model->getNumberOfStates()); EXPECT_EQ(20ul, model->getNumberOfTransitions()); ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc); std::shared_ptr> dtmc = model->as>(); storm::modelchecker::SymbolicDtmcPrctlModelChecker> checker(*dtmc, std::unique_ptr>(new storm::utility::solver::SymbolicLinearEquationSolverFactory())); std::shared_ptr formula = formulaParser.parseSingleFormulaFromString("P=? [F \"one\"]"); 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.0/6.0, quantitativeResult1.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(1.0/6.0, quantitativeResult1.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("P=? [F \"two\"]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult2 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(1.0/6.0, quantitativeResult2.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(1.0/6.0, quantitativeResult2.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("P=? [F \"three\"]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult3 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(1.0/6.0, quantitativeResult3.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(1.0/6.0, quantitativeResult3.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("R=? [F \"done\"]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult4 = result->asSymbolicQuantitativeCheckResult(); // FIXME: precision is not optimal. EXPECT_NEAR(3.6666622161865234, quantitativeResult4.getMin(), 10 * storm::settings::getModule().getPrecision()); EXPECT_NEAR(3.6666622161865234, quantitativeResult4.getMax(), 10 * storm::settings::getModule().getPrecision()); } TEST(SymbolicDtmcPrctlModelCheckerTest, Crowds_Cudd) { storm::storage::SymbolicModelDescription modelDescription = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/crowds-5-5.pm"); storm::prism::Program program = modelDescription.preprocess().asPrismProgram(); // A parser that we use for conveniently constructing the formulas. storm::parser::FormulaParser formulaParser; std::shared_ptr> model = storm::builder::DdPrismModelBuilder().build(program); EXPECT_EQ(8607ul, model->getNumberOfStates()); EXPECT_EQ(15113ul, model->getNumberOfTransitions()); ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc); std::shared_ptr> dtmc = model->as>(); storm::modelchecker::SymbolicDtmcPrctlModelChecker> checker(*dtmc, std::unique_ptr>(new storm::utility::solver::SymbolicLinearEquationSolverFactory())); std::shared_ptr formula = formulaParser.parseSingleFormulaFromString("P=? [F \"observe0Greater1\"]"); 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.33288236360191303, quantitativeResult1.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(0.33288236360191303, quantitativeResult1.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("P=? [F \"observeIGreater1\"]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult2 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(0.15222081144084315, quantitativeResult2.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(0.15222081144084315, quantitativeResult2.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("P=? [F \"observeOnlyTrueSender\"]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult3 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(0.3215392962289586, quantitativeResult3.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(0.3215392962289586, quantitativeResult3.getMax(), storm::settings::getModule().getPrecision()); } TEST(SymbolicDtmcPrctlModelCheckerTest, Crowds_Sylvan) { storm::storage::SymbolicModelDescription modelDescription = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/crowds-5-5.pm"); storm::prism::Program program = modelDescription.preprocess().asPrismProgram(); // A parser that we use for conveniently constructing the formulas. storm::parser::FormulaParser formulaParser; std::shared_ptr> model = storm::builder::DdPrismModelBuilder().build(program); EXPECT_EQ(8607ul, model->getNumberOfStates()); EXPECT_EQ(15113ul, model->getNumberOfTransitions()); ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc); std::shared_ptr> dtmc = model->as>(); storm::modelchecker::SymbolicDtmcPrctlModelChecker> checker(*dtmc, std::unique_ptr>(new storm::utility::solver::SymbolicLinearEquationSolverFactory())); std::shared_ptr formula = formulaParser.parseSingleFormulaFromString("P=? [F \"observe0Greater1\"]"); std::unique_ptr result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult1 = result->asSymbolicQuantitativeCheckResult(); // FIXME: precision not optimal. EXPECT_NEAR(0.33288236360191303, quantitativeResult1.getMin(), 10 * storm::settings::getModule().getPrecision()); EXPECT_NEAR(0.33288236360191303, quantitativeResult1.getMax(), 10 * storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("P=? [F \"observeIGreater1\"]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult2 = result->asSymbolicQuantitativeCheckResult(); // FIXME: precision not optimal. EXPECT_NEAR(0.15222081144084315, quantitativeResult2.getMin(), 10 * storm::settings::getModule().getPrecision()); EXPECT_NEAR(0.15222081144084315, quantitativeResult2.getMax(), 10 * storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("P=? [F \"observeOnlyTrueSender\"]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult3 = result->asSymbolicQuantitativeCheckResult(); // FIXME: precision not optimal. EXPECT_NEAR(0.3215392962289586, quantitativeResult3.getMin(), 10 * storm::settings::getModule().getPrecision()); EXPECT_NEAR(0.3215392962289586, quantitativeResult3.getMax(), 10 * storm::settings::getModule().getPrecision()); } TEST(SymbolicDtmcPrctlModelCheckerTest, SynchronousLeader_Cudd) { storm::storage::SymbolicModelDescription modelDescription = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader-3-5.pm"); storm::prism::Program program = modelDescription.preprocess().asPrismProgram(); // 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("num_rounds"); std::shared_ptr> model = storm::builder::DdPrismModelBuilder().build(program, options); EXPECT_EQ(273ul, model->getNumberOfStates()); EXPECT_EQ(397ul, model->getNumberOfTransitions()); ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc); std::shared_ptr> dtmc = model->as>(); storm::modelchecker::SymbolicDtmcPrctlModelChecker> checker(*dtmc, std::unique_ptr>(new storm::utility::solver::SymbolicLinearEquationSolverFactory())); std::shared_ptr formula = formulaParser.parseSingleFormulaFromString("P=? [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.0, quantitativeResult1.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(1.0, quantitativeResult1.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("P=? [F<=20 \"elected\"]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult2 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(0.99999989760000074, quantitativeResult2.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(0.99999989760000074, quantitativeResult2.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("R=? [F \"elected\"]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult3 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(1.0416666666666643, quantitativeResult3.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(1.0416666666666643, quantitativeResult3.getMax(), storm::settings::getModule().getPrecision()); } TEST(SymbolicDtmcPrctlModelCheckerTest, SynchronousLeader_Sylvan) { storm::storage::SymbolicModelDescription modelDescription = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader-3-5.pm"); storm::prism::Program program = modelDescription.preprocess().asPrismProgram(); // 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("num_rounds"); std::shared_ptr> model = storm::builder::DdPrismModelBuilder().build(program, options); EXPECT_EQ(273ul, model->getNumberOfStates()); EXPECT_EQ(397ul, model->getNumberOfTransitions()); ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc); std::shared_ptr> dtmc = model->as>(); storm::modelchecker::SymbolicDtmcPrctlModelChecker> checker(*dtmc, std::unique_ptr>(new storm::utility::solver::SymbolicLinearEquationSolverFactory())); std::shared_ptr formula = formulaParser.parseSingleFormulaFromString("P=? [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.0, quantitativeResult1.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(1.0, quantitativeResult1.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("P=? [F<=20 \"elected\"]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult2 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(0.99999989760000074, quantitativeResult2.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(0.99999989760000074, quantitativeResult2.getMax(), storm::settings::getModule().getPrecision()); formula = formulaParser.parseSingleFormulaFromString("R=? [F \"elected\"]"); result = checker.check(*formula); result->filter(storm::modelchecker::SymbolicQualitativeCheckResult(model->getReachableStates(), model->getInitialStates())); storm::modelchecker::SymbolicQuantitativeCheckResult& quantitativeResult3 = result->asSymbolicQuantitativeCheckResult(); EXPECT_NEAR(1.0416666666666643, quantitativeResult3.getMin(), storm::settings::getModule().getPrecision()); EXPECT_NEAR(1.0416666666666643, quantitativeResult3.getMax(), storm::settings::getModule().getPrecision()); }