from copy import deepcopy
from environments import ENVIRONMENTS
from geneticAlgorithm import population as p
import constants as C

envs = ENVIRONMENTS()

parents = p.POPULATION(10)
parents.evaluate(True)
parents.print('  0')

for g in range(C.numGens):
    children = p.POPULATION(initialize=False)
    children.fill_from(parents)
    children.evaluate(True)
    children.print('%3i' % (g + 1))
    parents = children

parents.evaluate(best=True)
import random
import copy
import logging
logging.basicConfig(level=logging.INFO)
import pickle
import pyrosim
import matplotlib.pyplot as plt
import numpy as np
from robot import ROBOT
from individual import INDIVIDUAL
from population import POPULATION
import constants
from environments import ENVIRONMENTS

# create environment with "light source"
envs = ENVIRONMENTS(numEnvs=constants.numEnvs, eval_time=constants.eval_time)

# create initial population
parents = POPULATION(envs,
                     popSize=constants.popSize,
                     eval_time=constants.eval_time)
parents.initialize()
parents.evaluate(play_blind=True, play_paused=False)
print(0, parents)

# evolve:
for g in range(constants.numGen):
    children = POPULATION(envs, parents=parents)
    children.fillFrom(parents)
    children.evaluate(play_blind=True, play_paused=False)
    parents.replaceWith(children)
from population import POPULATION
import constants as c
from environments import ENVIRONMENTS
import pickle
import csv
import os
import glob

finalData = []

for n in range(0, c.sampleSize):

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

    data = []

    # for loop that creates n iterations
    for g in range(1, c.numGens):

        # create the child population
        children = POPULATION(c.popSize)
        # fill the children population from the parents keeping best in first place and
        # filling the rest with mutations
        children.Fill_From(parents)
        # evaluate the children
        children.Evaluate(envs, pp=False, pb=True)
Esempio n. 4
0
from environments import ENVIRONMENTS
from swarm import SWARM
import constants as c
import pickle

envs = ENVIRONMENTS(c.numEnvs)
parents = pickle.load(open("save.txt", "rb"))
parents.evaluateSwarms(envs, pp=True, pb=False)
Esempio n. 5
0
def initialize_population(numSpecies, speciesSize, mutationRate, evalTime, numEnvs):
	parents = SWARM(numSpecies, speciesSize, mutationRate, evalTime, numEnvs)
	parents.Initialize()
	envs = ENVIRONMENTS(numEnvs)
	parents.evaluateSwarms(envs, pp=True, pb=True)
	return (parents)
    if play_result:
        parents.evaluate(envs, best=True)

    if store_fitness is not None:
        parents.p[0].print(to=store_fitness)


def test_loop(pop_range: list, t_fraction: float, m_fraction: float):
    with open('data_out3.csv', 'w') as output:
        output.write('pop_size,t_size,m_rate,score')

        for pop_size in range(*pop_range):

            for t_size in range(1,
                                int(t_fraction * pop_size) + 1,
                                int(pop_size / 10)):
                C.set_cons('t_size', t_size)

                for m_rate in range(1, int(m_fraction * 72) + 1, int(72 / 10)):

                    C.set_cons('m_rate', m_rate)
                    output.write(f'\n{pop_size},{t_size},{m_rate}')
                    genetic_algorithm(
                        pop_size, f'playbacks2/p{pop_size}t{t_size}m{m_rate}',
                        False, output)


envs = ENVIRONMENTS() if C.numEnvs > 0 else None
# test_loop([25, 26, 5], 0.7, 0.5)
genetic_algorithm()