We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3c7ceb4 commit 1a0576fCopy full SHA for 1a0576f
genetic_algorithm/knapsack.py
@@ -284,7 +284,7 @@ def run_ga(
284
285
# Elitism
286
sorted_indices = sorted(range(pop_size), key=lambda idx: fitnesses[idx])
287
- elite_indices = sorted_indices.reverse()[:elitism]
+ elite_indices = sorted_indices[::-1][:elitism] # reverse and take top indices
288
elites = [population[idx][:] for idx in elite_indices]
289
290
# New generation
0 commit comments