def _default_agents(self): agents = Agents(agent_type=self.agent_type) obstacles = geom_to_linear_obstacles(self.field.obstacles) # Add new spawns to the field for the leaders self.field.spawns.extend([ rectangle(25, 45, 10, 10), rectangle(80, 65, 10, 10), rectangle(75, 35, 10, 10), rectangle(35, 5, 10, 10), ]) for i in range(self.size_leaders): group_leader = AgentGroup( agent_type=self.agent_type, size=1, attributes=self.attributes(target=i, is_follower=False)) agents.add_non_overlapping_group( group_leader, position_gen=self.field.sample_spawn(i + 1), obstacles=obstacles) group_herding = AgentGroup( agent_type=self.agent_type, size=self.size_herding, attributes=self.attributes(target=NO_TARGET, is_follower=True)) agents.add_non_overlapping_group( group_herding, position_gen=self.field.sample_spawn(0), obstacles=obstacles) return agents
def update(self): agents = self.simulation.agents.array field = self.simulation.field obstacles = geom_to_linear_obstacles(field.obstacles) #direction = leader_follower_interaction(agents, obstacles, self.sight) value = leader_follower_interaction(agents, obstacles, self.sight)
def update(self): agents = self.simulation.agents.array field = self.simulation.field obstacles = geom_to_linear_obstacles(field.obstacles) direction = leader_follower_interaction(agents, obstacles, self.sight) is_follower = agents['is_follower'] agents['target_direction'][is_follower] = direction[is_follower]
def update(self): agents = self.simulation.agents.array if self.simulation.field.obstacles is None: obstacles = np.zeros(shape=0, dtype=obstacle_type_linear) else: obstacles = geom_to_linear_obstacles( self.simulation.field.obstacles) agent_obstacle(agents, obstacles)
def update(self): agents = self.simulation.agents.array field = self.simulation.field # FIXME: virtual obstacles add too much computational overhead # obstacles = geom_to_linear_obstacles( # field.obstacles.buffer(0.3, resolution=3)) obstacles = geom_to_linear_obstacles(field.obstacles) direction_herding = leader_follower_with_herding_interaction( agents, obstacles, self.sight_follower, self.size_nearest_other) is_follower = agents['is_follower'] agents['target_direction'][is_follower] = direction_herding[is_follower]
def _default_agents(self): agents = Agents(agent_type=self.agent_type) group = AgentGroup(agent_type=self.agent_type, size=self.size, attributes=self.attributes()) agents.add_non_overlapping_group( group, position_gen=self.field.sample_spawn(0), obstacles=geom_to_linear_obstacles(self.field.obstacles)) return agents
def update(self): agents = self.simulation.agents.array field = self.simulation.field center_door = np.stack( [np.mean(np.asarray(target), axis=0) for target in field.targets]) obstacles = geom_to_linear_obstacles(field.obstacles) targets, has_detected = exit_detection(center_door, agents['position'], obstacles, self.detection_range) mask = agents['is_follower'] & has_detected agents['target'][mask] = targets[mask] agents['is_follower'][mask] = False
def _default_agents(self): agents = Agents(agent_type=self.agent_type) for spawn, name in enumerate( ['finlandiahall', 'foyer', 'helsinkihall']): group = AgentGroup(agent_type=self.agent_type, size=getattr(self, f'size_{name}'), attributes=self.attributes(has_target=True, is_follower=False)) agents.add_non_overlapping_group( group, position_gen=self.field.sample_spawn(spawn), obstacles=geom_to_linear_obstacles(self.field.obstacles)) return agents
def _default_agents(self): agents = Agents(agent_type=self.agent_type) group_active = AgentGroup( agent_type=self.agent_type, size=self.size_leaders, attributes=self.attributes(has_target=True, is_follower=False)) group_herding = AgentGroup( agent_type=self.agent_type, size=self.size_herding, attributes=self.attributes(has_target=False, is_follower=True)) for group in (group_active, group_herding): agents.add_non_overlapping_group( group, position_gen=self.field.sample_spawn(0), obstacles=geom_to_linear_obstacles(self.field.obstacles)) return agents
def update(self): agents = self.simulation.agents.array mask = agents['active'] obstacles = geom_to_linear_obstacles(self.simulation.field.obstacles) agent_obstacle(agents, obstacles, mask)
def _default_agents(self): agents = Agents(agent_type=self.agent_type) # Generate iterators for group of leaders. #target_exits = [0,1,0] #cells = [913,695,652] target_exits = [] cells = [] n_guides = len(target_exits) speed_left = "fast" speed_lower = "fast" speed_right = "fast" speed_upper = "fast" # Exiting agents in left spawn group_follower_spawn_left = AgentGroup( agent_type=self.agent_type, size=getattr(self, 'size_spawn_left'), attributes=self.attributes(familiar=2, has_target=True, is_follower=True)) agents.add_non_overlapping_group( speed_left, "spawn_left", group_follower_spawn_left, position_gen=False, position_iter=iter([]), spawn=0, obstacles=geom_to_linear_obstacles(self.field.obstacles)) # Exiting agents in lower spawn group_follower_spawn_lower = AgentGroup( agent_type=self.agent_type, size=getattr(self, 'size_spawn_lower'), attributes=self.attributes(familiar=3, has_target=True, is_follower=True)) agents.add_non_overlapping_group( speed_lower, "spawn_lower", group_follower_spawn_lower, position_gen=False, position_iter=iter([]), spawn=0, obstacles=geom_to_linear_obstacles(self.field.obstacles)) # Exiting agents in right spawn group_follower_spawn_right = AgentGroup( agent_type=self.agent_type, size=getattr(self, 'size_spawn_right'), attributes=self.attributes(familiar=0, has_target=True, is_follower=True)) agents.add_non_overlapping_group( speed_right, "spawn_right", group_follower_spawn_right, position_gen=False, position_iter=iter([]), spawn=2, obstacles=geom_to_linear_obstacles(self.field.obstacles)) # Exiting agents in upper spawn group_follower_spawn_upper = AgentGroup( agent_type=self.agent_type, size=getattr(self, 'size_spawn_upper'), attributes=self.attributes(familiar=1, has_target=True, is_follower=True)) agents.add_non_overlapping_group( speed_upper, "spawn_upper", group_follower_spawn_upper, position_gen=False, position_iter=iter([]), spawn=3, obstacles=geom_to_linear_obstacles(self.field.obstacles)) if n_guides != 0: init_pos = self.generate_leader_pos(cells, n_guides) print(init_pos) # init_pos = [[8, 6]] target_exits = iter(target_exits) init_pos = iter(init_pos) # Guides in Variance Dilemma group_leader = AgentGroup( agent_type=self.agent_type, size=n_guides, attributes=self.attributes_leader(target_iter=target_exits, has_target=True, is_follower=False)) agents.add_non_overlapping_group( "group_leader", group_leader, position_gen=True, position_iter=init_pos, spawn=0, obstacles=geom_to_linear_obstacles(self.field.obstacles)) return agents
def run(individual, n_leaders, scenario): # Import simulation simulation = ComplexFloor() # Import Hallway floor field field = simulation.field # Generate iterators for group of guides. target_exits = [] # Target exit for the guide cells = [] if n_leaders > 0: for i in range(n_leaders): target_exits.append(individual[i][0]) cells.append(individual[i][1]) # Save the target_exits, in another list for later use exits = target_exits # Number of followers size_spawn_left = 50 size_spawn_lower = 50 size_spawn_right = 50 size_spawn_upper = 50 # Set the familiar exit for the followers based on the scenario. if scenario == 0: familiar_left = 0 familiar_lower = 1 familiar_right = 2 familiar_upper = 3 speed_left = "slow" speed_lower = "slow" speed_right = "slow" speed_upper = "slow" # Absolute worst elif scenario == 1: familiar_left = 2 familiar_lower = 3 familiar_right = 0 familiar_upper = 1 speed_left = "slow" speed_lower = "slow" speed_right = "slow" speed_upper = "slow" # Quite bad elif scenario == 2: familiar_left = 2 familiar_lower = 3 familiar_right = 0 familiar_upper = 1 speed_left = "fast" speed_lower = "fast" speed_right = "fast" speed_upper = "fast" # Not so bad elif scenario == 3: familiar_left = 0 familiar_lower = 1 familiar_right = 2 familiar_upper = 3 speed_left = "fast" speed_lower = "fast" speed_right = "fast" speed_upper = "fast" elif scenario == 4: familiar_left = 0 familiar_lower = 1 familiar_right = 2 familiar_upper = 3 speed_left = "slow" speed_lower = "slow" speed_right = "slow" speed_upper = "slow" elif scenario == 5: familiar_left = 0 familiar_lower = 1 familiar_right = 2 familiar_upper = 3 speed_left = "slow" speed_lower = "slow" speed_right = "slow" speed_upper = "slow" elif scenario == 6: familiar_left = 0 familiar_lower = 1 familiar_right = 2 familiar_upper = 3 speed_left = "slow" speed_lower = "slow" speed_right = "slow" speed_upper = "slow" elif scenario == 7: familiar_left = 0 familiar_lower = 1 familiar_right = 2 familiar_upper = 3 speed_left = "slow" speed_lower = "slow" speed_right = "slow" speed_upper = "slow" elif scenario == 8: familiar_left = 0 familiar_lower = 1 familiar_right = 2 familiar_upper = 3 speed_left = "slow" speed_lower = "slow" speed_right = "slow" speed_upper = "slow" elif scenario == 9: familiar_left = 0 familiar_lower = 1 familiar_right = 2 familiar_upper = 3 speed_left = "slow" speed_lower = "slow" speed_right = "slow" speed_upper = "slow" elif scenario == 10: familiar_left = 0 familiar_lower = 1 familiar_right = 2 familiar_upper = 3 speed_left = "slow" speed_lower = "slow" speed_right = "slow" speed_upper = "slow" elif scenario == 11: familiar_left = 0 familiar_lower = 1 familiar_right = 2 familiar_upper = 3 speed_left = "slow" speed_lower = "slow" speed_right = "slow" speed_upper = "slow" elif scenario == 12: familiar_left = 0 familiar_lower = 1 familiar_right = 2 familiar_upper = 3 speed_left = "slow" speed_lower = "slow" speed_right = "slow" speed_upper = "slow" elif scenario == 13: familiar_left = 0 familiar_lower = 1 familiar_right = 2 familiar_upper = 3 speed_left = "slow" speed_lower = "slow" speed_right = "slow" speed_upper = "slow" elif scenario == 14: familiar_left = 0 familiar_lower = 1 familiar_right = 2 familiar_upper = 3 speed_left = "slow" speed_lower = "slow" speed_right = "slow" speed_upper = "slow" else: familiar_left = 0 familiar_lower = 1 familiar_right = 2 familiar_upper = 3 speed_left = "slow" speed_lower = "slow" speed_right = "slow" speed_upper = "slow" # Exiting agents in left spawn group_follower_spawn_left = AgentGroup(agent_type=Circular, size=size_spawn_left, attributes=attributes( simulation, familiar=familiar_left, has_target=True, is_follower=True)) simulation.agents.add_non_overlapping_group( speed_left, "spawn_left", group_follower_spawn_left, position_gen=False, position_iter=iter([]), spawn=0, obstacles=geom_to_linear_obstacles(field.obstacles)) # Exiting agents in lower spawn group_follower_spawn_lower = AgentGroup(agent_type=Circular, size=size_spawn_lower, attributes=attributes( simulation, familiar=familiar_lower, has_target=True, is_follower=True)) simulation.agents.add_non_overlapping_group( speed_lower, "spawn_lower", group_follower_spawn_lower, position_gen=False, position_iter=iter([]), spawn=1, obstacles=geom_to_linear_obstacles(field.obstacles)) # Exiting agents in right spawn group_follower_spawn_right = AgentGroup(agent_type=Circular, size=size_spawn_right, attributes=attributes( simulation, familiar=familiar_right, has_target=True, is_follower=True)) simulation.agents.add_non_overlapping_group( speed_right, "spawn_right", group_follower_spawn_right, position_gen=False, position_iter=iter([]), spawn=2, obstacles=geom_to_linear_obstacles(field.obstacles)) # Exiting agents in upper spawn group_follower_spawn_upper = AgentGroup(agent_type=Circular, size=size_spawn_upper, attributes=attributes( simulation, familiar=familiar_upper, has_target=True, is_follower=True)) simulation.agents.add_non_overlapping_group( speed_upper, "spawn_upper", group_follower_spawn_upper, position_gen=False, position_iter=iter([]), spawn=3, obstacles=geom_to_linear_obstacles(field.obstacles)) if n_leaders == 0: # Check if the solution has already been evaluated, if it has print the penalty and total evacuation time and return bank_evactime = solutionbank(cells, target_exits, n_leaders, scenario) if bank_evactime != 0: print(bank_evactime) return if n_leaders > 0: # generate_leader_pos() should check that guides are not spawned in unfeasible positions init_pos = generate_leader_pos(simulation, cells, n_leaders) print(init_pos) target_exits = iter(target_exits) init_pos = iter(init_pos) # Check if the solution has already been evaluated, if it has print the penalty and total evacuation time and return bank_evactime = solutionbank(cells, target_exits, n_leaders, scenario) if bank_evactime != 0: print(bank_evactime) return # Add guides. # NB! If there are multiple guides, the function that is set to create the guides should check that the guides do # not overlap each other. group_leader = AgentGroup(agent_type=Circular, size=n_leaders, attributes=attributes_leader( simulation, target_iter=target_exits, has_target=True, is_follower=False)) # If it is not taken care before hand that leaders can't overlap, the function will terminate here. simulation.agents.add_non_overlapping_group( "dummy_speed", "group_leader", group_leader, position_gen=True, position_iter=init_pos, spawn=0, obstacles=geom_to_linear_obstacles(field.obstacles)) # We do not need to set the seed number, since we use the deterministic social force model #np.random.seed(seed) simulation.update() simulation.run() print(simulation.data['time_tot']) # Write the solution to the solution bank if n_leaders == 0: banksolution = "{}{}{}{}".format(simulation.data['time_tot'], ' ', scenario, '\n') if n_leaders == 1: banksolution = "{}{}{}{}{}{}{}{}".format(simulation.data['time_tot'], ' ', scenario, ' ', cells[0], ' ', exits[0], '\n') if n_leaders == 2: banksolution = "{}{}{}{}{}{}{}{}{}{}{}{}".format( simulation.data['time_tot'], ' ', scenario, ' ', cells[0], ' ', exits[0], ' ', cells[1], ' ', exits[1], '\n') if n_leaders == 3: banksolution = "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}".format( simulation.data['time_tot'], ' ', scenario, ' ', cells[0], ' ', exits[0], ' ', cells[1], ' ', exits[1], ' ', cells[2], ' ', exits[2], '\n') if n_leaders == 4: banksolution = "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}".format( simulation.data['time_tot'], ' ', scenario, ' ', cells[0], ' ', exits[0], ' ', cells[1], ' ', exits[1], ' ', cells[2], ' ', exits[2], ' ', cells[3], ' ', exits[3], '\n') if n_leaders == 5: banksolution = "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}".format( simulation.data['time_tot'], ' ', scenario, ' ', cells[0], ' ', exits[0], ' ', cells[1], ' ', exits[1], ' ', cells[2], ' ', exits[2], ' ', cells[3], ' ', exits[3], ' ', cells[4], ' ', exits[4], '\n') if n_leaders == 6: banksolution = "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}".format( simulation.data['time_tot'], ' ', scenario, ' ', cells[0], ' ', exits[0], ' ', cells[1], ' ', exits[1], ' ', cells[2], ' ', exits[2], ' ', cells[3], ' ', exits[3], ' ', cells[4], ' ', exits[4], ' ', cells[5], ' ', exits[5], '\n') if n_leaders == 7: banksolution = "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}".format( simulation.data['time_tot'], ' ', scenario, ' ', cells[0], ' ', exits[0], ' ', cells[1], ' ', exits[1], ' ', cells[2], ' ', exits[2], ' ', cells[3], ' ', exits[3], ' ', cells[4], ' ', exits[4], ' ', cells[5], ' ', exits[5], ' ', cells[6], ' ', exits[6], '\n') if n_leaders == 8: banksolution = "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}".format( simulation.data['time_tot'], ' ', scenario, ' ', cells[0], ' ', exits[0], ' ', cells[1], ' ', exits[1], ' ', cells[2], ' ', exits[2], ' ', cells[3], ' ', exits[3], ' ', cells[4], ' ', exits[4], ' ', cells[5], ' ', exits[5], ' ', cells[6], ' ', exits[6], ' ', cells[7], ' ', exits[7], '\n') if n_leaders == 9: banksolution = "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}".format( simulation.data['time_tot'], ' ', scenario, ' ', cells[0], ' ', exits[0], ' ', cells[1], ' ', exits[1], ' ', cells[2], ' ', exits[2], ' ', cells[3], ' ', exits[3], ' ', cells[4], ' ', exits[4], ' ', cells[5], ' ', exits[5], ' ', cells[6], ' ', exits[6], ' ', cells[7], ' ', exits[7], ' ', cells[8], ' ', exits[8], '\n') if n_leaders == 10: banksolution = "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}".format( simulation.data['time_tot'], ' ', scenario, ' ', cells[0], ' ', exits[0], ' ', cells[1], ' ', exits[1], ' ', cells[2], ' ', exits[2], ' ', cells[3], ' ', exits[3], ' ', cells[4], ' ', exits[4], ' ', cells[5], ' ', exits[5], ' ', cells[6], ' ', exits[6], ' ', cells[7], ' ', exits[7], ' ', cells[8], ' ', exits[8], ' ', cells[9], ' ', exits[9], '\n') if os.path.isfile("complex/bank_complex.out"): bankfile = open("complex/bank_complex.out", "a") bankfile.write(banksolution) bankfile.close() else: bankfile = open("complex/bank_complex.out", "w") bankfile.write(banksolution) bankfile.close() return