This commit is contained in:
UmbertoJr 2019-11-09 16:52:13 +01:00
parent 1ed1734e0a
commit 0c880aacd8
2 changed files with 12 additions and 9 deletions

20
run.py
View file

@ -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")

View file

@ -8,7 +8,6 @@ else:
from AI2019.src.utils import *
class Solver_TSP:
solution: ndarray