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
2.1 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. from sklearn.linear_model import LogisticRegression
  8. from dtcontrol.benchmark_suite import BenchmarkSuite
  9. from dtcontrol.decision_tree.decision_tree import DecisionTree
  10. from dtcontrol.decision_tree.determinization.max_freq_determinizer import MaxFreqDeterminizer
  11. from dtcontrol.decision_tree.impurity.entropy import Entropy
  12. from dtcontrol.decision_tree.impurity.multi_label_entropy import MultiLabelEntropy
  13. from dtcontrol.decision_tree.splitting.axis_aligned import AxisAlignedSplittingStrategy
  14. from dtcontrol.decision_tree.splitting.linear_classifier import LinearClassifierSplittingStrategy
  15. from stormpy.decision_tree import create_decision_tree
  16. def export_shield_as_dot():
  17. path = stormpy.examples.files.prism_mdp_lava_simple
  18. formula_str = "Pmax=? [G !\"AgentIsInLavaAndNotDone\"]"
  19. program = stormpy.parse_prism_program(path)
  20. formulas = stormpy.parse_properties_for_prism_program(formula_str, program)
  21. options = stormpy.BuilderOptions([p.raw_formula for p in formulas])
  22. options.set_build_state_valuations(True)
  23. options.set_build_choice_labels(True)
  24. options.set_build_all_labels()
  25. options.set_build_with_choice_origins(True)
  26. model = stormpy.build_sparse_model_with_options(program, options)
  27. shield_specification = stormpy.logic.ShieldExpression(stormpy.logic.ShieldingType.PRE_SAFETY, stormpy.logic.ShieldComparison.RELATIVE, 0.9)
  28. result = stormpy.model_checking(model, formulas[0], extract_scheduler=True, shield_expression=shield_specification)
  29. assert result.has_shield
  30. shield = result.shield
  31. filename = "preshield.storm.json"
  32. stormpy.shields.export_shield(model, shield, filename)
  33. output_folder = "pre_trees"
  34. name = 'pre_my_output'
  35. aa = AxisAlignedSplittingStrategy()
  36. aa.priority = 1
  37. classifiers = [DecisionTree([aa], Entropy(), name)]
  38. suite = create_decision_tree(filename, name=name , output_folder=output_folder, export_pdf=True, classifiers=classifiers)
  39. suite.display_html()
  40. if __name__ == '__main__':
  41. export_shield_as_dot()