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.

44 lines
1.3 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. """
  8. Example of exporting a Pre Safety Shield
  9. to a file
  10. """
  11. def pre_schield():
  12. path = stormpy.examples.files.prism_mdp_lava_simple
  13. formula_str = "Pmax=? [G !\"AgentIsInLavaAndNotDone\"]"
  14. program = stormpy.parse_prism_program(path)
  15. formulas = stormpy.parse_properties_for_prism_program(formula_str, program)
  16. options = stormpy.BuilderOptions([p.raw_formula for p in formulas])
  17. options.set_build_state_valuations(True)
  18. options.set_build_choice_labels(True)
  19. options.set_build_all_labels()
  20. model = stormpy.build_sparse_model_with_options(program, options)
  21. initial_state = model.initial_states[0]
  22. assert initial_state == 0
  23. shield_specification = stormpy.logic.ShieldExpression(stormpy.logic.ShieldingType.POST_SAFETY, stormpy.logic.ShieldComparison.RELATIVE, 0.9)
  24. result = stormpy.model_checking(model, formulas[0], extract_scheduler=True, shield_expression=shield_specification)
  25. assert result.has_scheduler
  26. assert result.has_shield
  27. shield = result.shield
  28. stormpy.shields.export_shield(model, shield, "post.shield")
  29. if __name__ == '__main__':
  30. pre_schield()