Worked on normative BPMN and Petri Net

This commit is contained in:
Nora Wickelmaier 2024-01-09 14:35:00 +01:00
parent ea002bb7c3
commit 64f9add148

144
code/create_petrinet.py Normal file
View File

@ -0,0 +1,144 @@
import pm4py
from pm4py.objects.petri_net.obj import PetriNet, Marking
from pm4py.objects.petri_net.utils import petri_utils
net = PetriNet("new_petri_net")
# creating source, p_1 and sink place
source = PetriNet.Place("source")
sink = PetriNet.Place("sink")
p_1 = PetriNet.Place("p_1")
p_2 = PetriNet.Place("p_2")
p_3 = PetriNet.Place("p_3")
p_4 = PetriNet.Place("p_4")
p_5 = PetriNet.Place("p_5")
p_6 = PetriNet.Place("p_6")
p_7 = PetriNet.Place("p_7")
p_8 = PetriNet.Place("p_8")
# add the places to the Petri Net
net.places.add(source)
net.places.add(sink)
net.places.add(p_1)
net.places.add(p_2)
net.places.add(p_3)
net.places.add(p_4)
net.places.add(p_5)
net.places.add(p_6)
net.places.add(p_7)
net.places.add(p_8)
# Create transitions
mv = PetriNet.Transition("mv", "move")
fc = PetriNet.Transition("fc", "flipCard")
ot = PetriNet.Transition("ot", "openTopic")
op = PetriNet.Transition("op", "openPopup")
## hidden transitions
t_1 = PetriNet.Transition("t_1")
t_2 = PetriNet.Transition("t_2")
t_3 = PetriNet.Transition("t_3")
t_4 = PetriNet.Transition("t_4")
t_5 = PetriNet.Transition("t_5")
t_6 = PetriNet.Transition("t_6")
t_7 = PetriNet.Transition("t_7")
t_8 = PetriNet.Transition("t_8")
t_9 = PetriNet.Transition("t_9")
t_10 = PetriNet.Transition("t_10")
t_11 = PetriNet.Transition("t_11")
t_12 = PetriNet.Transition("t_12")
t_13 = PetriNet.Transition("t_13")
t_14 = PetriNet.Transition("t_14")
t_15 = PetriNet.Transition("t_15")
t_16 = PetriNet.Transition("t_16")
# Add the transitions to the Petri Net
net.transitions.add(mv)
net.transitions.add(fc)
net.transitions.add(ot)
net.transitions.add(op)
# add hidden transitions
net.transitions.add(t_1)
net.transitions.add(t_2)
net.transitions.add(t_3)
net.transitions.add(t_4)
net.transitions.add(t_5)
net.transitions.add(t_6)
net.transitions.add(t_7)
net.transitions.add(t_8)
net.transitions.add(t_9)
net.transitions.add(t_10)
net.transitions.add(t_11)
net.transitions.add(t_12)
net.transitions.add(t_13)
net.transitions.add(t_14)
net.transitions.add(t_15)
net.transitions.add(t_16)
# Add arcs
petri_utils.add_arc_from_to(source, t_1, net)
petri_utils.add_arc_from_to(source, t_2, net)
petri_utils.add_arc_from_to(t_1, p_1, net)
petri_utils.add_arc_from_to(t_2, p_2, net)
petri_utils.add_arc_from_to(p_1, mv, net)
petri_utils.add_arc_from_to(p_2, fc, net)
petri_utils.add_arc_from_to(mv, p_3, net)
petri_utils.add_arc_from_to(p_3, t_3, net)
petri_utils.add_arc_from_to(p_3, t_4, net)
petri_utils.add_arc_from_to(p_3, t_5, net)
petri_utils.add_arc_from_to(p_3, t_6, net)
petri_utils.add_arc_from_to(p_3, t_7, net)
petri_utils.add_arc_from_to(t_7, p_1, net)
petri_utils.add_arc_from_to(fc, p_4, net)
petri_utils.add_arc_from_to(p_4, t_8, net)
petri_utils.add_arc_from_to(p_4, t_9, net)
petri_utils.add_arc_from_to(p_4, t_10, net)
petri_utils.add_arc_from_to(t_9, p_1, net)
petri_utils.add_arc_from_to(p_7, t_16, net)
petri_utils.add_arc_from_to(t_16, p_6, net)
petri_utils.add_arc_from_to(t_3, p_2, net)
petri_utils.add_arc_from_to(t_5, p_6, net)
petri_utils.add_arc_from_to(t_6, p_5, net)
petri_utils.add_arc_from_to(p_6, ot, net)
petri_utils.add_arc_from_to(p_5, op, net)
petri_utils.add_arc_from_to(ot, p_8, net)
petri_utils.add_arc_from_to(op, p_7, net)
petri_utils.add_arc_from_to(p_8, t_10, net)
petri_utils.add_arc_from_to(p_8, t_11, net)
petri_utils.add_arc_from_to(p_8, t_12, net)
petri_utils.add_arc_from_to(p_8, t_13, net)
petri_utils.add_arc_from_to(t_10, p_6, net)
petri_utils.add_arc_from_to(p_7, t_13, net)
petri_utils.add_arc_from_to(p_7, t_14, net)
petri_utils.add_arc_from_to(p_7, t_15, net)
petri_utils.add_arc_from_to(t_13, p_5, net)
petri_utils.add_arc_from_to(t_15, p_1, net)
petri_utils.add_arc_from_to(t_11, p_1, net)
petri_utils.add_arc_from_to(t_4, sink, net)
petri_utils.add_arc_from_to(t_8, sink, net)
petri_utils.add_arc_from_to(t_12, sink, net)
petri_utils.add_arc_from_to(t_14, sink, net)
# Adding tokens
initial_marking = Marking()
initial_marking[source] = 1
final_marking = Marking()
final_marking[sink] = 1
pm4py.view_petri_net(net, initial_marking, final_marking)
pm4py.write_pnml(net, initial_marking, final_marking, "results/normative_petrinet.pnml")
pm4py.vis.save_vis_petri_net(net, initial_marking, final_marking, "../figures/normative_petrinet.png")
bpmn = pm4py.convert.convert_to_bpmn(net, initial_marking, final_marking)
pm4py.view_bpmn(bpmn)
pm4py.vis.save_vis_bpmn(bpmn, "../figures/normative_bpmn.png")