diff --git a/src/gspn/gspn.cpp b/src/gspn/gspn.cpp index 012970b..4bf14f8 100644 --- a/src/gspn/gspn.cpp +++ b/src/gspn/gspn.cpp @@ -9,6 +9,9 @@ using GSPN = storm::gspn::GSPN; using GSPNBuilder = storm::gspn::GspnBuilder; using LayoutInfo = storm::gspn::LayoutInfo; using Place = storm::gspn::Place; +using TimedTransition = storm::gspn::TimedTransition; +using ImmediateTransition = storm::gspn::ImmediateTransition; +using Transition = storm::gspn::Transition; void define_gspn(py::module& m) { @@ -16,12 +19,13 @@ void define_gspn(py::module& m) { // LayoutInfo class py::class_(m, "LayoutInfo") .def(py::init<>()) - .def(py::init(), "x"_a, "y"_a, "rotation"_a = 0.0) //todo add rotation predefined + .def(py::init(), "x"_a, "y"_a, "rotation"_a = 0.0) .def_readwrite("x", &LayoutInfo::x) .def_readwrite("y", &LayoutInfo::y) .def_readwrite("rotation", &LayoutInfo::rotation) ; + // Place class py::class_>(m, "Place", "Place in a GSPN") .def(py::init(), "id"_a) .def("get_name", &Place::getName, "Get name of this place") @@ -34,17 +38,43 @@ void define_gspn(py::module& m) { .def("has_restricted_capacity", &Place::hasRestrictedCapacity, "Is capacity of this place restricted") ; + // Transition class + py::class_>(m, "Transition", "Transition in a GSPN") + .def(py::init<>()) + .def("get_name", &Transition::getName, "Get name of this transition") + .def("set_name", &Transition::setName, "name"_a, "Set name of this transition") + // todo add missing + ; + // TimedTransition class - // ImmediateTransition + py::class_>(m, "TimedTransition", "TimedTransition in a GSPN") + .def(py::init<>()) + .def("get_rate", &TimedTransition::getRate, "Get rate of this transition") + .def("set_rate", &TimedTransition::setRate, "rate"_a, "Set rate of this transition") + .def("set_k_server_semantics", &TimedTransition::setKServerSemantics, "k"_a, "Set semantics of this transition") + .def("set_single_server_semantics", &TimedTransition::setSingleServerSemantics, "Set semantics of this transition") + .def("set_infinite_server_semantics", &TimedTransition::setInfiniteServerSemantics, "Set semantics of this transition") + .def("has_k_server_semantics", &TimedTransition::hasKServerSemantics, "Get semantics of this transition") + .def("has_single_server_semantics", &TimedTransition::hasSingleServerSemantics, "Get semantics of this transition") + .def("has_infinite_server_semantics", &TimedTransition::hasInfiniteServerSemantics, "Get semantics of this transition") + .def("get_number_of_servers", &TimedTransition::getNumberOfServers, "Get number of servers") + ; + // ImmediateTransition class + py::class_>(m, "ImmediateTransition", "ImmediateTransition in a GSPN") + .def(py::init<>()) + .def("get_weight", &ImmediateTransition::getWeight, "Get weight of this transition") + .def("set_weight", &ImmediateTransition::setWeight, "weight"_a, "Set weight of this transition") + .def("no_weight_attached", &ImmediateTransition::noWeightAttached, "True iff no weight is attached") + ; // GSPN class py::class_>(m, "GSPN", "Generalized Stochastic Petri Net") .def("name", &GSPN::getName, "Name of GSPN") .def("set_name", &GSPN::setName, "Set name of GSPN") - //todo constructor - // .def(py::init, ... >()) + // todo constructor: + // .def(py::init, ... >()) // todo write tests: .def_static("timed_transition_id_to_transition_id", &GSPN::timedTransitionIdToTransitionId) @@ -52,9 +82,9 @@ void define_gspn(py::module& m) { .def_static("transition_id_to_timed_transition_id", &GSPN::transitionIdToTimedTransitionId) .def_static("transition_id_to_immediate_transition_id", &GSPN::transitionIdToImmediateTransitionId) - // getNumberOfPlaces, getNumberOfImmediateTransitions, getNumberOfTimedTransitions, ... + // todo: getNumberOfPlaces, getNumberOfImmediateTransitions, getNumberOfTimedTransitions, ... + // todo export (see JaniToString) toPnpro, toPnml - //todo private? ; // GSPN_Builder class @@ -68,26 +98,20 @@ 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 + // todo: 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")) - // todo add 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")) - - - .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) .def("build_gspn", &GSPNBuilder::buildGspn, "Construct GSPN", py::arg("exprManager") = nullptr, py::arg("constantsSubstitution") = std::map()) - - ; } diff --git a/tests/gspn/test_gspn.py b/tests/gspn/test_gspn.py index ae54da1..b62e8cc 100644 --- a/tests/gspn/test_gspn.py +++ b/tests/gspn/test_gspn.py @@ -30,8 +30,8 @@ class TestGSPNBuilder: 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 + # assert place.has_restricted_capacity() == True + # assert place.get_capacity() == 5 p_name = "P_0" place.set_name(name = p_name) @@ -41,6 +41,26 @@ class TestGSPNBuilder: place.set_number_of_initial_tokens(p_tokens) assert place.get_number_of_initial_tokens() == p_tokens + def test_transition(self): + # test TimedTrasnition + tt = stormpy.gspn.TimedTransition() + tt_name = " tt" + tt.set_name(tt_name) + assert tt_name == tt.get_name() + tt_rate = 0.2 + tt.set_rate(tt_rate) + assert tt_rate == tt.get_rate() + + # test ImmediateTransition + ti = stormpy.gspn.ImmediateTransition() + ti_name = " ti" + ti.set_name(ti_name) + assert ti_name == ti.get_name() + assert ti.no_weight_attached() == True + ti_weight = 0.2 + ti.set_weight(ti_weight) + assert ti_weight == ti.get_weight() + assert ti.no_weight_attached() == False def test_build_gspn(self):