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.

57 lines
2.9 KiB

  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_formulas_for_prism_program("P=? [ F \"one\" ]", program)
  9. model = stormpy.build_model(program, formulas[0])
  10. assert model.nr_states == 13
  11. assert model.nr_transitions == 20
  12. result = stormpy.model_checking(model, formulas[0])
  13. assert math.isclose(result, 0.16666666666666663)
  14. def test_model_checking_all_dtmc(self):
  15. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  16. formulas = stormpy.parse_formulas_for_prism_program("P=? [ F \"one\" ]", program)
  17. model = stormpy.build_model(program, formulas[0])
  18. assert model.nr_states == 13
  19. assert model.nr_transitions == 20
  20. results = stormpy.model_checking_all(model, formulas[0])
  21. reference = [0.16666666666666663, 0.3333333333333333, 0, 0.6666666666666666, 0, 0, 0, 1, 0, 0, 0, 0, 0]
  22. assert all(map(math.isclose, results, reference))
  23. def test_parametric_state_elimination(self):
  24. import pycarl
  25. import pycarl.formula
  26. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  27. prop = "P=? [F s=5]"
  28. formulas = stormpy.parse_formulas_for_prism_program(prop, program)
  29. model = stormpy.build_parametric_model_from_prism_program(program, formulas)
  30. assert model.nr_states == 613
  31. assert model.nr_transitions == 803
  32. assert model.model_type == stormpy.ModelType.DTMC
  33. assert model.has_parameters
  34. result = stormpy.model_checking(model, formulas[0])
  35. func = result.result_function
  36. one = pycarl.FactorizedPolynomial(pycarl.Rational(1))
  37. assert func.denominator == one
  38. constraints_well_formed = result.constraints_well_formed
  39. for constraint in constraints_well_formed:
  40. assert constraint.rel() == pycarl.formula.Relation.GEQ or constraint.rel() == pycarl.formula.Relation.LEQ
  41. constraints_graph_preserving = result.constraints_graph_preserving
  42. for constraint in constraints_graph_preserving:
  43. assert constraint.rel() == pycarl.formula.Relation.GREATER
  44. def test_model_checking_prob01(self):
  45. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  46. formulas = stormpy.parse_formulas_for_prism_program("P=? [ F \"one\" ]", program)
  47. model = stormpy.build_model(program, formulas[0])
  48. phiStates = stormpy.BitVector(model.nr_states, True)
  49. psiStates = stormpy.BitVector(model.nr_states, [model.nr_states-1])
  50. (prob0, prob1) = stormpy.compute_prob01states(model, phiStates, psiStates)
  51. assert prob0.number_of_set_bits() == 9
  52. assert prob1.number_of_set_bits() == 1