Example #1
0
def find_next_left_border(align, index, node, start_or_end, bound, ret_tuple_as_trans_desc):
    """
    Return the position of next left border

    Parameters
    -------------
    align
        alignment on the original process tree of one trace
    index
        the current position
    node
        the related node of next left border
    start_or_end
        start=1 and end=0
    bound
        the leftest boundary that muss stop
    ret_tuple_as_trans_desc
        True or False

    Returns
    -----------
    index
        the position of the next left border
    """

    if start_or_end == 1:
        while not align_utils.is_node_start(align[index], node, ret_tuple_as_trans_desc):
            index -= 1
    else:
        while not align_utils.is_node_end(align[index], node, ret_tuple_as_trans_desc):
            index -= 1
    return find_left_border(node, align, index, bound, ret_tuple_as_trans_desc)
Example #2
0
def find_next_right_border(align, index, node, start_or_end, border, ret_tuple_as_trans_desc):
    if start_or_end == 1:
        while not align_utils.is_node_start(align[index], node, ret_tuple_as_trans_desc):
            index += 1
    else:
        while not align_utils.is_node_end(align[index], node, ret_tuple_as_trans_desc):
            index += 1
    return find_right_border(node, align, index, border, ret_tuple_as_trans_desc)
Example #3
0
def alignment_reassemble(align, sub_aligns, anchor_index, subtree1,
                         ret_tuple_as_trans_desc):
    for i in range(len(anchor_index) - 1, -1, -1):
        sub_aligns[i] = copy.deepcopy(sub_aligns[i])
        sub_align = sub_aligns[i]['alignment']
        index = anchor_index[i]
        align[index] = sub_align.pop(0)
        index += 1
        while True:
            labels_in_subtree1 = pt_mani_utils.lock_tree_labels(subtree1)
            if len(sub_align) <= 1:
                while not align_utils.is_node_end(align[index], subtree1,
                                                  ret_tuple_as_trans_desc):
                    if align_utils.is_log_move(align[index], ret_tuple_as_trans_desc) or \
                            align_utils.check_model_label_belong_to_subtree(align[index], labels_in_subtree1,
                                                                            ret_tuple_as_trans_desc):
                        align.pop(index)
                    else:
                        index += 1
                align[index] = sub_align.pop(0) if len(
                    sub_align) == 1 else None
                break

            if align_utils.is_node_end(align[index], subtree1,
                                       ret_tuple_as_trans_desc):
                while len(sub_align) > 1:
                    align.insert(index, sub_align.pop(0))
                    index += 1
                align[index] = sub_align.pop(0)
                break

            if align_utils.is_model_move(sub_align[0],
                                         ret_tuple_as_trans_desc):
                align.insert(index, sub_align.pop(0))
                index += 1
            elif align_utils.compare_log_label(align[index], sub_align[0],
                                               ret_tuple_as_trans_desc):
                align[index] = sub_align.pop(0)
                index += 1
            elif align_utils.check_model_label_belong_to_subtree(
                    align[index], labels_in_subtree1, ret_tuple_as_trans_desc):
                align.pop(index)
            else:
                index += 1
Example #4
0
def detect_change_scope(align, subtree, trace, ret_tuple_as_trans_desc):
    """
    Return the change scope in the alignment

    Parameters
    ------------
    align
        alignment on the original process tree of one trace
    subtree
        the subtree that need to be detected
    trace
        the original trace
    ret_tuple_as_trans_desc
        True or False

    Returns
    -----------
    index_anchor
        `list()` Store the index of anchor in alignments e.g,[1, 3, 5, 9]

    """

    scope, index, e_index = Scope(), 0, 0
    children = pt_mani_utils.non_none_leaves_labels(subtree)
    while True:
        if index == len(align):
            break

        if align_utils.is_node_start(align[index], subtree,
                                     ret_tuple_as_trans_desc):
            scope.index_append(index)
            new_trace = Trace()
            while not align_utils.is_node_end(align[index], subtree,
                                              ret_tuple_as_trans_desc):
                if align_utils.is_log_move(align[index], ret_tuple_as_trans_desc) or \
                        (align_utils.check_model_label_belong_to_subtree(align[index], children,
                                                                         ret_tuple_as_trans_desc)
                         and not align_utils.is_model_move(align[index], ret_tuple_as_trans_desc)):
                    new_trace.append(trace[e_index])
                e_index = e_index + 1 if not align_utils.is_model_move(
                    align[index], ret_tuple_as_trans_desc) else e_index
                index += 1
            scope.traces_append(new_trace)
        e_index = e_index + 1 if not align_utils.is_model_move(
            align[index], ret_tuple_as_trans_desc) else e_index
        index += 1
    return scope
