From 48fcd8738b95b62b40cf4f1b4dad099bc4a764e8 Mon Sep 17 00:00:00 2001 From: UmbertoJr Date: Thu, 31 Oct 2019 11:57:26 +0100 Subject: [PATCH] solver --- code/TSP_solver.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/code/TSP_solver.py b/code/TSP_solver.py index d7028b6..274c429 100644 --- a/code/TSP_solver.py +++ b/code/TSP_solver.py @@ -33,7 +33,17 @@ class Solver_TSP: return self.solution def nn(self, instance_, starting_node=0): - pass + dist_matrix = np.copy(instance_.dist_matrix) + n = int(instance_.nPoints) + dist_matrix[np.arange(n), np.arange(n)] = 1000 + node = np.argmin([starting_node]) + tour = [node] + for _ in range(n- 2): + node = np.argmin([node]) + tour.append(node) + self.solution = np.array(tour) + self.solved = True + return self.solution def plot_solution(self): assert self.solved, "You can't plot the solution, you need to solve it first!"