Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 493fd13

Browse files
yrevarreachtarunhere
authored andcommitted
Fixed genetic_algorithm() population iterator (aimacode#296)
Seems like a typo, results in error: TypeError: 'int' object is not iterable. Fixing it: for i in len(population) -> for i in range(len(population))
1 parent fc287e2 commit 493fd13

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def genetic_algorithm(population, fitness_fn, ngen=1000, pmut=0.1):
584584
"[Figure 4.8]"
585585
for i in range(ngen):
586586
new_population = []
587-
for i in len(population):
587+
for i in range(len(population)):
588588
fitnesses = map(fitness_fn, population)
589589
p1, p2 = weighted_sample_with_replacement(population, fitnesses, 2)
590590
child = p1.mate(p2)

0 commit comments

Comments
 (0)