Esempio n. 1
0
def view_petri_net(petri_net: PetriNet,
                   initial_marking: Optional[Marking] = None,
                   final_marking: Optional[Marking] = None,
                   format: str = "png"):
    """
    Views a (composite) Petri net

    Parameters
    -------------
    petri_net
        Petri net
    initial_marking
        Initial marking
    final marking
        Final marking
    format
        Format of the output picture (default: png)
    """
    from pm4py.visualization.petri_net import visualizer as pn_visualizer
    gviz = pn_visualizer.apply(
        petri_net,
        initial_marking,
        final_marking,
        parameters={
            pn_visualizer.Variants.WO_DECORATION.value.Parameters.FORMAT:
            format
        })
    pn_visualizer.view(gviz)
Esempio n. 2
0
def execute_script():
    # import the log
    log_path = os.path.join("..", "tests", "input_data", "receipt.xes")
    log = xes_importer.apply(log_path)
    # apply Inductive Miner
    net, initial_marking, final_marking = inductive_miner.apply(log)
    # get visualization
    variant = pn_vis.Variants.PERFORMANCE
    parameters_viz = {
        pn_vis.Variants.PERFORMANCE.value.Parameters.AGGREGATION_MEASURE:
        "mean",
        pn_vis.Variants.PERFORMANCE.value.Parameters.FORMAT: "svg"
    }
    gviz = pn_vis.apply(net,
                        initial_marking,
                        final_marking,
                        log=log,
                        variant=variant,
                        parameters=parameters_viz)
    pn_vis.view(gviz)
    # do another visualization with frequency
    variant = pn_vis.Variants.FREQUENCY
    parameters_viz = {pn_vis.Variants.FREQUENCY.value.Parameters.FORMAT: "svg"}
    gviz = pn_vis.apply(net,
                        initial_marking,
                        final_marking,
                        log=log,
                        variant=variant,
                        parameters=parameters_viz)
    pn_vis.view(gviz)
Esempio n. 3
0
def execute_script():
    log_path = os.path.join("..", "tests", "input_data", "interval_event_log.xes")
    #log_path = os.path.join("..", "tests", "input_data", "reviewing.xes")
    log = xes_importer.apply(log_path)
    parameters = {}
    parameters[constants.PARAMETER_CONSTANT_START_TIMESTAMP_KEY] = "start_timestamp"
    parameters[constants.PARAMETER_CONSTANT_TIMESTAMP_KEY] = "time:timestamp"
    parameters[constants.PARAMETER_CONSTANT_ACTIVITY_KEY] = "concept:name"
    parameters["strict"] = False
    parameters["format"] = "svg"
    start_activities = sa_get.get_start_activities(log, parameters=parameters)
    end_activities = ea_get.get_end_activities(log, parameters=parameters)
    parameters["start_activities"] = start_activities
    parameters["end_activities"] = end_activities
    soj_time = soj_time_get.apply(log, parameters=parameters)
    print("soj_time")
    print(soj_time)
    conc_act = conc_act_get.apply(log, parameters=parameters)
    print("conc_act")
    print(conc_act)
    efg = efg_get.apply(log, parameters=parameters)
    print("efg")
    print(efg)
    dfg_freq = dfg_algorithm.apply(log, parameters=parameters, variant=dfg_algorithm.Variants.FREQUENCY)
    dfg_perf = dfg_algorithm.apply(log, parameters=parameters, variant=dfg_algorithm.Variants.PERFORMANCE)
    dfg_gv_freq = dfg_vis_fact.apply(dfg_freq, log=log, variant=dfg_vis_fact.Variants.FREQUENCY,
                                     parameters=parameters)
    dfg_vis_fact.view(dfg_gv_freq)
    dfg_gv_perf = dfg_vis_fact.apply(dfg_perf, log=log, variant=dfg_vis_fact.Variants.PERFORMANCE,
                                     parameters=parameters)
    dfg_vis_fact.view(dfg_gv_perf)
    net, im, fm = dfg_conv.apply(dfg_freq)
    gviz = pn_vis.apply(net, im, fm, parameters=parameters)
    pn_vis.view(gviz)
Esempio n. 4
0
def execute_script():
    log = xes_importer.apply(os.path.join("..", "tests", "compressed_input_data", "09_a32f0n00.xes.gz"))
    heu_net = heuristics_miner.apply_heu(log, parameters={
        heuristics_miner.Variants.CLASSIC.value.Parameters.DEPENDENCY_THRESH: 0.99})
    gviz = hn_vis.apply(heu_net, parameters={hn_vis.Variants.PYDOTPLUS.value.Parameters.FORMAT: "svg"})
    hn_vis.view(gviz)
    net, im, fm = heuristics_miner.apply(log, parameters={
        heuristics_miner.Variants.CLASSIC.value.Parameters.DEPENDENCY_THRESH: 0.99})
    gviz2 = petri_vis.apply(net, im, fm, parameters={petri_vis.Variants.WO_DECORATION.value.Parameters.FORMAT: "svg"})
    petri_vis.view(gviz2)
