Exemple #1
0
def newpop(popsize, genlength, pop, user):
    for i in range(popsize):
        a = Artist(population=pop,
                   generation=0,
                   fitness=0,
                   member=i,
                   seen=False,
                   image=None,
                   genome=GA.birth(genlength),
                   user=user)
        a.save()
        tasks.generate_image(a.id)
Exemple #2
0
def newgen(population):
    popNo = population[0].population
    gen = population[0].generation + 1
    user = population[0].user
    population = list(population)
    random.shuffle(population)

    for i in range(len(population) - int(len(population) / 10)):
        mother = select_parent(population)
        father = select_parent(population)
        if len(father.genome) < len(mother.genome):
            mother, father = father, mother
        child = crossover(mother, father)
        child = mutate(child, 0.1, 0.5)
        a = Artist(population=popNo,
                   generation=gen,
                   fitness=0,
                   member=i,
                   seen=False,
                   image='',
                   image500='',
                   genome=child,
                   user=user)
        a.save()
        a.mother.set([mother.id])
        a.father.set([father.id])
        a.save()
        tasks.generate_image(a.id)
    for i in range(int(len(population) / 10)):
        a = Artist(population=popNo,
                   generation=gen,
                   fitness=0,
                   member=len(population) - int(len(population) / 10) + i,
                   seen=False,
                   image='',
                   image500='',
                   genome=GA.birth(30),
                   user=user)
        a.save()
        tasks.generate_image(a.id)
Exemple #3
0
def global_mate(mother, population, username):
    popNo = mother.population
    gen = mother.generation + 1
    member = max([p.member
                  for p in population if p.generation == gen] + [-1]) + 1
    mf = round(sum([p.mean_fitness for p in population]))
    father = select_parent(population, mean=True)
    if len(father.genome) < len(mother.genome):
        mother, father = father, mother
    child = crossover(mother, father)
    child = mutate(child, 0.1, 0.5)
    a = Artist(population=popNo,
               generation=gen,
               fitness=mf,
               member=member,
               seen=False,
               image='',
               image500='',
               genome=child,
               user=username,
               global_pop=True)
    a.save()
    a.mother.set([mother.id])
    a.father.set([father.id])
    a.save()
    tasks.generate_image(a.id)
    if random.random() < 0.1:
        a = Artist(population=popNo,
                   generation=gen,
                   fitness=mf,
                   member=member + 1,
                   seen=False,
                   image='',
                   image500='',
                   genome=GA.birth(30),
                   user='******',
                   global_pop=True)
        a.save()
        tasks.generate_image(a.id)