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.

68 lines
3.0 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_constraints_collector(self):
  9. from pycarl.formula import FormulaType, Relation
  10. if stormpy.info.storm_ratfunc_use_cln():
  11. import pycarl.cln.formula
  12. else:
  13. import pycarl.gmp.formula
  14. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  15. prop = "P=? [F s=5]"
  16. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  17. model = stormpy.build_parametric_model(program, formulas)
  18. collector = stormpy.ConstraintCollector(model)
  19. constraints_well_formed = collector.wellformed_constraints
  20. for formula in constraints_well_formed:
  21. assert formula.type == FormulaType.CONSTRAINT
  22. constraint = formula.get_constraint()
  23. assert constraint.relation == Relation.LEQ
  24. constraints_graph_preserving = collector.graph_preserving_constraints
  25. for formula in constraints_graph_preserving:
  26. assert formula.type == FormulaType.CONSTRAINT
  27. constraint = formula.get_constraint()
  28. assert constraint.relation == Relation.NEQ
  29. def test_derivatives(self):
  30. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  31. prop = "P<=0.84 [F s=5 ]"
  32. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  33. model = stormpy.build_parametric_model(program, formulas)
  34. assert model.nr_states == 613
  35. assert model.nr_transitions == 803
  36. assert model.model_type == stormpy.ModelType.DTMC
  37. assert model.has_parameters
  38. parameters = model.collect_probability_parameters()
  39. assert len(parameters) == 2
  40. derivatives = stormpy.pars.gather_derivatives(model, list(parameters)[0])
  41. assert len(derivatives) == 0
  42. def test_dtmc_simplification(self):
  43. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  44. prop = "P<=0.84 [F s=5 ]"
  45. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  46. formula = formulas[0].raw_formula
  47. model = stormpy.build_parametric_model(program, formulas)
  48. assert model.nr_states == 613
  49. assert model.nr_transitions == 803
  50. model, formula = stormpy.pars.simplify_model(model, formula)
  51. assert model.nr_states == 193
  52. assert model.nr_transitions == 383
  53. def test_mdp_simplification(self):
  54. program = stormpy.parse_prism_program(get_example_path("pmdp", "two_dice.nm"))
  55. formulas = stormpy.parse_properties_for_prism_program("Pmin=? [ F \"two\" ]", program)
  56. formula = formulas[0].raw_formula
  57. model = stormpy.build_parametric_model(program, formulas)
  58. assert model.nr_states == 169
  59. assert model.nr_transitions == 435
  60. model, formula = stormpy.pars.simplify_model(model, formula)
  61. assert model.nr_states == 17
  62. assert model.nr_transitions == 50