Esempio n. 5
0
def execute_script():
    log = xes_importer.apply(os.path.join("..", "tests", "input_data", "receipt.xes"))
    log = sorting.sort_timestamp(log)
    net, im, fm = inductive_miner.apply(log)
    log1 = EventLog(log[:500])
    log2 = EventLog(log[len(log) - 500:])
    statistics = element_usage_comparison.compare_element_usage_two_logs(net, im, fm, log1, log2)
    gviz = pn_vis.apply(net, im, fm, variant=pn_vis.Variants.FREQUENCY, aggregated_statistics=statistics,
                        parameters={pn_vis.Variants.FREQUENCY.value.Parameters.FORMAT: "svg"})
    pn_vis.view(gviz)
Esempio n. 6
0
def execute_script():
    log_path = os.path.join("..", "tests", "input_data", "running-example.xes")
    log = xes_import.apply(log_path)

    net, i_m, f_m = alpha_miner.apply(log)

    gviz = pn_vis.apply(
        net,
        i_m,
        f_m,
        parameters={
            pn_vis.Variants.WO_DECORATION.value.Parameters.FORMAT: "svg",
            pn_vis.Variants.WO_DECORATION.value.Parameters.DEBUG: False
        })
    pn_vis.view(gviz)
Esempio n. 7
0
def execute_script():
    log_path = os.path.join("..", "tests", "input_data", "running-example.xes")

    log = xes_importer.apply(log_path)
    net, marking, final_marking = inductive.apply(
        log, variant=inductive.Variants.IM_CLEAN)
    for place in marking:
        print("initial marking " + place.name)
    for place in final_marking:
        print("final marking " + place.name)
    gviz = pn_vis.apply(
        net,
        marking,
        final_marking,
        parameters={
            pn_vis.Variants.WO_DECORATION.value.Parameters.FORMAT: "svg",
            pn_vis.Variants.WO_DECORATION.value.Parameters.DEBUG: True
        })
    pn_vis.view(gviz)

    if True:
        fit_traces = []

        for i in range(0, len(log)):
            try:
                print("\n", i, [x["concept:name"] for x in log[i]])
                cf_result = pm4py.algo.conformance.alignments.petri_net.variants.state_equation_a_star.apply(
                    log[i], net, marking, final_marking)['alignment']
                if cf_result is None:
                    print("alignment is none!")
                else:
                    is_fit = True
                    for couple in cf_result:
                        print(couple)
                        if not (couple[0] == couple[1]
                                or couple[0] == ">>" and couple[1] is None):
                            is_fit = False
                    print("isFit = " + str(is_fit))

                    if is_fit:
                        fit_traces.append(log[i])
            except TypeError:
                print("EXCEPTION ", i)
                traceback.print_exc()
        print(fit_traces)
        print(len(fit_traces))
Esempio n. 8
0
def execute_script():
    df = pd.read_csv("../tests/input_data/interval_event_log.csv")
    df = pm4py.format_dataframe(df)
    log = pm4py.read_xes("../tests/input_data/interval_event_log.xes")
    heu_net = plusplus.apply_heu(
        log, parameters={"heu_net_decoration": "performance"})
    heu_net_2 = plusplus.apply_heu_pandas(
        df, parameters={"heu_net_decoration": "performance"})
    gviz = visualizer.apply(heu_net, parameters={"format": "svg"})
    visualizer.view(gviz)
    gviz2 = visualizer.apply(heu_net_2, parameters={"format": "svg"})
    visualizer.view(gviz2)
    net1, im1, fm1 = plusplus.apply(log)
    net2, im2, fm2 = plusplus.apply(log)
    gviz3 = pn_visualizer.apply(net1, im1, fm1, parameters={"format": "svg"})
    pn_visualizer.view(gviz3)
    gviz4 = pn_visualizer.apply(net2, im2, fm2, parameters={"format": "svg"})
    pn_visualizer.view(gviz4)
Esempio n. 9
0
def apply(net, im, fm, parameters=None):
    """
    Transforms a WF-net to a process tree

    Parameters
    -------------
    net
        Petri net
    im
        Initial marking
    fm
        Final marking

    Returns
    -------------
    tree
        Process tree
    """
    if parameters is None:
        parameters = {}

    debug = exec_utils.get_param_value(Parameters.DEBUG, parameters, False)
    fold = exec_utils.get_param_value(Parameters.FOLD, parameters, True)

    grouped_net = group_blocks_in_net(net, parameters=parameters)

    if len(grouped_net.transitions) == 1:
        pt_str = list(grouped_net.transitions)[0].label
        pt = pt_util.parse(pt_str)
        ret = pt_util.fold(pt) if fold else pt
        tree_sort(ret)
        return ret
    else:
        if debug:
            from pm4py.visualization.petri_net import visualizer as pn_viz
            pn_viz.view(pn_viz.apply(grouped_net, parameters={"format":
                                                              "svg"}))
        raise ValueError('Parsing of WF-net Failed')
