diff --git a/src/TSP_solver.py b/src/TSP_solver.py index 7364c3b..1604113 100644 --- a/src/TSP_solver.py +++ b/src/TSP_solver.py @@ -62,7 +62,7 @@ class Solver_TSP: print(f"### solution found with {self.gap} % gap in {self.time_to_solve} seconds ####") print(f"the total length for the solution found is {self.found_length}", f"while the optimal length is {self.instance.best_sol}", - f"the gap is {self.solver.gap}%", + f"the gap is {self.gap}%", f"the solution is found in {self.time_to_solve} seconds", sep="\n") if return_value: diff --git a/src/meta_heuristics.py b/src/meta_heuristics.py index fa7677d..e86f5c1 100644 --- a/src/meta_heuristics.py +++ b/src/meta_heuristics.py @@ -13,9 +13,9 @@ class Simulated_Annealing: # initial setup temperature = instance.best_sol / np.sqrt(instance.nPoints) - current_sol = solution + current_sol = np.array(solution) current_len = compute_lenght(solution, instance.dist_matrix) - best_sol = solution + best_sol = np.array(solution) best_len = current_len # main loop @@ -41,7 +41,8 @@ class Simulated_Annealing: def random_sol_from_neig(solution, instance): i, j = np.random.choice(np.arange(1, len(solution) - 1), 2, replace=False) i, j = np.sort([i, j]) - return Simulated_Annealing.swap2opt(solution, i, j), Simulated_Annealing.gain() + return Simulated_Annealing.swap2opt(solution, i, j), Simulated_Annealing.gain(i, j, solution, + instance.dist_matrix) @staticmethod def swap2opt(tsp_sequence, i, j):