Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
GoalStateMergerTest.cpp
Go to the documentation of this file.
1#include <cmath>
2
3#include "storm-config.h"
4#include "test/storm_gtest.h"
5
8#include "storm/api/builder.h"
13
14namespace {
15
16class GoalStateMergerTest : public ::testing::Test {
17 protected:
18 void SetUp() override {
19#ifndef STORM_HAVE_Z3
20 GTEST_SKIP() << "Z3 not available.";
21#endif
22 }
23};
24
25void testGoalStateMerger(std::string const& prismModelFile, std::string const& formulaString) {
26 storm::prism::Program program = storm::parser::PrismParser::parse(prismModelFile, true);
28 auto model = storm::api::buildSparseModel<double>(program, formulas);
29 auto task = storm::api::createTask<double>(formulas.front(), false);
30 ASSERT_EQ(1ull, model->getInitialStates().getNumberOfSetBits()) << "For model " << prismModelFile << ".";
31
32 auto computeValue = [&task](auto const& m) {
33 auto result = storm::api::verifyWithSparseEngine(m, task);
34 return result->template asExplicitQuantitativeCheckResult<double>()[*m->getInitialStates().begin()];
35 };
36 auto const modelVal = computeValue(model);
37
39 for (bool dropUnreachableFromInit : {true, false}) {
40 auto mergerResult = merger.mergeForFormula(*formulas.front(), dropUnreachableFromInit);
41 ASSERT_TRUE(mergerResult.has_value()) << "Merging goal states failed for model " << prismModelFile << " and formula " << *formulas.front()
42 << " (dropUnreachableFromInit=" << dropUnreachableFromInit << ").";
43 ASSERT_EQ(1ull, mergerResult->model->getInitialStates().getNumberOfSetBits())
44 << "For merged model of " << prismModelFile << " (dropUnreachableFromInit=" << dropUnreachableFromInit << ").";
45
46 // The original (unmodified) formula must still be valid on the merged model and induce the same value at the initial state.
47 auto const mergedVal = computeValue(mergerResult->model);
48 bool const relativeDifferenceOk = std::abs(mergedVal - modelVal) <= 1e-6 * std::abs(modelVal);
49 EXPECT_TRUE(relativeDifferenceOk) << "Relative difference between original model result (" << modelVal << ") and merged model result (" << mergedVal
50 << ") is too high.\nFailed for model " << prismModelFile << " and formula " << *formulas.front()
51 << " (dropUnreachableFromInit=" << dropUnreachableFromInit << ").";
52 }
53}
54
55TEST_F(GoalStateMergerTest, BrpUntilTest) {
56 testGoalStateMerger(STORM_TEST_RESOURCES_DIR "/dtmc/brp-16-2.pm", "P=? [ true U \"target\"]");
57}
58
59TEST_F(GoalStateMergerTest, BrpBoundedUntilTest) {
60 testGoalStateMerger(STORM_TEST_RESOURCES_DIR "/dtmc/brp-16-2.pm", "P=? [ true U<=100 \"target\"]");
61}
62
63TEST_F(GoalStateMergerTest, DieUntilTest) {
64 testGoalStateMerger(STORM_TEST_RESOURCES_DIR "/dtmc/die.pm", "P=? [ !\"done\" U \"one\"]");
65}
66
67TEST_F(GoalStateMergerTest, LeaderUntilTest) {
68 testGoalStateMerger(STORM_TEST_RESOURCES_DIR "/dtmc/leader-3-5.pm", "P=? [ true U \"elected\"]");
69}
70
71TEST_F(GoalStateMergerTest, CrowdsUntilTest) {
72 testGoalStateMerger(STORM_TEST_RESOURCES_DIR "/dtmc/crowds-4-3.pm", "P=? [ true U \"observeIGreater1\"]");
73}
74
75TEST_F(GoalStateMergerTest, LeaderBoundedUntilTest) {
76 testGoalStateMerger(STORM_TEST_RESOURCES_DIR "/dtmc/leader-3-5.pm", "P=? [F<=5 \"elected\"]");
77}
78
79TEST_F(GoalStateMergerTest, DieReachabilityRewardTest) {
80 testGoalStateMerger(STORM_TEST_RESOURCES_DIR "/dtmc/die.pm", "R=? [F \"done\"]");
81}
82
83TEST_F(GoalStateMergerTest, TwoDiceUntilMinTest) {
84 testGoalStateMerger(STORM_TEST_RESOURCES_DIR "/mdp/two_dice.nm", "Pmin=? [ true U \"two\"]");
85}
86
87TEST_F(GoalStateMergerTest, TwoDiceUntilMaxTest) {
88 testGoalStateMerger(STORM_TEST_RESOURCES_DIR "/mdp/two_dice.nm", "Pmax=? [ true U \"two\"]");
89}
90
91TEST_F(GoalStateMergerTest, LeaderMdpBoundedUntilMinTest) {
92 testGoalStateMerger(STORM_TEST_RESOURCES_DIR "/mdp/leader4.nm", "Pmin=? [F<=25 \"elected\"]");
93}
94
95TEST_F(GoalStateMergerTest, LeaderMdpBoundedUntilMaxTest) {
96 testGoalStateMerger(STORM_TEST_RESOURCES_DIR "/mdp/leader4.nm", "Pmax=? [F<=25 \"elected\"]");
97}
98
99TEST_F(GoalStateMergerTest, ChainBoundedUntilTest) {
100 testGoalStateMerger(STORM_TEST_RESOURCES_DIR "/mdp/chain.nm", "Pmax=? [ x<3 U<=4 x=5]");
101}
102
103TEST_F(GoalStateMergerTest, TinyRewardsCumulativeRewardTest) {
104 testGoalStateMerger(STORM_TEST_RESOURCES_DIR "/mdp/tiny_rewards.nm", "Rmax=? [C<=2]");
105}
106
107TEST_F(GoalStateMergerTest, Coin22ReachabilityRewardTest) {
108 testGoalStateMerger(STORM_TEST_RESOURCES_DIR "/mdp/coin2-2.nm", "Rmax=? [ F \"finished\"]");
109}
110
111TEST_F(GoalStateMergerTest, TandemReachabilityRewardTest) {
112 testGoalStateMerger(STORM_TEST_RESOURCES_DIR "/ctmc/tandem5.sm", "R=? [F \"first_queue_full\"&\"second_queue_full\"]");
113}
114
115TEST_F(GoalStateMergerTest, ClusterCumulativeRewardTest) {
116 testGoalStateMerger(STORM_TEST_RESOURCES_DIR "/ctmc/cluster2.sm", "R{\"num_repairs\"}=? [C<=200]");
117}
118
119TEST_F(GoalStateMergerTest, StreamReachabilityRewardTest) {
120 testGoalStateMerger(STORM_TEST_RESOURCES_DIR "/ma/stream2.ma", "R{\"buffering\"}max=? [ F \"done\"]");
121}
122
123} // namespace
TEST_F(AssumptionCheckerTest, Brp_no_bisimulation)
static storm::prism::Program parse(std::string const &filename, bool prismCompatability=false)
Parses the given file into the PRISM storage classes assuming it complies with the PRISM syntax.
storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > createTask(std::shared_ptr< const storm::logic::Formula > const &formula, bool onlyInitialStatesRelevant=false)
std::vector< storm::jani::Property > parsePropertiesForPrismProgram(std::string const &inputString, storm::prism::Program const &program, boost::optional< std::set< std::string > > const &propertyFilter)
std::shared_ptr< storm::models::sparse::Model< ValueType > > buildSparseModel(storm::storage::SymbolicModelDescription const &model, storm::builder::BuilderOptions const &options, typename storm::builder::ExplicitModelBuilder< ValueType >::Options const &explorationOptions=typename storm::builder::ExplicitModelBuilder< ValueType >::Options())
Definition builder.h:117
std::vector< std::shared_ptr< storm::logic::Formula const > > extractFormulasFromProperties(std::vector< storm::jani::Property > const &properties)
std::unique_ptr< storm::modelchecker::CheckResult > verifyWithSparseEngine(storm::Environment const &env, std::shared_ptr< storm::models::sparse::Dtmc< ValueType > > const &dtmc, storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > const &task, bool preferEliminationChecker=false)