diff --git a/src/gspn/gspn.cpp b/src/gspn/gspn.cpp index a0c3394..012970b 100644 --- a/src/gspn/gspn.cpp +++ b/src/gspn/gspn.cpp @@ -8,18 +8,36 @@ using GSPN = storm::gspn::GSPN; using GSPNBuilder = storm::gspn::GspnBuilder; using LayoutInfo = storm::gspn::LayoutInfo; +using Place = storm::gspn::Place; void define_gspn(py::module& m) { + // LayoutInfo class py::class_(m, "LayoutInfo") .def(py::init<>()) - .def(py::init(), py::arg("x"), py::arg("y"), py::arg("rotation") = 0.0) //todo add rotation predefined + .def(py::init(), "x"_a, "y"_a, "rotation"_a = 0.0) //todo add rotation predefined .def_readwrite("x", &LayoutInfo::x) .def_readwrite("y", &LayoutInfo::y) .def_readwrite("rotation", &LayoutInfo::rotation) ; + py::class_>(m, "Place", "Place in a GSPN") + .def(py::init(), "id"_a) + .def("get_name", &Place::getName, "Get name of this place") + .def("set_name", &Place::setName, "name"_a, "Set name of this place") + .def("get_id", &Place::getID, "Get the id of this place") + .def("set_number_of_initial_tokens", &Place::setNumberOfInitialTokens, "tokens"_a, "Set the number of initial tokens of this place") + .def("get_number_of_initial_tokens", &Place::getNumberOfInitialTokens, "Get the number of initial tokens of this place") + .def("set_capacity", &Place::setCapacity, "cap"_a, "Set the capacity of tokens of this place") + .def("get_capacity", &Place::getCapacity, "Get the capacity of tokens of this place") + .def("has_restricted_capacity", &Place::hasRestrictedCapacity, "Is capacity of this place restricted") + ; + + // TimedTransition class + // ImmediateTransition + + // GSPN class py::class_>(m, "GSPN", "Generalized Stochastic Petri Net") .def("name", &GSPN::getName, "Name of GSPN") @@ -46,7 +64,6 @@ void define_gspn(py::module& m) { // todo: boost::optional capacity //.def("add_place", &GSPNBuilder::addPlace, "Add a place to the GSPN", py::arg("capacity") = 1, py::arg("initialTokens") = 0, py::arg("name") = "") - //.def("set_place_layout_info", &GSPNBuilder::setPlaceLayoutInfo, "Set place layout information", py::arg("placeId"), py::arg("layoutInfo")) .def("add_immediate_transition", &GSPNBuilder::addImmediateTransition, "Adds an immediate transition to the GSPN", py::arg("priority") = 0, py::arg("weight") = 0, py::arg("name") = "") @@ -63,8 +80,8 @@ void define_gspn(py::module& m) { .def("add_output_arc", py::overload_cast(&GSPNBuilder::addOutputArc), py::arg("from"), py::arg("to"), py::arg("multiplicity")) .def("add_output_arc", py::overload_cast(&GSPNBuilder::addOutputArc), py::arg("from"), py::arg("to"), py::arg("multiplicity")) - // todo LayoutInfo - //.def("set_transition_layout_info", &GSPNBuilder::setTransitionLayoutInfo, "set transition layout information", py::arg("transitionId"), py::arg("layoutInfo")) + + .def("set_transition_layout_info", &GSPNBuilder::setTransitionLayoutInfo, "set transition layout information", py::arg("transitionId"), py::arg("layoutInfo")) .def("add_normal_arc", &GSPNBuilder::addNormalArc, "Add normal arc from a named element to a named element", py::arg("from"), py::arg("to"), py::arg("multiplicity") = 1) diff --git a/tests/gspn/test_gspn.py b/tests/gspn/test_gspn.py index 0b8078e..ae54da1 100644 --- a/tests/gspn/test_gspn.py +++ b/tests/gspn/test_gspn.py @@ -22,10 +22,28 @@ class TestGSPNBuilder: layout_xyr = stormpy.gspn.LayoutInfo(2, 3, 4) assert layout_xyr.rotation == 4 + def test_place(self): + p_id = 4 + place = stormpy.gspn.Place(id = p_id) + assert p_id == place.get_id() + + assert place.has_restricted_capacity() == False + # todo this does not work (boost::optional ?): + place.set_capacity(cap = 5) + #assert place.has_restricted_capacity() == True + #assert place.get_capacity() == 5 + + p_name = "P_0" + place.set_name(name = p_name) + assert place.get_name() == p_name + + p_tokens = 2 + place.set_number_of_initial_tokens(p_tokens) + assert place.get_number_of_initial_tokens() == p_tokens - def test_build_gspn(self): + def test_build_gspn(self): gspn_name = "gspn_test" builder = stormpy.gspn.GSPNBuilder() @@ -46,15 +64,16 @@ class TestGSPNBuilder: # todo test addNormalArc # todo test setTransitionLayoutInfo ... - - #builder.setTransitionLayoutInfo(tPropagationDontCare,layout); - + # todo test setLayout info + layout = stormpy.gspn.LayoutInfo(1,2) + builder.set_transition_layout_info(ti_id_0, layout) gspn = builder.build_gspn() assert gspn.name() == gspn_name gspn_new_name = "new_name" gspn.set_name(gspn_new_name) + assert gspn.name() == gspn_new_name