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
1.8 KiB

3 months ago
  1. import stormpy
  2. # Check if numpy is available
  3. try:
  4. import numpy as np
  5. numpy_found = True
  6. except ModuleNotFoundError:
  7. numpy_found = False
  8. def example_building_mas_01():
  9. if not numpy_found:
  10. print("Numpy not available")
  11. return
  12. # Building the transition matrix using numpy
  13. transitions = np.array([
  14. [0, 1, 0, 0, 0],
  15. [0.8, 0, 0.2, 0, 0],
  16. [0.9, 0, 0, 0.1, 0],
  17. [0, 0, 0, 0, 1],
  18. [0, 0, 0, 1, 0],
  19. [0, 0, 0, 0, 1]
  20. ], dtype='float64')
  21. # Build matrix and define indices of row groups (ascending order)
  22. transition_matrix = stormpy.build_sparse_matrix(transitions, [0, 2, 3, 4, 5])
  23. print(transition_matrix)
  24. # StateLabeling
  25. state_labeling = stormpy.storage.StateLabeling(5)
  26. # Add labels
  27. state_labels = {'init', 'deadlock'}
  28. # Set labeling of states
  29. for label in state_labels:
  30. state_labeling.add_label(label)
  31. state_labeling.add_label_to_state('init', 0)
  32. # Choice labeling
  33. choice_labeling = stormpy.storage.ChoiceLabeling(6)
  34. # Add labels
  35. choice_labels = {'alpha', 'beta'}
  36. # Set labeling of choices
  37. for label in choice_labels:
  38. choice_labeling.add_label(label)
  39. choice_labeling.add_label_to_choice('alpha', 0)
  40. choice_labeling.add_label_to_choice('beta', 1)
  41. exit_rates = [0.0, 10.0, 12.0, 1.0, 1.0]
  42. markovian_states = stormpy.BitVector(5, [1, 2, 3, 4])
  43. # Collect components
  44. components = stormpy.SparseModelComponents(transition_matrix=transition_matrix, state_labeling=state_labeling,
  45. markovian_states=markovian_states)
  46. components.choice_labeling = choice_labeling
  47. components.exit_rates = exit_rates
  48. # Build the model
  49. ma = stormpy.storage.SparseMA(components)
  50. print(ma)
  51. if __name__ == '__main__':
  52. example_building_mas_01()