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:
|
||||
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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in a new issue