def Evolve(self):
     for g in range(c.numGens):
         print(g, end=' ')
         self.parent.Print()
         child = POPULATION(c.popSize)
         child.Fill_From(self.parent)
         child.Evaluate()
         self.parent.ReplaceWith(child)
Example #2
0
import pickle
from population import POPULATION
from individual import INDIVIDUAL
import constants as c
from environments import ENVIRONMENTS
from environment import ENVIRONMENT

envs = ENVIRONMENTS()

parents = POPULATION(c.popSize)
parents.Initialize()
parents.Evaluate(envs, pp=False, pb=True)
#
parents.Print()

for g in range(1, c.numGens):

    children = POPULATION(c.popSize)
    children.Fill_From(parents)
    children.Evaluate(envs, pp=False, pb=True)
    print(g),
    children.Print(),
    print(),
    parents.ReplaceWith(children)

if (g == c.numGens - 1):
    print(parents.p[0].fitness)
    for e in range(0, c.numEnvs):
        parents.p[0].Start_Evaluation(envs.envs[e], pp=False, pb=False)
        parents.p[0].Compute_Fitness()
Example #3
0
    print("\nfitness of parents 2 in envs 2:"),
    parents_2.Print()
    print("\nfitness of parents 3 in envs 3:"),
    parents_3.Print()
    print("\n")

    ###################
    # EVOLVE CHILDREN #
    ###################

    startTime = time.time()
    g = 0
    while (time.time() - startTime < c.runTime):
        # initialize children
        children_1 = POPULATION(c.popSize)
        children_1.Fill_From(parents_1)
        #--------------------#
        children_2 = POPULATION(c.popSize)
        children_2.Fill_From(parents_2)
        #--------------------#
        children_3 = POPULATION(c.popSize)
        children_3.Fill_From(parents_3)

        # evaluate children in respective environment types
        children_1.Evaluate(envs_1, True)
        children_2.Evaluate(envs_2, True)
        children_3.Evaluate(envs_3, True)

        # print generation and time
        print("\n results of generation: ", g)
        print("\n evaluation time:", time.time() - startTime)
Example #4
0
evalTimes = []
generations = []
fillTimes = []
entire_fill = []

recorder = Recorder()

children = None
for g in range(1, c.numGens):
    start = time.time()
    # generations.append(g)
    starttime = time.time() - start
    if g > 0:
        del children
    children = POPULATION(c.popSize)
    entire_fill_temp = children.Fill_From(parents)
    fillTime = time.time() - starttime
    # pp.pformat(children.pop[0])
    children.Evaluate(envs, pb=True, pp=False)
    evaluateTime = time.time() - fillTime
    parents = copy.deepcopy(children)
    copyTime = time.time() - evaluateTime
    if g % 2 == 0:
        print(g, end=" ")
        children.Print()
    else:
        print(g)
    recorder.record_times(g, evaluateTime, copyTime, fillTime, starttime,
                          entire_fill_temp)
    recorder.add_metrics(parents.pop[0])
Example #5
0
import pickle
import constants as c
from population import POPULATION
# import matplotlib.pyplot as plt

parent = POPULATION(c.popSize)
parent.Initialize()
parent.Evaluate(True)
for g in range(c.numGens):
    print(g, end=' ')
    parent.Print()
    child = POPULATION(c.popSize)
    child.Fill_From(parent)
    child.Evaluate()
    parent.ReplaceWith(child)
bestIndividual = parent.Best_Individual()
parent.p[bestIndividual].Start_Evaluation(pb=False, pp=True)
parent.p[bestIndividual].Compute_Fitness()

f = open('robot.p', 'wb')
pickle.dump(parent, f)
f.close()
Example #6
0
envs = ENVIRONMENTS()

parents = POPULATION(c.popSize)
parents.Initialize()
parents.Evaluate(envs, True, True, c.evalTime)
parents.Print()

parents2 = POPULATION(c.popSize)
parents2.Initialize2()
parents2.Evaluate(envs, True, True, c.evalTime)
parents2.Print()

for g in range(1, c.numGens):
    children = POPULATION(c.popSize)
    children.Fill_From(parents)
#    children.Fill_From2(parents)
    children.Evaluate(envs, False, True, c.evalTime)
    parents.ReplaceWith(children)
#    parents.ReplaceWith2(children)
    print('Whegged: '),
    print(g),
    children.Print()
    
    children2 = POPULATION(c.popSize)
    children2.Fill_From(parents2)
    children2.Evaluate(envs, False, True, c.evalTime)
    parents2.ReplaceWith(children2)

    print('Wheeled: '),
    print(g),