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.

137 lines
6.5 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_parameters(self):
  48. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  49. formulas = stormpy.parse_properties_for_prism_program("P=? [F s=5]", program)
  50. model = stormpy.build_parametric_model(program, formulas)
  51. model_parameters = model.collect_probability_parameters()
  52. reward_parameters = model.collect_reward_parameters()
  53. all_parameters = model.collect_all_parameters()
  54. assert len(model_parameters) == 2
  55. assert len(reward_parameters) == 0
  56. assert len(all_parameters) == 2
  57. program_reward = stormpy.parse_prism_program(get_example_path("pdtmc", "brp_rewards16_2.pm"))
  58. formulas_reward = stormpy.parse_properties_for_prism_program("Rmin=? [ F \"target\" ]", program_reward)
  59. model = stormpy.build_parametric_model(program_reward, formulas_reward)
  60. model_parameters = model.collect_probability_parameters()
  61. reward_parameters = model.collect_reward_parameters()
  62. all_parameters = model.collect_all_parameters()
  63. assert len(model_parameters) == 2
  64. assert len(reward_parameters) == 2
  65. assert len(all_parameters) == 4
  66. model = stormpy.build_symbolic_parametric_model(program, formulas)
  67. assert len(model.get_parameters()) == 4
  68. model = stormpy.build_symbolic_parametric_model(program_reward, formulas_reward)
  69. assert len(model.get_parameters()) == 4
  70. def test_constraints_collector(self):
  71. from pycarl.formula import FormulaType, Relation
  72. if stormpy.info.storm_ratfunc_use_cln():
  73. import pycarl.cln.formula
  74. else:
  75. import pycarl.gmp.formula
  76. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  77. prop = "P=? [F s=5]"
  78. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  79. model = stormpy.build_parametric_model(program, formulas)
  80. collector = stormpy.ConstraintCollector(model)
  81. constraints_well_formed = collector.wellformed_constraints
  82. for formula in constraints_well_formed:
  83. assert formula.type == FormulaType.CONSTRAINT
  84. constraint = formula.get_constraint()
  85. assert constraint.relation == Relation.LEQ
  86. constraints_graph_preserving = collector.graph_preserving_constraints
  87. for formula in constraints_graph_preserving:
  88. assert formula.type == FormulaType.CONSTRAINT
  89. constraint = formula.get_constraint()
  90. assert constraint.relation == Relation.NEQ
  91. def test_derivatives(self):
  92. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  93. prop = "P<=0.84 [F s=5 ]"
  94. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  95. model = stormpy.build_parametric_model(program, formulas)
  96. assert model.nr_states == 613
  97. assert model.nr_transitions == 803
  98. assert model.model_type == stormpy.ModelType.DTMC
  99. assert model.has_parameters
  100. parameters = model.collect_probability_parameters()
  101. assert len(parameters) == 2
  102. derivatives = stormpy.pars.gather_derivatives(model, list(parameters)[0])
  103. assert len(derivatives) == 0
  104. def test_dtmc_simplification(self):
  105. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  106. prop = "P<=0.84 [F s=5 ]"
  107. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  108. formula = formulas[0].raw_formula
  109. model = stormpy.build_parametric_model(program, formulas)
  110. assert model.nr_states == 613
  111. assert model.nr_transitions == 803
  112. model, formula = stormpy.pars.simplify_model(model, formula)
  113. assert model.nr_states == 193
  114. assert model.nr_transitions == 383
  115. def test_mdp_simplification(self):
  116. program = stormpy.parse_prism_program(get_example_path("pmdp", "two_dice.nm"))
  117. formulas = stormpy.parse_properties_for_prism_program("Pmin=? [ F \"two\" ]", program)
  118. formula = formulas[0].raw_formula
  119. model = stormpy.build_parametric_model(program, formulas)
  120. assert model.nr_states == 169
  121. assert model.nr_transitions == 435
  122. model, formula = stormpy.pars.simplify_model(model, formula)
  123. assert model.nr_states == 17
  124. assert model.nr_transitions == 50