Example #5
0
def search_scope_index(align, node, ret_tuple_as_trans_desc):
    """
    Return the border index list of the node in alignment.

    Parameters
    ------------
    align
        alignment on the original process tree of one trace
    node
        `Process tree` the subtree that to detect
    ret_tuple_as_trans_desc
        True or False

    Returns
    ---------
    index
        `list()` [start_pos, end_pos, start_pos, end_pos....]
    """
    index = list()
    for i, move in enumerate(align):
        index.append(i) if align_utils.is_node_start(move, node, ret_tuple_as_trans_desc) or \
                           align_utils.is_node_end(move, node, ret_tuple_as_trans_desc) else None
    return index
Example #6
0
def find_left_border(node, align, cur_pos, bound, ret_tuple_as_trans_desc):
    """
    Iteratively move the left border(align[cur_pos]) util meet the stop condition and
    return the the leftest border of the scope for the given subtree
    Stop condition:
        1. meet boundary
        2. meet the sync-move if the alignment-move is node-end

    Parameters
    -----------
    node
        `Process Tree` the related subtree of the current alignment-move
    align
        `list()` alignment on the original process tree of one trace
    cur_pos
        the position of the border that need to expand
    bound
        the leftest boundary that muss stop
    ret_tuple_as_trans_desc
        True or False

    Returns
    -----------
    index
        The current position of the left border
    """

    index = cur_pos
    if index <= bound:
        return bound

    if node.parent is None:
        move_move(align, cur_pos, 0)
        return 0

    if align_utils.is_node_end(align[index], node, ret_tuple_as_trans_desc):
        flag = 0
        children = pt_mani_utils.lock_tree_labels(node)
        while not align_utils.is_node_start(align[index], node, ret_tuple_as_trans_desc):
            if not align_utils.check_model_label_belong_to_subtree(align[index], children, ret_tuple_as_trans_desc):
                move_move(align, index, cur_pos)
                cur_pos -= 1
            elif align_utils.is_sync_move(align[index], ret_tuple_as_trans_desc) or index == bound:
                flag = 1
                break
            index -= 1
        if flag == 0:
            block_length = cur_pos - index
            index = find_left_border(node, align, index, bound, ret_tuple_as_trans_desc)
            for i in range(block_length):
                move_move(align, cur_pos, index + 1)
            return index + block_length
        else:
            return cur_pos

    elif align_utils.is_node_start(align[index], node, ret_tuple_as_trans_desc):
        # parent is not NONE, otherwise index = 0
        if node.parent.operator == Operator.PARALLEL or node.parent.operator == Operator.XOR:
            index = find_next_left_border(align, index, node.parent, 1, bound, ret_tuple_as_trans_desc)

        elif node.parent.operator == Operator.SEQUENCE:
            child_no = 0
            for i in range(len(node.parent.children)):
                if node.parent.children[i].index == node.index:
                    child_no = i
                    break
            if child_no == 0:
                index = find_next_left_border(align, index, node.parent, 1, bound, ret_tuple_as_trans_desc)
            else:
                index = find_next_left_border(align, index, node.parent.children[child_no - 1], 0, bound,
                                              ret_tuple_as_trans_desc)

        elif node.parent.operator == Operator.LOOP:

            if node.parent.children[0].index == node.index:  # first child
                while not align_utils.is_node_end(align[index], node.parent.children[1],
                                                  ret_tuple_as_trans_desc) and \
                        not align_utils.is_node_start(align[index], node.parent, ret_tuple_as_trans_desc):
                    index -= 1
                if align_utils.is_node_end(align[index], node.parent.children[1], ret_tuple_as_trans_desc):
                    index = find_left_border(node.parent.children[1], align, index, bound, ret_tuple_as_trans_desc)
                else:
                    index = find_left_border(node.parent, align, index, bound, ret_tuple_as_trans_desc)

            else:  # second child
                index = find_next_left_border(align, index, node.parent.children[0], 0, bound, ret_tuple_as_trans_desc)
    move_move(align, cur_pos, index + 1)
    return index + 1
