Skip to content

Commit

Permalink
fix(pm4py): bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fit-alessandro-berti committed Jun 8, 2022
1 parent 9548cd5 commit 3b2082f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 29 deletions.
51 changes: 26 additions & 25 deletions pm4py/algo/conformance/alignments/petri_net/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,31 +112,32 @@ def apply_trace(trace, petri_net, initial_marking, final_marking, parameters=Non
# Instead of using the length of the trace, use the sum of the trace cost function
trace_cost_function_sum = sum(trace_cost_function)

ltrace_bwc = trace_cost_function_sum + best_worst_cost

fitness_num = ali['cost'] // align_utils.STD_MODEL_LOG_MOVE_COST
fitness_den = ltrace_bwc // align_utils.STD_MODEL_LOG_MOVE_COST
fitness = 1 - fitness_num / fitness_den if fitness_den > 0 else 0

# other possibility: avoid integer division but proceed to rounding.
# could lead to small differences with respect to the adopted-since-now fitness
# (since it is rounded)

"""
initial_trace_cost_function = exec_utils.get_param_value(Parameters.PARAM_TRACE_COST_FUNCTION, parameters, None)
initial_model_cost_function = exec_utils.get_param_value(Parameters.PARAM_MODEL_COST_FUNCTION, parameters, None)
initial_sync_cost_function = exec_utils.get_param_value(Parameters.PARAM_SYNC_COST_FUNCTION, parameters, None)
uses_standard_cost_function = initial_trace_cost_function is None and initial_model_cost_function is None and \
initial_sync_cost_function is None
fitness = 1 - ali['cost'] / ltrace_bwc if ltrace_bwc > 0 else 0
fitness_round_digits = exec_utils.get_param_value(Parameters.FITNESS_ROUND_DIGITS, parameters, 3)
fitness = round(fitness, fitness_round_digits)
"""

ali["fitness"] = fitness
# returning also the best worst cost, for log fitness computation
ali["bwc"] = ltrace_bwc
if ali is not None and best_worst_cost is not None:
ltrace_bwc = trace_cost_function_sum + best_worst_cost

fitness_num = ali['cost'] // align_utils.STD_MODEL_LOG_MOVE_COST
fitness_den = ltrace_bwc // align_utils.STD_MODEL_LOG_MOVE_COST
fitness = 1 - fitness_num / fitness_den if fitness_den > 0 else 0

# other possibility: avoid integer division but proceed to rounding.
# could lead to small differences with respect to the adopted-since-now fitness
# (since it is rounded)

"""
initial_trace_cost_function = exec_utils.get_param_value(Parameters.PARAM_TRACE_COST_FUNCTION, parameters, None)
initial_model_cost_function = exec_utils.get_param_value(Parameters.PARAM_MODEL_COST_FUNCTION, parameters, None)
initial_sync_cost_function = exec_utils.get_param_value(Parameters.PARAM_SYNC_COST_FUNCTION, parameters, None)
uses_standard_cost_function = initial_trace_cost_function is None and initial_model_cost_function is None and \
initial_sync_cost_function is None
fitness = 1 - ali['cost'] / ltrace_bwc if ltrace_bwc > 0 else 0
fitness_round_digits = exec_utils.get_param_value(Parameters.FITNESS_ROUND_DIGITS, parameters, 3)
fitness = round(fitness, fitness_round_digits)
"""

ali["fitness"] = fitness
# returning also the best worst cost, for log fitness computation
ali["bwc"] = ltrace_bwc

return ali

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ def get_best_worst_cost(petri_net, initial_marking, final_marking, parameters=No

best_worst = apply(trace, petri_net, initial_marking, final_marking, parameters=parameters)

return best_worst['cost']
if best_worst is not None:
return best_worst['cost']

return None


def apply_from_variants_list_petri_string(var_list, petri_net_string, parameters=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ def get_best_worst_cost(petri_net, initial_marking, final_marking, parameters=No

best_worst = apply(trace, petri_net, initial_marking, final_marking, parameters=parameters)

return best_worst['cost']
if best_worst is not None:
return best_worst['cost']

return None


def apply(trace: Trace, petri_net: PetriNet, initial_marking: Marking, final_marking: Marking, parameters: Optional[Dict[Union[str, Parameters], Any]] = None) -> typing.AlignmentResult:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ def get_best_worst_cost(petri_net, initial_marking, final_marking, parameters=No

best_worst = apply(trace, petri_net, initial_marking, final_marking, parameters=parameters)

return best_worst['cost']
if best_worst is not None:
return best_worst['cost']

return None


def apply(trace: Trace, petri_net: PetriNet, initial_marking: Marking, final_marking: Marking, parameters: Optional[Dict[Union[str, Parameters], Any]] = None) -> typing.AlignmentResult:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ def get_best_worst_cost(petri_net, initial_marking, final_marking, parameters=No

best_worst = apply(trace, petri_net, initial_marking, final_marking, parameters=parameters)

return best_worst['cost']
if best_worst is not None:
return best_worst['cost']

return None


def apply(trace: Trace, petri_net: PetriNet, initial_marking: Marking, final_marking: Marking, parameters: Optional[Dict[Union[str, Parameters], Any]] = None) -> typing.AlignmentResult:
Expand Down

0 comments on commit 3b2082f

Please sign in to comment.