Skip to content

Commit

Permalink
Merge branch 'ft-1466-fix-process-tree-loop-to-binary-conversion' int…
Browse files Browse the repository at this point in the history
…o 'integration'

FT 1466 Fix process tree loop to binary conversion

See merge request process-mining/pm4py/pm4py-core!553
  • Loading branch information
fit-sebastiaan-van-zelst committed Dec 10, 2021
2 parents 9b79512 + 1d17ddb commit 5dccbe6
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions pm4py/objects/process_tree/utils/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,25 @@ def get_process_tree_height(pt: ProcessTree) -> int:
return 1 + max([get_process_tree_height(x) for x in pt.children])


def process_tree_to_binary_process_tree(pt: ProcessTree) -> ProcessTree:
if len(pt.children) > 2:
new_subtree = ProcessTree()
new_subtree.operator = pt.operator
new_subtree.children = pt.children[1:]
pt.children = pt.children[:1]
pt.children.append(new_subtree)
new_subtree.parent = pt
for c in pt.children:
process_tree_to_binary_process_tree(c)
return pt
def process_tree_to_binary_process_tree(tree: ProcessTree) -> ProcessTree:
if len(tree.children) > 2:
left_tree = tree.children[0]

right_tree_op = tree.operator
if tree.operator == pt_op.Operator.LOOP:
right_tree_op = pt_op.Operator.XOR

right_tree = ProcessTree(operator=right_tree_op, parent=tree,
children=tree.children[1:])
for child in right_tree.children:
child.parent = right_tree

tree.children = [left_tree, right_tree]

for child in tree.children:
process_tree_to_binary_process_tree(child)

return tree


def common_ancestor(t1: ProcessTree, t2: ProcessTree) -> Optional[ProcessTree]:
Expand Down

0 comments on commit 5dccbe6

Please sign in to comment.