The source code and dockerfile for the GSW2024 AI Lab.
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

53 lines
1.4 KiB

4 weeks 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_ctmcs_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.5, 0, 0],
  15. [3, 0, 1.5, 0],
  16. [0, 3, 0, 1.5],
  17. [0, 0, 3, 0], ], dtype='float64')
  18. # Default row groups: [0,1,2,3]
  19. transition_matrix = stormpy.build_sparse_matrix(transitions)
  20. print(transition_matrix)
  21. # State labeling
  22. state_labeling = stormpy.storage.StateLabeling(4)
  23. state_labels = {'empty', 'init', 'deadlock', 'full'}
  24. for label in state_labels:
  25. state_labeling.add_label(label)
  26. # Adding label to states
  27. state_labeling.add_label_to_state('init', 0)
  28. state_labeling.add_label_to_state('empty', 0)
  29. state_labeling.add_label_to_state('full', 3)
  30. # Exit rate for each state
  31. exit_rates = [1.5, 4.5, 4.5, 3.0]
  32. # Collect components
  33. # rate_transitions = True, because the transition values are interpreted as rates
  34. components = stormpy.SparseModelComponents(transition_matrix=transition_matrix, state_labeling=state_labeling, rate_transitions=True)
  35. components.exit_rates = exit_rates
  36. # Build the model
  37. ctmc = stormpy.storage.SparseCtmc(components)
  38. print(ctmc)
  39. if __name__ == '__main__':
  40. example_building_ctmcs_01()