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.

99 lines
5.0 KiB

8 years ago
8 years ago
8 years ago
8 years 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("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("0.4<=pL<=0.65,0.75<=pK<=0.95", parameters)
  25. result = checker.check_region(env, region, stormpy.pars.RegionResultHypothesis.UNKNOWN,
  26. stormpy.pars.RegionResult.UNKNOWN, True)
  27. assert result == stormpy.pars.RegionResult.EXISTSBOTH
  28. region = stormpy.pars.ParameterRegion("0.1<=pL<=0.73,0.2<=pK<=0.715", parameters)
  29. result = checker.check_region(env, region)
  30. assert result == stormpy.pars.RegionResult.ALLVIOLATED
  31. def test_pla_bounds(self):
  32. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  33. prop = "P=? [F s=5 ]"
  34. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  35. model = stormpy.build_parametric_model(program, formulas)
  36. assert model.has_parameters
  37. env = stormpy.Environment()
  38. checker = stormpy.pars.create_region_checker(env, model, formulas[0].raw_formula)
  39. parameters = model.collect_probability_parameters()
  40. assert len(parameters) == 2
  41. region = stormpy.pars.ParameterRegion("0.7<=pL<=0.9,0.75<=pK<=0.95", parameters)
  42. result = checker.get_bound(env, region, True)
  43. assert math.isclose(float(result.constant_part()), 0.8369631383670559)
  44. #result_vec = checker.get_bound_all_states(env, region, True)
  45. #result = result_vec.at(model.initial_states[0])
  46. #assert math.isclose(float(result.constant_part()), 0.8369631383670559)
  47. def test_pla_manual(self):
  48. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  49. prop = "P=? [F s=5 ]"
  50. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  51. model = stormpy.build_parametric_model(program, formulas)
  52. assert model.has_parameters
  53. env = stormpy.Environment()
  54. checker = stormpy.pars.DtmcParameterLiftingModelChecker()
  55. checker.specify(env, model, formulas[0].raw_formula)
  56. parameters = model.collect_probability_parameters()
  57. assert len(parameters) == 2
  58. region = stormpy.pars.ParameterRegion("0.7<=pL<=0.9,0.75<=pK<=0.95", parameters)
  59. result = checker.get_bound(env, region, True)
  60. assert math.isclose(float(result.constant_part()), 0.8369631383670559)
  61. def test_pla_manual_no_simplification(self):
  62. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  63. prop = "P=? [F s=5 ]"
  64. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  65. model = stormpy.build_parametric_model(program, formulas)
  66. assert model.has_parameters
  67. env = stormpy.Environment()
  68. checker = stormpy.pars.DtmcParameterLiftingModelChecker()
  69. checker.specify(env, model, formulas[0].raw_formula, allow_model_simplification=False)
  70. parameters = model.collect_probability_parameters()
  71. assert len(parameters) == 2
  72. region = stormpy.pars.ParameterRegion("0.7<=pL<=0.9,0.75<=pK<=0.95", parameters)
  73. result = checker.get_bound(env, region, True)
  74. assert math.isclose(float(result.constant_part()), 0.836963056082918)
  75. def test_pla_state_bounds(self):
  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. assert model.has_parameters
  81. env = stormpy.Environment()
  82. checker = stormpy.pars.DtmcParameterLiftingModelChecker()
  83. checker.specify(env, model, formulas[0].raw_formula, allow_model_simplification=False)
  84. parameters = model.collect_probability_parameters()
  85. assert len(parameters) == 2
  86. region = stormpy.pars.ParameterRegion("0.7<=pL<=0.9,0.75<=pK<=0.95", parameters)
  87. result_vec = checker.get_bound_all_states(env, region, True)
  88. assert len(result_vec.get_values()) == model.nr_states
  89. assert math.isclose(result_vec.at(model.initial_states[0]), 0.836963056082918)