def output_winner(self): SingleExperiment.output_winner(self) self.exp_runner.render = True self.exp_runner.run(self.winner, self.learning_config) self.exp_runner.env.produce_trajectory(self.base_directory + 'trajectory' + str(self.exp_name) + '.png') self.exp_runner.render = False
def __init__(self, learning_config, num_generations, controller_keeper, exp_name='', num_trails=1, base_directory='', cntrl_draw_func=None): """ Note the additional parameter genome_encoder, which encodes a genome for sending. """ SingleExperiment.__init__(self, learning_config, num_generations, exp_name, num_trails, base_directory, cntrl_draw_func) self.controllers = controller_keeper self.genome_encoder = self.controllers.genome_encoder # Initialise the variables needed to communicate with the others trough ROS. self.gen_hash = 0 rospy.init_node('evolutionary_algorithm', anonymous=True)
from examples.experiment_functions import SMSwarmExperimentRunner from examples.experiment_template import SingleExperiment # Important variables. from neat.state_machine_genome import StateMachineGenome experiment_name = 'SM_4_reference_block_long' num_steps = 3000 num_generations = 200 num_runs = 1 config_name = 'config-state_machine' if __name__ == '__main__': env = gym.make('tiling-pattern11x11-block-v0') runner = SMSwarmExperimentRunner(env, num_steps) # Create learning configuration. local_dir = os.path.dirname(__file__) config_path = os.path.join(local_dir, config_name) config = neat.Config(StateMachineGenome, neat.DefaultReproduction, neat.DefaultSpeciesSet, neat.DefaultStagnation, config_path) # Create and run experiment. experiment = SingleExperiment(config, runner, num_generations, experiment_name) for i in range(num_runs): experiment.run(experiment_name + str(i))