Browse Source

added functions to gspn_builder

refactoring
hannah 5 years ago
committed by Matthias Volk
parent
commit
279c24d6bd
  1. 45
      src/gspn/gspn.cpp
  2. 24
      tests/gspn/test_gspn.py

45
src/gspn/gspn.cpp

@ -20,20 +20,37 @@ void define_gspn(py::module& m) {
// GSPN_Builder class
py::class_<GSPNBuilder, std::shared_ptr<GSPNBuilder>>(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<uint64_t>
.def("add_timed_transition", py::overload_cast<uint_fast64_t const&, double const& , std::string const&>(&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<uint_fast64_t const&, double const& , boost::optional<uint64_t>, 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<uint_fast64_t const&, uint_fast64_t const&, uint_fast64_t const&>(&GSPNBuilder::addInputArc), py::arg("from"), py::arg("to"), py::arg("multiplicity"))
.def("add_input_arc", py::overload_cast<std::string const&, std::string const&, uint64_t>(&GSPNBuilder::addInputArc), py::arg("from"), py::arg("to"), py::arg("multiplicity"))
.def("add_inhibition_arc", py::overload_cast<uint_fast64_t const&, uint_fast64_t const&, uint_fast64_t const&>(&GSPNBuilder::addInhibitionArc), py::arg("from"), py::arg("to"), py::arg("multiplicity"))
.def("add_inhibition_arc", py::overload_cast<std::string const&, std::string const&, uint64_t>(&GSPNBuilder::addInhibitionArc), 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"))
// 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<storm::expressions::Variable, storm::expressions::Expression>())
// todo py::arg(...
// , py::arg("constantsSubstitution") = std::map<storm::expressions::Variable, storm::expressions::Expression>()
// todo: argument ExpressionManager, map <Variable,Expression> 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
;
}

24
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
Loading…
Cancel
Save