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.

51 lines
1.5 KiB

4 weeks ago
  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. """
  8. Example for the extraction of a Post Safety Shield
  9. from a model checking result and querying the shield
  10. for allowed actions.
  11. """
  12. def post_shield_extraction():
  13. path = stormpy.examples.files.prism_mdp_lava_simple
  14. formula_str = "Pmax=? [G !\"AgentIsInLavaAndNotDone\"]"
  15. program = stormpy.parse_prism_program(path)
  16. formulas = stormpy.parse_properties_for_prism_program(formula_str, program)
  17. options = stormpy.BuilderOptions([p.raw_formula for p in formulas])
  18. options.set_build_state_valuations(True)
  19. options.set_build_choice_labels(True)
  20. options.set_build_all_labels()
  21. model = stormpy.build_sparse_model_with_options(program, options)
  22. initial_state = model.initial_states[0]
  23. assert initial_state == 0
  24. shield_specification = stormpy.logic.ShieldExpression(stormpy.logic.ShieldingType.POST_SAFETY, stormpy.logic.ShieldComparison.RELATIVE, 0.9)
  25. result = stormpy.model_checking(model, formulas[0], extract_scheduler=True, shield_expression=shield_specification)
  26. assert result.has_scheduler
  27. assert result.has_shield
  28. shield = result.shield
  29. post_scheduler = shield.construct()
  30. for state_id in model.states:
  31. choices = post_scheduler.get_choice(state_id)
  32. print(F"Applied corrections in state {state_id}, are {choices.choice_map} ")
  33. if __name__ == '__main__':
  34. post_shield_extraction()