def observe_agents(other_agent): ''' fill in information communicated/observed between agents ''' # check if node is terminated is_terminated = 0 if isinstance(other_agent, MortalAgent) and other_agent.terminated: is_terminated = 1 # relative speed and position of other agent # dx = dy = dvx = dvy = 0. # if not is_terminated: dx, dy = delta_pos(other_agent, agent) dvx, dvy = delta_vel(other_agent, agent) # get local reward function at position of other agent other_landmark_sensor_reading = 0.0 for lm in world.landmarks: other_landmark_sensor_reading += lm.reward_fn.get_value( *other_agent.state.p_pos) ag_obs = [ is_terminated, dx, dy, dvx, dvy, other_landmark_sensor_reading ] assert (len(ag_obs) == _AGENT_OBSERVATION_LEN) return ag_obs
def communications_observed(other_comm_node): ''' Communication between agents is just the conductance Notes: - inverse of comm resistance (i.e. conductance) used so that we can use zero for out of range comms - noisy measurement of heading - TODO: observation of failures ''' # check if node is terminated is_terminated = 0 if isinstance(other_comm_node, MortalAgent) and other_comm_node.terminated: is_terminated = 1 dx = dy = dvx = dvy = 0. if not is_terminated: dx, dy = delta_pos(other_comm_node, agent) dvx, dvy = delta_vel(other_comm_node, agent) comms = [is_terminated, dx, dy, dvx, dvy] # set comms to zero if out for range # if distance(agent, other_comm_node) > agent.max_observation_distance: if not check_2way_communicability(agent, other_comm_node): comms = [0] * len(comms) return comms
def communications_observed(other_comm_node): ''' Communication between agents is just the conductance Notes: - inverse of comm resistance (i.e. conductance) used so that we can use zero for out of range comms - noisy measurement of heading - TODO: observation of failures ''' # check if node is terminated is_terminated = 0 if isinstance(other_comm_node, MortalAgent) and other_comm_node.terminated: is_terminated = 1 dx = dy = dvx = dvy = 0. if not is_terminated: dx, dy = delta_pos(other_comm_node, agent) dvx, dvy = delta_vel(other_comm_node, agent) comms = [is_terminated, dx, dy, dvx, dvy] # dx_noisy = dx + np.random.normal(0.0, 0.01) # dy_noisy = dy + np.random.normal(0.0, 0.01) # comms = [dx_noisy, dy_noisy] # heading = np.arctan2(dy,dx) + np.random.normal(0.0, 0.1) # conductance = 1.0/self._calculate_resistance(agent, other_comm_node, world) # comms = [heading, conductance] # set comms to zero if out for range # if distance(agent, other_comm_node) > agent.max_observation_distance: # comms = [0] * len(comms) return comms
def observe_agents(other_agent): ''' fill in information communicated/observed between agents ''' # check if node is terminated is_terminated = 0 if isinstance(other_agent, MortalAgent) and other_agent.terminated: is_terminated = 1 dx = dy = dvx = dvy = 0. if not is_terminated: dx, dy = delta_pos(other_agent, agent) dvx, dvy = delta_vel(other_agent, agent) ag_obs = [is_terminated, dx, dy, dvx, dvy] assert (len(ag_obs) == _AGENT_OBSERVATION_LEN) return ag_obs