Beispiel #1
0
def reproduceAsexual(ga, index, child, mom, dad):
    if index > len(ga.population) * 0.9:
        geneticAlgorithm.randomizeIndividual(child)
    else:
        geneticAlgorithm.copyIndividual(mom, child)
        if random.random() < 0.8:
            mutate(child, ga, 0.5)
Beispiel #2
0
def reproduce(ga, index, child, mom, dad):
    if index == 0:
        geneticAlgorithm.copyIndividual(ga.mostfit, child)
    elif index < len(ga.population) / 2:
        for i in range(len(dad)):
            for j in range(len(dad[i])):
                child[i][j] = dad[i][j] if random.random() < 0.5 else mom[i][j]
        if random.random() < 0.01:
            mutate(child, ga)
    elif ga.newbest:
        geneticAlgorithm.copyIndividual(ga.mostfit, child)
        mutate(child, ga)
    elif index < len(ga.population) * 0.75:
        reproduceAsexual(ga, index, child, mom, dad)
    else:
        geneticAlgorithm.randomizeIndividual(child)
Beispiel #3
0
def reproduceSexualMergeElitist(ga, index, child, mom, dad):
    if index == 0:
        geneticAlgorithm.copyIndividual(ga.mostfit, child)
    else:
        reproduceSexualMerge(ga, index, child, mom, dad)