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.

150 lines
7.3 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. import stormpy
  2. import stormpy.logic
  3. from helpers.helper import get_example_path
  4. import pytest
  5. class TestModel:
  6. def test_build_dtmc_from_prism_program(self):
  7. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  8. model = stormpy.build_model(program)
  9. assert model.nr_states == 13
  10. assert model.nr_transitions == 20
  11. assert model.model_type == stormpy.ModelType.DTMC
  12. assert not model.supports_parameters
  13. assert type(model) is stormpy.SparseDtmc
  14. def test_build_dtmc_from_prism_program_formulas(self):
  15. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  16. prop = "P=? [F \"one\"]"
  17. properties = stormpy.parse_properties_for_prism_program(prop, program, None)
  18. model = stormpy.build_model(program, properties)
  19. assert model.nr_states == 13
  20. assert model.nr_transitions == 20
  21. assert model.model_type == stormpy.ModelType.DTMC
  22. assert len(model.reward_models) == 0
  23. assert not model.supports_parameters
  24. assert type(model) is stormpy.SparseDtmc
  25. def test_build_dtmc_from_prism_program_formulas(self):
  26. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  27. prop = "R=? [F \"done\"]"
  28. properties = stormpy.parse_properties_for_prism_program(prop, program, None)
  29. model = stormpy.build_model(program, properties)
  30. assert model.nr_states == 13
  31. assert model.nr_transitions == 20
  32. assert model.model_type == stormpy.ModelType.DTMC
  33. assert len(model.reward_models) == 1
  34. assert not model.reward_models["coin_flips"].has_state_rewards
  35. assert model.reward_models["coin_flips"].has_state_action_rewards
  36. for reward in model.reward_models["coin_flips"].state_action_rewards:
  37. assert reward == 1.0 or reward == 0.0
  38. assert not model.reward_models["coin_flips"].has_transition_rewards
  39. assert not model.supports_parameters
  40. assert type(model) is stormpy.SparseDtmc
  41. def test_reduce_to_state_based_rewards(self):
  42. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  43. prop = "R=? [F \"done\"]"
  44. properties = stormpy.parse_properties_for_prism_program(prop, program, None)
  45. model = stormpy.build_model(program, properties)
  46. model.reduce_to_state_based_rewards()
  47. assert len(model.reward_models) == 1
  48. assert model.reward_models["coin_flips"].has_state_rewards
  49. assert not model.reward_models["coin_flips"].has_state_action_rewards
  50. for reward in model.reward_models["coin_flips"].state_rewards:
  51. assert reward == 1.0 or reward == 0.0
  52. assert not model.reward_models["coin_flips"].has_transition_rewards
  53. def test_build_parametric_dtmc_from_prism_program(self):
  54. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  55. prop = "P=? [F s=5]"
  56. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  57. model = stormpy.build_parametric_model(program, formulas)
  58. assert model.nr_states == 613
  59. assert model.nr_transitions == 803
  60. assert model.model_type == stormpy.ModelType.DTMC
  61. assert model.supports_parameters
  62. assert model.has_parameters
  63. assert type(model) is stormpy.SparseParametricDtmc
  64. def test_build_dtmc_from_jani_model(self):
  65. jani_model, properties = stormpy.parse_jani_model(get_example_path("dtmc", "die.jani"))
  66. model = stormpy.build_model(jani_model)
  67. assert model.nr_states == 13
  68. assert model.nr_transitions == 20
  69. assert model.model_type == stormpy.ModelType.DTMC
  70. assert not model.supports_parameters
  71. assert type(model) is stormpy.SparseDtmc
  72. def test_build_dtmc(self):
  73. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  74. formulas = stormpy.parse_properties_for_prism_program("P=? [ F \"one\" ]", program)
  75. model = stormpy.build_model(program, formulas)
  76. assert model.nr_states == 13
  77. assert model.nr_transitions == 20
  78. assert model.model_type == stormpy.ModelType.DTMC
  79. assert not model.supports_parameters
  80. assert type(model) is stormpy.SparseDtmc
  81. def test_build_dtmc_with_undefined_constants(self):
  82. jani_model, properties = stormpy.parse_jani_model(get_example_path("dtmc", "brp.jani"))
  83. assert jani_model.has_undefined_constants
  84. assert not jani_model.undefined_constants_are_graph_preserving
  85. with pytest.raises(stormpy.StormError):
  86. model = stormpy.build_model(jani_model)
  87. def test_build_instantiated_dtmc(self):
  88. jani_model, properties = stormpy.parse_jani_model(get_example_path("dtmc", "brp.jani"))
  89. assert jani_model.has_undefined_constants
  90. assert not jani_model.undefined_constants_are_graph_preserving
  91. description = stormpy.SymbolicModelDescription(jani_model)
  92. constant_definitions = description.parse_constant_definitions("N=16, MAX=2")
  93. instantiated_jani_model = description.instantiate_constants(constant_definitions).as_jani_model()
  94. model = stormpy.build_model(instantiated_jani_model)
  95. assert model.nr_states == 677
  96. assert model.nr_transitions == 867
  97. assert model.model_type == stormpy.ModelType.DTMC
  98. assert not model.supports_parameters
  99. assert type(model) is stormpy.SparseDtmc
  100. def test_build_parametric_dtmc(self):
  101. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  102. formulas = stormpy.parse_properties_for_prism_program("P=? [ F s=5 ]", program)
  103. model = stormpy.build_parametric_model(program, formulas)
  104. assert model.nr_states == 613
  105. assert model.nr_transitions == 803
  106. assert model.model_type == stormpy.ModelType.DTMC
  107. assert model.supports_parameters
  108. assert model.has_parameters
  109. assert type(model) is stormpy.SparseParametricDtmc
  110. def test_build_dtmc_supporting_parameters(self):
  111. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  112. formulas = stormpy.parse_properties_for_prism_program("P=? [ F \"one\" ]", program)
  113. model = stormpy.build_parametric_model(program, formulas)
  114. assert model.nr_states == 13
  115. assert model.nr_transitions == 20
  116. assert model.model_type == stormpy.ModelType.DTMC
  117. assert model.supports_parameters
  118. assert not model.has_parameters
  119. assert type(model) is stormpy.SparseParametricDtmc
  120. def test_build_mdp(self):
  121. program = stormpy.parse_prism_program(get_example_path("mdp", "two_dice.nm"))
  122. formulas = stormpy.parse_properties_for_prism_program("P=? [ F \"two\" ]", program)
  123. model = stormpy.build_model(program, formulas)
  124. assert model.nr_states == 169
  125. assert model.nr_transitions == 435
  126. assert model.model_type == stormpy.ModelType.MDP
  127. assert not model.supports_parameters
  128. assert type(model) is stormpy.SparseMdp
  129. def test_initial_states(self):
  130. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  131. formulas = stormpy.parse_properties_for_prism_program("P=? [ F \"one\" ]", program)
  132. model = stormpy.build_model(program, formulas)
  133. initial_states = model.initial_states
  134. assert len(initial_states) == 1
  135. assert 0 in initial_states