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

2 months ago
  1. import stormpy
  2. import stormpy.gspn
  3. import stormpy.examples
  4. import stormpy.examples.files
  5. def example_gspns_02():
  6. # Use GSPNBuilder to construct a GSPN
  7. builder = stormpy.gspn.GSPNBuilder()
  8. builder.set_name("my_gspn")
  9. # Add immediate transition
  10. it_1 = builder.add_immediate_transition(1, 0.0, "it_1")
  11. it_layout = stormpy.gspn.LayoutInfo(1.5, 2.0)
  12. builder.set_transition_layout_info(it_1, it_layout)
  13. # Add timed transition
  14. tt_1 = builder.add_timed_transition(0, 0.4, "tt_1")
  15. tt_layout = stormpy.gspn.LayoutInfo(12.5, 2.0)
  16. builder.set_transition_layout_info(tt_1, tt_layout)
  17. # Add places
  18. place_1 = builder.add_place(1, 1, "place_1")
  19. p1_layout = stormpy.gspn.LayoutInfo(6.5, 2.0)
  20. builder.set_place_layout_info(place_1, p1_layout)
  21. place_2 = builder.add_place(1, 0, "place_2")
  22. p2_layout = stormpy.gspn.LayoutInfo(18.5, 2.0)
  23. builder.set_place_layout_info(place_2, p2_layout)
  24. # Link places and transitions by arcs
  25. builder.add_output_arc(it_1, place_1)
  26. builder.add_inhibition_arc(place_1, it_1)
  27. builder.add_input_arc(place_1, tt_1)
  28. builder.add_output_arc(tt_1, place_2)
  29. # Build GSPN
  30. gspn = builder.build_gspn()
  31. print("Name of GSPN: {}.".format(gspn.get_name()))
  32. print("Number of places: {}.".format(gspn.get_number_of_places()))
  33. print("Number of immediate transitions: {}.".format(gspn.get_number_of_immediate_transitions()))
  34. print("Number of timed transitions: {}.".format(gspn.get_number_of_timed_transitions()))
  35. # Export to file (PNPRO format)
  36. export_path = stormpy.examples.files.gspn_pnpro_simple
  37. gspn.export_gspn_pnpro_file(export_path)
  38. if __name__ == '__main__':
  39. example_gspns_02()