This commit is contained in:
UmbertoJr 2019-10-31 16:32:43 +01:00
parent 501a636738
commit 69c29e47b2
2 changed files with 7 additions and 5 deletions

2
run.py
View File

@ -14,7 +14,7 @@ def run(show_plots=False):
if show_plots:
instance.plot_data()
for method in ["random", "nearest_neighbors"]:
for method in ["random", "nearest_neighbors", "best_nn"]:
solver = Solver_TSP(method)
solver(instance, return_value=False)

View File

@ -41,10 +41,12 @@ class Solver_TSP:
n = int(instance_.nPoints)
node = np.argmin([starting_node])
tour = [node]
for _ in range(n - 2):
for node in np.argsort(dist_matrix[node]):
if node not in tour:
tour.append(node)
for _ in range(n - 1):
for new_node in np.argsort(dist_matrix[node]):
if new_node not in tour:
tour.append(new_node)
node = new_node
break
tour.append(starting_node)
self.solution = np.array(tour)
self.solved = True