Example #7
0
def find_right_border(node, align, cur_pos, bound, ret_tuple_as_trans_desc):
    index = cur_pos
    if index == bound:
        return index
    elif index > bound:
        return bound

    if node.parent is None:
        move_move(align, cur_pos, len(align) - 1)
        return len(align) - 1

    if align_utils.is_node_start(align[index], node, ret_tuple_as_trans_desc):
        flag = 0
        children = pt_mani_utils.lock_tree_labels(node)
        while not align_utils.is_node_end(align[index], node, ret_tuple_as_trans_desc):
            if not align_utils.check_model_label_belong_to_subtree(align[index], children, ret_tuple_as_trans_desc):
                move_move(align, index, cur_pos)
                cur_pos += 1
            elif align_utils.is_sync_move(align[index], ret_tuple_as_trans_desc) or index == bound:
                flag = 1
                break
            index += 1
        if flag == 0:
            block_length = index - cur_pos
            index = find_right_border(node, align, index, bound, ret_tuple_as_trans_desc)
            for i in range(block_length):
                move_move(align, cur_pos, index - 1)
            return index - block_length
        else:
            return cur_pos

    elif align_utils.is_node_end(align[index], node, ret_tuple_as_trans_desc):
        # parent is not NONE, otherwise index = 0

        if node.parent.operator == Operator.PARALLEL or node.parent.operator == Operator.XOR:
            index = find_next_right_border(align, index, node.parent, 0, bound, ret_tuple_as_trans_desc)

        elif node.parent.operator == Operator.SEQUENCE:
            child_no = 0
            for i in range(len(node.parent.children)):
                if node.parent.children[i].index == node.index:
                    child_no = i
                    break
            if child_no == len(node.parent.children) - 1:
                index = find_next_right_border(align, index, node.parent, 0, bound, ret_tuple_as_trans_desc)
            else:
                index = find_next_right_border(align, index, node.parent.children[child_no + 1], 1, bound,
                                               ret_tuple_as_trans_desc)

        elif node.parent.operator == Operator.LOOP:
            if node.parent.children[0].index == node.index:  # first child
                while not align_utils.is_node_start(align[index], node.parent.children[1],
                                                    ret_tuple_as_trans_desc) and \
                        not align_utils.is_node_start(align[index], node.parent.children[2],
                                                      ret_tuple_as_trans_desc):
                    index += 1
                if align_utils.is_node_start(align[index], node.parent.children[1], ret_tuple_as_trans_desc):
                    index = find_right_border(node.parent.children[1], align, index, bound, ret_tuple_as_trans_desc)
                else:
                    index = find_right_border(node.parent.children[2], align, index, bound, ret_tuple_as_trans_desc)
            elif node.parent.children[1].index == node.index:  # second child
                index = find_next_right_border(align, index, node.parent.children[0], 1, bound, ret_tuple_as_trans_desc)
            else:
                index = find_next_right_border(align, index, node.parent, 0, bound, ret_tuple_as_trans_desc)
    move_move(align, cur_pos, index - 1)
    return index - 1