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.

131 lines
7.1 KiB

3 months ago
  1. import stormpy
  2. import stormpy.logic
  3. import math
  4. from helpers.helper import get_example_path
  5. from configurations import pars
  6. @pars
  7. class TestPLA:
  8. def test_pla(self):
  9. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  10. prop = "P<=0.84 [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. env = stormpy.Environment()
  18. checker = stormpy.pars.create_region_checker(env, model, formulas[0].raw_formula)
  19. parameters = model.collect_probability_parameters()
  20. assert len(parameters) == 2
  21. region = stormpy.pars.ParameterRegion.create_from_string("0.7<=pL<=0.9,0.75<=pK<=0.95", parameters)
  22. result = checker.check_region(env, region)
  23. assert result == stormpy.pars.RegionResult.ALLSAT
  24. region = stormpy.pars.ParameterRegion.create_from_string("0.4<=pL<=0.65,0.75<=pK<=0.95", parameters)
  25. result = checker.check_region(env, region, stormpy.pars.RegionResultHypothesis.UNKNOWN, stormpy.pars.RegionResult.UNKNOWN, True)
  26. assert result == stormpy.pars.RegionResult.EXISTSBOTH
  27. region = stormpy.pars.ParameterRegion.create_from_string("0.1<=pL<=0.73,0.2<=pK<=0.715", parameters)
  28. result = checker.check_region(env, region)
  29. assert result == stormpy.pars.RegionResult.ALLVIOLATED
  30. def test_pla_region_valuation(self):
  31. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  32. prop = "P<=0.84 [F s=5 ]"
  33. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  34. model = stormpy.build_parametric_model(program, formulas)
  35. assert model.nr_states == 613
  36. assert model.nr_transitions == 803
  37. assert model.model_type == stormpy.ModelType.DTMC
  38. assert model.has_parameters
  39. env = stormpy.Environment()
  40. checker = stormpy.pars.create_region_checker(env, model, formulas[0].raw_formula)
  41. parameters = model.collect_probability_parameters()
  42. assert len(parameters) == 2
  43. for par in parameters:
  44. if par.name == "pL":
  45. pL = par
  46. elif par.name == "pK":
  47. pK = par
  48. else:
  49. assert False
  50. region_valuation = dict()
  51. region_valuation[pL] = (stormpy.RationalRF(0.7), stormpy.RationalRF(0.9))
  52. region_valuation[pK] = (stormpy.RationalRF(0.75), stormpy.RationalRF(0.95))
  53. region = stormpy.pars.ParameterRegion(region_valuation)
  54. result = checker.check_region(env, region)
  55. assert result == stormpy.pars.RegionResult.ALLSAT
  56. region_valuation[pL] = (stormpy.RationalRF(0.4), stormpy.RationalRF(0.65))
  57. region = stormpy.pars.ParameterRegion(region_valuation)
  58. result = checker.check_region(env, region, stormpy.pars.RegionResultHypothesis.UNKNOWN, stormpy.pars.RegionResult.UNKNOWN, True)
  59. assert result == stormpy.pars.RegionResult.EXISTSBOTH
  60. region_valuation[pK] = (stormpy.RationalRF(0.2), stormpy.RationalRF(0.715))
  61. region_valuation[pL] = (stormpy.RationalRF(0.1), stormpy.RationalRF(0.73))
  62. region = stormpy.pars.ParameterRegion(region_valuation)
  63. result = checker.check_region(env, region)
  64. assert result == stormpy.pars.RegionResult.ALLVIOLATED
  65. def test_pla_bounds(self):
  66. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  67. prop = "P=? [F s=5 ]"
  68. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  69. model = stormpy.build_parametric_model(program, formulas)
  70. assert model.has_parameters
  71. env = stormpy.Environment()
  72. checker = stormpy.pars.create_region_checker(env, model, formulas[0].raw_formula)
  73. parameters = model.collect_probability_parameters()
  74. assert len(parameters) == 2
  75. region = stormpy.pars.ParameterRegion.create_from_string("0.7<=pL<=0.9,0.75<=pK<=0.95", parameters)
  76. result = checker.get_bound(env, region, True)
  77. assert math.isclose(float(result.constant_part()), 0.8369631383670559, rel_tol=1e-6)
  78. result_vec = checker.get_bound_all_states(env, region, True)
  79. result = result_vec.at(model.initial_states[0])
  80. assert math.isclose(result, 0.8369631383670559, rel_tol=1e-6)
  81. def test_pla_manual(self):
  82. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  83. prop = "P=? [F s=5 ]"
  84. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  85. model = stormpy.build_parametric_model(program, formulas)
  86. assert model.has_parameters
  87. env = stormpy.Environment()
  88. checker = stormpy.pars.DtmcParameterLiftingModelChecker()
  89. checker.specify(env, model, formulas[0].raw_formula)
  90. parameters = model.collect_probability_parameters()
  91. assert len(parameters) == 2
  92. region = stormpy.pars.ParameterRegion.create_from_string("0.7<=pL<=0.9,0.75<=pK<=0.95", parameters)
  93. result = checker.get_bound(env, region, True)
  94. assert math.isclose(float(result.constant_part()), 0.8369631383670559, rel_tol=1e-6)
  95. def test_pla_manual_no_simplification(self):
  96. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  97. prop = "P=? [F s=5 ]"
  98. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  99. model = stormpy.build_parametric_model(program, formulas)
  100. assert model.has_parameters
  101. env = stormpy.Environment()
  102. checker = stormpy.pars.DtmcParameterLiftingModelChecker()
  103. checker.specify(env, model, formulas[0].raw_formula, allow_model_simplification=False)
  104. parameters = model.collect_probability_parameters()
  105. assert len(parameters) == 2
  106. region = stormpy.pars.ParameterRegion.create_from_string("0.7<=pL<=0.9,0.75<=pK<=0.95", parameters)
  107. result = checker.get_bound(env, region, True)
  108. assert math.isclose(float(result.constant_part()), 0.836963056082918, rel_tol=1e-6)
  109. def test_pla_state_bounds(self):
  110. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  111. prop = "P=? [F s=5 ]"
  112. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  113. model = stormpy.build_parametric_model(program, formulas)
  114. assert model.has_parameters
  115. env = stormpy.Environment()
  116. checker = stormpy.pars.DtmcParameterLiftingModelChecker()
  117. checker.specify(env, model, formulas[0].raw_formula, allow_model_simplification=False)
  118. parameters = model.collect_probability_parameters()
  119. assert len(parameters) == 2
  120. region = stormpy.pars.ParameterRegion.create_from_string("0.7<=pL<=0.9,0.75<=pK<=0.95", parameters)
  121. result_vec = checker.get_bound_all_states(env, region, True)
  122. assert len(result_vec.get_values()) == model.nr_states
  123. assert math.isclose(result_vec.at(model.initial_states[0]), 0.836963056082918, rel_tol=1e-6)