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.

99 lines
5.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_all_dtmc(self):
  29. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  30. formulas = stormpy.parse_properties_for_prism_program("P=? [ F \"one\" ]", program)
  31. model = stormpy.build_model(program, formulas)
  32. assert model.nr_states == 13
  33. assert model.nr_transitions == 20
  34. result = stormpy.model_checking(model, formulas[0])
  35. assert result.result_for_all_states
  36. reference = [0.16666666666666663, 0.3333333333333333, 0, 0.6666666666666666, 0, 0, 0, 1, 0, 0, 0, 0, 0]
  37. assert all(map(math.isclose, result.get_values(), reference))
  38. def test_parametric_state_elimination(self):
  39. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  40. prop = "P=? [F s=5]"
  41. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  42. model = stormpy.build_parametric_model(program, formulas)
  43. assert model.nr_states == 613
  44. assert model.nr_transitions == 803
  45. assert model.model_type == stormpy.ModelType.DTMC
  46. assert model.has_parameters
  47. initial_state = model.initial_states[0]
  48. assert initial_state == 0
  49. result = stormpy.model_checking(model, formulas[0])
  50. func = result.at(initial_state)
  51. one = stormpy.FactorizedPolynomial(stormpy.RationalRF(1))
  52. assert func.denominator == one
  53. # constraints_well_formed = result.constraints_well_formed
  54. # for constraint in constraints_well_formed:
  55. # assert constraint.rel() == pycarl.formula.Relation.GEQ or constraint.rel() == pycarl.formula.Relation.LEQ
  56. # constraints_graph_preserving = result.constraints_graph_preserving
  57. # for constraint in constraints_graph_preserving:
  58. # assert constraint.rel() == pycarl.formula.Relation.GREATER
  59. def test_model_checking_prob01(self):
  60. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  61. formulaPhi = stormpy.parse_properties("true")[0]
  62. formulaPsi = stormpy.parse_properties("\"six\"")[0]
  63. model = stormpy.build_model(program, [formulaPsi])
  64. phiResult = stormpy.model_checking(model, formulaPhi)
  65. phiStates = phiResult.get_truth_values()
  66. assert phiStates.number_of_set_bits() == model.nr_states
  67. psiResult = stormpy.model_checking(model, formulaPsi)
  68. psiStates = psiResult.get_truth_values()
  69. assert psiStates.number_of_set_bits() == 1
  70. (prob0, prob1) = stormpy.compute_prob01_states(model, phiStates, psiStates)
  71. assert prob0.number_of_set_bits() == 9
  72. assert prob1.number_of_set_bits() == 1
  73. (prob0, prob1) = stormpy.compute_prob01min_states(model, phiStates, psiStates)
  74. assert prob0.number_of_set_bits() == 9
  75. assert prob1.number_of_set_bits() == 1
  76. (prob0, prob1) = stormpy.compute_prob01max_states(model, phiStates, psiStates)
  77. assert prob0.number_of_set_bits() == 9
  78. assert prob1.number_of_set_bits() == 1
  79. labelprop = stormpy.core.Property("cora", formulaPsi.raw_formula)
  80. result = stormpy.model_checking(model, labelprop)
  81. assert result.get_truth_values().number_of_set_bits() == 1
  82. def test_model_checking_ctmc(self):
  83. model = stormpy.build_model_from_drn(get_example_path("ctmc", "dft.drn"))
  84. formulas = stormpy.parse_properties("T=? [ F \"failed\" ]")
  85. assert model.nr_states == 16
  86. assert model.nr_transitions == 33
  87. assert len(model.initial_states) == 1
  88. initial_state = model.initial_states[0]
  89. assert initial_state == 0
  90. result = stormpy.model_checking(model, formulas[0])
  91. assert math.isclose(result.at(initial_state), 4.166666667)