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.

65 lines
2.6 KiB

  1. import stormpy
  2. import stormpy.logic
  3. from helpers.helper import get_example_path
  4. import math
  5. class TestScheduler:
  6. def test_scheduler_mdp(self):
  7. program = stormpy.parse_prism_program(get_example_path("mdp", "coin2-2.nm"))
  8. formulas = stormpy.parse_properties_for_prism_program("Pmin=? [ F \"finished\" & \"all_coins_equal_1\"]", program)
  9. model = stormpy.build_model(program, formulas)
  10. assert model.nr_states == 272
  11. assert model.nr_transitions == 492
  12. assert len(model.initial_states) == 1
  13. initial_state = model.initial_states[0]
  14. assert initial_state == 0
  15. result = stormpy.model_checking(model, formulas[0], extract_scheduler=True)
  16. assert result.has_scheduler
  17. scheduler = result.scheduler
  18. assert scheduler.memoryless
  19. assert scheduler.memory_size == 1
  20. assert scheduler.deterministic
  21. for state in model.states:
  22. choice = scheduler.get_choice(state)
  23. assert choice.defined
  24. assert choice.deterministic
  25. action = choice.get_deterministic_choice()
  26. assert 0 <= action
  27. assert action < len(state.actions)
  28. def test_scheduler_ma_via_mdp(self):
  29. program = stormpy.parse_prism_program(get_example_path("ma", "simple.ma"), False, True)
  30. formulas = stormpy.parse_properties_for_prism_program("Tmin=? [ F s=4 ]", program)
  31. ma = stormpy.build_model(program, formulas)
  32. assert ma.nr_states == 5
  33. assert ma.nr_transitions == 8
  34. assert ma.model_type == stormpy.ModelType.MA
  35. # Convert MA to MDP
  36. mdp, mdp_formulas = stormpy.transform_to_discrete_time_model(ma, formulas)
  37. assert mdp.nr_states == 5
  38. assert mdp.nr_transitions == 8
  39. assert mdp.model_type == stormpy.ModelType.MDP
  40. assert len(mdp.initial_states) == 1
  41. initial_state = mdp.initial_states[0]
  42. assert initial_state == 0
  43. result = stormpy.model_checking(mdp, mdp_formulas[0], extract_scheduler=True)
  44. assert math.isclose(result.at(initial_state), 0.08333333333)
  45. assert result.has_scheduler
  46. scheduler = result.scheduler
  47. assert scheduler.memoryless
  48. assert scheduler.memory_size == 1
  49. assert scheduler.deterministic
  50. for state in mdp.states:
  51. choice = scheduler.get_choice(state)
  52. assert choice.defined
  53. assert choice.deterministic
  54. action = choice.get_deterministic_choice()
  55. if state.id == 0:
  56. assert action == 1
  57. else:
  58. assert action == 0