I'm in need of help, I'm developing a genetic algorithm, well my problem is that I need my loop not to stop as long as I have space on the list. As for example I have a population of 10 already created, as soon as it enters the selection function random numbers are drawn according to the fitness and then another population is constructed with those 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