Ejemplo n.º 1
0
import random
from child import Child

population = []
for i in range(0, 200):
    c = Child()
    c.randomize()
    population.append(c)

while (1):
    selection = []
    for i in population:
        i.calc_fitness()
        i.show()
        print("Fitness is ", i.fitness)
        if i.fitness == 28:
            find()
        for j in range(0, i.fitness):
            selection.append(i)
    population = []
    print("length is ", len(selection))
    for i in range(0, 200):
        a = random.randint(0, len(selection) - 1)
        #print ("a is ", a)
        b = random.randint(0, len(selection) - 1)
        #print ("b is ", b)
        c = selection[a].crossover(selection[b])
        population.append(c)


def find():