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.

46 lines
1.5 KiB

2 months ago
  1. import stormpy
  2. import stormpy.core
  3. import stormpy.simulator
  4. import stormpy.examples
  5. import stormpy.examples.files
  6. """
  7. Simulator for deterministic models
  8. """
  9. def example_simulator_01():
  10. path = stormpy.examples.files.prism_dtmc_die
  11. prism_program = stormpy.parse_prism_program(path)
  12. model = stormpy.build_model(prism_program)
  13. simulator = stormpy.simulator.create_simulator(model, seed=42)
  14. final_outcomes = dict()
  15. for n in range(1000):
  16. while not simulator.is_done():
  17. observation, reward = simulator.step()
  18. if observation not in final_outcomes:
  19. final_outcomes[observation] = 1
  20. else:
  21. final_outcomes[observation] += 1
  22. simulator.restart()
  23. options = stormpy.BuilderOptions([])
  24. options.set_build_state_valuations()
  25. model = stormpy.build_sparse_model_with_options(prism_program, options)
  26. simulator = stormpy.simulator.create_simulator(model, seed=42)
  27. simulator.set_observation_mode(stormpy.simulator.SimulatorObservationMode.PROGRAM_LEVEL)
  28. final_outcomes = dict()
  29. for n in range(1000):
  30. while not simulator.is_done():
  31. observation, reward = simulator.step()
  32. if observation not in final_outcomes:
  33. final_outcomes[observation] = 1
  34. else:
  35. final_outcomes[observation] += 1
  36. simulator.restart()
  37. print(", ".join([f"{str(k)}: {v}" for k,v in final_outcomes.items()]))
  38. if __name__ == '__main__':
  39. example_simulator_01()