Esempio n. 10
0
def execute_script():
    log_path = os.path.join("..", "tests", "input_data", "running-example.xes")
    log = xes_importer.apply(log_path)
    net, marking, final_marking = alpha_miner.apply(log)
    for place in marking:
        print("initial marking " + place.name)
    for place in final_marking:
        print("final marking " + place.name)
    gviz = pn_vis.apply(
        net,
        marking,
        final_marking,
        parameters={
            pn_vis.Variants.WO_DECORATION.value.Parameters.FORMAT: "svg"
        })
    pn_vis.view(gviz)
    print("started token replay")
    aligned_traces = token_replay.apply(log, net, marking, final_marking)
    fit_traces = [x for x in aligned_traces if x['trace_is_fit']]
    perc_fitness = 0.00
    if len(aligned_traces) > 0:
        perc_fitness = len(fit_traces) / len(aligned_traces)
    print("perc_fitness=", perc_fitness)
Esempio n. 11
0
def execute_script():
    log_path = os.path.join("..", "tests", "input_data", "interval_event_log.csv")
    dataframe = pd.read_csv(log_path)
    log_path = os.path.join("..", "tests", "input_data", "reviewing.xes")
    log = pm4py.read_xes(log_path)
    dataframe = pm4py.convert_to_dataframe(log)
    parameters = {}
    #parameters[constants.PARAMETER_CONSTANT_START_TIMESTAMP_KEY] = "start_timestamp"
    parameters[constants.PARAMETER_CONSTANT_TIMESTAMP_KEY] = "time:timestamp"
    parameters[constants.PARAMETER_CONSTANT_ACTIVITY_KEY] = "concept:name"
    parameters[constants.PARAMETER_CONSTANT_CASEID_KEY] = "case:concept:name"
    parameters["strict"] = True
    parameters["format"] = "svg"
    start_activities = sa_get.get_start_activities(dataframe, parameters=parameters)
    end_activities = ea_get.get_end_activities(dataframe, parameters=parameters)
    att_count = att_get.get_attribute_values(dataframe, "concept:name", parameters=parameters)
    parameters["start_activities"] = start_activities
    parameters["end_activities"] = end_activities
    soj_time = soj_time_get.apply(dataframe, parameters=parameters)
    print("soj_time")
    print(soj_time)
    conc_act = conc_act_get.apply(dataframe, parameters=parameters)
    print("conc_act")
    print(conc_act)
    efg = efg_get.apply(dataframe, parameters=parameters)
    print("efg")
    print(efg)
    dfg_freq, dfg_perf = df_statistics.get_dfg_graph(dataframe, measure="both", start_timestamp_key="start_timestamp")
    dfg_gv_freq = dfg_vis_fact.apply(dfg_freq, activities_count=att_count, variant=dfg_vis_fact.Variants.FREQUENCY,
                                     soj_time=soj_time, parameters=parameters)
    dfg_vis_fact.view(dfg_gv_freq)
    dfg_gv_perf = dfg_vis_fact.apply(dfg_perf, activities_count=att_count, variant=dfg_vis_fact.Variants.PERFORMANCE,
                                     soj_time=soj_time, parameters=parameters)
    dfg_vis_fact.view(dfg_gv_perf)
    net, im, fm = dfg_conv.apply(dfg_freq)
    gviz = pn_vis.apply(net, im, fm, parameters=parameters)
    pn_vis.view(gviz)
Esempio n. 12
0
        bpmn_output_path = bpmn_output_path.name
        log_path = os.path.join(LOGS_FOLDER, log_name)
        print("")
        print(log_path)
        log = pm4py.read_xes(log_path)
        fp_log = pm4py.algo.discovery.footprints.log.variants.entire_event_log.apply(
            log)
        net, im, fm = pm4py.discover_petri_net_heuristics(log)
        fitness0 = pm4py.evaluate_fitness_alignments(log, net, im, fm)
        precision0 = pm4py.evaluate_precision_alignments(log, net, im, fm)
        print("fitness 0", fitness0)
        print("precision 0", precision0)
        bpmn_graph = pm4py.objects.conversion.wf_net.variants.to_bpmn.apply(
            net, im, fm)
        bpmn_graph = layouter.apply(bpmn_graph)
        exporter.apply(bpmn_graph, bpmn_output_path)
        bpmn_graph = importer.apply(bpmn_output_path)
        bpmn_graph = layouter.apply(bpmn_graph)
        # gets the net back
        net, im, fm = pm4py.objects.conversion.bpmn.variants.to_petri_net.apply(
            bpmn_graph)
        gviz = pn_visualizer.apply(net, im, fm)
        pn_visualizer.view(gviz)
        fitness1 = pm4py.evaluate_fitness_alignments(log, net, im, fm)
        precision1 = pm4py.evaluate_precision_alignments(log, net, im, fm)
        print("fitness 1", fitness1, fitness0 == fitness1)
        print("precision 1", precision1, precision0 == precision1)
        if not (fitness0 == fitness1 and precision0 == precision1):
            print("ALERT")
            input()