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.

55 lines
3.6 KiB

6 years ago
6 years ago
  1. #include "counterexample.h"
  2. #include "storm/environment/Environment.h"
  3. #include "storm-counterexamples/api/counterexamples.h"
  4. using namespace storm::counterexamples;
  5. // Define python bindings
  6. void define_counterexamples(py::module& m) {
  7. py::class_<boost::container::flat_set<uint_fast64_t>>(m, "FlatSet", "Container to pass to program")
  8. .def(py::init<>())
  9. .def("insert", [](boost::container::flat_set<uint_fast64_t>& flatset, uint64_t value) {flatset.insert(value);})
  10. .def("__str__", [](boost::container::flat_set<uint64_t> const& set) { std::stringstream str; str << "["; for(auto const& i : set) { str << i << ", ";} str << "]"; return str.str(); })
  11. .def("__len__", [](boost::container::flat_set<uint64_t> const& set) { return set.size();})
  12. ;
  13. using CexGeneratorStats = SMTMinimalLabelSetGenerator<double>::GeneratorStats;
  14. py::class_<CexGeneratorStats>(m, "SMTCounterExampleGeneratorStats", "Stats for highlevel counterexample generation")
  15. .def(py::init<>())
  16. .def_readonly("analysis_time", &CexGeneratorStats::analysisTime)
  17. .def_readonly("setup_time", &CexGeneratorStats::setupTime)
  18. .def_readonly("model_checking_time", &CexGeneratorStats::modelCheckingTime)
  19. .def_readonly("solver_time", &CexGeneratorStats::solverTime)
  20. .def_readonly("cut_time", &CexGeneratorStats::cutTime)
  21. .def_readonly("iterations", &CexGeneratorStats::iterations);
  22. using CexGeneratorOptions = SMTMinimalLabelSetGenerator<double>::Options;
  23. py::class_<CexGeneratorOptions>(m, "SMTCounterExampleGeneratorOptions", "Options for highlevel counterexample generation")
  24. .def(py::init<>())
  25. .def_readwrite("check_threshold_feasible", &CexGeneratorOptions::checkThresholdFeasible)
  26. .def_readwrite("encode_reachability", &CexGeneratorOptions::encodeReachability)
  27. .def_readwrite("silent", &CexGeneratorOptions::silent)
  28. .def_readwrite("add_backward_implication_cuts", &CexGeneratorOptions::addBackwardImplicationCuts)
  29. .def_readwrite("use_dynamic_constraints", &CexGeneratorOptions::useDynamicConstraints)
  30. .def_readwrite("maximum_counterexamples", &CexGeneratorOptions::maximumCounterexamples)
  31. .def_readwrite("continue_after_first_counterexample", &CexGeneratorOptions::continueAfterFirstCounterexampleUntil)
  32. .def_readwrite("maximum_iterations_after_counterexample", &CexGeneratorOptions::maximumExtraIterations)
  33. ;
  34. py::class_<SMTMinimalLabelSetGenerator<double>>(m, "SMTCounterExampleGenerator", "Highlevel Counterexample Generator with SMT as backend").
  35. def_static("precompute", &SMTMinimalLabelSetGenerator<double>::precompute, "Precompute input for counterexample generation", py::arg("env"), py::arg("symbolic_model"), py::arg("model"), py::arg("formula")).
  36. def_static("build", &SMTMinimalLabelSetGenerator<double>::computeCounterexampleLabelSet, "Compute counterexample", py::arg("env"), py::arg("stats"), py::arg("symbolic_model"), py::arg("model"), py::arg("cex_input"), py::arg("dontcare"), py::arg("options"))
  37. ;
  38. using CexInput = SMTMinimalLabelSetGenerator<double>::CexInput;
  39. py::class_<CexInput>(m, "SMTCounterExampleInput", "Precomputed input for counterexample generation")
  40. .def("add_reward_and_threshold", &CexInput::addRewardThresholdCombination, "add another reward structure and threshold", py::arg("reward_name"), py::arg("threshold"));
  41. }