From 8ee531b024e70ede172a5a00fc49f07a7b3d0819 Mon Sep 17 00:00:00 2001 From: Laouen Date: Sun, 1 Sep 2024 12:12:14 +0200 Subject: [PATCH] cloning initial best solucion to current solution to avoid aliasing between the best and the current solutions --- thoi/heuristics/simulated_annealing.py | 6 +++--- thoi/heuristics/simulated_annealing_multi_order.py | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/thoi/heuristics/simulated_annealing.py b/thoi/heuristics/simulated_annealing.py index 827d0d2..9e9aea5 100644 --- a/thoi/heuristics/simulated_annealing.py +++ b/thoi/heuristics/simulated_annealing.py @@ -111,15 +111,15 @@ def simulated_annealing(X: np.ndarray, # Best solution found # |batch_size| x |order| - best_solution = current_solution + best_solution = current_solution.clone() # |batch_size| - best_energy = current_energy + best_energy = current_energy.clone() no_progress_count = 0 pbar = trange(max_iterations, leave=False) for _ in pbar: - pbar.set_description(f'mean({metric.upper()}) = {(1 if largest else -1) * best_energy.mean()}') + pbar.set_description(f'mean({metric.upper()}) = {(1 if largest else -1) * best_energy.mean()} - ES: {no_progress_count}') # Generate new solution by modifying the current solution # |batch_size| x |order| diff --git a/thoi/heuristics/simulated_annealing_multi_order.py b/thoi/heuristics/simulated_annealing_multi_order.py index d593574..1aabe74 100644 --- a/thoi/heuristics/simulated_annealing_multi_order.py +++ b/thoi/heuristics/simulated_annealing_multi_order.py @@ -122,15 +122,15 @@ def simulated_annealing_multi_order(X: np.ndarray, # Best solution found # |batch_size| x |order| - best_solution = current_solution + best_solution = current_solution.clone() # |batch_size| - best_energy = current_energy + best_energy = current_energy.clone() no_progress_count = 0 - pbar = trange(max_iterations, leave=False) + pbar = trange(max_iterations, leave=True) for _ in pbar: - pbar.set_description(f'mean({metric.upper()}) = {(1 if largest else -1) * best_energy.mean()}') + pbar.set_description(f'mean({metric.upper()}) = {(1 if largest else -1) * best_energy.mean()} - ES: {no_progress_count}') # |batch_size|