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.

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