update
This commit is contained in:
parent
501a636738
commit
69c29e47b2
2 changed files with 7 additions and 5 deletions
2
run.py
2
run.py
|
@ -14,7 +14,7 @@ def run(show_plots=False):
|
||||||
if show_plots:
|
if show_plots:
|
||||||
instance.plot_data()
|
instance.plot_data()
|
||||||
|
|
||||||
for method in ["random", "nearest_neighbors"]:
|
for method in ["random", "nearest_neighbors", "best_nn"]:
|
||||||
solver = Solver_TSP(method)
|
solver = Solver_TSP(method)
|
||||||
solver(instance, return_value=False)
|
solver(instance, return_value=False)
|
||||||
|
|
||||||
|
|
|
@ -41,10 +41,12 @@ class Solver_TSP:
|
||||||
n = int(instance_.nPoints)
|
n = int(instance_.nPoints)
|
||||||
node = np.argmin([starting_node])
|
node = np.argmin([starting_node])
|
||||||
tour = [node]
|
tour = [node]
|
||||||
for _ in range(n - 2):
|
for _ in range(n - 1):
|
||||||
for node in np.argsort(dist_matrix[node]):
|
for new_node in np.argsort(dist_matrix[node]):
|
||||||
if node not in tour:
|
if new_node not in tour:
|
||||||
tour.append(node)
|
tour.append(new_node)
|
||||||
|
node = new_node
|
||||||
|
break
|
||||||
tour.append(starting_node)
|
tour.append(starting_node)
|
||||||
self.solution = np.array(tour)
|
self.solution = np.array(tour)
|
||||||
self.solved = True
|
self.solved = True
|
||||||
|
|
Reference in a new issue