Skip to content

Commit 1a0576f

Browse files
Fix issues
1 parent 3c7ceb4 commit 1a0576f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

genetic_algorithm/knapsack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def run_ga(
284284

285285
# Elitism
286286
sorted_indices = sorted(range(pop_size), key=lambda idx: fitnesses[idx])
287-
elite_indices = sorted_indices.reverse()[:elitism]
287+
elite_indices = sorted_indices[::-1][:elitism] # reverse and take top indices
288288
elites = [population[idx][:] for idx in elite_indices]
289289

290290
# New generation

0 commit comments

Comments
 (0)