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]
# Set target direction for herding agents that do not have a target
# if field.obstacles is None:
# agents['target_direction'][is_follower] = direction_herding[is_follower]
# else:
# # Obstacle avoidance
# mgrid = field.meshgrid(self.step)
# dir_map_obs, dmap_obs = field.direction_map_obstacles(self.step)
# indices = np.fliplr(mgrid.indicer(agents['position'][is_follower]))
# direction = obstacle_handling_continuous(
# dmap_obs, dir_map_obs, direction_herding[is_follower], indices,
# self.radius, self.strength)
# agents['target_direction'][is_follower] = direction
评论列表
文章目录