Exemplo n.º 1
0
def __approximate_alignment_for_trace(pt: ProcessTree, a_sets: Dict[ProcessTree, Set[str]],
                                      sa_sets: Dict[ProcessTree, Set[str]], ea_sets: Dict[ProcessTree, Set[str]],
                                      tau_flags: Dict[ProcessTree, bool], trace: Trace, max_tl: int,
                                      max_th: int, parameters=None):
    if parameters is None:
        parameters = {}

    max_align_time_trace = exec_utils.get_param_value(Parameters.PARAM_MAX_ALIGN_TIME_TRACE, parameters,
                                                      sys.maxsize)

    start_time = parameters["trace_alignment_start_time"]
    current_time = time.time()

    if current_time - start_time > max_align_time_trace:
        # the alignment of the trace did not terminate in an useful time
        return None

    try:
        if len(trace) <= max_tl or get_process_tree_height(pt) <= max_th:
            return calculate_optimal_alignment(pt, trace, parameters=parameters)
        else:
            if pt.operator == Operator.SEQUENCE:
                return __approximate_alignment_on_sequence(pt, trace, a_sets, sa_sets, ea_sets, tau_flags, max_tl,
                                                           max_th,
                                                           parameters=parameters)
            elif pt.operator == Operator.LOOP:
                return __approximate_alignment_on_loop(pt, trace, a_sets, sa_sets, ea_sets, tau_flags, max_tl, max_th,
                                                       parameters=parameters)
            elif pt.operator == Operator.XOR:
                return __approximate_alignment_on_choice(pt, trace, a_sets, sa_sets, ea_sets, tau_flags, max_tl, max_th,
                                                         parameters=parameters)
            elif pt.operator == Operator.PARALLEL:
                return __approximate_alignment_on_parallel(pt, trace, a_sets, sa_sets, ea_sets, tau_flags, max_tl,
                                                           max_th,
                                                           parameters=parameters)
    except AlignmentNoneException:
        # alignment did not terminate correctly. return None
        return None
Exemplo n.º 2
0
def __approximate_alignment_for_trace(pt: ProcessTree, a_sets: Dict[ProcessTree, Set[str]],
                                      sa_sets: Dict[ProcessTree, Set[str]], ea_sets: Dict[ProcessTree, Set[str]],
                                      tau_flags: Dict[ProcessTree, bool], trace: Trace, max_tl: int,
                                      max_th: int, parameters=None):
    if parameters is None:
        parameters = {}

    max_align_time_trace = exec_utils.get_param_value(Parameters.PARAM_MAX_ALIGN_TIME_TRACE, parameters,
                                                      sys.maxsize)
    subtree_align_cache = exec_utils.get_param_value(Parameters.SUBTREE_ALIGN_CACHE, parameters, {})
    activity_key = exec_utils.get_param_value(Parameters.ACTIVITY_KEY, parameters, DEFAULT_NAME_KEY)

    start_time = parameters["trace_alignment_start_time"]
    current_time = time.time()

    trace_activities = tuple([x[activity_key] for x in trace])

    id_pt = id(pt)

    # if the combination process tree-trace is in the cache
    # use the cache to avoid further computations
    if (id_pt, trace_activities) in subtree_align_cache:
        return copy(subtree_align_cache[(id_pt, trace_activities)])

    if current_time - start_time > max_align_time_trace:
        # the alignment of the trace did not terminate in an useful time
        subtree_align_cache[(id_pt, trace_activities)] = None
        return None

    try:
        if len(trace) <= max_tl or get_process_tree_height(pt) <= max_th:
            aligned_trace = calculate_optimal_alignment(pt, trace, parameters=parameters)
            subtree_align_cache[(id_pt, trace_activities)] = copy(aligned_trace)
            return aligned_trace
        else:
            if pt.operator == Operator.SEQUENCE:
                aligned_trace = __approximate_alignment_on_sequence(pt, trace, a_sets, sa_sets, ea_sets, tau_flags,
                                                                    max_tl,
                                                                    max_th,
                                                                    parameters=parameters)
                subtree_align_cache[(id_pt, trace_activities)] = copy(aligned_trace)
                return aligned_trace
            elif pt.operator == Operator.LOOP:
                aligned_trace = __approximate_alignment_on_loop(pt, trace, a_sets, sa_sets, ea_sets, tau_flags, max_tl,
                                                                max_th,
                                                                parameters=parameters)
                subtree_align_cache[(id_pt, trace_activities)] = copy(aligned_trace)
                return aligned_trace
            elif pt.operator == Operator.XOR:
                aligned_trace = __approximate_alignment_on_choice(pt, trace, a_sets, sa_sets, ea_sets, tau_flags,
                                                                  max_tl, max_th,
                                                                  parameters=parameters)
                subtree_align_cache[(id_pt, trace_activities)] = copy(aligned_trace)
                return aligned_trace
            elif pt.operator == Operator.PARALLEL:
                aligned_trace = __approximate_alignment_on_parallel(pt, trace, a_sets, sa_sets, ea_sets, tau_flags,
                                                                    max_tl,
                                                                    max_th,
                                                                    parameters=parameters)
                subtree_align_cache[(id_pt, trace_activities)] = copy(aligned_trace)
                return aligned_trace
    except AlignmentNoneException:
        # alignment did not terminate correctly. return None
        subtree_align_cache[(id_pt, trace_activities)] = None
        return None
    except IndexError:
        # alignment did not terminate correctly. return None
        subtree_align_cache[(id_pt, trace_activities)] = None
        return None