if EVO_MODE == 1: print("evolving for robustness") else: print("evolving for maximum fitness") def GetNewController(): return np.random.choice(controllerTypes) aggregates = FIXEDAGGPOP(AGGREGATE, num_cubes=num_cubes) controllers = POPULATION(GetNewController(), pop_size=N, unique=True) aggregates.initialize() controllers.initialize() coevolve = COEVOLVE(aggregates, controllers, EVO_MODE, seed) latestGen = 1 if os.path.exists("./saved_generations/gen%d.p" % latestGen): while os.path.exists("./saved_generations/gen%d.p" % latestGen): print("Gen", latestGen, "exists") latestGen += 1 f = open("./saved_generations/gen%d.p" % (latestGen - 1), 'rb') saveState = pickle.load(f) coevolve = saveState[0] seed = saveState[1] np.random.set_state(seed) f.close()
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) print(g + 1, parents) parents.playbest()