简单世界通信¶

警告
环境 pettingzoo.mpe.simple_world_comm_v3 已移至新的 MPE2 包中,并将在未来的版本中从 PettingZoo 中移除。请将你的导入更新为 mpe2.simple_world_comm_v3。
此环境是 MPE 环境的一部分。请先阅读该页面以获取一般信息。
导入 |
|
---|---|
动作 |
离散/连续 |
并行 API |
是 |
手动控制 |
否 |
智能体 |
|
智能体 |
6 |
动作形状 |
(5),(20) |
动作值 |
Discrete(5),(20)/Box(0.0, 1.0, (5)), Box(0.0, 1.0, (9)) |
观察形状 |
(28),(34) |
观察值 |
(-inf,inf) |
状态形状 |
(192,) |
状态值 |
(-inf,inf) |
此环境与 simple_tag 类似,不同之处在于:存在食物(蓝色小球),良好智能体靠近食物会获得奖励;存在“森林”,智能体藏身其中不会被看见;存在“领导对手”,它可以始终看到所有智能体,并能与其他对手通信以协调追捕。默认情况下,有 2 个良好智能体,3 个对手,1 个障碍物,2 个食物和 2 个森林。
具体来说,良好智能体的奖励:每次与对手碰撞 -5,由 simple_tag 中描述的 bound
函数界定的 -2 x 值,每次与食物碰撞 +2,以及 -0.05 x 到任意食物的最小距离。对手智能体因碰撞获得 +5 奖励,以及 -0.1 x 到良好智能体的最小距离。 s
良好智能体观察值:[self_vel, self_pos, landmark_rel_positions, other_agent_rel_positions, self_in_forest, other_agent_velocities]
普通对手观察值:[self_vel, self_pos, landmark_rel_positions, other_agent_rel_positions, other_agent_velocities, self_in_forest, leader_comm]
对手领导者观察值:[self_vel, self_pos, landmark_rel_positions, other_agent_rel_positions, other_agent_velocities, self_in_forest, leader_comm]
请注意,当森林阻止智能体被看见时,该智能体的相对位置观察值将设为 (0,0)。
良好智能体动作空间:[no_action, move_left, move_right, move_down, move_up]
普通对手动作空间:[no_action, move_left, move_right, move_down, move_up]
对手领导者离散动作空间:[say_0, say_1, say_2, say_3] X [no_action, move_left, move_right, move_down, move_up]
其中 X 是笛卡尔积(总动作空间为 50)。
对手领导者连续动作空间:[no_action, move_left, move_right, move_down, move_up, say_0, say_1, say_2, say_3]
参数¶
simple_world_comm_v3.env(num_good=2, num_adversaries=4, num_obstacles=1,
num_food=2, max_cycles=25, num_forests=2, continuous_actions=False, dynamic_rescaling=False)
num_good
: 良好智能体数量
num_adversaries
: 对手数量
num_obstacles
: 障碍物数量
num_food
: 良好智能体因靠近而获得奖励的食物位置数量
max_cycles
: 游戏终止前的帧数(每个智能体一步)
num_forests
: 智能体藏身其中不会被看见的森林数量
continuous_actions
: 智能体动作空间是离散(默认)还是连续
dynamic_rescaling
: 是否根据屏幕尺寸缩放智能体和地标的大小
用法¶
AEC¶
from pettingzoo.mpe import simple_world_comm_v3
env = simple_world_comm_v3.env(render_mode="human")
env.reset(seed=42)
for agent in env.agent_iter():
observation, reward, termination, truncation, info = env.last()
if termination or truncation:
action = None
else:
# this is where you would insert your policy
action = env.action_space(agent).sample()
env.step(action)
env.close()
并行¶
from pettingzoo.mpe import simple_world_comm_v3
env = simple_world_comm_v3.parallel_env(render_mode="human")
observations, infos = env.reset()
while env.agents:
# this is where you would insert your policy
actions = {agent: env.action_space(agent).sample() for agent in env.agents}
observations, rewards, terminations, truncations, infos = env.step(actions)
env.close()