示例#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
示例#2
0
def remove_first_log_move(align, ret_tuple_as_trans_desc):
    left_bound = 0
    while True:
        move = align[left_bound]
        if not align_utils.is_log_move(move, ret_tuple_as_trans_desc):
            break
        left_bound += 1
    return [RangeInterval(left_bound, len(align) - 1)]
示例#3
0
def find_left_bound(range_interval, align, node_index, tree_info, mapping_t, ret_tuple_as_trans_desc):
    left_bound = range_interval.lower_bound
    tree_range = tree_info[node_index].tree_range
    while True:
        if left_bound > range_interval.upper_bound:
            return -1
        move = align[left_bound]
        if not align_utils.is_log_move(move, ret_tuple_as_trans_desc):
            model_index = align_utils.move_index(move, mapping_t, ret_tuple_as_trans_desc)
            if tree_range.is_in_range(model_index):
                break
        left_bound += 1
    return left_bound
示例#4
0
def remove_first_log_move(align, begin, mapping_t, subtree_range,
                          ret_tuple_as_trans_desc):
    left_bound = begin
    while True:
        if left_bound == len(align):
            return None
        move = align[left_bound]
        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)
            if subtree_range.is_in_range(move_cur_index):
                break
        left_bound += 1
    return RangeInterval(left_bound, len(align) - 1)
示例#5
0
def find_right_bound(range_interval, align, node_index, tree_info, mapping_t, ret_tuple_as_trans_desc):
    right_bound = cur_index = range_interval.upper_bound
    tree_range = tree_info[node_index].tree_range
    while True:
        if cur_index < range_interval.lower_bound:
            return -1
        move = align[cur_index]
        if not align_utils.is_log_move(move, ret_tuple_as_trans_desc):
            model_index = align_utils.move_index(move, mapping_t, ret_tuple_as_trans_desc)
            if tree_range.is_in_range(model_index):
                break
            else:
                right_bound = cur_index - 1
        cur_index -= 1
    return right_bound
示例#6
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
示例#7
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
示例#8
0
def apply(align, tree_info, mapping_t, com_res, stop_condition,
          ret_tuple_as_trans_desc):
    ranges = list()
    subtree_range = tree_info[com_res.subtree1.index].tree_range

    anchor = True
    range_interval = remove_first_log_move(align, 0, mapping_t, subtree_range,
                                           ret_tuple_as_trans_desc)
    if range_interval is not None:
        cur_index = left_bound = right_bound = range_interval.lower_bound
        while cur_index < len(align):
            move = align[cur_index]
            if align_utils.is_log_move(move, ret_tuple_as_trans_desc):
                if anchor:
                    right_bound += 1
            else:
                move_cur_index = align_utils.move_index(
                    move, mapping_t, ret_tuple_as_trans_desc)
                if subtree_range.is_in_range(move_cur_index):
                    anchor = True
                    right_bound = cur_index
                elif stop_condition[0].is_in_range(
                        move_cur_index) or stop_condition[1].is_in_range(
                            move_cur_index):
                    ranges.append(RangeInterval(left_bound, right_bound))
                    anchor = True
                    range_interval = remove_first_log_move(
                        align, cur_index, mapping_t, subtree_range,
                        ret_tuple_as_trans_desc)
                    if range_interval is None:
                        break
                    cur_index = left_bound = right_bound = range_interval.lower_bound
                else:
                    anchor = False
            if cur_index == len(align) - 1:
                ranges.append(RangeInterval(left_bound, right_bound))
            cur_index += 1
    return ranges
示例#9
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,
                                            ret_tuple_as_trans_desc)
        if ri is not None:
            cur_pos = left_bound = ri.lower_bound
            while cur_pos <= ri.upper_bound:
                move = align[cur_pos]
                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)
                else:
                    move_in_nei = False
                if 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),
                                                                     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),
                                                        ret_tuple_as_trans_desc)
                    if ri is None:
                        break
                    elif ri.upper_bound == ri.lower_bound:
                        new_ranges.append(RangeInterval(ri.lower_bound, ri.upper_bound))
                    left_bound = cur_pos = ri.lower_bound
                cur_pos += 1
    return new_ranges
示例#10
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