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.

31 lines
1.0 KiB

3 months ago
  1. # TODO: it is not obvious which of these imports are needed under what circumstances
  2. # note that this script runs fine without stormpy[.core]!
  3. import stormpy
  4. import stormpy.core
  5. import stormpy.examples
  6. import stormpy.examples.files
  7. from stormpy.utility import ShortestPathsGenerator
  8. def example_shortest_paths():
  9. path = stormpy.examples.files.prism_dtmc_die
  10. prism_program = stormpy.parse_prism_program(path)
  11. model = stormpy.build_model(prism_program)
  12. state_id = 8
  13. spg = ShortestPathsGenerator(model, state_id)
  14. # TODO: it's unintuitive to return the paths reversed, change that
  15. # the reason for being reversed in the first place is that the algorithm traverses them in that order
  16. print("Note: Paths are traversed in reverse (from target back to the initial state).")
  17. for k in range(1, 4):
  18. path = spg.get_path_as_list(k)
  19. distance = spg.get_distance(k)
  20. print("{}-shortest path to state #{}: {}, with distance {}".format(k, state_id, path, distance))
  21. if __name__ == '__main__':
  22. example_shortest_paths()