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.

59 lines
2.7 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(self):
  35. ctmc = stormpy.build_model_from_drn(get_example_path("ctmc", "dft.drn"))
  36. formulas = stormpy.parse_properties("T=? [ F \"failed\" ]")
  37. print(formulas)
  38. assert ctmc.nr_states == 16
  39. assert ctmc.nr_transitions == 33
  40. assert len(ctmc.initial_states) == 1
  41. initial_state = ctmc.initial_states[0]
  42. assert initial_state == 1
  43. result = stormpy.model_checking(ctmc, formulas[0])
  44. assert math.isclose(result.at(initial_state), 4.166666667)
  45. dtmc, dtmc_formulas = stormpy.transform_to_discrete_time_model(ctmc, formulas)
  46. print(dtmc_formulas)
  47. assert dtmc.nr_states == 16
  48. assert dtmc.nr_transitions == 33
  49. assert len(dtmc.initial_states) == 1
  50. initial_state = dtmc.initial_states[0]
  51. assert initial_state == 1
  52. result = stormpy.model_checking(dtmc, dtmc_formulas[0])
  53. assert math.isclose(result.at(initial_state), 4.166666667)