This commit is contained in:
UmbertoJr 2019-10-31 15:49:48 +01:00
parent 8e6fa8eff9
commit 29dc605f6a

View file

@ -35,12 +35,13 @@ class Solver_TSP:
def nn(self, instance_, starting_node=0): def nn(self, instance_, starting_node=0):
dist_matrix = np.copy(instance_.dist_matrix) dist_matrix = np.copy(instance_.dist_matrix)
n = int(instance_.nPoints) n = int(instance_.nPoints)
dist_matrix[np.arange(n), np.arange(n)] = 1000
node = np.argmin([starting_node]) node = np.argmin([starting_node])
tour = [node] tour = [node]
for _ in range(n- 2): for _ in range(n - 2):
node = np.argmin([node]) for node in np.argsort(dist_matrix[node]):
tour.append(node) if node not in tour:
tour.append(node)
tour.append(starting_node)
self.solution = np.array(tour) self.solution = np.array(tour)
self.solved = True self.solved = True
return self.solution return self.solution