diff --git a/src/gspn/gspn.cpp b/src/gspn/gspn.cpp index d0afd99..ac8f4e5 100644 --- a/src/gspn/gspn.cpp +++ b/src/gspn/gspn.cpp @@ -4,6 +4,7 @@ #include "storm-gspn/storage/gspn/GspnBuilder.h" #include "storm/settings/SettingsManager.h" +#include "storm-gspn/parser/GspnParser.h" #include "storm/utility/file.h" using GSPN = storm::gspn::GSPN; @@ -14,12 +15,19 @@ using TimedTransition = storm::gspn::TimedTransition; using ImmediateTransition = storm::gspn::ImmediateTransition; using Transition = storm::gspn::Transition; using TransitionPartition = storm::gspn::TransitionPartition; +using GSPNParser = storm::parser::GspnParser; -// todo to toPnproFile, totoPnmlFile (switch? to_pnpro) -void gspnToFile(GSPN const& gspn, std::string const& filepath) { + +void gspnToFile(GSPN const& gspn, std::string const& filepath, std::string const& option) { std::ofstream fs; storm::utility::openFile(filepath, fs); - gspn.toPnpro(fs); //gspn.toPnml(fs); + + if(option == "to-pnpro") { + gspn.toPnpro(fs); + } + else if (option == "to-pnml"){ + gspn.toPnml(fs); + } storm::utility::closeFile(fs); } @@ -42,7 +50,7 @@ void define_gspn(py::module& m) { .def("add_immediate_transition", &GSPNBuilder::addImmediateTransition, "Adds an immediate transition to the GSPN", py::arg("priority") = 0, py::arg("weight") = 0, py::arg("name") = "") - // todo: boost::optional + write tests: + // todo: problem with boost::optional + write tests: .def("add_timed_transition", py::overload_cast(&GSPNBuilder::addTimedTransition), "Adds an timed transition to the GSPN", py::arg("priority"), py::arg("rate"), py::arg("name") = "") .def("add_timed_transition", py::overload_cast, std::string const&>(&GSPNBuilder::addTimedTransition), "Adds an timed transition to the GSPN", py::arg("priority"), py::arg("rate"), py::arg("numServers"), py::arg("name") = "") .def("set_transition_layout_info", &GSPNBuilder::setTransitionLayoutInfo, "set transition layout information", py::arg("transitionId"), py::arg("layoutInfo")) @@ -62,10 +70,8 @@ void define_gspn(py::module& m) { py::class_>(m, "GSPN", "Generalized Stochastic Petri Net") // Constructor .def(py::init const& , std::vector const& , - std::vector const& , std::vector const& , - std::shared_ptr const& , std::map const& > (), - "name"_a, "places"_a, "itransitions"_a, "ttransitions"_a, "partitions"_a, "exprManager"_a, "constantsSubstitution"_a = std::map()) + std::vector const& , std::vector const& , std::shared_ptr const& , std::map const& > (), "name"_a, "places"_a, "itransitions"_a, "ttransitions"_a, "partitions"_a, "exprManager"_a, "constantsSubstitution"_a = std::map()) .def("name", &GSPN::getName, "Name of GSPN") .def("set_name", &GSPN::setName, "Set name of GSPN") @@ -73,20 +79,29 @@ void define_gspn(py::module& m) { .def("get_number_of_immediate_transitions", &GSPN::getNumberOfImmediateTransitions, "Get the number of immediate transitions in this GSPN") .def("get_number_of_timed_transitions", &GSPN::getNumberOfTimedTransitions, "Get the timed transitions in this GSPN") - // todo write tests: + // todo write tests: .def_static("timed_transition_id_to_transition_id", &GSPN::timedTransitionIdToTransitionId) .def_static("immediate_transition_id_to_transition_id", &GSPN::immediateTransitionIdToTransitionId) .def_static("transition_id_to_timed_transition_id", &GSPN::transitionIdToTimedTransitionId) .def_static("transition_id_to_immediate_transition_id", &GSPN::transitionIdToImmediateTransitionId) - // todo: getPartitions, getNumberOfPlaces, getNumberOfImmediateTransitions, getNumberOfTimedTransitions, ... and test (returns vector) - // todo getPlace getTra... + tests (returns pointer to place/..) + // todo: getPartitions, getNumberOfPlaces, getNumberOfImmediateTransitions, getNumberOfTimedTransitions, ... and test (returns vector) + // todo getPlace getTra... + tests (returns pointer to place/..) + + // GSPN export + .def("export_gspn_pnpro_file", [](GSPN& g, std::string const& filepath) -> void { gspnToFile(g, filepath, "to-pnpro"); }, "filepath"_a) + .def("export_gspn_pnml_file", [](GSPN& g, std::string const& filepath) -> void { gspnToFile(g, filepath, "to-pnml"); }, "filepath"_a) + + ; - // todo export (see JaniToString) toPnpro, toPnml - .def("export_gspn_pnpro_file", &gspnToFile, "filepath"_a) - .def("export_gspn_pnml_file", &gspnToFile, "filepath"_a) + // GspnParser class + py::class_>(m, "GSPNParser") + .def(py::init<>()) + //todo .def("parse", ) ; + + // LayoutInfo class py::class_(m, "LayoutInfo") .def(py::init<>()) @@ -149,6 +164,4 @@ void define_gspn(py::module& m) { - - }