Browse Source

added Place class

refactoring
hannah 5 years ago
committed by Matthias Volk
parent
commit
c8a9230e6e
  1. 25
      src/gspn/gspn.cpp
  2. 27
      tests/gspn/test_gspn.py

25
src/gspn/gspn.cpp

@ -8,18 +8,36 @@
using GSPN = storm::gspn::GSPN; using GSPN = storm::gspn::GSPN;
using GSPNBuilder = storm::gspn::GspnBuilder; using GSPNBuilder = storm::gspn::GspnBuilder;
using LayoutInfo = storm::gspn::LayoutInfo; using LayoutInfo = storm::gspn::LayoutInfo;
using Place = storm::gspn::Place;
void define_gspn(py::module& m) { void define_gspn(py::module& m) {
// LayoutInfo class // LayoutInfo class
py::class_<LayoutInfo>(m, "LayoutInfo") py::class_<LayoutInfo>(m, "LayoutInfo")
.def(py::init<>()) .def(py::init<>())
.def(py::init<double, double, double>(), py::arg("x"), py::arg("y"), py::arg("rotation") = 0.0) //todo add rotation predefined
.def(py::init<double, double, double>(), "x"_a, "y"_a, "rotation"_a = 0.0) //todo add rotation predefined
.def_readwrite("x", &LayoutInfo::x) .def_readwrite("x", &LayoutInfo::x)
.def_readwrite("y", &LayoutInfo::y) .def_readwrite("y", &LayoutInfo::y)
.def_readwrite("rotation", &LayoutInfo::rotation) .def_readwrite("rotation", &LayoutInfo::rotation)
; ;
py::class_<Place, std::shared_ptr<Place>>(m, "Place", "Place in a GSPN")
.def(py::init<uint64_t>(), "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 // GSPN class
py::class_<GSPN, std::shared_ptr<GSPN>>(m, "GSPN", "Generalized Stochastic Petri Net") py::class_<GSPN, std::shared_ptr<GSPN>>(m, "GSPN", "Generalized Stochastic Petri Net")
.def("name", &GSPN::getName, "Name of GSPN") .def("name", &GSPN::getName, "Name of GSPN")
@ -46,7 +64,6 @@ void define_gspn(py::module& m) {
// todo: boost::optional<uint64_t> capacity // todo: boost::optional<uint64_t> capacity
//.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("initialTokens") = 0, py::arg("name") = "")
//.def("set_place_layout_info", &GSPNBuilder::setPlaceLayoutInfo, "Set place layout information", py::arg("placeId"), py::arg("layoutInfo")) //.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") = "") .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<uint_fast64_t const&, uint_fast64_t const&, uint_fast64_t const&>(&GSPNBuilder::addOutputArc), py::arg("from"), py::arg("to"), py::arg("multiplicity")) .def("add_output_arc", py::overload_cast<uint_fast64_t const&, uint_fast64_t const&, uint_fast64_t const&>(&GSPNBuilder::addOutputArc), py::arg("from"), py::arg("to"), py::arg("multiplicity"))
.def("add_output_arc", py::overload_cast<std::string const&, std::string const&, uint64_t>(&GSPNBuilder::addOutputArc), py::arg("from"), py::arg("to"), py::arg("multiplicity")) .def("add_output_arc", py::overload_cast<std::string const&, std::string const&, uint64_t>(&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) .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)

27
tests/gspn/test_gspn.py

@ -22,10 +22,28 @@ class TestGSPNBuilder:
layout_xyr = stormpy.gspn.LayoutInfo(2, 3, 4) layout_xyr = stormpy.gspn.LayoutInfo(2, 3, 4)
assert layout_xyr.rotation == 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<uint64_t> ?):
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" gspn_name = "gspn_test"
builder = stormpy.gspn.GSPNBuilder() builder = stormpy.gspn.GSPNBuilder()
@ -46,15 +64,16 @@ class TestGSPNBuilder:
# todo test addNormalArc # todo test addNormalArc
# todo test setTransitionLayoutInfo ... # 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() gspn = builder.build_gspn()
assert gspn.name() == gspn_name assert gspn.name() == gspn_name
gspn_new_name = "new_name" gspn_new_name = "new_name"
gspn.set_name(gspn_new_name) gspn.set_name(gspn_new_name)
assert gspn.name() == gspn_new_name assert gspn.name() == gspn_new_name

Loading…
Cancel
Save