File tree Expand file tree Collapse file tree 1 file changed +3
-4
lines changed Expand file tree Collapse file tree 1 file changed +3
-4
lines changed Original file line number Diff line number Diff line change @@ -267,8 +267,7 @@ def run_ga(
267267 >>> out['capacity'] == cap
268268 True
269269 """
270- n = len (items )
271- population = [random_genome (n ) for _ in range (pop_size )]
270+ population = [random_genome (len (items )) for _ in range (pop_size )]
272271 best_history = [] # track best fitness per generation
273272 avg_history = []
274273 best_overall = None
@@ -287,9 +286,9 @@ def run_ga(
287286 best_overall = population [best_idx ][:]
288287
289288 # Elitism
290- get_fitness = lambda i : fitnesses [i ]
289+ get_fitness = lambda idx : fitnesses [idx ]
291290 elite_indices = sorted (range (pop_size ), key = get_fitness , reverse = True )[:elitism ]
292- elites = [population [i ][:] for i in elite_indices ]
291+ elites = [population [idx ][:] for idx in elite_indices ]
293292
294293 # New generation
295294 new_pop = elites [:]
You can’t perform that action at this time.
0 commit comments