|
| 1 | +import pm4py |
| 2 | +from pm4py.algo.conformance.tokenreplay import algorithm as token_based_replay |
| 3 | + |
| 4 | + |
| 5 | +def get_tbr_statistics(log, net, im, fm): |
| 6 | + tbr_parameters = {"enable_pltr_fitness": True, "show_progress_bar": False} |
| 7 | + |
| 8 | + replayed_traces, place_fitness_per_trace, transition_fitness_per_trace, notexisting_activities_in_model = token_based_replay.apply(log, net, im, fm, parameters=tbr_parameters) |
| 9 | + place_diagnostics = {place: {"m": 0, "r": 0, "c": 0, "p": 0} for place in place_fitness_per_trace} |
| 10 | + trans_count = {trans: 0 for trans in net.transitions} |
| 11 | + # computes the missing, remaining, consumed, and produced tokens |
| 12 | + # per place. |
| 13 | + for place, res in place_fitness_per_trace.items(): |
| 14 | + place_diagnostics[place]["m"] += res["m"] |
| 15 | + place_diagnostics[place]["r"] += res["r"] |
| 16 | + place_diagnostics[place]["c"] += res["c"] |
| 17 | + place_diagnostics[place]["p"] += res["p"] |
| 18 | + # counts the number of times a transition has been fired during the |
| 19 | + # replay. |
| 20 | + for trace in replayed_traces: |
| 21 | + for trans in trace["activated_transitions"]: |
| 22 | + trans_count[trans] += 1 |
| 23 | + return (place_diagnostics, trans_count) |
| 24 | + |
| 25 | + |
| 26 | +def execute_script(): |
| 27 | + log = pm4py.read_xes("../tests/input_data/running-example.xes") |
| 28 | + |
| 29 | + net, im, fm = pm4py.discover_petri_net_inductive(log) |
| 30 | + |
| 31 | + ocpn = {} |
| 32 | + ocpn["petri_nets"] = {} |
| 33 | + ocpn["double_arcs_on_activity"] = {} |
| 34 | + ocpn["tbr_results"] = {} |
| 35 | + ocpn["activities"] = set() |
| 36 | + |
| 37 | + for ot in {"ciao1", "ciao2"}: |
| 38 | + for trans in net.transitions: |
| 39 | + if trans.label is not None: |
| 40 | + ocpn["activities"].add(trans.label) |
| 41 | + |
| 42 | + ocpn["petri_nets"][ot] = [net, im, fm] |
| 43 | + |
| 44 | + ocpn["double_arcs_on_activity"][ot] = {} |
| 45 | + for x in net.transitions: |
| 46 | + ocpn["double_arcs_on_activity"][ot][x.label] = True if ot == "ciao2" and x.label is not None else False |
| 47 | + |
| 48 | + ocpn["tbr_results"][ot] = pm4py.conformance_diagnostics_token_based_replay(log, net, im, fm) |
| 49 | + |
| 50 | + ocpn["tbr_results"][ot] = get_tbr_statistics(log, net, im, fm) |
| 51 | + |
| 52 | + pm4py.view_ocpn(ocpn, format="svg") |
| 53 | + |
| 54 | + |
| 55 | +if __name__ == "__main__": |
| 56 | + execute_script() |
0 commit comments