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.

131 lines
6.3 KiB

  1. import stormpy
  2. import stormpy.logic
  3. from helpers.helper import get_example_path
  4. import math
  5. class TestTransformation:
  6. def test_transform_symbolic_dtmc_to_sparse(self):
  7. program = stormpy.parse_prism_program(get_example_path("dtmc", "crowds5_5.pm"))
  8. symbolic_model = stormpy.build_symbolic_model(program)
  9. assert symbolic_model.nr_states == 8607
  10. assert symbolic_model.nr_transitions == 15113
  11. assert symbolic_model.model_type == stormpy.ModelType.DTMC
  12. assert not symbolic_model.supports_parameters
  13. assert type(symbolic_model) is stormpy.SymbolicSylvanDtmc
  14. sparse_model = stormpy.transform_to_sparse_model(symbolic_model)
  15. assert sparse_model.nr_states == 8607
  16. assert sparse_model.nr_transitions == 15113
  17. assert sparse_model.model_type == stormpy.ModelType.DTMC
  18. assert not sparse_model.supports_parameters
  19. assert type(sparse_model) is stormpy.SparseDtmc
  20. def test_transform_symbolic_parametric_dtmc_to_sparse(self):
  21. program = stormpy.parse_prism_program(get_example_path("pdtmc", "parametric_die.pm"))
  22. model = stormpy.build_symbolic_parametric_model(program)
  23. assert model.nr_states == 13
  24. assert model.nr_transitions == 20
  25. assert model.model_type == stormpy.ModelType.DTMC
  26. assert model.supports_parameters
  27. assert type(model) is stormpy.SymbolicSylvanParametricDtmc
  28. symbolic_model = stormpy.transform_to_sparse_model(model)
  29. assert symbolic_model.nr_states == 13
  30. assert symbolic_model.nr_transitions == 20
  31. assert symbolic_model.model_type == stormpy.ModelType.DTMC
  32. assert symbolic_model.supports_parameters
  33. assert type(symbolic_model) is stormpy.SparseParametricDtmc
  34. def test_transform_continuous_to_discrete_time_model_ctmc(self):
  35. ctmc = stormpy.build_model_from_drn(get_example_path("ctmc", "dft.drn"))
  36. formulas = stormpy.parse_properties("T=? [ F \"failed\" ]")
  37. assert ctmc.nr_states == 16
  38. assert ctmc.nr_transitions == 33
  39. assert len(ctmc.initial_states) == 1
  40. initial_state = ctmc.initial_states[0]
  41. assert initial_state == 1
  42. result = stormpy.model_checking(ctmc, formulas[0])
  43. assert math.isclose(result.at(initial_state), 4.166666667)
  44. dtmc, dtmc_formulas = stormpy.transform_to_discrete_time_model(ctmc, formulas)
  45. assert dtmc.nr_states == 16
  46. assert dtmc.nr_transitions == 33
  47. assert len(dtmc.initial_states) == 1
  48. initial_state = dtmc.initial_states[0]
  49. assert initial_state == 1
  50. result = stormpy.model_checking(dtmc, dtmc_formulas[0])
  51. assert math.isclose(result.at(initial_state), 4.166666667)
  52. def test_transform_continuous_to_discrete_time_model_ma(self):
  53. program = stormpy.parse_prism_program(get_example_path("ma", "simple.ma"), False, True)
  54. formulas = stormpy.parse_properties_for_prism_program("Tmin=? [ F s=4 ]", program)
  55. ma = stormpy.build_model(program, formulas)
  56. assert ma.nr_states == 5
  57. assert ma.nr_transitions == 8
  58. assert ma.model_type == stormpy.ModelType.MA
  59. assert len(ma.initial_states) == 1
  60. initial_state = ma.initial_states[0]
  61. assert initial_state == 0
  62. result = stormpy.model_checking(ma, formulas[0])
  63. assert math.isclose(result.at(initial_state), 0.08333333333)
  64. mdp, mdp_formulas = stormpy.transform_to_discrete_time_model(ma, formulas)
  65. assert mdp.nr_states == 5
  66. assert mdp.nr_transitions == 8
  67. assert mdp.model_type == stormpy.ModelType.MDP
  68. assert len(mdp.initial_states) == 1
  69. initial_state = mdp.initial_states[0]
  70. assert initial_state == 0
  71. result = stormpy.model_checking(mdp, mdp_formulas[0])
  72. assert math.isclose(result.at(initial_state), 0.08333333333)
  73. def test_eliminate_non_markovian_chains(self):
  74. program = stormpy.parse_prism_program(get_example_path("ma", "stream2.ma"), False, True)
  75. formulas = stormpy.parse_properties_for_prism_program("Pmin=? [ F \"done\"];Tmin=? [ F \"done\" ]", program)
  76. ma = stormpy.build_model(program, formulas)
  77. assert ma.nr_states == 12
  78. assert ma.nr_transitions == 14
  79. assert ma.model_type == stormpy.ModelType.MA
  80. assert len(ma.initial_states) == 1
  81. initial_state = ma.initial_states[0]
  82. assert initial_state == 0
  83. assert len(formulas) == 2
  84. result = stormpy.model_checking(ma, formulas[0])
  85. assert math.isclose(result.at(initial_state), 1)
  86. # Keep labels
  87. ma_elim, ma_formulas_elim = stormpy.eliminate_non_markovian_chains(ma, formulas, stormpy.EliminationLabelBehavior.KEEP_LABELS)
  88. assert ma_elim.nr_states == 9
  89. assert ma_elim.nr_transitions == 11
  90. assert ma_elim.model_type == stormpy.ModelType.MA
  91. assert len(ma_elim.initial_states) == 1
  92. initial_state = ma_elim.initial_states[0]
  93. assert initial_state == 0
  94. assert len(ma_formulas_elim) == 1
  95. result = stormpy.model_checking(ma_elim, ma_formulas_elim[0])
  96. assert math.isclose(result.at(initial_state), 1)
  97. # Merge labels
  98. ma_elim, ma_formulas_elim = stormpy.eliminate_non_markovian_chains(ma, formulas, stormpy.EliminationLabelBehavior.MERGE_LABELS)
  99. assert ma_elim.nr_states == 8
  100. assert ma_elim.nr_transitions == 10
  101. assert ma_elim.model_type == stormpy.ModelType.MA
  102. assert len(ma_elim.initial_states) == 1
  103. initial_state = ma_elim.initial_states[0]
  104. assert initial_state == 0
  105. assert len(ma_formulas_elim) == 1
  106. result = stormpy.model_checking(ma_elim, ma_formulas_elim[0])
  107. assert math.isclose(result.at(initial_state), 1)
  108. # Delete labels
  109. ma_elim, ma_formulas_elim = stormpy.eliminate_non_markovian_chains(ma, formulas, stormpy.EliminationLabelBehavior.DELETE_LABELS)
  110. assert ma_elim.nr_states == 8
  111. assert ma_elim.nr_transitions == 10
  112. assert ma_elim.model_type == stormpy.ModelType.MA
  113. assert len(ma_elim.initial_states) == 1
  114. initial_state = ma_elim.initial_states[0]
  115. assert initial_state == 0
  116. assert len(ma_formulas_elim) == 1
  117. result = stormpy.model_checking(ma_elim, ma_formulas_elim[0])
  118. assert math.isclose(result.at(initial_state), 1)