Skip to content

Commit 8ee531b

Browse files
committed
cloning initial best solucion to current solution to avoid aliasing
between the best and the current solutions
1 parent 2a85f7a commit 8ee531b

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

thoi/heuristics/simulated_annealing.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ def simulated_annealing(X: np.ndarray,
111111

112112
# Best solution found
113113
# |batch_size| x |order|
114-
best_solution = current_solution
114+
best_solution = current_solution.clone()
115115
# |batch_size|
116-
best_energy = current_energy
116+
best_energy = current_energy.clone()
117117

118118
no_progress_count = 0
119119
pbar = trange(max_iterations, leave=False)
120120
for _ in pbar:
121121

122-
pbar.set_description(f'mean({metric.upper()}) = {(1 if largest else -1) * best_energy.mean()}')
122+
pbar.set_description(f'mean({metric.upper()}) = {(1 if largest else -1) * best_energy.mean()} - ES: {no_progress_count}')
123123

124124
# Generate new solution by modifying the current solution
125125
# |batch_size| x |order|

thoi/heuristics/simulated_annealing_multi_order.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ def simulated_annealing_multi_order(X: np.ndarray,
122122

123123
# Best solution found
124124
# |batch_size| x |order|
125-
best_solution = current_solution
125+
best_solution = current_solution.clone()
126126
# |batch_size|
127-
best_energy = current_energy
127+
best_energy = current_energy.clone()
128128

129129
no_progress_count = 0
130-
pbar = trange(max_iterations, leave=False)
130+
pbar = trange(max_iterations, leave=True)
131131
for _ in pbar:
132132

133-
pbar.set_description(f'mean({metric.upper()}) = {(1 if largest else -1) * best_energy.mean()}')
133+
pbar.set_description(f'mean({metric.upper()}) = {(1 if largest else -1) * best_energy.mean()} - ES: {no_progress_count}')
134134

135135

136136
# |batch_size|

0 commit comments

Comments
 (0)