solver
This commit is contained in:
parent
8e6fa8eff9
commit
29dc605f6a
1 changed files with 5 additions and 4 deletions
|
@ -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]):
|
||||||
|
if node not in tour:
|
||||||
tour.append(node)
|
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
|
||||||
|
|
Reference in a new issue