From 2eec1828c186374177314a023e4ebd4f29da9b98 Mon Sep 17 00:00:00 2001 From: Matthias Volk Date: Mon, 30 Mar 2020 18:51:06 +0200 Subject: [PATCH] GSPNs methods using boost::optional are working after fix in Storm --- src/gspn/gspn.cpp | 6 +++--- tests/gspn/test_gspn.py | 30 +++++++++++++----------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/gspn/gspn.cpp b/src/gspn/gspn.cpp index 99e0a0b..c6dba99 100644 --- a/src/gspn/gspn.cpp +++ b/src/gspn/gspn.cpp @@ -40,8 +40,8 @@ void define_gspn(py::module& m) { .def("set_name", &GSPNBuilder::setGspnName, "Set name of GSPN", "name"_a) // 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_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")) // does not work either: //.def("add_place", [](GSPNBuilder& b, boost::optional capacity = boost::optional(1), uint_fast64_t const& initialTokens = 0, std::string const& name = "") { @@ -51,7 +51,7 @@ void define_gspn(py::module& m) { // todo: problem with boost::optional + write tests: .def("add_timed_transition", py::overload_cast(&GSPNBuilder::addTimedTransition), "Adds an timed transition to the GSPN", "priority"_a, "rate"_a, "name"_a = "") - .def("add_timed_transition", py::overload_cast, std::string const&>(&GSPNBuilder::addTimedTransition), "Adds an timed transition to the GSPN", "priority"_a, "rate"_a, "numServers"_a, "name"_a = "") + .def("add_timed_transition", py::overload_cast const&, std::string const&>(&GSPNBuilder::addTimedTransition), "Adds an timed transition to the GSPN", "priority"_a, "rate"_a, "numServers"_a, "name"_a = "") .def("set_transition_layout_info", &GSPNBuilder::setTransitionLayoutInfo, "set transition layout information", "transitionId"_a, "layoutInfo"_a) // todo write tests diff --git a/tests/gspn/test_gspn.py b/tests/gspn/test_gspn.py index 7da5ecd..c1ebcd1 100644 --- a/tests/gspn/test_gspn.py +++ b/tests/gspn/test_gspn.py @@ -32,8 +32,8 @@ class TestGSPNBuilder: assert place.has_restricted_capacity() == False # todo this does not work (boost::optional problem?): place.set_capacity(cap = 5) - # assert place.has_restricted_capacity() == True - # assert place.get_capacity() == 5 + assert place.has_restricted_capacity() == True + assert place.get_capacity() == 5 p_name = "P_0" place.set_name(name = p_name) @@ -44,7 +44,7 @@ class TestGSPNBuilder: assert place.get_number_of_initial_tokens() == p_tokens def test_transition(self): - # test TimedTrasnition + # test TimedTransition tt = stormpy.gspn.TimedTransition() tt_name = " tt" tt.set_name(tt_name) @@ -72,17 +72,17 @@ class TestGSPNBuilder: builder.set_name(gspn_name) # todo place tests, set_place_layout_info (boost) - # p_0 = builder.add_place() - # p_1 = builder.add_place(capacity = 2, initialTokens = 0, name = "place_test") - # p_layout = stormpy.gspn.LayoutInfo(1, 2) - # builder.set_place_layout_info(p_0, t_layout) + p_0 = builder.add_place() + p_1 = builder.add_place(capacity = 2, initialTokens = 0, name = "place_test") + p_layout = stormpy.gspn.LayoutInfo(1, 2) + builder.set_place_layout_info(p_0, p_layout) ti_0 = builder.add_immediate_transition(priority=1, weight=0.5, name="ti_0") ti_1 = builder.add_immediate_transition() tt_0 = builder.add_timed_transition(priority=2, rate=0.4, name="tt_0") # todo problems with sumServers (boost) - # tt_1 = builder.add_timed_transition(priority=0, rate=0.5, numServers=2, name="tt_1") + tt_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) @@ -96,8 +96,8 @@ class TestGSPNBuilder: assert gspn.get_name() == gspn_name assert gspn.get_number_of_immediate_transitions() == 2 - # assert gspn.get_number_of_timed_transitions() == 2 - # assert gspn.get_number_of_places() == 2 + assert gspn.get_number_of_timed_transitions() == 2 + assert gspn.get_number_of_places() == 2 cp_ti_0 = gspn.get_immediate_transition("ti_0") assert cp_ti_0.get_id() == ti_0 assert cp_ti_0.get_weight() == 0.5 @@ -106,9 +106,9 @@ class TestGSPNBuilder: assert cp_tt_0.get_id() == tt_0 assert cp_tt_0.get_rate() == 0.4 assert cp_tt_0.get_priority() == 2 - # cp_p_0 = gspn.get_immediate_transition("p_0") - # assert cp_p_0.get_id() == p_0 - # assert cp_p_0.get_capacity() == 2 + cp_p_1 = gspn.get_place("place_test") + assert cp_p_1.get_id() == p_1 + assert cp_p_1.get_capacity() == 2 gspn_new_name = "new_name" gspn.set_name(gspn_new_name) @@ -163,7 +163,3 @@ class TestGSPNBuilder: cp_ti_0 = gspn_import.get_immediate_transition("ti_0") assert cp_ti_0.get_id() == ti_0 - - - -