def __init__(self, env, n_lidar_per_agent=30, lidar_range=6.0, compress_lidar_scale=None, visualize_lidar=False): super().__init__(env) self.n_lidar_per_agent = n_lidar_per_agent self.lidar_range = lidar_range self.compress_lidar_scale = compress_lidar_scale self.visualize_lidar = visualize_lidar self.n_agents = self.unwrapped.n_agents self.observation_space = update_obs_space( env, {'lidar': (self.n_agents, self.n_lidar_per_agent, 1)}) # generate concentric lidar rays centered at origin self.lidar_angles = np.linspace(0, 2 * np.pi, num=self.n_lidar_per_agent, endpoint=False) self.lidar_rays = self.lidar_range * np.array([ np.cos(self.lidar_angles), np.sin(self.lidar_angles), np.zeros_like(self.lidar_angles) ]).T self.lidar_rays = self.lidar_rays[None, :]
def __init__(self, env, body_names, radius_multiplier=1.5, agent_idx_allowed_to_lock=None, lock_type="any_lock", ac_obs_prefix='', obj_in_game_metadata_keys=None, agent_allowed_to_lock_keys=None): super().__init__(env) self.n_agents = self.unwrapped.n_agents self.n_obj = len(body_names) self.body_names = body_names self.agent_idx_allowed_to_lock = np.arange( self.n_agents ) if agent_idx_allowed_to_lock is None else agent_idx_allowed_to_lock self.lock_type = lock_type self.ac_obs_prefix = ac_obs_prefix self.obj_in_game_metadata_keys = obj_in_game_metadata_keys self.agent_allowed_to_lock_keys = agent_allowed_to_lock_keys self.action_space.spaces[f'action_{ac_obs_prefix}glue'] = (Tuple( [MultiDiscrete([2] * self.n_obj) for _ in range(self.n_agents)])) self.observation_space = update_obs_space( env, { f'{ac_obs_prefix}obj_lock': (self.n_obj, 1), f'{ac_obs_prefix}you_lock': (self.n_agents, self.n_obj, 1), f'{ac_obs_prefix}team_lock': (self.n_agents, self.n_obj, 1) }) self.lock_radius = radius_multiplier * self.metadata['box_size'] self.obj_locked = np.zeros((self.n_obj, ), dtype=int)
def __init__(self, env, horizon): super().__init__(env) self.n_agents = self.unwrapped.n_agents self.horizon = horizon self.current_step = 0 self.observation_space = update_obs_space( env, {'current_step': (self.n_agents, 1)})
def __init__(self, env, prep_fraction=.2): super().__init__(env) self.prep_fraction = prep_fraction self.prep_time = self.prep_fraction * self.unwrapped.horizon self.n_agents = self.metadata['n_agents'] self.step_counter = 0 self.observation_space = update_obs_space( self, {'prep_obs': [self.n_agents, 1]})
def __init__(self, env, pos_obs_key, mask_obs_key, cone_angle=3 / 8 * np.pi): super().__init__(env) self.cone_angle = cone_angle self.n_agents = self.unwrapped.n_agents assert (self.n_agents == self.observation_space.spaces['agent_pos'].shape[0]) self.n_objects = self.observation_space.spaces[pos_obs_key].shape[0] self.observation_space = update_obs_space( env, {mask_obs_key: (self.n_agents, self.n_objects)}) self.pos_obs_key = pos_obs_key self.mask_obs_key = mask_obs_key
def __init__(self, env, team_index=None, n_teams=2): super().__init__(env) self.n_agents = self.metadata['n_actors'] if team_index is None: assert n_teams >= 1, "Number of teams must be at least 1" # split teams: 5 agents and 3 teams will result in team_index = [0,0,1,1,2] team_index = np.array_split(np.arange(self.n_agents), n_teams) team_index = np.concatenate([np.ones_like(ar) * i for i, ar in enumerate(team_index)]) assert len(team_index) == self.n_agents, ( "team_index parameter length must be equal to number of agents") if isinstance(team_index, np.ndarray): assert team_index.ndim == 1, ( "team_index parameter must be numpy array of dimension 1") # store in metadata property that gets automatically inherited # make sure we copy value of team_index if it's a numpy array self.metadata['team_index'] = np.array(team_index) self.team_idx = np.array(team_index) self.observation_space = update_obs_space(env, {'team_size': (self.n_agents, 1)})
def __init__(self, env, body_names, radius_multiplier=1.7, grab_dist=None, grab_exclusive=False, obj_in_game_metadata_keys=None): super().__init__(env) self.n_agents = self.unwrapped.n_agents self.body_names = body_names self.n_obj = len(body_names) self.obj_in_game_metadata_keys = obj_in_game_metadata_keys self.action_space.spaces['action_pull'] = (Tuple( [MultiDiscrete([2] * self.n_obj) for _ in range(self.n_agents)])) self.observation_space = update_obs_space(env, { 'obj_pull': (self.n_obj, 1), 'you_pull': (self.n_obj, self.n_agents) }) self.grab_radius = radius_multiplier * self.metadata['box_size'] self.grab_dist = grab_dist self.grab_exclusive = grab_exclusive
def __init__(self, env, eat_thresh=0.5, max_food_health=10, respawn_time=np.inf, food_rew_type='selfish', reward_scale=1.0, reward_scale_obs=False): super().__init__(env) self.eat_thresh = eat_thresh self.max_food_health = max_food_health self.respawn_time = respawn_time self.food_rew_type = food_rew_type self.n_agents = self.metadata['n_agents'] if type(reward_scale) not in [list, tuple, np.ndarray]: reward_scale = [reward_scale, reward_scale] self.reward_scale = reward_scale self.reward_scale_obs = reward_scale_obs # Reset obs/action space to match self.max_n_food = self.metadata['max_n_food'] self.curr_n_food = self.metadata['curr_n_food'] self.max_food_size = self.metadata['food_size'] food_dim = 5 if self.reward_scale_obs else 4 self.observation_space = update_obs_space(self.env, {'food_obs': (self.max_n_food, food_dim), 'food_health': (self.max_n_food, 1), 'food_eat': (self.max_n_food, 1)}) self.action_space.spaces['action_eat_food'] = Tuple([MultiDiscrete([2] * self.max_n_food) for _ in range(self.n_agents)])
def __init__(self, env, cone_angle=3 / 8 * np.pi): super().__init__(env) self.cone_angle = cone_angle self.n_agents = self.unwrapped.n_agents self.observation_space = update_obs_space( env, {'mask_aa_obs': (self.n_agents, self.n_agents)})