Browse Source

added dtcontrol dependency

export file handling
refactoring
Thomas Knoll 1 year ago
parent
commit
f2695b54d8
  1. 2
      examples/shields/04_pre_shield_export.py
  2. 2
      examples/shields/05_post_shield_export.py
  3. 2
      examples/shields/06_optimal_shield_export.py
  4. 40
      examples/shields/09_dtcontrol.py
  5. 17
      lib/stormpy/dtcontrol.py
  6. 2
      setup.py
  7. 2
      src/shields/shield_handling.cpp

2
examples/shields/04_pre_shield_export.py

@ -36,7 +36,7 @@ def pre_schield():
shield = result.shield
stormpy.shields.export_shieldDouble(model, shield)
stormpy.shields.export_shieldDouble(model, shield, "pre.shield")

2
examples/shields/05_post_shield_export.py

@ -36,7 +36,7 @@ def pre_schield():
shield = result.shield
stormpy.shields.export_shieldDouble(model, shield)
stormpy.shields.export_shieldDouble(model, shield, "post.shield")

2
examples/shields/06_optimal_shield_export.py

@ -33,7 +33,7 @@ def optimal_shield_export():
shield = result.shield
stormpy.shields.export_shieldDouble(model, shield)
stormpy.shields.export_shieldDouble(model, shield, "optimal.shield")
if __name__ == '__main__':

40
examples/shields/09_dtcontrol.py

@ -0,0 +1,40 @@
import stormpy
import stormpy.core
import stormpy.simulator
import stormpy.shields
import stormpy.examples
import stormpy.examples.files
from stormpy.dtcontrol import export_decision_tree
def export_shield_as_dot():
path = stormpy.examples.files.prism_mdp_lava_simple
formula_str = "<pre, PreSafety, lambda=0.9> Pmax=? [G !\"AgentIsInLavaAndNotDone\"]"
program = stormpy.parse_prism_program(path)
formulas = stormpy.parse_properties_for_prism_program(formula_str, program)
options = stormpy.BuilderOptions([p.raw_formula for p in formulas])
options.set_build_state_valuations(True)
options.set_build_choice_labels(True)
options.set_build_all_labels()
options.set_build_with_choice_origins(True)
model = stormpy.build_sparse_model_with_options(program, options)
result = stormpy.model_checking(model, formulas[0], extract_scheduler=True) #, shielding_expression=shield_specification)
assert result.has_shield
shield = result.shield
stormpy.shields.export_shieldDouble(model, shield, "preshield.storm.json")
export_decision_tree(result.shield)
if __name__ == '__main__':
export_shield_as_dot()

17
lib/stormpy/dtcontrol.py

@ -0,0 +1,17 @@
import json
import logging
from os.path import splitext, exists
from sklearn.linear_model import LogisticRegression
import numpy as np
from dtcontrol.dataset.dataset_loader import DatasetLoader
from dtcontrol.decision_tree.decision_tree import DecisionTree
from dtcontrol.decision_tree.impurity.entropy import Entropy
from dtcontrol.decision_tree.splitting.axis_aligned import AxisAlignedSplittingStrategy
from dtcontrol.decision_tree.splitting.linear_classifier import LinearClassifierSplittingStrategy
def export_decision_tree(filename):
pass

2
setup.py

@ -275,7 +275,7 @@ setup(
cmdclass={'build_ext': CMakeBuild},
zip_safe=False,
install_requires=['pycarl>=2.0.4'],
install_requires=['pycarl>=2.0.4', 'dtcontrol'],
setup_requires=['pytest-runner'],
tests_require=['pytest', 'nbval'],
extras_require={

2
src/shields/shield_handling.cpp

@ -7,7 +7,7 @@ template <typename ValueType, typename IndexType>
void define_shield_handling(py::module& m, std::string vt_suffix) {
std::string shieldHandlingname = std::string("export_shield") + vt_suffix;
m.def(shieldHandlingname.c_str(), &storm::api::exportShield<ValueType, IndexType>, py::arg("model"), py::arg("shield"));
m.def(shieldHandlingname.c_str(), &storm::api::exportShield<ValueType, IndexType>, py::arg("model"), py::arg("shield"), py::arg("filename"));
}
template void define_shield_handling<double, typename storm::storage::SparseMatrix<double>::index_type>(py::module& m, std::string vt_suffix);

Loading…
Cancel
Save