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.

110 lines
5.1 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_model_checking_sparse(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_parametric_model_checking_dd(self):
  24. program = stormpy.parse_prism_program(get_example_path("pdtmc", "parametric_die.pm"))
  25. prop = "P=? [F s=5]"
  26. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  27. model = stormpy.build_symbolic_parametric_model(program, formulas)
  28. assert model.nr_states == 11
  29. assert model.nr_transitions == 17
  30. assert model.model_type == stormpy.ModelType.DTMC
  31. assert model.has_parameters
  32. result = stormpy.check_model_dd(model, formulas[0])
  33. assert type(result) is stormpy.SymbolicParametricQuantitativeCheckResult
  34. def test_parametric_model_checking_hybrid(self):
  35. program = stormpy.parse_prism_program(get_example_path("pdtmc", "parametric_die.pm"))
  36. prop = "P=? [F s=5]"
  37. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  38. model = stormpy.build_symbolic_parametric_model(program, formulas)
  39. assert model.nr_states == 11
  40. assert model.nr_transitions == 17
  41. assert model.model_type == stormpy.ModelType.DTMC
  42. assert model.has_parameters
  43. result = stormpy.check_model_hybrid(model, formulas[0])
  44. assert type(result) is stormpy.HybridParametricQuantitativeCheckResult
  45. values = result.get_values()
  46. assert len(values) == 3
  47. def test_constraints_collector(self):
  48. from pycarl.formula import FormulaType, Relation
  49. if stormpy.info.storm_ratfunc_use_cln():
  50. import pycarl.cln.formula
  51. else:
  52. import pycarl.gmp.formula
  53. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  54. prop = "P=? [F s=5]"
  55. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  56. model = stormpy.build_parametric_model(program, formulas)
  57. collector = stormpy.ConstraintCollector(model)
  58. constraints_well_formed = collector.wellformed_constraints
  59. for formula in constraints_well_formed:
  60. assert formula.type == FormulaType.CONSTRAINT
  61. constraint = formula.get_constraint()
  62. assert constraint.relation == Relation.LEQ
  63. constraints_graph_preserving = collector.graph_preserving_constraints
  64. for formula in constraints_graph_preserving:
  65. assert formula.type == FormulaType.CONSTRAINT
  66. constraint = formula.get_constraint()
  67. assert constraint.relation == Relation.NEQ
  68. def test_derivatives(self):
  69. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  70. prop = "P<=0.84 [F s=5 ]"
  71. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  72. model = stormpy.build_parametric_model(program, formulas)
  73. assert model.nr_states == 613
  74. assert model.nr_transitions == 803
  75. assert model.model_type == stormpy.ModelType.DTMC
  76. assert model.has_parameters
  77. parameters = model.collect_probability_parameters()
  78. assert len(parameters) == 2
  79. derivatives = stormpy.pars.gather_derivatives(model, list(parameters)[0])
  80. assert len(derivatives) == 0
  81. def test_dtmc_simplification(self):
  82. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  83. prop = "P<=0.84 [F s=5 ]"
  84. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  85. formula = formulas[0].raw_formula
  86. model = stormpy.build_parametric_model(program, formulas)
  87. assert model.nr_states == 613
  88. assert model.nr_transitions == 803
  89. model, formula = stormpy.pars.simplify_model(model, formula)
  90. assert model.nr_states == 193
  91. assert model.nr_transitions == 383
  92. def test_mdp_simplification(self):
  93. program = stormpy.parse_prism_program(get_example_path("pmdp", "two_dice.nm"))
  94. formulas = stormpy.parse_properties_for_prism_program("Pmin=? [ F \"two\" ]", program)
  95. formula = formulas[0].raw_formula
  96. model = stormpy.build_parametric_model(program, formulas)
  97. assert model.nr_states == 169
  98. assert model.nr_transitions == 435
  99. model, formula = stormpy.pars.simplify_model(model, formula)
  100. assert model.nr_states == 17
  101. assert model.nr_transitions == 50