def performance_testing(): # Heuristics h_alg = [solverNN.algorithm, solverCHH.algorithm] h_alg_name = ["solverNN.algorithm", "solverCHH.algorithm"] ls_alg_name = [ "SolverLS_close_index_route_swap", "SolverLS_all_combination_route_swap", "TwoOPT" ] try: for (idx, algo) in enumerate(h_alg): with open('../results/' + h_alg_name[idx] + '.dat', "a") as filehandle: filehandle.write("{} {} {}\n".format("Instance", "Cost", "Time")) for path, subdirs, files in os.walk('../data'): for name in files: if fnmatch.fnmatch(name, "*.xml"): t0 = time.clock() instance = data.Data(os.path.join(path, name)) ch = ConstructionHeuristics(instance, algo) sol = ch.construct(60 - t0) splitted_name = re.compile("^[a-zA-Z]+").findall( name) filehandle.write("{} {} {}".format( splitted_name[0], sol.cost(), round(t0, 2))) filehandle.write("\n") ls_alg = [ SolverLS(sol).run_first, SolverLS(sol).run_second, TwoOPT(sol).run ] for (ls_idx, l_alg) in enumerate(ls_alg): with open( '../results/' + ls_alg_name[ls_idx] + '_' + h_alg_name[idx] + '.dat', "a") as ls_fh: if os.stat('../results/' + ls_alg_name[ls_idx] + '_' + h_alg_name[idx] + '.dat').st_size == 0: ls_fh.write("{} {} {}\n".format( "Instance", "Cost", "Time")) t0 = time.clock() ls = LocalSearch(solution=sol, alg=l_alg) try: sol = ls.construct(60 - t0) except TimeOutExeption as e: print("timeout") sol = e.solution ls_fh.write("{} {} {}".format( splitted_name[0], sol.cost(), round(t0, 2))) ls_fh.write("\n") ls_fh.close() filehandle.close() boxplotter('../results/' + h_alg_name[idx]) for ls_idx in range(len(ls_alg_name)): boxplotter('../results/' + ls_alg_name[ls_idx] + '_' + h_alg_name[idx]) except TimeOutExeption as e: print("timeout") sol = e.solution