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.

66 lines
3.3 KiB

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. import pycarl
  29. import pycarl.formula
  30. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  31. prop = "P=? [F s=5]"
  32. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  33. model = stormpy.build_parametric_model(program, formulas)
  34. assert model.nr_states == 613
  35. assert model.nr_transitions == 803
  36. assert model.model_type == stormpy.ModelType.DTMC
  37. assert model.has_parameters
  38. result = stormpy.model_checking(model, formulas[0])
  39. func = result.result_function
  40. one = pycarl.FactorizedPolynomial(pycarl.Rational(1))
  41. assert func.denominator == one
  42. constraints_well_formed = result.constraints_well_formed
  43. for constraint in constraints_well_formed:
  44. assert constraint.rel() == pycarl.formula.Relation.GEQ or constraint.rel() == pycarl.formula.Relation.LEQ
  45. constraints_graph_preserving = result.constraints_graph_preserving
  46. for constraint in constraints_graph_preserving:
  47. assert constraint.rel() == pycarl.formula.Relation.GREATER
  48. def test_model_checking_prob01(self):
  49. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  50. formulaPhi = stormpy.parse_properties("true")[0]
  51. formulaPsi = stormpy.parse_properties("\"six\"")[0]
  52. model = stormpy.build_model(program, [formulaPsi])
  53. phiResult = stormpy.model_checking(model, formulaPhi)
  54. phiStates = phiResult.get_truth_values()
  55. assert phiStates.number_of_set_bits() == model.nr_states
  56. psiResult = stormpy.model_checking(model, formulaPsi)
  57. psiStates = psiResult.get_truth_values()
  58. assert psiStates.number_of_set_bits() == 1
  59. (prob0, prob1) = stormpy.compute_prob01_states(model, phiStates, psiStates)
  60. assert prob0.number_of_set_bits() == 9
  61. assert prob1.number_of_set_bits() == 1