I'm having problems on the line that is parcial += pacum [i-1]
I'm getting the error "list index out of range", about the variables and lists: Population and fitness list depend on the size Population that can be any integer value.
def selecao(fitness, populacao):
populacaoIntermediaria=[]
somatotal = sum(fitness)
probSelecao = []
pacum = []
for j in range(len(fitness)):
probSelecao.append(fitness[j]/somatotal)
pacum.append(sum(probSelecao))
print('Pacum({}): {}'.format(j, pacum[j]))
for j in range(tamPopulacao):
i = 1
parcial = 0
r = uniform(0, somatotal)
while (r >= parcial or i == len(pacum)):
print('Posição{}'.format(i))
parcial += pacum[i-1]
i += 1
print('Parcial: {}'.format(parcial))
populacaoIntermediaria.append(populacao[i-1])
print('População Intermediaria: {}'.format(populacaoIntermediaria))
return populacaoIntermediaria