PNML
Note
Depreciated
the library Pm4Py is used to create pnml-files more easily. So you can create pnml files with python. In the example-folder under example/create_pnml
examples
initialize a net
net = PetriNet("new_petri_net")
create places
source = PetriNet.Place("source")
sink = PetriNet.Place("sink")
p_1 = PetriNet.Place("p_1")
add place to net
net.places.add(source)
net.places.add(sink)
net.places.add(p_1)
create transitions
t_1 = PetriNet.Transition("name_1", "1")
t_2 = PetriNet.Transition("name_2", "2")
add transitions to net
net.transitions.add(t_1)
net.transitions.add(t_2)
combine place with transistion
utils.add_arc_from_to(source, t_1, net)
utils.add_arc_from_to(t_1, p_1, net)
now the source is connected with place p_1 over the transistion t_1
initialize markings
initial_marking = Marking()
final_marking = Marking()
a selction of a place is not neccessary, but can be done as followed: initial_marking[source] = 1
export net
pnml_exporter.apply(net, initial_marking, "ontologysim/example/config/createdPetriNet.pnml", final_marking=final_marking)
(optional) plot pnml
from pm4py.visualization.petrinet import visualizer as pn_visualizer
parameters = {pn_visualizer.Variants.WO_DECORATION.value.Parameters.FORMAT:"svg"}
gviz = pn_visualizer.apply(net, initial_marking, final_marking, parameters=parameters)
pn_visualizer.view(gviz)