def __get_end_activity_set_binary_tree(pt: ProcessTree, ea_set=None) -> Set[str]: assert pt.children is None or len(pt.children) <= 2 if ea_set is None: ea_set = set() if is_leaf(pt) and not is_tau_leaf(pt): ea_set.add(pt.label) elif not is_tau_leaf(pt): assert len(pt.children) == 2 tau_in_language_sub_pt_1 = __check_empty_sequence_accepted( pt.children[0]) tau_in_language_sub_pt_2 = __check_empty_sequence_accepted( pt.children[1]) if pt.operator == Operator.SEQUENCE: if not tau_in_language_sub_pt_2: return __get_end_activity_set_binary_tree( pt.children[1], ea_set) else: for c in pt.children: ea_set.union(__get_end_activity_set_binary_tree(c, ea_set)) elif pt.operator == Operator.PARALLEL or pt.operator == Operator.XOR: for c in pt.children: ea_set.union(__get_end_activity_set_binary_tree(c, ea_set)) elif pt.operator == Operator.LOOP: if not tau_in_language_sub_pt_1: return __get_end_activity_set_binary_tree( pt.children[0], ea_set) else: for c in pt.children: ea_set.union(__get_end_activity_set_binary_tree(c, ea_set)) return ea_set
def __check_empty_sequence_accepted(pt: ProcessTree) -> bool: if is_leaf(pt): if is_tau_leaf(pt): return True else: return False else: assert len(pt.children) == 2 if pt.operator == Operator.SEQUENCE or pt.operator == Operator.PARALLEL: return __check_empty_sequence_accepted(pt.children[0]) and __check_empty_sequence_accepted(pt.children[1]) elif pt.operator == Operator.XOR: return __check_empty_sequence_accepted(pt.children[0]) or __check_empty_sequence_accepted(pt.children[1]) else: assert pt.operator == Operator.LOOP return __check_empty_sequence_accepted(pt.children[0])