meta
This commit is contained in:
parent
6a9f4f187c
commit
573bc9a38f
2 changed files with 5 additions and 4 deletions
|
@ -62,7 +62,7 @@ class Solver_TSP:
|
||||||
print(f"### solution found with {self.gap} % gap in {self.time_to_solve} seconds ####")
|
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}",
|
print(f"the total length for the solution found is {self.found_length}",
|
||||||
f"while the optimal length is {self.instance.best_sol}",
|
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")
|
f"the solution is found in {self.time_to_solve} seconds", sep="\n")
|
||||||
|
|
||||||
if return_value:
|
if return_value:
|
||||||
|
|
|
@ -13,9 +13,9 @@ class Simulated_Annealing:
|
||||||
|
|
||||||
# initial setup
|
# initial setup
|
||||||
temperature = instance.best_sol / np.sqrt(instance.nPoints)
|
temperature = instance.best_sol / np.sqrt(instance.nPoints)
|
||||||
current_sol = solution
|
current_sol = np.array(solution)
|
||||||
current_len = compute_lenght(solution, instance.dist_matrix)
|
current_len = compute_lenght(solution, instance.dist_matrix)
|
||||||
best_sol = solution
|
best_sol = np.array(solution)
|
||||||
best_len = current_len
|
best_len = current_len
|
||||||
|
|
||||||
# main loop
|
# main loop
|
||||||
|
@ -41,7 +41,8 @@ class Simulated_Annealing:
|
||||||
def random_sol_from_neig(solution, instance):
|
def random_sol_from_neig(solution, instance):
|
||||||
i, j = np.random.choice(np.arange(1, len(solution) - 1), 2, replace=False)
|
i, j = np.random.choice(np.arange(1, len(solution) - 1), 2, replace=False)
|
||||||
i, j = np.sort([i, j])
|
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
|
@staticmethod
|
||||||
def swap2opt(tsp_sequence, i, j):
|
def swap2opt(tsp_sequence, i, j):
|
||||||
|
|
Reference in a new issue