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.

81 lines
3.8 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)