diff --git a/run.py b/run.py index ea418c1..7ff77ff 100644 --- a/run.py +++ b/run.py @@ -3,29 +3,33 @@ import pandas as pd from time import time as t -def run(show_plots=False): +def run(show_plots=False, verbose=False): # names = [name_ for name_ in os.listdir("./problems") if "tsp" in name_] names = ["eil76.tsp", "kroA100.tsp"] methods = Solver_TSP.available_methods.keys() results = [] index = [] for name in names: - print("\n\n#############################") filename = f"problems/{name}" instance = Instance(filename) - instance.print_info() + if verbose: + print("\n\n#############################") + instance.print_info() if show_plots: instance.plot_data() for method in methods: solver = Solver_TSP(method) start = t() - solver(instance, return_value=False) + solver(instance, return_value=False, verbose=verbose) end = t() - print(f"the total length for the solution found is {solver.found_length}", - f"while the optimal length is {instance.best_sol}", - f"the gap is {solver.gap} %", sep="\n") + if verbose: + print(f"the total length for the solution found is {solver.found_length}", + f"while the optimal length is {instance.best_sol}", + f"the gap is {solver.gap}%", + f"the solution is found in {np.round(end - start, 5)} seconds", sep="\n") + index.append((name, method)) results.append([solver.found_length, instance.best_sol, solver.gap, end - start]) @@ -43,4 +47,4 @@ def run(show_plots=False): if __name__ == '__main__': - run(show_plots=True).to_csv("./results.csv") + run(show_plots=True, verbose=True).to_csv("./results.csv") diff --git a/src/TSP_solver.py b/src/TSP_solver.py index a33db56..d027dd3 100644 --- a/src/TSP_solver.py +++ b/src/TSP_solver.py @@ -8,7 +8,6 @@ else: from AI2019.src.utils import * - class Solver_TSP: solution: ndarray