Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ft wf to powl #509

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions examples/wf_net_to_powl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
def execute_script():
import pm4py
from pm4py.objects.conversion.wf_net.variants import to_powl
from pm4py.objects.powl.obj import StrictPartialOrder, OperatorPOWL, Transition, SilentTransition
from pm4py.objects.process_tree.obj import Operator

# Define basic transitions
A = Transition(label="A")
B = Transition(label="B")
C = Transition(label="C")
D = Transition(label="D")
E = Transition(label="E")
F = Transition(label="F")
G = Transition(label="G")
H = Transition(label="H")
I = Transition(label="I")
J = Transition(label="J")
K = Transition(label="K")
L = Transition(label="L")
M = Transition(label="M")

# Define inner partial order PO_G: I and J must be executed before K
PO_G_nodes = [I, J, K]
PO_G = StrictPartialOrder(nodes=PO_G_nodes)
PO_G.order.add_edge(I, K)
PO_G.order.add_edge(J, K)

# Define H as a choice between L and M
H_choice = OperatorPOWL(operator=Operator.XOR, children=[L, M])

# Define LOOP1: loop between PO_G and H_choice
LOOP1 = OperatorPOWL(operator=Operator.LOOP, children=[PO_G, H_choice])

# Define PO1: A and B must be executed before C and D
PO1_nodes = [A, B, C, D]
PO1 = StrictPartialOrder(nodes=PO1_nodes)
PO1.order.add_edge(A, C)
PO1.order.add_edge(A, D)
PO1.order.add_edge(B, C)
PO1.order.add_edge(B, D)

# Define XOR1: choice between E and F
XOR1 = OperatorPOWL(operator=Operator.XOR, children=[E, F])

# Combine PO1, XOR1, and LOOP1 into the main partial order
main_nodes = [PO1, XOR1, LOOP1]
main_PO = StrictPartialOrder(nodes=main_nodes)
main_PO.order.add_edge(PO1, XOR1)
main_PO.order.add_edge(XOR1, LOOP1)

# The resulting POWL model (main_PO) represents a complex process with nested partial orders

pm4py.view_powl(main_PO, format="svg")
print(main_PO)
net, im, fm = pm4py.convert_to_petri_net(main_PO)
#pm4py.view_petri_net(net, im, fm, format="svg")

log = pm4py.play_out(net, im, fm)

if True:
fitness = pm4py.fitness_alignments(log, net, im, fm)
print(fitness)
precision = pm4py.precision_alignments(log, net, im, fm)
print(precision)

powl = to_powl.apply(net, im, fm)
pm4py.view_powl(powl, format="svg")

print(powl)
net2, im2, fm2 = pm4py.convert_to_petri_net(powl)
pm4py.view_petri_net(net2, im2, fm2, format="svg")

if True:
fitness = pm4py.fitness_alignments(log, net2, im2, fm2)
print(fitness)
precision = pm4py.precision_alignments(log, net2, im2, fm2)
print(precision)


if __name__ == "__main__":
execute_script()
28 changes: 28 additions & 0 deletions examples/wf_net_to_powl_alt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def execute_script():
import pm4py
from pm4py.objects.conversion.wf_net.variants import to_powl

log = pm4py.read_xes("../tests/input_data/receipt.xes")
log = pm4py.filter_variants_top_k(log, 11)

powl = pm4py.discover_powl(log)
print(powl)
net, im, fm = pm4py.convert_to_petri_net(powl)

fitness = pm4py.fitness_alignments(log, net, im, fm)
print(fitness)
precision = pm4py.precision_alignments(log, net, im, fm)
print(precision)

powl2 = to_powl.apply(net, im, fm)
print(powl2)
net2, im2, fm2 = pm4py.convert_to_petri_net(powl2)

fitness = pm4py.fitness_alignments(log, net2, im2, fm2)
print(fitness)
precision = pm4py.precision_alignments(log, net2, im2, fm2)
print(precision)


if __name__ == "__main__":
execute_script()
Loading
Loading