def main(): # Get behavior behavior_function = agent_behavior_base.behavior # Open log file logfile = open('average_baseline.txt', 'w') logfile.write('gen, survive, avgF\n') print('gen, survive, avgF') for gen in range(200): sim_count = 10 # Average over sim_count simulations fit_sum = 0 survive_sum = 0 for i in range(sim_count): # Create and initialize environment env = environment.Environment(behavior_function, dt = .1, sim_time = 0, time_out = 50, hash_map_grid_size = 40, width = 800, height = 600, show_bins = False) env.create_perimeter_walls(location = 'inside', thickness = 5) # Walls create.create_test_terrain(env) # Terrain create.create_random_swarm(env, count = 10, radius = 20) # Swarm sim_time, survivor_count, total_agent_health, predator_health = env.run_sim_no_gfx() fitness = total_agent_health - predator_health fit_sum += fitness survive_sum += survivor_count log_string = '{:>3d}, {:>4.1f}, {:>7.1f}'.format(gen, survive_sum/sim_count, fit_sum/sim_count) logfile.write('{:}\n'.format(log_string)) print(log_string) logfile.close()
def main(): # Get behavior behavior_function = behavior_from_json('test11_data.json') #behavior_function = agent_behavior_base.behavior sim_count = 30 # Average over sim_count simulations fit_sum = 0 survive_sum = 0 for i in range(sim_count): # Create and initialize environment env = environment.Environment(behavior_function, dt = .1, sim_time = 0, time_out = 50, hash_map_grid_size = 40, width = 800, height = 600, show_bins = False) env.create_perimeter_walls(location = 'inside', thickness = 5) # Walls create.create_test_terrain(env) # Terrain create.create_random_swarm(env, count = 10, radius = 20) # Swarm sim_time, survivor_count, total_agent_health, predator_health = env.run_sim_no_gfx() fitness = total_agent_health - predator_health fit_sum += fitness survive_sum += survivor_count print('trial {:}/{:}, fitness = {:}'.format(i+1, sim_count, fitness), end='\r') print('\navg fitness over {:} simulations = {:.1f}'.format(sim_count, fit_sum / sim_count))
def main(): # Get behavior behavior_function = behavior_from_json('test11_data.json') #behavior_function = agent_behavior_base.behavior sim_count = 30 # Average over sim_count simulations fit_sum = 0 survive_sum = 0 for i in range(sim_count): # Create and initialize environment env = environment.Environment(behavior_function, dt=.1, sim_time=0, time_out=50, hash_map_grid_size=40, width=800, height=600, show_bins=False) env.create_perimeter_walls(location='inside', thickness=5) # Walls create.create_test_terrain(env) # Terrain create.create_random_swarm(env, count=10, radius=20) # Swarm sim_time, survivor_count, total_agent_health, predator_health = env.run_sim_no_gfx( ) fitness = total_agent_health - predator_health fit_sum += fitness survive_sum += survivor_count print('trial {:}/{:}, fitness = {:}'.format(i + 1, sim_count, fitness), end='\r') print('\navg fitness over {:} simulations = {:.1f}'.format( sim_count, fit_sum / sim_count))
def main(): # Get behavior behavior_function = agent_behavior_base.behavior # Open log file logfile = open('average_baseline.txt', 'w') logfile.write('gen, survive, avgF\n') print('gen, survive, avgF') for gen in range(200): sim_count = 10 # Average over sim_count simulations fit_sum = 0 survive_sum = 0 for i in range(sim_count): # Create and initialize environment env = environment.Environment(behavior_function, dt=.1, sim_time=0, time_out=50, hash_map_grid_size=40, width=800, height=600, show_bins=False) env.create_perimeter_walls(location='inside', thickness=5) # Walls create.create_test_terrain(env) # Terrain create.create_random_swarm(env, count=10, radius=20) # Swarm sim_time, survivor_count, total_agent_health, predator_health = env.run_sim_no_gfx( ) fitness = total_agent_health - predator_health fit_sum += fitness survive_sum += survivor_count log_string = '{:>3d}, {:>4.1f}, {:>7.1f}'.format( gen, survive_sum / sim_count, fit_sum / sim_count) logfile.write('{:}\n'.format(log_string)) print(log_string) logfile.close()
def simulator(input, output): for index, individual, sim_time_step, sim_time_out, sim_count in iter(input.get, 'STOP'): # Average over sim_count simulations fit_sum = 0 survive_sum = 0 for i in range(sim_count): # Create and initialize environment env = environment.Environment(individual.behavior, dt = sim_time_step, sim_time = 0, time_out = sim_time_out, hash_map_grid_size = 40, width = 800, height = 600, show_bins = False) env.create_perimeter_walls(location = 'inside', thickness = 5) # Walls create.create_test_terrain(env) # Terrain create.create_random_swarm(env, count = 10, radius = 20) # Swarm sim_time, survivor_count, total_agent_health, predator_health = env.run_sim_no_gfx() fitness = total_agent_health - predator_health fit_sum += fitness survive_sum += survivor_count result = (index, fit_sum/sim_count, survive_sum/sim_count) output.put(result)
from simulation_environment import create from simulation_environment import environment from simulation_environment import agent_behavior_base # Baseline agent_behavior_function = agent_behavior_base.behavior # Create and initialize environment environment = environment.Environment(agent_behavior_function, dt = .1, sim_time = 0, time_out = 150, hash_map_grid_size = 40, width = 800, height = 600, show_bins = False) environment.create_perimeter_walls(location = 'inside', thickness = 5) # Walls create.create_test_terrain(environment) # Terrain create.create_random_swarm(environment, count = 10, radius = 20) # Swarm time, survivor_count, total_agent_health, predator_health = environment.run_sim_no_gfx() print("time = ", time) print("survivor_count = ", survivor_count) print("total_agent_health = ", total_agent_health) print("predator_health = ", predator_health)
max_fit = float('-inf') elite_individual = None for i, individual_data in enumerate(pop_data): if individual_data['_fit'] > max_fit: max_fit = individual_data['_fit'] elite_individual = lgp.Behavior() elite_individual.s_lgp.prog = individual_data['s_lgp'] elite_individual.a_lgp.prog = individual_data['a_lgp'] return elite_individual.behavior # Genetic program loaded from json file agent_behavior_function = behavior_from_json('test13_data.json') #agent_behavior_function = agent_behavior_base.behavior # Create and initialize environment env = environment.Environment(agent_behavior_function, dt = .1, sim_time = 0, time_out = 100, hash_map_grid_size = 40, width = 800, height = 600, show_bins = False, run_max_speed = True) env.create_perimeter_walls(location = 'inside', thickness = 5) # Walls create.create_test_terrain(env) # Terrain create.create_random_swarm(env, count = 10, radius = 20) # Swarm # Create active action manager active_actions = active_actions.ActiveActions(env) pyglet.clock.schedule_interval(update, 1/120) # Update display 60 times per second window.push_handlers(event_handlers.EventHandlers(env, window, active_actions)) pyglet.app.run() # Run pyglet