Skip to content

Commit

Permalink
Merge branch '212-process-tree-to-powl-converter-utility' into 'integ…
Browse files Browse the repository at this point in the history
…ration'

[priority 2] Process tree to POWL converter utility

Closes #212

See merge request process-mining/pm4py/pm4py-core!1212
  • Loading branch information
fit-humam-kourani committed Feb 7, 2024
2 parents c227811 + 1f38c85 commit c4d24d5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pm4py/objects/conversion/process_tree/converter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pm4py.objects.conversion.process_tree.variants import to_petri_net
from pm4py.objects.conversion.process_tree.variants import to_petri_net_transition_bordered
from pm4py.objects.conversion.process_tree.variants import to_bpmn
from pm4py.objects.conversion.process_tree.variants import to_powl
from pm4py.util import exec_utils
from enum import Enum

Expand All @@ -9,6 +10,7 @@ class Variants(Enum):
TO_PETRI_NET = to_petri_net
TO_PETRI_NET_TRANSITION_BORDERED = to_petri_net_transition_bordered
TO_BPMN = to_bpmn
TO_POWL = to_powl


def apply(tree, parameters=None, variant=Variants.TO_PETRI_NET):
Expand Down
53 changes: 53 additions & 0 deletions pm4py/objects/conversion/process_tree/variants/to_powl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from pm4py.objects.process_tree.obj import ProcessTree, Operator as PTOperator
from pm4py.objects.powl.obj import POWL, StrictPartialOrder, OperatorPOWL, Transition, SilentTransition
from typing import Optional, Dict, Any


def apply_recursive(tree: ProcessTree, rec_depth=0) -> POWL:
"""
Internal method
"""
nodes = []

for c in tree.children:
nodes.append(apply_recursive(c, rec_depth+1))

if tree.operator is None:
if tree.label is not None:
powl = Transition(label=tree.label)
else:
powl = SilentTransition()
elif tree.operator == PTOperator.OR:
raise Exception("conversion of process trees containing OR nodes is not supported!")
elif tree.operator == PTOperator.XOR:
powl = OperatorPOWL(PTOperator.XOR, nodes)
elif tree.operator == PTOperator.LOOP:
powl = OperatorPOWL(PTOperator.LOOP, nodes)
else:
powl = StrictPartialOrder(nodes=nodes)

if tree.operator == PTOperator.SEQUENCE:
for i in range(len(nodes)-1):
powl.order.add_edge(nodes[i], nodes[i+1])

return powl


def apply(tree: ProcessTree, parameters: Optional[Dict[Any, Any]] = None) -> POWL:
"""
Converts a process tree model to a POWL model
Parameters
---------------
tree
Process tree
Returns
---------------
powl_model
POWL model
"""
if parameters is None:
parameters = {}

return apply_recursive(tree)

0 comments on commit c4d24d5

Please sign in to comment.