From 279c24d6bd1d6d7fa1297ba63935ed14df2b018b Mon Sep 17 00:00:00 2001 From: hannah Date: Tue, 10 Mar 2020 20:11:16 +0100 Subject: [PATCH] added functions to gspn_builder --- src/gspn/gspn.cpp | 45 ++++++++++++++++++++++++++++------------- tests/gspn/test_gspn.py | 24 +++++++++++++++++++--- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/gspn/gspn.cpp b/src/gspn/gspn.cpp index 2049d0f..b1c00b4 100644 --- a/src/gspn/gspn.cpp +++ b/src/gspn/gspn.cpp @@ -20,20 +20,37 @@ void define_gspn(py::module& m) { // GSPN_Builder class py::class_>(m, "GSPNBuilder", "Generalized Stochastic Petri Net Builder") .def(py::init(), "Constructor") - .def("set_name", &GSPNBuilder::setGspnName, "Name of GSPN", py::arg("name")) - //.def("add_place", &GSPNBuilder::addPlace, "Add a place to the gspn", py::arg("todo")) - //.def("set_place_layout_info", &GSPNBuilder::setPlaceLayoutInfo, "Layout"py::arg("todo")) - //addImmediateTransition - //addTimedTransition - //addTimedTransition - //setTransitionLayoutInfo - //addInputArc todo overloaded fcts - //addInhibitionArc //todo overloaded fcts - //addOutputArc //todo overloaded fcts - //addNormalArc + .def("set_name", &GSPNBuilder::setGspnName, "Set name of GSPN", py::arg("name")) + + // todo: boost::optional + //.def("add_place", &GSPNBuilder::addPlace, "Add a place to the GSPN", py::arg("capacity") = 1, py::arg("initialTokens") = 0, py::arg("name") = std::string("")) + //.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") = uint_fast64_t(0), py::arg("weight") = double(0), py::arg("name") = std::string("")) + + // todo: boost::optional + .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") = std::string("")) + .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") = "") + + // todo descriptions + .def("add_input_arc", py::overload_cast(&GSPNBuilder::addInputArc), py::arg("from"), py::arg("to"), py::arg("multiplicity")) + .def("add_input_arc", py::overload_cast(&GSPNBuilder::addInputArc), py::arg("from"), py::arg("to"), py::arg("multiplicity")) + .def("add_inhibition_arc", py::overload_cast(&GSPNBuilder::addInhibitionArc), py::arg("from"), py::arg("to"), py::arg("multiplicity")) + .def("add_inhibition_arc", py::overload_cast(&GSPNBuilder::addInhibitionArc), 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")) + .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("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") = uint64_t(1)) + .def("build_gspn", &GSPNBuilder::buildGspn, "Construct GSPN", py::arg("exprManager") = nullptr, py::arg("constantsSubstitution") = std::map()) - // todo py::arg(... - // , py::arg("constantsSubstitution") = std::map() - // todo: argument ExpressionManager, map constantsSubstitution (aufrufe auch ohne args) + + // todo prvate? + // .def("is_timed_transition_id", &GSPNBuilder::isTimedTransitionId, py::arg("tid")) + // .def("is_immediate_transition_id", &GSPNBuilder::isImmediateTransitionId, py::arg("tid")) + // getTransition + ; } diff --git a/tests/gspn/test_gspn.py b/tests/gspn/test_gspn.py index 4948f27..d7a3b33 100644 --- a/tests/gspn/test_gspn.py +++ b/tests/gspn/test_gspn.py @@ -11,10 +11,28 @@ class TestGSPNBuilder: def test_build_gspn(self): # assert True # builder: ~/storm/src/storm-dft/transformations/DFTToGSPNTransformator.cpp - name = "gspn_test" + gspn_name = "gspn_test" builder = stormpy.gspn.GSPNBuilder() - builder.set_name(name) + builder.set_name(gspn_name) + # todo place tests, set_place_layout_info (boost) + # p_id_0 = builder.add_place(capacity = 1, initialTokens=0, name="place_test") + + ti_id_0 = builder.add_immediate_transition() + ti_id_1 = builder.add_immediate_transition(priority=0, weight=0.5, name="ti_1") + + tt_id_0 = builder.add_timed_transition(priority=0, rate=0.5, name="tt_0") + # todo problems with sumServers (boost) + # tt_id_1 = builder.add_timed_transition(priority=0, rate=0.5, numServers=2, name="tt_1") + + # todo tests for add_ (add_place needed) + # builder.add_input_arc(ti_id_0, ti_id_1, multiplicity = 2) + # todo test addNormalArc + # todo test setTransitionLayoutInfo ... + + gspn = builder.build_gspn() - assert gspn.name() == name + assert gspn.name() == gspn_name + +