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.

47 lines
1.5 KiB

  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 = 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. print(final_outcomes)
  24. options = stormpy.BuilderOptions([])
  25. options.set_build_state_valuations()
  26. model = stormpy.build_sparse_model_with_options(prism_program, options)
  27. simulator = stormpy.simulator.create_simulator(model, seed=42)
  28. simulator.set_observation_mode(stormpy.simulator.SimulatorObservationMode.PROGRAM_LEVEL)
  29. final_outcomes = dict()
  30. for n in range(1000):
  31. while not simulator.is_done():
  32. observation = simulator.step()
  33. if observation not in final_outcomes:
  34. final_outcomes[observation] = 1
  35. else:
  36. final_outcomes[observation] += 1
  37. simulator.restart()
  38. print(", ".join([f"{str(k)}: {v}" for k,v in final_outcomes.items()]))
  39. if __name__ == '__main__':
  40. example_simulator_01()