Beispiel #1
0
def find_right_bound(range_interval, align, node_index, tree_info, mapping_t,
                     neighbors_ranges, ret_tuple_as_trans_desc):
    right_bound = cur_pos = range_interval.upper_bound
    while True:
        if cur_pos < range_interval.lower_bound:
            return -1
        move = align[cur_pos]
        if not align_utils.is_log_move(move, ret_tuple_as_trans_desc):
            if align_utils.move_in_subtree(move,
                                           tree_info[node_index].tree_range,
                                           mapping_t):
                break
            move_in_right_neighbors = neighbors_ranges.is_in_range(
                align_utils.move_index(move, mapping_t,
                                       ret_tuple_as_trans_desc))

            if align_utils.is_sync_move(
                    move, ret_tuple_as_trans_desc) and move_in_right_neighbors:
                right_bound = cur_pos - 1
            elif align_utils.is_model_move(
                    move, ret_tuple_as_trans_desc) and move_in_right_neighbors:
                if cur_pos != right_bound:
                    move_move(align, cur_pos, right_bound)
                right_bound -= 1
        cur_pos -= 1
    return right_bound
Beispiel #2
0
def compute_ranges_for_loop(align, tree_info, mapping_t, node_index, ranges,
                            ret_tuple_as_trans_desc):
    parent_node_index = tree_info[node_index].tree.parent.index
    if node_index == parent_node_index + 1:
        ub = tree_info[parent_node_index].tree_range.upper_bound
        nei_ranges = RangeInterval(
            tree_info[node_index].tree_range.upper_bound + 1, ub)
    else:
        lb = tree_info[parent_node_index].tree_range.lower_bound
        nei_ranges = RangeInterval(
            lb, tree_info[node_index].tree_range.lower_bound - 1)

    new_ranges = list()
    for range_interval in ranges:
        ri = compute_one_range_for_sequence(align, tree_info, mapping_t,
                                            node_index, range_interval,
                                            nei_ranges, nei_ranges,
                                            ret_tuple_as_trans_desc)
        if ri is not None:
            left_bound = cur_pos = ri.lower_bound
            scatter_align = False
            while cur_pos <= ri.upper_bound:
                move = align[cur_pos]
                move_in_nei = True
                if not align_utils.is_log_move(move, ret_tuple_as_trans_desc):
                    move_cur_index = align_utils.move_index(
                        move, mapping_t, ret_tuple_as_trans_desc)
                    move_in_nei = nei_ranges.is_in_range(move_cur_index)
                    scatter_align = True if move_in_nei else scatter_align
                    if scatter_align and align_utils.move_in_subtree(
                            move, tree_info[node_index].tree_range, mapping_t):
                        new_ranges.append(
                            compute_one_range_for_sequence(
                                align, tree_info, mapping_t, node_index,
                                RangeInterval(left_bound,
                                              cur_pos - 1), nei_ranges,
                                nei_ranges, ret_tuple_as_trans_desc))
                        ri = compute_one_range_for_sequence(
                            align, tree_info, mapping_t, node_index,
                            RangeInterval(cur_pos, ri.upper_bound), nei_ranges,
                            nei_ranges, ret_tuple_as_trans_desc)
                        if ri is None:
                            break
                        left_bound = cur_pos = ri.lower_bound
                        scatter_align = False
                if (align_utils.is_sync_move(move, True)
                        and move_in_nei) or cur_pos == ri.upper_bound:
                    new_ranges.append(
                        compute_one_range_for_sequence(
                            align, tree_info, mapping_t, node_index,
                            RangeInterval(left_bound, cur_pos), nei_ranges,
                            nei_ranges, ret_tuple_as_trans_desc))
                    ri = compute_one_range_for_sequence(
                        align, tree_info, mapping_t, node_index,
                        RangeInterval(cur_pos + 1, ri.upper_bound), nei_ranges,
                        nei_ranges, ret_tuple_as_trans_desc)
                    if ri is None:
                        break
                    left_bound = cur_pos = ri.lower_bound
                    scatter_align = False
                else:
                    cur_pos += 1
    return new_ranges
Beispiel #3
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
Beispiel #4
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