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.

84 lines
3.8 KiB

  1. import stormpy
  2. import stormpy.info
  3. import stormpy.logic
  4. from helpers.helper import get_example_path
  5. from configurations import pars
  6. @pars
  7. class TestParametric:
  8. def test_parametric_state_elimination(self):
  9. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  10. prop = "P=? [F s=5]"
  11. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  12. model = stormpy.build_parametric_model(program, formulas)
  13. assert model.nr_states == 613
  14. assert model.nr_transitions == 803
  15. assert model.model_type == stormpy.ModelType.DTMC
  16. assert model.has_parameters
  17. initial_state = model.initial_states[0]
  18. assert initial_state == 0
  19. result = stormpy.model_checking(model, formulas[0])
  20. func = result.at(initial_state)
  21. one = stormpy.FactorizedPolynomial(stormpy.RationalRF(1))
  22. assert func.denominator == one
  23. def test_constraints_collector(self):
  24. from pycarl.formula import FormulaType, Relation
  25. if stormpy.info.storm_ratfunc_use_cln():
  26. import pycarl.cln.formula
  27. else:
  28. import pycarl.gmp.formula
  29. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  30. prop = "P=? [F s=5]"
  31. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  32. model = stormpy.build_parametric_model(program, formulas)
  33. collector = stormpy.ConstraintCollector(model)
  34. constraints_well_formed = collector.wellformed_constraints
  35. for formula in constraints_well_formed:
  36. assert formula.type == FormulaType.CONSTRAINT
  37. constraint = formula.get_constraint()
  38. assert constraint.relation == Relation.LEQ
  39. constraints_graph_preserving = collector.graph_preserving_constraints
  40. for formula in constraints_graph_preserving:
  41. assert formula.type == FormulaType.CONSTRAINT
  42. constraint = formula.get_constraint()
  43. assert constraint.relation == Relation.NEQ
  44. def test_derivatives(self):
  45. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  46. prop = "P<=0.84 [F s=5 ]"
  47. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  48. model = stormpy.build_parametric_model(program, formulas)
  49. assert model.nr_states == 613
  50. assert model.nr_transitions == 803
  51. assert model.model_type == stormpy.ModelType.DTMC
  52. assert model.has_parameters
  53. parameters = model.collect_probability_parameters()
  54. assert len(parameters) == 2
  55. derivatives = stormpy.pars.gather_derivatives(model, list(parameters)[0])
  56. assert len(derivatives) == 0
  57. def test_dtmc_simplification(self):
  58. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  59. prop = "P<=0.84 [F s=5 ]"
  60. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  61. formula = formulas[0].raw_formula
  62. model = stormpy.build_parametric_model(program, formulas)
  63. assert model.nr_states == 613
  64. assert model.nr_transitions == 803
  65. model, formula = stormpy.pars.simplify_model(model, formula)
  66. assert model.nr_states == 193
  67. assert model.nr_transitions == 383
  68. def test_mdp_simplification(self):
  69. program = stormpy.parse_prism_program(get_example_path("pmdp", "two_dice.nm"))
  70. formulas = stormpy.parse_properties_for_prism_program("Pmin=? [ F \"two\" ]", program)
  71. formula = formulas[0].raw_formula
  72. model = stormpy.build_parametric_model(program, formulas)
  73. assert model.nr_states == 169
  74. assert model.nr_transitions == 435
  75. model, formula = stormpy.pars.simplify_model(model, formula)
  76. assert model.nr_states == 17
  77. assert model.nr_transitions == 50