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.

66 lines
2.8 KiB

5 years ago
  1. import stormpy
  2. import stormpy.logic
  3. from helpers.helper import get_example_path
  4. import pytest
  5. class TestSparseModelComponents:
  6. def test_init_default(self):
  7. components = stormpy.SparseModelComponents()
  8. assert components.state_labeling.get_labels() == set()
  9. assert components.reward_models == {}
  10. assert components.transition_matrix.nr_rows == 0
  11. assert components.transition_matrix.nr_columns == 0
  12. assert components.markovian_states is None
  13. assert components.player1_matrix is None
  14. assert not components.rate_transitions
  15. def test_build_dtmc_from_model_components(self):
  16. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  17. options = stormpy.BuilderOptions(True, True)
  18. options.set_build_with_choice_origins()
  19. options.set_build_state_valuations()
  20. options.set_build_all_labels()
  21. model = stormpy.build_sparse_model_with_options(program, options)
  22. components = stormpy.SparseModelComponents(transition_matrix=model.transition_matrix,
  23. state_labeling=model.labeling,
  24. reward_models=model.reward_models)
  25. components.choice_origins = model.choice_origins
  26. components.state_valuations = model.state_valuations
  27. dtmc = stormpy.storage.SparseDtmc(components)
  28. assert type(dtmc) is stormpy.SparseDtmc
  29. assert not dtmc.supports_parameters
  30. # test transition matrix
  31. assert dtmc.nr_choices == 13
  32. assert dtmc.nr_states == 13
  33. assert dtmc.nr_transitions == 20
  34. assert dtmc.transition_matrix.nr_entries == 20
  35. assert dtmc.transition_matrix.nr_entries == model.nr_transitions
  36. for e in dtmc.transition_matrix:
  37. assert e.value() == 0.5 or e.value() == 0 or (e.value() == 1 and e.column > 6)
  38. for state in dtmc.states:
  39. assert len(state.actions) <= 1
  40. # test state_labeling
  41. assert dtmc.labeling.get_labels() == {'init', 'deadlock', 'done', 'one', 'two', 'three', 'four', 'five', 'six'}
  42. # test reward_models
  43. assert len(model.reward_models) == 1
  44. assert not model.reward_models["coin_flips"].has_state_rewards
  45. assert model.reward_models["coin_flips"].has_state_action_rewards
  46. for reward in model.reward_models["coin_flips"].state_action_rewards:
  47. assert reward == 1.0 or reward == 0.0
  48. assert not model.reward_models["coin_flips"].has_transition_rewards
  49. # choice_labeling
  50. assert not dtmc.has_choice_labeling()
  51. # state_valuations
  52. assert dtmc.has_state_valuations()
  53. # choice_origins
  54. assert dtmc.has_choice_origins()
  55. assert dtmc.choice_origins is components.choice_origins # todo correct?