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.

42 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. def optimal_shield_extraction():
  8. path = stormpy.examples.files.prism_smg_robot
  9. formula_str = "<Optimal> <<sh>> R{\"travel_costs\"}min=? [ LRA ]"
  10. program = stormpy.parse_prism_program(path)
  11. formulas = stormpy.parse_properties_for_prism_program(formula_str, program)
  12. options = stormpy.BuilderOptions([p.raw_formula for p in formulas])
  13. options.set_build_state_valuations(True)
  14. options.set_build_choice_labels(True)
  15. options.set_build_all_labels()
  16. model = stormpy.build_sparse_model_with_options(program, options)
  17. shield_specification = stormpy.logic.ShieldExpression(stormpy.logic.ShieldingType.OPTIMAL)
  18. result = stormpy.model_checking(model, formulas[0], extract_scheduler=True, shield_expression=shield_specification)
  19. assert result.has_scheduler
  20. assert result.has_shield
  21. shield = result.shield
  22. state_ids = [x for x in model.states]
  23. scheduler = shield.construct()
  24. for state_id in state_ids[0:50]:
  25. choices = scheduler.get_choice(state_id)
  26. print(F"Corrections in state {state_id}, are {choices.choice_map} ")
  27. if __name__ == '__main__':
  28. optimal_shield_extraction()