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.

152 lines
8.2 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.bounded = false;
  31. options.type = storm::storage::BisimulationType::Weak;
  32. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>> bisim3(*dtmc, options);
  33. ASSERT_NO_THROW(bisim3.computeBisimulationDecomposition());
  34. ASSERT_NO_THROW(result = bisim3.getQuotient());
  35. EXPECT_EQ(storm::models::ModelType::Dtmc, result->getType());
  36. EXPECT_EQ(5ul, result->getNumberOfStates());
  37. EXPECT_EQ(8ul, result->getNumberOfTransitions());
  38. auto labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("one");
  39. auto eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  40. #ifdef WINDOWS
  41. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options2(*dtmc, *eventuallyFormula);
  42. #else
  43. typename storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options2(*dtmc, *eventuallyFormula);
  44. #endif
  45. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>> bisim4(*dtmc, options2);
  46. ASSERT_NO_THROW(bisim4.computeBisimulationDecomposition());
  47. ASSERT_NO_THROW(result = bisim4.getQuotient());
  48. EXPECT_EQ(storm::models::ModelType::Dtmc, result->getType());
  49. EXPECT_EQ(5ul, result->getNumberOfStates());
  50. EXPECT_EQ(8ul, result->getNumberOfTransitions());
  51. }
  52. TEST(DeterministicModelBisimulationDecomposition, Crowds) {
  53. 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", "", "");
  54. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Dtmc);
  55. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc = abstractModel->as<storm::models::sparse::Dtmc<double>>();
  56. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>> bisim(*dtmc);
  57. std::shared_ptr<storm::models::sparse::Model<double>> result;
  58. ASSERT_NO_THROW(bisim.computeBisimulationDecomposition());
  59. ASSERT_NO_THROW(result = bisim.getQuotient());
  60. EXPECT_EQ(storm::models::ModelType::Dtmc, result->getType());
  61. EXPECT_EQ(334ul, result->getNumberOfStates());
  62. EXPECT_EQ(546ul, result->getNumberOfTransitions());
  63. #ifdef WINDOWS
  64. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options;
  65. #else
  66. typename storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options;
  67. #endif
  68. options.respectedAtomicPropositions = std::set<std::string>({"observe0Greater1"});
  69. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>> bisim2(*dtmc, options);
  70. ASSERT_NO_THROW(bisim2.computeBisimulationDecomposition());
  71. ASSERT_NO_THROW(result = bisim2.getQuotient());
  72. EXPECT_EQ(storm::models::ModelType::Dtmc, result->getType());
  73. EXPECT_EQ(65ul, result->getNumberOfStates());
  74. EXPECT_EQ(105ul, result->getNumberOfTransitions());
  75. options.bounded = false;
  76. options.type = storm::storage::BisimulationType::Weak;
  77. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>> bisim3(*dtmc, options);
  78. ASSERT_NO_THROW(bisim3.computeBisimulationDecomposition());
  79. ASSERT_NO_THROW(result = bisim3.getQuotient());
  80. EXPECT_EQ(storm::models::ModelType::Dtmc, result->getType());
  81. EXPECT_EQ(43ul, result->getNumberOfStates());
  82. EXPECT_EQ(83ul, result->getNumberOfTransitions());
  83. auto labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("observe0Greater1");
  84. auto eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  85. #ifdef WINDOWS
  86. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options2(*dtmc, *eventuallyFormula);
  87. #else
  88. typename storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options2(*dtmc, *eventuallyFormula);
  89. #endif
  90. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>> bisim4(*dtmc, options2);
  91. ASSERT_NO_THROW(bisim4.computeBisimulationDecomposition());
  92. ASSERT_NO_THROW(result = bisim4.getQuotient());
  93. EXPECT_EQ(storm::models::ModelType::Dtmc, result->getType());
  94. EXPECT_EQ(64ul, result->getNumberOfStates());
  95. EXPECT_EQ(104ul, result->getNumberOfTransitions());
  96. auto probabilityOperatorFormula = std::make_shared<storm::logic::ProbabilityOperatorFormula>(eventuallyFormula);
  97. #ifdef WINDOWS
  98. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options3(*dtmc, *probabilityOperatorFormula);
  99. #else
  100. typename storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options3(*dtmc, *probabilityOperatorFormula);
  101. #endif
  102. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>> bisim5(*dtmc, options3);
  103. ASSERT_NO_THROW(bisim5.computeBisimulationDecomposition());
  104. ASSERT_NO_THROW(result = bisim5.getQuotient());
  105. EXPECT_EQ(storm::models::ModelType::Dtmc, result->getType());
  106. EXPECT_EQ(64ul, result->getNumberOfStates());
  107. EXPECT_EQ(104ul, result->getNumberOfTransitions());
  108. auto boundedUntilFormula = std::make_shared<storm::logic::BoundedUntilFormula>(std::make_shared<storm::logic::BooleanLiteralFormula>(true), labelFormula, 50);
  109. #ifdef WINDOWS
  110. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options4(*dtmc, *boundedUntilFormula);
  111. #else
  112. typename storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>>::Options options4(*dtmc, *boundedUntilFormula);
  113. #endif
  114. storm::storage::DeterministicModelBisimulationDecomposition<storm::models::sparse::Dtmc<double>> bisim6(*dtmc, options4);
  115. ASSERT_NO_THROW(bisim6.computeBisimulationDecomposition());
  116. ASSERT_NO_THROW(result = bisim6.getQuotient());
  117. EXPECT_EQ(storm::models::ModelType::Dtmc, result->getType());
  118. EXPECT_EQ(65ul, result->getNumberOfStates());
  119. EXPECT_EQ(105ul, result->getNumberOfTransitions());
  120. }