This commit is contained in:
UmbertoJr 2019-12-02 08:29:53 +01:00
parent 6a9f4f187c
commit 573bc9a38f
2 changed files with 5 additions and 4 deletions

View file

@ -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:

View file

@ -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):