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.

61 lines
3.1 KiB

8 years ago
  1. #include "core.h"
  2. void define_core(py::module& m) {
  3. // Init
  4. m.def("_set_up", [](std::string const& args) {
  5. storm::utility::setUp();
  6. storm::settings::initializeAll("StoRM-Py", "stormpy");
  7. storm::settings::SettingsManager::manager().setFromString(args);
  8. }, "Initialize Storm", py::arg("arguments"));
  9. }
  10. void define_parse(py::module& m) {
  11. // Parse formulas
  12. m.def("parse_properties", &storm::parsePropertiesForExplicit, R"dox(
  13. Parse properties given in the prism format.
  14. :param str formula_str: A string of formulas
  15. :param str property_filter: A filter
  16. )dox", py::arg("formula_string"), py::arg("property_filter") = boost::none);
  17. m.def("parse_properties_for_prism_program", &storm::parsePropertiesForPrismProgram, R"dox(
  18. Parses properties given in the prism format, allows references to variables in the prism program.
  19. :param str formula_str: A string of formulas
  20. :param PrismProgram prism_program: A prism program
  21. :param str property_filter: A filter
  22. :return: A list of properties
  23. )dox", py::arg("formula_string"), py::arg("prism_program"), py::arg("property_filter") = boost::none);
  24. // Pair <Model,Formulas>
  25. py::class_<storm::storage::ModelFormulasPair>(m, "ModelFormulasPair", "Pair of model and formulas")
  26. .def_property_readonly("model", [](storm::storage::ModelFormulasPair const& pair) {
  27. return pair.model;
  28. }, "The model")
  29. .def_property_readonly("formulas", [](storm::storage::ModelFormulasPair const& pair) {
  30. return pair.formulas;
  31. }, "The formulas")
  32. ;
  33. // Parse explicit models
  34. m.def("parse_explicit_model", &storm::parser::AutoParser<>::parseModel, "Parse explicit model", py::arg("transition_file"), py::arg("labeling_file"), py::arg("state_reward_file") = "", py::arg("transition_reward_file") = "", py::arg("choice_labeling_file") = "");
  35. }
  36. // Thin wrapper for model building using one formula as argument
  37. template<typename ValueType>
  38. std::shared_ptr<storm::models::ModelBase> buildSymbolicModel(storm::prism::Program const& program, std::shared_ptr<storm::logic::Formula const> const& formula) {
  39. return storm::buildSymbolicModel<ValueType>(program, std::vector<std::shared_ptr<storm::logic::Formula const>>(1,formula));
  40. }
  41. template<typename ValueType>
  42. std::shared_ptr<storm::models::ModelBase> buildSparseModel(storm::prism::Program const& program, std::shared_ptr<storm::logic::Formula const> const& formula) {
  43. return storm::buildSparseModel<ValueType>(program, std::vector<std::shared_ptr<storm::logic::Formula const>>(1,formula));
  44. }
  45. void define_build(py::module& m) {
  46. // Build model
  47. m.def("_build_sparse_model_from_prism_program", &storm::buildSparseModel<double>, "Build the model", py::arg("program"), py::arg("formulas") = std::vector<std::shared_ptr<storm::logic::Formula const>>());
  48. m.def("_build_sparse_parametric_model_from_prism_program", &storm::buildSparseModel<storm::RationalFunction>, "Build the parametric model", py::arg("program"), py::arg("formulas"));
  49. }