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.

57 lines
1.5 KiB

  1. import stormpy
  2. import stormpy.core
  3. import stormpy.simulator
  4. import stormpy.shields
  5. import stormpy.examples
  6. import stormpy.examples.files
  7. import random
  8. def optimal_shield_03():
  9. path = stormpy.examples.files.prism_smg_robot
  10. formula_str = "<path_correction, Optimal> <<sh>> R{\"travel_costs\"}min=? [ LRA ]"
  11. program = stormpy.parse_prism_program(path)
  12. formulas = stormpy.parse_properties_for_prism_program(formula_str, program)
  13. options = stormpy.BuilderOptions([p.raw_formula for p in formulas])
  14. options.set_build_state_valuations(True)
  15. options.set_build_choice_labels(True)
  16. options.set_build_all_labels()
  17. model = stormpy.build_sparse_model_with_options(program, options)
  18. result = stormpy.model_checking(model, formulas[0], extract_scheduler=True)
  19. assert result.has_scheduler
  20. print(F"Check Scheduler: {result.has_scheduler}")
  21. print(F"Check Shield: {result.has_schield}")
  22. print(type(result))
  23. shield = result.shield
  24. scheduler = result.scheduler
  25. print(type(shield))
  26. assert scheduler.memoryless
  27. assert scheduler.deterministic
  28. constructed_shield = shield.construct()
  29. print(type(constructed_shield))
  30. stormpy.shields.export_shieldDouble(model, shield)
  31. # for state in model.states:
  32. # choice = scheduler.get_choice(state)
  33. # action = choice.get_deterministic_choice()
  34. # print("In state {} choose action {}".format(state, action))
  35. # dtmc = model.apply_scheduler(scheduler)
  36. # print(dtmc)
  37. if __name__ == '__main__':
  38. optimal_shield_03()