mtt_haum/code/03_create-petrinet.py

163 lines
4.9 KiB
Python
Raw Normal View History

# 03_create-petrinet.py
#
# content: (1) Create places and transitions
# (2) Normative net
#
# input: --
# output: ../results/normative_petrinet.pnml
# ../results/processmaps/normative_petrinet.png
# ../results/processmaps/normative_bpmn.png
#
# last mod: 2024-03-22
import pm4py
from pm4py.objects.petri_net.obj import PetriNet, Marking
from pm4py.objects.petri_net.utils import petri_utils
#--------------- (1) Create places and transitions ---------------
# Create places
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")
p_9 = PetriNet.Place("p_9")
p_10 = PetriNet.Place("p_10")
p_11 = PetriNet.Place("p_11")
p_12 = PetriNet.Place("p_12")
# Create transitions
mv = PetriNet.Transition("mv", "move")
fc = PetriNet.Transition("fc", "flipCard")
ot = PetriNet.Transition("ot", "openTopic")
op = PetriNet.Transition("op", "openPopup")
# Create 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")
t_17 = PetriNet.Transition("t_17")
t_18 = PetriNet.Transition("t_18")
#--------------- (2) Normative net ---------------
net = PetriNet("new_petri_net")
# Add places
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)
net.places.add(p_9)
net.places.add(p_10)
net.places.add(p_11)
net.places.add(p_12)
# Add transitions
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)
# Add arcs
petri_utils.add_arc_from_to(source, t_1, net)
petri_utils.add_arc_from_to(t_1, p_1, net)
petri_utils.add_arc_from_to(t_1, p_2, net)
petri_utils.add_arc_from_to(p_1, t_2, net)
petri_utils.add_arc_from_to(p_1, t_3, net)
petri_utils.add_arc_from_to(t_3, p_5, net)
petri_utils.add_arc_from_to(t_2, p_3, net)
petri_utils.add_arc_from_to(p_3, mv, net)
petri_utils.add_arc_from_to(mv, p_4, net)
petri_utils.add_arc_from_to(p_4, t_5, net)
petri_utils.add_arc_from_to(p_4, t_6, net)
petri_utils.add_arc_from_to(t_6, p_3, net)
petri_utils.add_arc_from_to(t_5, p_5, net)
petri_utils.add_arc_from_to(p_5, t_15, net)
petri_utils.add_arc_from_to(t_15, sink, net)
petri_utils.add_arc_from_to(p_2, fc, net)
petri_utils.add_arc_from_to(p_2, t_8, net)
petri_utils.add_arc_from_to(t_8, p_12, net)
petri_utils.add_arc_from_to(p_12, t_15, net)
petri_utils.add_arc_from_to(fc, p_6, net)
petri_utils.add_arc_from_to(p_6, t_9, net)
petri_utils.add_arc_from_to(t_9, p_12, net)
petri_utils.add_arc_from_to(p_6, t_4, net)
petri_utils.add_arc_from_to(t_4, p_7, net)
petri_utils.add_arc_from_to(p_7, ot, net)
petri_utils.add_arc_from_to(ot, p_8, net)
petri_utils.add_arc_from_to(p_8, t_10, net)
petri_utils.add_arc_from_to(t_10, p_11, net)
petri_utils.add_arc_from_to(p_11, t_13, net)
petri_utils.add_arc_from_to(t_13, p_12, net)
petri_utils.add_arc_from_to(p_8, t_7, net)
petri_utils.add_arc_from_to(t_7, p_9, net)
petri_utils.add_arc_from_to(p_9, op, net)
petri_utils.add_arc_from_to(op, p_10, net)
petri_utils.add_arc_from_to(p_10, t_11, net)
petri_utils.add_arc_from_to(p_10, t_12, net)
petri_utils.add_arc_from_to(t_12, p_9, net)
petri_utils.add_arc_from_to(t_11, p_11, net)
petri_utils.add_arc_from_to(p_11, t_14, net)
petri_utils.add_arc_from_to(t_14, p_7, net)
# Add 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,
"../results/processmaps/normative_petrinet.png")
bpmn = pm4py.convert.convert_to_bpmn(net, initial_marking, final_marking)
pm4py.view_bpmn(bpmn)
pm4py.vis.save_vis_bpmn(bpmn, "../results/processmaps/normative_bpmn.png")