diff --git a/src/gspn/gspn.cpp b/src/gspn/gspn.cpp index 378a626..a9b64de 100644 --- a/src/gspn/gspn.cpp +++ b/src/gspn/gspn.cpp @@ -18,14 +18,14 @@ using TransitionPartition = storm::gspn::TransitionPartition; using GSPNParser = storm::parser::GspnParser; -void gspnToFile(GSPN const& gspn, std::string const& filepath, std::string const& option) { +void gspnToFile(GSPN const& gspn, std::string const& filepath, bool toPnpro) { std::ofstream fs; storm::utility::openFile(filepath, fs); - if(option == "to-pnpro") { + if(toPnpro) { gspn.toPnpro(fs); } - else if (option == "to-pnml"){ + else { gspn.toPnml(fs); } storm::utility::closeFile(fs); @@ -39,7 +39,7 @@ void define_gspn(py::module& m) { .def(py::init(), "Constructor") .def("set_name", &GSPNBuilder::setGspnName, "Set name of GSPN", "name"_a) - .def("add_place", &GSPNBuilder::addPlace, "Add a place to the GSPN", py::arg("capacity") = 1, py::arg("initialTokens") = 0, py::arg("name") = "") + .def("add_place", &GSPNBuilder::addPlace, "Add a place to the GSPN", py::arg("capacity") = 1, py::arg("initial_tokens") = 0, py::arg("name") = "") .def("set_place_layout_info", &GSPNBuilder::setPlaceLayoutInfo, py::arg("place_id"), py::arg("layout_info"), R"doc( Set place layout information. @@ -49,8 +49,8 @@ void define_gspn(py::module& m) { .def("add_immediate_transition", &GSPNBuilder::addImmediateTransition, "Add an immediate transition to the GSPN", "priority"_a = 0, "weight"_a = 0, "name"_a = "") .def("add_timed_transition", py::overload_cast(&GSPNBuilder::addTimedTransition), "Add a timed transition to the GSPN", "priority"_a, "rate"_a, "name"_a = "") - .def("add_timed_transition", py::overload_cast const&, std::string const&>(&GSPNBuilder::addTimedTransition), "priority"_a, "rate"_a, "numServers"_a, "name"_a = "") - .def("set_transition_layout_info", &GSPNBuilder::setTransitionLayoutInfo, "transitionId"_a, "layoutInfo"_a, R"doc( + .def("add_timed_transition", py::overload_cast const&, std::string const&>(&GSPNBuilder::addTimedTransition), "priority"_a, "rate"_a, "num_servers"_a, "name"_a = "") + .def("set_transition_layout_info", &GSPNBuilder::setTransitionLayoutInfo, "transition_id"_a, "layout_info"_a, R"doc( Set transition layout information. :param uint64_t id: The ID of the transition. @@ -97,21 +97,21 @@ void define_gspn(py::module& m) { :param uint64_t multiplicity: Multiplicity of the arc, default = 1. )doc") - .def("build_gspn", &GSPNBuilder::buildGspn, "Construct GSPN", "exprManager"_a = nullptr, "constantsSubstitution"_a = std::map()) + .def("build_gspn", &GSPNBuilder::buildGspn, "Construct GSPN", "expression_manager"_a = nullptr, "constants_substitution"_a = std::map()) ; // GspnParser class py::class_>(m, "GSPNParser") .def(py::init<>()) - .def("parse", [](GSPNParser& p, std::string const& filename, std::string const& constantDefinitions) -> GSPN& {return *(p.parse(filename,constantDefinitions)); }, "filename"_a, "constantDefinitions"_a = "") + .def("parse", [](GSPNParser& p, std::string const& filename, std::string const& constantDefinitions) -> GSPN& {return *(p.parse(filename,constantDefinitions)); }, "filename"_a, "constant_definitions"_a = "") ; // GSPN class 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()) + .def(py::init const&, std::vector const&, + std::vector const&, std::vector const&, std::shared_ptr const&, std::map const&>(), "name"_a, "places"_a, "immediate_transitions"_a, "timed_transitions"_a, "partitions"_a, "expression_manager"_a, "constants_substitution"_a = std::map()) .def("get_name", &GSPN::getName, "Get name of GSPN") .def("set_name", &GSPN::setName, "Set name of GSPN") @@ -152,8 +152,8 @@ void define_gspn(py::module& m) { .def("is_valid", &GSPN::isValid, "Perform some checks") // GSPN export - .def("export_gspn_pnpro_file", [](GSPN& g, std::string const& filepath) -> void { gspnToFile(g, filepath, "to-pnpro"); }, "filepath"_a, "Export GSPN to PNPRO file") - .def("export_gspn_pnml_file", [](GSPN& g, std::string const& filepath) -> void { gspnToFile(g, filepath, "to-pnml"); }, "filepath"_a, "Export GSPN to PNML file") + .def("export_gspn_pnpro_file", [](GSPN& g, std::string const& filepath) -> void { gspnToFile(g, filepath, true); }, "filepath"_a, "Export GSPN to PNPRO file") + .def("export_gspn_pnml_file", [](GSPN& g, std::string const& filepath) -> void { gspnToFile(g, filepath, false); }, "filepath"_a, "Export GSPN to PNML file") .def_static("timed_transition_id_to_transition_id", &GSPN::timedTransitionIdToTransitionId) .def_static("immediate_transition_id_to_transition_id", &GSPN::immediateTransitionIdToTransitionId) diff --git a/tests/gspn/test_gspn.py b/tests/gspn/test_gspn.py index cd797b6..a89142e 100644 --- a/tests/gspn/test_gspn.py +++ b/tests/gspn/test_gspn.py @@ -27,7 +27,7 @@ class TestGSPNBuilder: place = stormpy.gspn.Place(id=p_id) assert p_id == place.get_id() - assert not place.has_restricted_capacity() + assert not place.has_restricted_capacity() place.set_capacity(cap=5) assert place.has_restricted_capacity() assert place.get_capacity() == 5 @@ -90,9 +90,9 @@ class TestGSPNBuilder: builder = stormpy.gspn.GSPNBuilder() id_p_0 = builder.add_place() - id_p_1 = builder.add_place(initialTokens=1) - id_p_2 = builder.add_place(initialTokens=0, name="place_2") - id_p_3 = builder.add_place(capacity=2, initialTokens=3, name="place_3") + id_p_1 = builder.add_place(initial_tokens=1) + id_p_2 = builder.add_place(initial_tokens=0, name="place_2") + id_p_3 = builder.add_place(capacity=2, initial_tokens=3, name="place_3") p_layout = stormpy.gspn.LayoutInfo(1, 2) builder.set_place_layout_info(id_p_0, p_layout) @@ -100,7 +100,7 @@ class TestGSPNBuilder: id_ti_1 = builder.add_immediate_transition() id_tt_0 = builder.add_timed_transition(priority=2, rate=0.4, name="tt_0") - id_tt_1 = builder.add_timed_transition(priority=0, rate=0.5, numServers=2, name="tt_1") + id_tt_1 = builder.add_timed_transition(priority=0, rate=0.5, num_servers=2, name="tt_1") t_layout = stormpy.gspn.LayoutInfo(1, 2) builder.set_transition_layout_info(id_ti_0, t_layout) @@ -176,9 +176,9 @@ class TestGSPNBuilder: # add places and transitions id_p_0 = builder.add_place() - id_p_1 = builder.add_place(initialTokens=3, name="place_1", capacity=2) + id_p_1 = builder.add_place(initial_tokens=3, name="place_1", capacity=2) id_ti_0 = builder.add_immediate_transition(priority=0, weight=0.5, name="ti_0") - id_tt_0 = builder.add_timed_transition(priority=0, rate=0.5, numServers=2, name="tt_0") + id_tt_0 = builder.add_timed_transition(priority=0, rate=0.5, num_servers=2, name="tt_0") gspn = builder.build_gspn() @@ -217,9 +217,9 @@ class TestGSPNBuilder: # add places and transitions id_p_0 = builder.add_place() - id_p_1 = builder.add_place(initialTokens=3, name="place_1", capacity=2) + id_p_1 = builder.add_place(initial_tokens=3, name="place_1", capacity=2) id_ti_0 = builder.add_immediate_transition(priority=0, weight=0.5, name="ti_0") - id_tt_0 = builder.add_timed_transition(priority=0, rate=0.5, numServers=2, name="tt_0") + id_tt_0 = builder.add_timed_transition(priority=0, rate=0.5, num_servers=2, name="tt_0") gspn = builder.build_gspn()