You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
8.1 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/parser/AutoParser.h"
  4. #include "src/storage/bisimulation/DeterministicModelBisimulationDecomposition.h"
  5. #include "src/models/sparse/Dtmc.h"
  6. #include "src/models/sparse/StandardRewardModel.h"
  7. TEST(DeterministicModelBisimulationDecomposition, Die) {
  8. std::shared_ptr<storm::models::sparse::Model<double>> abstractModel = storm::parser::AutoParser<>::parseModel(STORM_CPP_BASE_PATH "/examples/dtmc/die/die.tra", STORM_CPP_BASE_PATH "/examples/dtmc/die/die.lab", "", "");
  9. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Dtmc);
  10. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc = abstractModel->as<storm::models::sparse::Dtmc<double>>();
  11. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>> bisim(*dtmc);
  12. ASSERT_NO_THROW(bisim.computeBisimulationDecomposition());
  13. std::shared_ptr<storm::models::sparse::Model<double>> result;
  14. ASSERT_NO_THROW(result = bisim.getQuotient());
  15. EXPECT_EQ(storm::models::ModelType::Dtmc, result->getType());
  16. EXPECT_EQ(13ul, result->getNumberOfStates());
  17. EXPECT_EQ(20ul, result->getNumberOfTransitions());
  18. #ifdef WINDOWS
  19. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options;
  20. #else
  21. typename storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options;
  22. #endif
  23. options.respectedAtomicPropositions = std::set<std::string>({"one"});
  24. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>> bisim2(*dtmc, options);
  25. ASSERT_NO_THROW(bisim2.computeBisimulationDecomposition());
  26. ASSERT_NO_THROW(result = bisim2.getQuotient());
  27. EXPECT_EQ(storm::models::ModelType::Dtmc, result->getType());
  28. EXPECT_EQ(5ul, result->getNumberOfStates());
  29. EXPECT_EQ(8ul, result->getNumberOfTransitions());
  30. options.setType(storm::storage::BisimulationType::Weak);
  31. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>> bisim3(*dtmc, options);
  32. ASSERT_NO_THROW(bisim3.computeBisimulationDecomposition());
  33. ASSERT_NO_THROW(result = bisim3.getQuotient());
  34. EXPECT_EQ(storm::models::ModelType::Dtmc, result->getType());
  35. EXPECT_EQ(5ul, result->getNumberOfStates());
  36. EXPECT_EQ(8ul, result->getNumberOfTransitions());
  37. auto labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("one");
  38. auto eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  39. #ifdef WINDOWS
  40. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options2(*dtmc, *eventuallyFormula);
  41. #else
  42. typename storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options2(*dtmc, *eventuallyFormula);
  43. #endif
  44. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>> bisim4(*dtmc, options2);
  45. ASSERT_NO_THROW(bisim4.computeBisimulationDecomposition());
  46. ASSERT_NO_THROW(result = bisim4.getQuotient());
  47. EXPECT_EQ(storm::models::ModelType::Dtmc, result->getType());
  48. EXPECT_EQ(5ul, result->getNumberOfStates());
  49. EXPECT_EQ(8ul, result->getNumberOfTransitions());
  50. }
  51. TEST(DeterministicModelBisimulationDecomposition, Crowds) {
  52. std::shared_ptr<storm::models::sparse::Model<double>> abstractModel = storm::parser::AutoParser<>::parseModel(STORM_CPP_BASE_PATH "/examples/dtmc/crowds/crowds5_5.tra", STORM_CPP_BASE_PATH "/examples/dtmc/crowds/crowds5_5.lab", "", "");
  53. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Dtmc);
  54. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc = abstractModel->as<storm::models::sparse::Dtmc<double>>();
  55. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>> bisim(*dtmc);
  56. std::shared_ptr<storm::models::sparse::Model<double>> result;
  57. ASSERT_NO_THROW(bisim.computeBisimulationDecomposition());
  58. ASSERT_NO_THROW(result = bisim.getQuotient());
  59. EXPECT_EQ(storm::models::ModelType::Dtmc, result->getType());
  60. EXPECT_EQ(334ul, result->getNumberOfStates());
  61. EXPECT_EQ(546ul, result->getNumberOfTransitions());
  62. #ifdef WINDOWS
  63. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options;
  64. #else
  65. typename storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options;
  66. #endif
  67. options.respectedAtomicPropositions = std::set<std::string>({"observe0Greater1"});
  68. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>> bisim2(*dtmc, options);
  69. ASSERT_NO_THROW(bisim2.computeBisimulationDecomposition());
  70. ASSERT_NO_THROW(result = bisim2.getQuotient());
  71. EXPECT_EQ(storm::models::ModelType::Dtmc, result->getType());
  72. EXPECT_EQ(65ul, result->getNumberOfStates());
  73. EXPECT_EQ(105ul, result->getNumberOfTransitions());
  74. options.setType(storm::storage::BisimulationType::Weak);
  75. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>> bisim3(*dtmc, options);
  76. ASSERT_NO_THROW(bisim3.computeBisimulationDecomposition());
  77. ASSERT_NO_THROW(result = bisim3.getQuotient());
  78. EXPECT_EQ(storm::models::ModelType::Dtmc, result->getType());
  79. EXPECT_EQ(43ul, result->getNumberOfStates());
  80. EXPECT_EQ(83ul, result->getNumberOfTransitions());
  81. auto labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("observe0Greater1");
  82. auto eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  83. #ifdef WINDOWS
  84. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options2(*dtmc, *eventuallyFormula);
  85. #else
  86. typename storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options2(*dtmc, *eventuallyFormula);
  87. #endif
  88. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>> bisim4(*dtmc, options2);
  89. ASSERT_NO_THROW(bisim4.computeBisimulationDecomposition());
  90. ASSERT_NO_THROW(result = bisim4.getQuotient());
  91. EXPECT_EQ(storm::models::ModelType::Dtmc, result->getType());
  92. EXPECT_EQ(64ul, result->getNumberOfStates());
  93. EXPECT_EQ(104ul, result->getNumberOfTransitions());
  94. auto probabilityOperatorFormula = std::make_shared<storm::logic::ProbabilityOperatorFormula>(eventuallyFormula);
  95. #ifdef WINDOWS
  96. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options3(*dtmc, *probabilityOperatorFormula);
  97. #else
  98. typename storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options3(*dtmc, *probabilityOperatorFormula);
  99. #endif
  100. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>> bisim5(*dtmc, options3);
  101. ASSERT_NO_THROW(bisim5.computeBisimulationDecomposition());
  102. ASSERT_NO_THROW(result = bisim5.getQuotient());
  103. EXPECT_EQ(storm::models::ModelType::Dtmc, result->getType());
  104. EXPECT_EQ(64ul, result->getNumberOfStates());
  105. EXPECT_EQ(104ul, result->getNumberOfTransitions());
  106. auto boundedUntilFormula = std::make_shared<storm::logic::BoundedUntilFormula>(std::make_shared<storm::logic::BooleanLiteralFormula>(true), labelFormula, 50);
  107. #ifdef WINDOWS
  108. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options4(*dtmc, *boundedUntilFormula);
  109. #else
  110. typename storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options4(*dtmc, *boundedUntilFormula);
  111. #endif
  112. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>> bisim6(*dtmc, options4);
  113. ASSERT_NO_THROW(bisim6.computeBisimulationDecomposition());
  114. ASSERT_NO_THROW(result = bisim6.getQuotient());
  115. EXPECT_EQ(storm::models::ModelType::Dtmc, result->getType());
  116. EXPECT_EQ(65ul, result->getNumberOfStates());
  117. EXPECT_EQ(105ul, result->getNumberOfTransitions());
  118. }