run
This commit is contained in:
parent
1ed1734e0a
commit
0c880aacd8
2 changed files with 12 additions and 9 deletions
14
run.py
14
run.py
|
@ -3,16 +3,17 @@ import pandas as pd
|
||||||
from time import time as t
|
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 = [name_ for name_ in os.listdir("./problems") if "tsp" in name_]
|
||||||
names = ["eil76.tsp", "kroA100.tsp"]
|
names = ["eil76.tsp", "kroA100.tsp"]
|
||||||
methods = Solver_TSP.available_methods.keys()
|
methods = Solver_TSP.available_methods.keys()
|
||||||
results = []
|
results = []
|
||||||
index = []
|
index = []
|
||||||
for name in names:
|
for name in names:
|
||||||
print("\n\n#############################")
|
|
||||||
filename = f"problems/{name}"
|
filename = f"problems/{name}"
|
||||||
instance = Instance(filename)
|
instance = Instance(filename)
|
||||||
|
if verbose:
|
||||||
|
print("\n\n#############################")
|
||||||
instance.print_info()
|
instance.print_info()
|
||||||
if show_plots:
|
if show_plots:
|
||||||
instance.plot_data()
|
instance.plot_data()
|
||||||
|
@ -20,12 +21,15 @@ def run(show_plots=False):
|
||||||
for method in methods:
|
for method in methods:
|
||||||
solver = Solver_TSP(method)
|
solver = Solver_TSP(method)
|
||||||
start = t()
|
start = t()
|
||||||
solver(instance, return_value=False)
|
solver(instance, return_value=False, verbose=verbose)
|
||||||
end = t()
|
end = t()
|
||||||
|
|
||||||
|
if verbose:
|
||||||
print(f"the total length for the solution found is {solver.found_length}",
|
print(f"the total length for the solution found is {solver.found_length}",
|
||||||
f"while the optimal length is {instance.best_sol}",
|
f"while the optimal length is {instance.best_sol}",
|
||||||
f"the gap is {solver.gap} %", sep="\n")
|
f"the gap is {solver.gap}%",
|
||||||
|
f"the solution is found in {np.round(end - start, 5)} seconds", sep="\n")
|
||||||
|
|
||||||
index.append((name, method))
|
index.append((name, method))
|
||||||
results.append([solver.found_length, instance.best_sol, solver.gap, end - start])
|
results.append([solver.found_length, instance.best_sol, solver.gap, end - start])
|
||||||
|
|
||||||
|
@ -43,4 +47,4 @@ def run(show_plots=False):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
run(show_plots=True).to_csv("./results.csv")
|
run(show_plots=True, verbose=True).to_csv("./results.csv")
|
||||||
|
|
|
@ -8,7 +8,6 @@ else:
|
||||||
from AI2019.src.utils import *
|
from AI2019.src.utils import *
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Solver_TSP:
|
class Solver_TSP:
|
||||||
|
|
||||||
solution: ndarray
|
solution: ndarray
|
||||||
|
|
Reference in a new issue