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.

83 lines
4.1 KiB

  1. import stormpy
  2. from helpers.helper import get_example_path
  3. class TestModelIterators:
  4. def test_states_dtmc(self):
  5. model = stormpy.parse_explicit_model(get_example_path("dtmc", "die.tra"), get_example_path("dtmc", "die.lab"))
  6. s = stormpy.state.State(0, model)
  7. i = 0
  8. for state in stormpy.state.State(0, model):
  9. assert state.id == i
  10. i += 1
  11. assert i == model.nr_states
  12. def test_states_mdp(self):
  13. model = stormpy.parse_explicit_model(get_example_path("mdp", "two_dice.tra"), get_example_path("mdp", "two_dice.lab"))
  14. s = stormpy.state.State(0, model)
  15. i = 0
  16. for state in stormpy.state.State(0, model):
  17. assert state.id == i
  18. i += 1
  19. assert i == model.nr_states
  20. def test_actions_dtmc(self):
  21. model = stormpy.parse_explicit_model(get_example_path("dtmc", "die.tra"), get_example_path("dtmc", "die.lab"))
  22. s = stormpy.state.State(0, model)
  23. for state in stormpy.state.State(0, model):
  24. for action in state.actions():
  25. assert action.row == 0
  26. def test_actions_mdp(self):
  27. model = stormpy.parse_explicit_model(get_example_path("mdp", "two_dice.tra"), get_example_path("mdp", "two_dice.lab"))
  28. s = stormpy.state.State(0, model)
  29. for state in stormpy.state.State(0, model):
  30. for action in state.actions():
  31. assert action.row == 0 or action.row == 1
  32. def test_transitions_dtmc(self):
  33. transitions_orig = [(0, 0, 0), (0, 1, 0.5), (0, 2, 0.5), (1, 1, 0), (1, 3, 0.5), (1, 4, 0.5),
  34. (2, 2, 0), (2, 5, 0.5), (2, 6, 0.5), (3, 1, 0.5), (3, 3, 0), (3, 7, 0.5),
  35. (4, 4, 0), (4, 8, 0.5), (4, 9, 0.5), (5, 5, 0), (5, 10, 0.5), (5, 11, 0.5),
  36. (6, 2, 0.5), (6, 6, 0), (6, 12, 0.5), (7, 7, 1), (8, 8, 1),
  37. (9, 9, 1), (10, 10, 1), (11, 11, 1), (12, 12, 1)
  38. ]
  39. model = stormpy.parse_explicit_model(get_example_path("dtmc", "die.tra"), get_example_path("dtmc", "die.lab"))
  40. s = stormpy.state.State(0, model)
  41. i = 0
  42. for state in stormpy.state.State(0, model):
  43. for action in state.actions():
  44. for transition in action.transitions():
  45. transition_orig = transitions_orig[i]
  46. i += 1
  47. assert state.id == transition_orig[0]
  48. assert transition.column == transition_orig[1]
  49. assert transition.value() == transition_orig[2]
  50. def test_transitions_mdp(self):
  51. model = stormpy.parse_explicit_model(get_example_path("mdp", "two_dice.tra"), get_example_path("mdp", "two_dice.lab"))
  52. s = stormpy.state.State(0, model)
  53. for state in stormpy.state.State(0, model):
  54. i = 0
  55. for action in state.actions():
  56. i += 1
  57. for transition in action.transitions():
  58. assert transition.value() == 0.5 or transition.value() == 1
  59. assert i == 1 or i == 2
  60. def test_row_iterator(self):
  61. transitions_orig = [(0, 0, 0), (0, 1, 0.5), (0, 2, 0.5), (1, 1, 0), (1, 3, 0.5), (1, 4, 0.5),
  62. (2, 2, 0), (2, 5, 0.5), (2, 6, 0.5), (3, 1, 0.5), (3, 3, 0), (3, 7, 0.5),
  63. (4, 4, 0), (4, 8, 0.5), (4, 9, 0.5), (5, 5, 0), (5, 10, 0.5), (5, 11, 0.5),
  64. (6, 2, 0.5), (6, 6, 0), (6, 12, 0.5), (7, 7, 1), (8, 8, 1),
  65. (9, 9, 1), (10, 10, 1), (11, 11, 1), (12, 12, 1)
  66. ]
  67. model = stormpy.parse_explicit_model(get_example_path("dtmc", "die.tra"), get_example_path("dtmc", "die.lab"))
  68. i = 0
  69. for state in stormpy.state.State(0, model):
  70. for transition in model.transition_matrix.row_iter(state.id, state.id):
  71. transition_orig = transitions_orig[i]
  72. i += 1
  73. assert state.id == transition_orig[0]
  74. assert transition.column == transition_orig[1]
  75. assert transition.value() == transition_orig[2]