#include "gtest/gtest.h" #include "storm-config.h" #include "src/settings/Settings.h" #include "src/modelchecker/prctl/SparseMdpPrctlModelChecker.h" #include "src/solver/AbstractNondeterministicLinearEquationSolver.h" #include "src/parser/AutoParser.h" TEST(SparseMdpPrctlModelCheckerTest, AsynchronousLeader) { storm::settings::Settings* s = storm::settings::Settings::getInstance(); storm::parser::AutoParser parser(STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader7.tra", STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader7.lab", "", STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader7.trans.rew"); ASSERT_EQ(parser.getType(), storm::models::MDP); std::shared_ptr> mdp = parser.getModel>(); ASSERT_EQ(mdp->getNumberOfStates(), 2095783u); ASSERT_EQ(mdp->getNumberOfTransitions(), 7714385u); storm::modelchecker::prctl::SparseMdpPrctlModelChecker mc(*mdp, new storm::solver::AbstractNondeterministicLinearEquationSolver()); storm::property::prctl::Ap* apFormula = new storm::property::prctl::Ap("elected"); storm::property::prctl::Eventually* eventuallyFormula = new storm::property::prctl::Eventually(apFormula); storm::property::prctl::ProbabilisticNoBoundOperator* probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator(eventuallyFormula, true); LOG4CPLUS_WARN(logger, "Model Checking Pmin=? [F elected] on asynchronous_leader/leader7..."); std::vector* result = mc.checkNoBoundOperator(*probFormula); LOG4CPLUS_WARN(logger, "Done."); ASSERT_NE(nullptr, result); ASSERT_LT(std::abs((*result)[0] - 1), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble()); delete probFormula; delete result; apFormula = new storm::property::prctl::Ap("elected"); eventuallyFormula = new storm::property::prctl::Eventually(apFormula); probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator(eventuallyFormula, false); LOG4CPLUS_WARN(logger, "Model Checking Pmax=? [F elected] on asynchronous_leader/leader7..."); result = mc.checkNoBoundOperator(*probFormula); LOG4CPLUS_WARN(logger, "Done."); ASSERT_NE(nullptr, result); ASSERT_LT(std::abs((*result)[0] - 1), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble()); delete probFormula; delete result; apFormula = new storm::property::prctl::Ap("elected"); storm::property::prctl::BoundedEventually* boundedEventuallyFormula = new storm::property::prctl::BoundedEventually(apFormula, 25); probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator(boundedEventuallyFormula, true); LOG4CPLUS_WARN(logger, "Model Checking Pmin=? [F<=25 elected] on asynchronous_leader/leader7..."); result = mc.checkNoBoundOperator(*probFormula); LOG4CPLUS_WARN(logger, "Done."); ASSERT_NE(nullptr, result); ASSERT_LT(std::abs((*result)[0] - 0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble()); delete probFormula; delete result; apFormula = new storm::property::prctl::Ap("elected"); boundedEventuallyFormula = new storm::property::prctl::BoundedEventually(apFormula, 25); probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator(boundedEventuallyFormula, false); LOG4CPLUS_WARN(logger, "Model Checking Pmax=? [F<=25 elected] on asynchronous_leader/leader7..."); result = mc.checkNoBoundOperator(*probFormula); LOG4CPLUS_WARN(logger, "Done."); ASSERT_NE(nullptr, result); ASSERT_LT(std::abs((*result)[0] - 0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble()); delete probFormula; delete result; apFormula = new storm::property::prctl::Ap("elected"); storm::property::prctl::ReachabilityReward* reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward(apFormula); storm::property::prctl::RewardNoBoundOperator* rewardFormula = new storm::property::prctl::RewardNoBoundOperator(reachabilityRewardFormula, true); LOG4CPLUS_WARN(logger, "Model Checking Rmin=? [F elected] on asynchronous_leader/leader7..."); result = mc.checkNoBoundOperator(*rewardFormula); LOG4CPLUS_WARN(logger, "Done."); ASSERT_LT(std::abs((*result)[0] - 6.172433512), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble()); delete rewardFormula; delete result; apFormula = new storm::property::prctl::Ap("elected"); reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward(apFormula); rewardFormula = new storm::property::prctl::RewardNoBoundOperator(reachabilityRewardFormula, false); LOG4CPLUS_WARN(logger, "Model Checking Rmax=? [F elected] on asynchronous_leader/leader7..."); result = mc.checkNoBoundOperator(*rewardFormula); LOG4CPLUS_WARN(logger, "Done"); ASSERT_NE(nullptr, result); ASSERT_LT(std::abs((*result)[0] - 6.1724344), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble()); delete rewardFormula; delete result; } TEST(SparseMdpPrctlModelCheckerTest, Consensus) { storm::settings::Settings* s = storm::settings::Settings::getInstance(); // Increase the maximal number of iterations, because the solver does not converge otherwise. // This is done in the main cpp unit storm::parser::AutoParser parser(STORM_CPP_BASE_PATH "/examples/mdp/consensus/coin4_6.tra", STORM_CPP_BASE_PATH "/examples/mdp/consensus/coin4_6.lab", STORM_CPP_BASE_PATH "/examples/mdp/consensus/coin4_6.steps.state.rew", ""); ASSERT_EQ(parser.getType(), storm::models::MDP); std::shared_ptr> mdp = parser.getModel>(); ASSERT_EQ(mdp->getNumberOfStates(), 63616u); ASSERT_EQ(mdp->getNumberOfTransitions(), 213472u); storm::modelchecker::prctl::SparseMdpPrctlModelChecker mc(*mdp, new storm::solver::AbstractNondeterministicLinearEquationSolver()); storm::property::prctl::Ap* apFormula = new storm::property::prctl::Ap("finished"); storm::property::prctl::Eventually* eventuallyFormula = new storm::property::prctl::Eventually(apFormula); storm::property::prctl::ProbabilisticNoBoundOperator* probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator(eventuallyFormula, true); LOG4CPLUS_WARN(logger, "Model Checking Pmin=? [F finished] on consensus/coin4_6..."); std::vector* result = mc.checkNoBoundOperator(*probFormula); LOG4CPLUS_WARN(logger, "Done."); ASSERT_NE(nullptr, result); ASSERT_LT(std::abs((*result)[31168] - 1), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble()); delete probFormula; delete result; apFormula = new storm::property::prctl::Ap("finished"); storm::property::prctl::Ap* apFormula2 = new storm::property::prctl::Ap("all_coins_equal_0"); storm::property::prctl::And* andFormula = new storm::property::prctl::And(apFormula, apFormula2); eventuallyFormula = new storm::property::prctl::Eventually(andFormula); probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator(eventuallyFormula, true); LOG4CPLUS_WARN(logger, "Model Checking Pmin=? [F finished & all_coins_equal_0] on consensus/coin4_6..."); result = mc.checkNoBoundOperator(*probFormula); LOG4CPLUS_WARN(logger, "Done."); ASSERT_NE(nullptr, result); ASSERT_LT(std::abs((*result)[31168] - 0.43742828319177884388579), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble()); delete probFormula; delete result; apFormula = new storm::property::prctl::Ap("finished"); apFormula2 = new storm::property::prctl::Ap("all_coins_equal_1"); andFormula = new storm::property::prctl::And(apFormula, apFormula2); eventuallyFormula = new storm::property::prctl::Eventually(andFormula); probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator(eventuallyFormula, false); LOG4CPLUS_WARN(logger, "Model Checking Pmax=? [F finished & all_coins_equal_1] on consensus/coin4_6..."); result = mc.checkNoBoundOperator(*probFormula); LOG4CPLUS_WARN(logger, "Done."); ASSERT_NE(nullptr, result); ASSERT_LT(std::abs((*result)[31168] - 0.52932863686144482340267813924583606421947479248047), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble()); delete probFormula; delete result; apFormula = new storm::property::prctl::Ap("finished"); apFormula2 = new storm::property::prctl::Ap("agree"); storm::property::prctl::Not* notFormula = new storm::property::prctl::Not(apFormula2); andFormula = new storm::property::prctl::And(apFormula, notFormula); eventuallyFormula = new storm::property::prctl::Eventually(andFormula); probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator(eventuallyFormula, false); LOG4CPLUS_WARN(logger, "Model Checking Pmax=? [F finished & !agree] on consensus/coin4_6..."); result = mc.checkNoBoundOperator(*probFormula); LOG4CPLUS_WARN(logger, "Done."); ASSERT_NE(nullptr, result); ASSERT_LT(std::abs((*result)[31168] - 0.1041409700076474653673841), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble()); delete probFormula; delete result; apFormula = new storm::property::prctl::Ap("finished"); storm::property::prctl::BoundedEventually* boundedEventuallyFormula = new storm::property::prctl::BoundedEventually(apFormula, 50); probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator(boundedEventuallyFormula, true); LOG4CPLUS_WARN(logger, "Model Checking Pmin=? [F<=50 finished] on consensus/coin4_6..."); result = mc.checkNoBoundOperator(*probFormula); LOG4CPLUS_WARN(logger, "Done."); ASSERT_NE(nullptr, result); ASSERT_LT(std::abs((*result)[31168] - 0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble()); delete probFormula; delete result; apFormula = new storm::property::prctl::Ap("finished"); boundedEventuallyFormula = new storm::property::prctl::BoundedEventually(apFormula, 50); probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator(boundedEventuallyFormula, false); LOG4CPLUS_WARN(logger, "Model Checking Pmax=? [F<=50 finished] on consensus/coin4_6..."); result = mc.checkNoBoundOperator(*probFormula); LOG4CPLUS_WARN(logger, "Done."); ASSERT_NE(nullptr, result); ASSERT_LT(std::abs((*result)[31168] - 0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble()); delete probFormula; delete result; apFormula = new storm::property::prctl::Ap("finished"); storm::property::prctl::ReachabilityReward* reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward(apFormula); storm::property::prctl::RewardNoBoundOperator* rewardFormula = new storm::property::prctl::RewardNoBoundOperator(reachabilityRewardFormula, true); LOG4CPLUS_WARN(logger, "Model Checking Rmin=? [F finished] on consensus/coin4_6..."); result = mc.checkNoBoundOperator(*rewardFormula); LOG4CPLUS_WARN(logger, "Done."); ASSERT_NE(nullptr, result); ASSERT_LT(std::abs((*result)[31168] - 1725.5933133943854045), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble()); delete rewardFormula; delete result; apFormula = new storm::property::prctl::Ap("finished"); reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward(apFormula); rewardFormula = new storm::property::prctl::RewardNoBoundOperator(reachabilityRewardFormula, false); LOG4CPLUS_WARN(logger, "Model Checking Rmax=? [F finished] on consensus/coin4_6..."); result = mc.checkNoBoundOperator(*rewardFormula); LOG4CPLUS_WARN(logger, "Done."); ASSERT_NE(nullptr, result); ASSERT_LT(std::abs((*result)[31168] - 2183.1424220082612919213715), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble()); delete rewardFormula; delete result; }