#include "gtest/gtest.h" #include "storm-config.h" #include "src/logic/Formulas.h" #include "src/utility/solver.h" #include "src/modelchecker/prctl/SparseMdpPrctlModelChecker.h" #include "src/modelchecker/results/ExplicitQuantitativeCheckResult.h" #include "src/settings/SettingsManager.h" #include "src/settings/SettingMemento.h" #include "src/parser/AutoParser.h" #include "storm-config.h" TEST(TopologicalValueIterationMdpPrctlModelCheckerTest, Dice) { //storm::settings::Settings* s = storm::settings::Settings::getInstance(); std::shared_ptr> mdp = storm::parser::AutoParser::parseModel(STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.tra", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.lab", "", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.flip.trans.rew")->as>(); ASSERT_EQ(mdp->getNumberOfStates(), 169ull); ASSERT_EQ(mdp->getNumberOfTransitions(), 436ull); storm::modelchecker::SparseMdpPrctlModelChecker mc(*mdp, std::unique_ptr>(new storm::utility::solver::TopologicalMinMaxLinearEquationSolverFactory())); //storm::property::prctl::Ap* apFormula = new storm::property::prctl::Ap("two"); auto apFormula = std::make_shared("two"); //storm::property::prctl::Eventually* eventuallyFormula = new storm::property::prctl::Eventually(apFormula); auto eventuallyFormula = std::make_shared(apFormula); //storm::property::prctl::ProbabilisticNoBoundOperator* probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator(eventuallyFormula, true); auto probabilityOperatorFormula = std::make_shared(storm::logic::OptimalityType::Minimize, eventuallyFormula); //std::vector result = mc.checkNoBoundOperator(*probFormula); std::unique_ptr result = mc.check(*probabilityOperatorFormula); //ASSERT_LT(std::abs(result[0] - 0.0277777612209320068), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble()); ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 0.0277777612209320068), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); //delete probFormula; probabilityOperatorFormula.reset(); //apFormula = new storm::property::prctl::Ap("two"); apFormula = std::make_shared("two"); //eventuallyFormula = new storm::property::prctl::Eventually(apFormula); eventuallyFormula = std::make_shared(apFormula); //probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator(eventuallyFormula, false); probabilityOperatorFormula = std::make_shared(storm::logic::OptimalityType::Maximize, eventuallyFormula); //result = mc.checkNoBoundOperator(*probFormula); result = mc.check(*probabilityOperatorFormula); //ASSERT_LT(std::abs(result[0] - 0.0277777612209320068), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble()); ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 0.0277777612209320068), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); //delete probFormula; probabilityOperatorFormula.reset(); // ---------------- test ap "three" ---------------- apFormula = std::make_shared("three"); eventuallyFormula = std::make_shared(apFormula); probabilityOperatorFormula = std::make_shared(storm::logic::OptimalityType::Minimize, eventuallyFormula); result = mc.check(*probabilityOperatorFormula); ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 0.0555555224418640136), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); probabilityOperatorFormula.reset(); apFormula = std::make_shared("three"); eventuallyFormula = std::make_shared(apFormula); probabilityOperatorFormula = std::make_shared(storm::logic::OptimalityType::Maximize, eventuallyFormula); result = mc.check(*probabilityOperatorFormula); ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 0.0555555224418640136), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); probabilityOperatorFormula.reset(); // ---------------- test ap "four" ---------------- apFormula = std::make_shared("four"); eventuallyFormula = std::make_shared(apFormula); probabilityOperatorFormula = std::make_shared(storm::logic::OptimalityType::Minimize, eventuallyFormula); result = mc.check(*probabilityOperatorFormula); ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 0.083333283662796020508), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); probabilityOperatorFormula.reset(); apFormula = std::make_shared("four"); eventuallyFormula = std::make_shared(apFormula); probabilityOperatorFormula = std::make_shared(storm::logic::OptimalityType::Maximize, eventuallyFormula); result = mc.check(*probabilityOperatorFormula); ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 0.083333283662796020508), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); probabilityOperatorFormula.reset(); // ---------------- test ap "done" ---------------- apFormula = std::make_shared("done"); auto reachabilityRewardFormula = std::make_shared(apFormula); auto rewardFormula = std::make_shared(storm::logic::OptimalityType::Minimize, reachabilityRewardFormula); result = mc.check(*rewardFormula); #ifdef STORM_HAVE_CUDA ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 7.333329499), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); #else ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 7.33332904), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); #endif rewardFormula.reset(); apFormula = std::make_shared("done"); reachabilityRewardFormula = std::make_shared(apFormula); rewardFormula = std::make_shared(storm::logic::OptimalityType::Maximize, reachabilityRewardFormula); result = mc.check(*rewardFormula); #ifdef STORM_HAVE_CUDA ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 7.333329499), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); #else ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 7.33333151), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); #endif rewardFormula.reset(); // ------------- state rewards -------------- std::shared_ptr> stateRewardMdp = storm::parser::AutoParser::parseModel(STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.tra", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.lab", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.flip.state.rew", "")->as>(); storm::modelchecker::SparseMdpPrctlModelChecker stateRewardModelChecker(*stateRewardMdp, std::unique_ptr>(new storm::utility::solver::TopologicalMinMaxLinearEquationSolverFactory())); apFormula = std::make_shared("done"); reachabilityRewardFormula = std::make_shared(apFormula); rewardFormula = std::make_shared(storm::logic::OptimalityType::Minimize, reachabilityRewardFormula); result = stateRewardModelChecker.check(*rewardFormula); #ifdef STORM_HAVE_CUDA ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 7.333329499), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); #else ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 7.33332904), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); #endif rewardFormula.reset(); apFormula = std::make_shared("done"); reachabilityRewardFormula = std::make_shared(apFormula); rewardFormula = std::make_shared(storm::logic::OptimalityType::Maximize, reachabilityRewardFormula); result = stateRewardModelChecker.check(*rewardFormula); #ifdef STORM_HAVE_CUDA ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 7.333329499), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); #else ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 7.33333151), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); #endif rewardFormula.reset(); // -------------------------------- state and transition reward ------------------------ std::shared_ptr> stateAndTransitionRewardMdp = storm::parser::AutoParser::parseModel(STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.tra", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.lab", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.flip.state.rew", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.flip.trans.rew")->as>(); storm::modelchecker::SparseMdpPrctlModelChecker stateAndTransitionRewardModelChecker(*stateAndTransitionRewardMdp, std::unique_ptr>(new storm::utility::solver::TopologicalMinMaxLinearEquationSolverFactory())); apFormula = std::make_shared("done"); reachabilityRewardFormula = std::make_shared(apFormula); rewardFormula = std::make_shared(storm::logic::OptimalityType::Minimize, reachabilityRewardFormula); result = stateAndTransitionRewardModelChecker.check(*rewardFormula); #ifdef STORM_HAVE_CUDA ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 14.666658998), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); #else ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 14.6666581), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); #endif rewardFormula.reset(); apFormula = std::make_shared("done"); reachabilityRewardFormula = std::make_shared(apFormula); rewardFormula = std::make_shared(storm::logic::OptimalityType::Maximize, reachabilityRewardFormula); result = stateAndTransitionRewardModelChecker.check(*rewardFormula); #ifdef STORM_HAVE_CUDA ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 14.666658998), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); #else ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 14.666663), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); #endif rewardFormula.reset(); } TEST(TopologicalValueIterationMdpPrctlModelCheckerTest, AsynchronousLeader) { std::shared_ptr> mdp = storm::parser::AutoParser::parseModel(STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader4.tra", STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader4.lab", "", STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader4.trans.rew")->as>(); ASSERT_EQ(mdp->getNumberOfStates(), 3172ull); ASSERT_EQ(mdp->getNumberOfTransitions(), 7144ull); storm::modelchecker::SparseMdpPrctlModelChecker mc(*mdp, std::unique_ptr>(new storm::utility::solver::TopologicalMinMaxLinearEquationSolverFactory())); auto apFormula = std::make_shared("elected"); auto eventuallyFormula = std::make_shared(apFormula); auto probabilityOperatorFormula = std::make_shared(storm::logic::OptimalityType::Minimize, eventuallyFormula); std::unique_ptr result = mc.check(*probabilityOperatorFormula); ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 1), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); probabilityOperatorFormula.reset(); apFormula = std::make_shared("elected"); eventuallyFormula = std::make_shared(apFormula); probabilityOperatorFormula = std::make_shared(storm::logic::OptimalityType::Maximize, eventuallyFormula); result = mc.check(*probabilityOperatorFormula); ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 1), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); probabilityOperatorFormula.reset(); apFormula = std::make_shared("elected"); auto boundedEventuallyFormula = std::make_shared(std::make_shared(true), apFormula, 25); probabilityOperatorFormula = std::make_shared(storm::logic::OptimalityType::Maximize, boundedEventuallyFormula); result = mc.check(*probabilityOperatorFormula); ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 0.0625), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); probabilityOperatorFormula.reset(); apFormula = std::make_shared("elected"); boundedEventuallyFormula = std::make_shared(std::make_shared(true), apFormula, 25); probabilityOperatorFormula = std::make_shared(storm::logic::OptimalityType::Minimize, boundedEventuallyFormula); result = mc.check(*probabilityOperatorFormula); ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 0.0625), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); probabilityOperatorFormula.reset(); apFormula = std::make_shared("elected"); auto reachabilityRewardFormula = std::make_shared(apFormula); auto rewardFormula = std::make_shared(storm::logic::OptimalityType::Minimize, reachabilityRewardFormula); result = mc.check(*rewardFormula); #ifdef STORM_HAVE_CUDA ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 4.285689611), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); #else ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 4.285701547), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); #endif probabilityOperatorFormula.reset(); apFormula = std::make_shared("elected"); reachabilityRewardFormula = std::make_shared(apFormula); rewardFormula = std::make_shared(storm::logic::OptimalityType::Maximize, reachabilityRewardFormula); result = mc.check(*rewardFormula); #ifdef STORM_HAVE_CUDA ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 4.285689611), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); #else ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult()[0] - 4.285703591), storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision()); #endif probabilityOperatorFormula.reset(); }