-1
I’m in need of help, I’m developing a genetic algorithm, well my problem is that I need my loop to not stop as long as there’s room on the list. As for example I have a population of 10 already created, as soon as it enters the selected function random numbers are drawn according to the apitidão (fitness) and then another population is built with these numbers that were "drawn".
def selecao(fitness, populacao):
populacaoIntermediaria=[]
somatotal = sum(fitness)
for i in range(tamPopulacao):
r = uniform(0, somatotal)
if (fitness[i] > r):
populacaoIntermediaria.append(populacao[i])
print('População Intermediaria: {}'.format(populacaoIntermediaria))
return populacaoIntermediaria
Possible duplicate of Python: fill a list
– Woss