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.

121 lines
6.0 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. import stormpy
  2. import stormpy.logic
  3. from helpers.helper import get_example_path
  4. import math
  5. class TestModelChecking:
  6. def test_model_checking_prism_dtmc(self):
  7. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  8. formulas = stormpy.parse_properties_for_prism_program("P=? [ F \"one\" ]", program)
  9. model = stormpy.build_model(program, formulas)
  10. assert model.nr_states == 13
  11. assert model.nr_transitions == 20
  12. assert len(model.initial_states) == 1
  13. initial_state = model.initial_states[0]
  14. assert initial_state == 0
  15. result = stormpy.model_checking(model, formulas[0])
  16. assert math.isclose(result.at(initial_state), 0.16666666666666663)
  17. def test_model_checking_jani_dtmc(self):
  18. jani_model, properties = stormpy.parse_jani_model(get_example_path("dtmc", "die.jani"))
  19. formula = properties["Probability to throw a six"]
  20. model = stormpy.build_model(jani_model, [formula])
  21. assert model.nr_states == 13
  22. assert model.nr_transitions == 20
  23. assert len(model.initial_states) == 1
  24. initial_state = model.initial_states[0]
  25. assert initial_state == 0
  26. result = stormpy.model_checking(model, formula)
  27. assert math.isclose(result.at(initial_state), 0.16666666666666663)
  28. def test_model_checking_jani_dtmc(self):
  29. jani_model, properties = stormpy.parse_jani_model(get_example_path("dtmc", "die.jani"))
  30. formula = properties["Expected number of coin flips"]
  31. model = stormpy.build_model(jani_model, [formula])
  32. assert model.nr_states == 13
  33. assert model.nr_transitions == 20
  34. assert len(model.initial_states) == 1
  35. initial_state = model.initial_states[0]
  36. assert initial_state == 0
  37. # Unsupported formula yields None result
  38. result = stormpy.model_checking(model, formula)
  39. assert result is None
  40. def test_model_checking_dtmc_all_labels(self):
  41. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  42. formulas = stormpy.parse_properties_for_prism_program("P=? [ F \"one\" ]", program)
  43. model = stormpy.build_model(program)
  44. assert model.nr_states == 13
  45. assert model.nr_transitions == 20
  46. assert len(model.initial_states) == 1
  47. initial_state = model.initial_states[0]
  48. assert initial_state == 0
  49. result = stormpy.model_checking(model, formulas[0])
  50. assert math.isclose(result.at(initial_state), 0.16666666666666663)
  51. formulas = stormpy.parse_properties_for_prism_program("P=? [ F \"two\" ]", program)
  52. result = stormpy.model_checking(model, formulas[0])
  53. assert math.isclose(result.at(initial_state), 0.16666666666666663)
  54. def test_model_checking_all_dtmc(self):
  55. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  56. formulas = stormpy.parse_properties_for_prism_program("P=? [ F \"one\" ]", program)
  57. model = stormpy.build_model(program, formulas)
  58. assert model.nr_states == 13
  59. assert model.nr_transitions == 20
  60. result = stormpy.model_checking(model, formulas[0])
  61. assert result.result_for_all_states
  62. reference = [0.16666666666666663, 0.3333333333333333, 0, 0.6666666666666666, 0, 0, 0, 1, 0, 0, 0, 0, 0]
  63. assert all(map(math.isclose, result.get_values(), reference))
  64. def test_parametric_state_elimination(self):
  65. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  66. prop = "P=? [F s=5]"
  67. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  68. model = stormpy.build_parametric_model(program, formulas)
  69. assert model.nr_states == 613
  70. assert model.nr_transitions == 803
  71. assert model.model_type == stormpy.ModelType.DTMC
  72. assert model.has_parameters
  73. initial_state = model.initial_states[0]
  74. assert initial_state == 0
  75. result = stormpy.model_checking(model, formulas[0])
  76. func = result.at(initial_state)
  77. one = stormpy.FactorizedPolynomial(stormpy.RationalRF(1))
  78. assert func.denominator == one
  79. def test_model_checking_prob01(self):
  80. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  81. formulaPhi = stormpy.parse_properties("true")[0]
  82. formulaPsi = stormpy.parse_properties("\"six\"")[0]
  83. model = stormpy.build_model(program, [formulaPsi])
  84. phiResult = stormpy.model_checking(model, formulaPhi)
  85. phiStates = phiResult.get_truth_values()
  86. assert phiStates.number_of_set_bits() == model.nr_states
  87. psiResult = stormpy.model_checking(model, formulaPsi)
  88. psiStates = psiResult.get_truth_values()
  89. assert psiStates.number_of_set_bits() == 1
  90. (prob0, prob1) = stormpy.compute_prob01_states(model, phiStates, psiStates)
  91. assert prob0.number_of_set_bits() == 9
  92. assert prob1.number_of_set_bits() == 1
  93. (prob0, prob1) = stormpy.compute_prob01min_states(model, phiStates, psiStates)
  94. assert prob0.number_of_set_bits() == 9
  95. assert prob1.number_of_set_bits() == 1
  96. (prob0, prob1) = stormpy.compute_prob01max_states(model, phiStates, psiStates)
  97. assert prob0.number_of_set_bits() == 9
  98. assert prob1.number_of_set_bits() == 1
  99. labelprop = stormpy.core.Property("cora", formulaPsi.raw_formula)
  100. result = stormpy.model_checking(model, labelprop)
  101. assert result.get_truth_values().number_of_set_bits() == 1
  102. def test_model_checking_ctmc(self):
  103. model = stormpy.build_model_from_drn(get_example_path("ctmc", "dft.drn"))
  104. formulas = stormpy.parse_properties("T=? [ F \"failed\" ]")
  105. assert model.nr_states == 16
  106. assert model.nr_transitions == 33
  107. assert len(model.initial_states) == 1
  108. initial_state = model.initial_states[0]
  109. assert initial_state == 0
  110. result = stormpy.model_checking(model, formulas[0])
  111. assert math.isclose(result.at(initial_state), 4.166666667)