class GENEALG:
    def __init__(self, play_back=False):
        if play_back:
            f = open('robot.p', 'rb')
            self.parent = pickle.load(f)
            f.close()
        else:
            self.parent = POPULATION(c.popSize)
            self.parent.Initialize()
            self.parent.Evaluate()

    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)

    def Show_Best(self):
        bestIndividual = self.parent.Best_Individual()
        self.parent.p[bestIndividual].Start_Evaluation(pb=False, pp=True)
        self.parent.p[bestIndividual].Compute_Fitness()
        print(self.parent.p[bestIndividual].fitness)

    def Save(self):
        f = open('robot.p', 'wb')
        pickle.dump(self.parent, f)
        f.close()
Example #2
0
from population import POPULATION
import copy

parents = POPULATION(10)

parents.Initialize()  # 09

parents.Evaluate(pp=False, pb=True)

parents.Print()

for g in range(1, 200):
    children = copy.deepcopy(parents)
    children.Mutate()
    children.Evaluate(pp=False, pb=True)
    parents.ReplaceWith(children)
    #parents.Sort()
    print g,
    parents.Print()

parents.Evaluate(pp=True, pb=False)
import pyrosim
import matplotlib.pyplot as plt
import random
import numpy
import copy
import pickle

from individual import INDIVIDUAL
from robot import ROBOT
from population import POPULATION

parents = POPULATION(
    10)  # creates a empty population but stores the population size
parents.Initialize()  #start a population of individuals of size 'i'
parents.Evaluate(True)  # Evaluates the fitness of each individual
#exit() # exit the program immediately
parents.Print()  #print ID and fitness of each individual

for i in range(1, 200):
    children = POPULATION(5)
    #children.Print()
    children.Fill_From(parents)
    #children.Print()
    children.Evaluate(True)
    children.Print()
    parents = children

parents.Evaluate(False)
parents.Print()
Example #4
0
from archive import Archive

envs = PLATFORMS()
# f = open('saved_files/bestJumpEver2019-04-27.p', 'rb')
# f = open('saved_files/4hidden_500gen_apfo_thruwall2019-05-02.p', 'rb')
# f = open('saved_files/2019-05-02.p', 'rb')
# f = open('saved_files/samplesave2019-05-01.p', 'rb')
# f = open('saved_files/4hidden_6legs_apfo_500gen_ind.p', 'rb')
f = open('saved_files/1env_500gens_genetic_6legs_4hidden_trial32019-05-05.p',
         'rb')
best_genome = pickle.load(f)
f.close()
best_pop = POPULATION(1)

if isinstance(best_genome, Archive):
    best_pop.Initialize(best_genome.genome, best_genome.cppn)
elif isinstance(best_genome, list):
    best_pop.Initialize(best_genome)
else:
    print("Could not determine class")
    exit()

# best_pop.Initialize(best_genome)
best_pop.Evaluate_Best(envs, pb=False, pp=True, retain_data=True)

recorder = Recorder()
recorder.plot_touch_values(best_pop.pop[0])

newSave = input("New Save? (y/n)")
if (newSave == 'y'):
    label = input("New Label: ") + '.p'
Example #5
0
# ENVIRONMENTS #
################

envs_1 = ENVIRONMENTS_1()
envs_2 = ENVIRONMENTS_2()
envs_3 = ENVIRONMENTS_3()

###########
# PARENTS #
###########

#---NEW POPULATION---#
if (c.newMode):
    # initialize parents
    parents_1 = POPULATION(c.popSize)
    parents_1.Initialize()
    #--------------------#
    parents_2 = POPULATION(c.popSize)
    parents_2.Initialize()
    #--------------------#
    parents_3 = POPULATION(c.popSize)
    parents_3.Initialize()

#---LOAD POPULATION---#
if (c.loadMode):
    # load in parents
    parents_1 = pickle.load(file_1)
    parents_2 = pickle.load(file_2)
    parents_3 = pickle.load(file_3)
    # close files
    file_1.close()
Example #6
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 #7
0
import pickle
from population import POPULATION
from platforms import PLATFORMS
import constants as c
import datetime
import time
from recorder import Recorder
import os
import pprint
from archive import Archive
import matplotlib.pyplot as plt

envs = PLATFORMS()

parents = POPULATION(c.popSize)
parents.Initialize()
parents.Evaluate(envs, pb=True, pp=False)
while not parents.pop[0].test_pass:
    print("test failure")
    parents = POPULATION(c.popSize)
    parents.Initialize()
    parents.Evaluate(envs, pb=True, pp=False)
parents.Print()
startTimes = []
copyTimes = []
evalTimes = []
generations = []
fillTimes = []
entire_fill = []

pop_size = c.popSize