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.

50 lines
1.5 KiB

2 months ago
  1. import stormpy
  2. import stormpy.core
  3. import stormpy.simulator
  4. import stormpy.shields
  5. import stormpy.logic
  6. import stormpy.examples
  7. import stormpy.examples.files
  8. """
  9. Example for the extraction of a Pre Safety Shield
  10. from a model checking result and querying the shield
  11. for allowed choices in a state.
  12. """
  13. def pre_shield_extraction():
  14. path = stormpy.examples.files.prism_mdp_lava_simple
  15. formula_str = "Pmax=? [G !\"AgentIsInLavaAndNotDone\"]"
  16. program = stormpy.parse_prism_program(path)
  17. formulas = stormpy.parse_properties_for_prism_program(formula_str, program)
  18. options = stormpy.BuilderOptions([p.raw_formula for p in formulas])
  19. options.set_build_state_valuations(True)
  20. options.set_build_choice_labels(True)
  21. options.set_build_all_labels()
  22. model = stormpy.build_sparse_model_with_options(program, options)
  23. initial_state = model.initial_states[0]
  24. assert initial_state == 0
  25. shield_specification = stormpy.logic.ShieldExpression(stormpy.logic.ShieldingType.PRE_SAFETY, stormpy.logic.ShieldComparison.RELATIVE, 0.9)
  26. result = stormpy.model_checking(model, formulas[0], extract_scheduler=True, shield_expression=shield_specification)
  27. assert result.has_scheduler
  28. assert result.has_shield
  29. shield = result.shield
  30. pre_scheduler = shield.construct()
  31. for state_id in model.states:
  32. choices = pre_scheduler.get_choice(state_id)
  33. print(F"Allowed choices in state {state_id}, are {choices.choice_map} ")
  34. if __name__ == '__main__':
  35. pre_shield_extraction()