Exemplo n.º 1
0
def conformance_diagnostics_alignments(log: EventLog, *args, multi_processing: bool = False) -> List[Dict[str, Any]]:
    """
    Apply the alignments algorithm between a log and a process model.
    The methods return the full alignment diagnostics.

    Parameters
    -------------
    log
        Event log
    args
        Specification of the process model
    multi_processing
        Boolean value that enables the multiprocessing (default: False)

    Returns
    -------------
    aligned_traces
        A list of alignments for each trace of the log (in the same order as the traces in the event log)
    """
    if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

    if len(args) == 3:
        if type(args[0]) is PetriNet:
            # Petri net alignments
            from pm4py.algo.conformance.alignments.petri_net import algorithm as alignments
            if multi_processing:
                return alignments.apply_multiprocessing(log, args[0], args[1], args[2], parameters=get_properties(log))
            else:
                return alignments.apply(log, args[0], args[1], args[2], parameters=get_properties(log))
        elif type(args[0]) is dict or type(args[0]) is Counter:
            # DFG alignments
            from pm4py.algo.conformance.alignments.dfg import algorithm as dfg_alignment
            return dfg_alignment.apply(log, args[0], args[1], args[2], parameters=get_properties(log))
    elif len(args) == 1:
        if type(args[0]) is ProcessTree:
            # process tree alignments
            from pm4py.algo.conformance.alignments.process_tree.variants import search_graph_pt
            if multi_processing:
                return search_graph_pt.apply_multiprocessing(log, args[0], parameters=get_properties(log))
            else:
                return search_graph_pt.apply(log, args[0], parameters=get_properties(log))
    # try to convert to Petri net
    import pm4py
    from pm4py.algo.conformance.alignments.petri_net import algorithm as alignments
    net, im, fm = pm4py.convert_to_petri_net(*args)
    if multi_processing:
        return alignments.apply_multiprocessing(log, net, im, fm, parameters=get_properties(log))
    else:
        return alignments.apply(log, net, im, fm, parameters=get_properties(log))
Exemplo n.º 2
0
def execute_script():
    log = pm4py.read_xes("../tests/compressed_input_data/02_teleclaims.xes.gz")
    tree = pm4py.discover_process_tree_inductive(log, noise_threshold=0.3)
    net, im, fm = pm4py.convert_to_petri_net(tree)
    # reduce the log to one trace per variant
    log = filtering_utils.keep_one_trace_per_variant(log)
    for index, trace in enumerate(log):
        print(index)
        aa = time.time()
        check_tree = pm4py.check_is_fitting(trace, tree)
        bb = time.time()
        check_petri = pm4py.check_is_fitting(trace, net, im, fm)
        cc = time.time()
        print("check on tree: ", check_tree, "time", bb - aa)
        print("check on Petri net: ", check_petri, "time", cc - bb)
        print()
Exemplo n.º 3
0
def execute_script():
    log = pm4py.read_xes(
        os.path.join("..", "tests", "input_data", "receipt.xes"))
    print("number of cases", len(log))
    print("number of events", sum(len(x) for x in log))
    print("number of variants", len(pm4py.get_variants(log)))
    ac = get.get_attribute_values(log, "concept:name")
    dfg, sa, ea = pm4py.discover_dfg(log)
    perc = 0.5
    dfg, sa, ea, ac = dfg_filtering.filter_dfg_on_activities_percentage(
        dfg, sa, ea, ac, perc)
    dfg, sa, ea, ac = dfg_filtering.filter_dfg_on_paths_percentage(
        dfg, sa, ea, ac, perc)
    aa = time.time()
    aligned_traces = dfg_alignment.apply(log, dfg, sa, ea)
    bb = time.time()
    net, im, fm = pm4py.convert_to_petri_net(dfg, sa, ea)
    for trace in aligned_traces:
        if trace["cost"] != trace["internal_cost"]:
            print(trace)
            pass
    print(bb - aa)
    print(sum(x["visited_states"] for x in aligned_traces))
    print(
        sum(x["cost"] // align_utils.STD_MODEL_LOG_MOVE_COST
            for x in aligned_traces))
    gviz = visualizer.apply(dfg,
                            activities_count=ac,
                            parameters={
                                "start_activities": sa,
                                "end_activities": ea,
                                "format": "svg"
                            })
    visualizer.view(gviz)
    cc = time.time()
    aligned_traces2 = petri_alignments.apply(
        log,
        net,
        im,
        fm,
        variant=petri_alignments.Variants.VERSION_DIJKSTRA_LESS_MEMORY)
    dd = time.time()
    print(dd - cc)
    print(sum(x["visited_states"] for x in aligned_traces2))
    print(
        sum(x["cost"] // align_utils.STD_MODEL_LOG_MOVE_COST
            for x in aligned_traces2))
Exemplo n.º 4
0
def conformance_diagnostics_alignments(log: EventLog, *args) -> List[Dict[str, Any]]:
    """
    Apply the alignments algorithm between a log and a process model.
    The methods return the full alignment diagnostics.

    Parameters
    -------------
    log
        Event log
    args
        Specification of the process model

    Returns
    -------------
    aligned_traces
        A list of alignments for each trace of the log (in the same order as the traces in the event log)
    """
    if len(args) == 3:
        if type(args[0]) is PetriNet:
            # Petri net alignments
            from pm4py.algo.conformance.alignments import algorithm as alignments
            return alignments.apply(log, args[0], args[1], args[2])
        elif type(args[0]) is dict or type(args[0]) is Counter:
            # DFG alignments
            from pm4py.objects.dfg.utils import dfg_alignment
            return dfg_alignment.apply(log, args[0], args[1], args[2])
    elif len(args) == 1:
        if type(args[0]) is ProcessTree:
            # process tree alignments
            from pm4py.algo.conformance.tree_alignments import algorithm as tree_alignments
            return tree_alignments.apply(log, args[0])
    # try to convert to Petri net
    import pm4py
    from pm4py.algo.conformance.alignments import algorithm as alignments
    net, im, fm = pm4py.convert_to_petri_net(*args)
    return alignments.apply(log, net, im, fm)
Exemplo n.º 5
0
 def test_convert_to_net_from_heu(self):
     log = pm4py.read_xes("input_data/running-example.xes")
     heu_net = pm4py.discover_heuristics_net(log)
     net, im, fm = pm4py.convert_to_petri_net(heu_net)
     self.assertTrue(isinstance(net, PetriNet))
Exemplo n.º 6
0
 def test_convert_to_net_from_dfg(self):
     dfg, sa, ea = pm4py.read_dfg("input_data/running-example.dfg")
     net, im, fm = pm4py.convert_to_petri_net(dfg, sa, ea)
     self.assertTrue(isinstance(net, PetriNet))
Exemplo n.º 7
0
 def test_convert_to_net_from_bpmn(self):
     bpmn = pm4py.read_bpmn("input_data/running-example.bpmn")
     net, im, fm = pm4py.convert_to_petri_net(bpmn)
     self.assertTrue(isinstance(net, PetriNet))
Exemplo n.º 8
0
 def test_convert_to_net_from_tree(self):
     tree = pm4py.read_ptml("input_data/running-example.ptml")
     net, im, fm = pm4py.convert_to_petri_net(tree)
     self.assertTrue(isinstance(net, PetriNet))