Exemple #1
0
#________________________________________________________________________________________________________________________________
while contGeracao < geracao:

    print("*GERACÃO ", contGeracao)

    pop = gera_population(family, quantIndividuos)

    bestsIndividuos = selecao.select_bests(fits, pop, quantIndividuos)

    family[0] = bestsIndividuos[0].copy()
    family[1] = bestsIndividuos[1].copy()

    print("MELHOR IND 1:  ", convert_bin(bestsIndividuos[0]))
    print("MELHOR IND 2:  ", convert_bin(bestsIndividuos[1]))

    bestsIndividuosCrossing = selecao.crossing(bestsIndividuos[0],
                                               bestsIndividuos[1])

    family[2] = bestsIndividuosCrossing[0].copy()
    family[3] = bestsIndividuosCrossing[1].copy()

    print(
        "---------------------------------------------------------------------------------------------------------------------------------------"
    )
    print("IND 1 CRUZADO: ", convert_bin(bestsIndividuosCrossing[0]))
    print("IND 2 CRUZADO: ", convert_bin(bestsIndividuosCrossing[1]))

    individuoMutation = selecao.mutation(bestsIndividuosCrossing[0],
                                         bestsIndividuosCrossing[1],
                                         quantGenes, porcent)

    family[4] = individuoMutation[0].copy()