def benchmark_function(graphe, nbr_it, func, *func_args, **func_kwargs): best_sol = None best_score = float("inf") dist_mat = get_distance_matrix(graphe) prob = GraphProblem(dist_mat) if hasattr(graphe, "name"): prob.name = graphe.name for i in range(nbr_it): print(func.__name__, "#", i) sol = func(prob, *func_args, **func_kwargs) if sol.get_max_col() < best_score: best_sol = sol best_score = best_sol.get_max_col() search_step_trace.clear_all() tracefname = "{0}.qst".format(func.__name__) with open(tracefname, 'a') as f: for name, data in sol.record.items(): print(prob.name, ", ", sol.get_max_col(), ", ", search_step_trace.csv_format().format(name, data), file=f, sep="") print("", file=f) solfname = "{0}_{1}.pcol".format(prob.name, best_sol.get_max_col()) with open(solfname, 'a') as f: print(best_sol, file=f) print("", file=f) return best_sol
def benchmark_function(graphe, func, *func_args, **func_kwargs): dist_mat = get_distance_matrix(graphe) prob = GraphProblem(dist_mat) if hasattr(graphe, "name"): prob.name = graphe.name if bu.search_step_trace.enabled: bu.search_step_trace.env_name = func.__name__ sol = func(prob, *func_args, **func_kwargs) return prob, sol