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.

72 lines
2.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. import stormpy
  2. def example_building_dtmcs_01():
  3. # Use the SparseMatrixBuilder for constructing the transition matrix
  4. builder = stormpy.SparseMatrixBuilder(rows=0, columns=0, entries=0, force_dimensions=False,
  5. has_custom_row_grouping=False)
  6. # New Transition from state 0 to target state 1 with probability 0.5
  7. builder.add_next_value(row=0, column=1, value=0.5)
  8. builder.add_next_value(0, 2, 0.5)
  9. builder.add_next_value(1, 3, 0.5)
  10. builder.add_next_value(1, 4, 0.5)
  11. builder.add_next_value(2, 5, 0.5)
  12. builder.add_next_value(2, 6, 0.5)
  13. builder.add_next_value(3, 7, 0.5)
  14. builder.add_next_value(3, 1, 0.5)
  15. builder.add_next_value(4, 8, 0.5)
  16. builder.add_next_value(4, 9, 0.5)
  17. builder.add_next_value(5, 10, 0.5)
  18. builder.add_next_value(5, 11, 0.5)
  19. builder.add_next_value(6, 2, 0.5)
  20. builder.add_next_value(6, 12, 0.5)
  21. # Add transitions for the final states
  22. for s in range(7, 13):
  23. builder.add_next_value(s, s, 1)
  24. # Build matrix
  25. transition_matrix = builder.build()
  26. print(transition_matrix)
  27. # State labeling
  28. state_labeling = stormpy.storage.StateLabeling(13)
  29. # Add labels
  30. labels = {'init', 'one', 'two', 'three', 'four', 'five', 'six', 'done', 'deadlock'}
  31. for label in labels:
  32. state_labeling.add_label(label)
  33. # Set label of state 0
  34. state_labeling.add_label_to_state('init', 0)
  35. print(state_labeling.get_states('init'))
  36. # Set remaining labels
  37. state_labeling.add_label_to_state('one', 7)
  38. state_labeling.add_label_to_state('two', 8)
  39. state_labeling.add_label_to_state('three', 9)
  40. state_labeling.add_label_to_state('four', 10)
  41. state_labeling.add_label_to_state('five', 11)
  42. state_labeling.add_label_to_state('six', 12)
  43. # Set label 'done' for multiple states
  44. state_labeling.set_states('done', stormpy.BitVector(13, [7, 8, 9, 10, 11, 12]))
  45. print(state_labeling)
  46. # Reward models:
  47. reward_models = {}
  48. # Create a vector representing the state-action rewards
  49. action_reward = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
  50. reward_models['coin_flips'] = stormpy.SparseRewardModel(optional_state_action_reward_vector=action_reward)
  51. components = stormpy.SparseModelComponents(transition_matrix=transition_matrix, state_labeling=state_labeling,
  52. reward_models=reward_models)
  53. dtmc = stormpy.storage.SparseDtmc(components)
  54. print(dtmc)
  55. if __name__ == '__main__':
  56. example_building_dtmcs_01()