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.

42 lines
1.2 KiB

  1. import stormpy
  2. import stormpy.core
  3. import stormpy.simulator
  4. import stormpy.examples
  5. import stormpy.examples.files
  6. import random
  7. """
  8. Simulator for nondeterministic models
  9. """
  10. def example_simulator_01():
  11. path = stormpy.examples.files.prism_mdp_maze
  12. prism_program = stormpy.parse_prism_program(path)
  13. model = stormpy.build_model(prism_program)
  14. simulator = stormpy.simulator.create_simulator(model, seed=42)
  15. # 5 paths of at most 20 steps.
  16. paths = []
  17. for m in range(5):
  18. path = []
  19. state = simulator.restart()
  20. path = [f"{state}"]
  21. for n in range(20):
  22. actions = simulator.available_actions()
  23. select_action = random.randint(0,len(actions)-1)
  24. #print(f"Randomly select action nr: {select_action} from actions {actions}")
  25. path.append(f"--act={actions[select_action]}-->")
  26. state = simulator.step(actions[select_action])
  27. #print(state)
  28. path.append(f"{state}")
  29. if simulator.is_done():
  30. #print("Trapped!")
  31. break
  32. paths.append(path)
  33. for path in paths:
  34. print(" ".join(path))
  35. if __name__ == '__main__':
  36. example_simulator_01()