def simulate_res1(env, iteration): """Test the performane of evolved behavior.""" phenotypes = env[0] threshold = 1.0 sim = SimModel( 100, 100, 100, 10, iter=iteration, xmlstrings=phenotypes, pname=env[1], expname='MSFRes1', agent='SimAgentRes1') sim.build_environment_from_json() # for all agents store the information about hub for agent in sim.agents: agent.shared_content['Hub'] = {sim.hub} # agent.shared_content['Sites'] = {sim.site} simresults = SimulationResults( sim.pname, sim.connect, sim.sn, sim.stepcnt, sim.food_in_hub(), phenotypes[0] ) simresults.save_phenotype() simresults.save_to_file() # Iterate and execute each step in the environment for i in range(iteration): # For every iteration we need to store the results # Save them into db or a file sim.step() simresults = SimulationResults( sim.pname, sim.connect, sim.sn, sim.stepcnt, sim.food_in_hub(), phenotypes[0] ) simresults.save_to_file() # print ('food at site', len(sim.food_in_loc(sim.site.location))) # print ('food at hub', len(sim.food_in_loc(sim.hub.location))) # print("Total food in the hub", len(food_objects)) food_objects = sim.food_in_loc(sim.hub.location) for food in food_objects: print('simulate phenotye:', dir(food)) value = sim.food_in_hub() foraging_percent = ( value * 100.0) / (sim.num_agents * 2.0) sucess = False print('Foraging percent', value) if foraging_percent >= threshold: print('Foraging success') sucess = True sim.experiment.update_experiment_simulation(value, sucess) # Plot the fitness in the graph graph = GraphACC(sim.pname, 'simulation.csv') graph.gen_plot()
def main(): iteration = 1500 env = SimModel(100, width, height, 10, iter=iteration, viewer=False) env.build_environment_from_json() # for all agents store the information about hub for agent in env.agents: agent.shared_content['Hub'] = {env.hub} # Iterate and execute each step in the environment # print ('Step', 'Name', 'TS', 'DEL', 'OVF', 'EXP', 'CAR', 'FOR', 'GNM') for i in range(iteration): env.step() print(len(env.food_in_loc(env.hub.location)))
def simulate_res1(env, iteration): """Test the performane of evolved behavior with type 1 resilience.""" phenotypes = env[0] threshold = 1.0 sim = SimModel(100, 100, 100, 10, iter=iteration, xmlstrings=phenotypes, pname=env[1], expname='NMRes1', agent='SimAgentRes1') sim.build_environment_from_json() after_simulation(sim, phenotypes, iteration, threshold)
def simulate_res2(env, iteration): """Test the performane of evolved behavior.""" phenotypes = env[0] threshold = 1.0 sim = SimModel(100, 100, 100, 10, iter=iteration, xmlstrings=phenotypes, pname=env[1], expname='COTCommRes2', agent='SimAgentResComm2') sim.build_environment_from_json() after_simluation(sim, phenotypes, iteration, threshold)
def simulate(env, iteration): """Test the performane of evolved behavior.""" # phenotype = agent.individual[0].phenotype # phenotypes = extract_phenotype(agents) phenotypes = env[0] threshold = 1.0 sim = SimModel(100, 100, 100, 10, iter=iteration, xmlstrings=phenotypes, pname=env[1]) sim.build_environment_from_json() after_simulation(sim, phenotypes, iteration, threshold)
def simulate(env, iteration, N=100): """Test the performane of evolved behavior.""" phenotypes = env[0] threshold = 1.0 sim = SimModel(N, 100, 100, 10, seed=None, iter=iteration, xmlstrings=phenotypes, pname=env[1]) sim.build_environment_from_json() # print(len(sim.obstacles), len(sim.debris)) # py_trees.display.print_ascii_tree(sim.agents[0].bt.behaviour_tree.root) after_simulation(sim, phenotypes, iteration, threshold)