Simple Spread¶

警告
环境 pettingzoo.mpe.simple_spread_v3 已移至新的 MPE2 包,并在 PettingZoo 未来版本中移除。请将导入更新为 mpe2.simple_spread_v3。
此环境是 MPE 环境 的一部分。请先阅读该页面以获取一般信息。
导入 |
|
---|---|
动作 |
离散/连续 |
Parallel API |
是 |
手动控制 |
否 |
智能体 |
|
智能体 |
3 |
动作空间形状 |
(5) |
动作值 |
Discrete(5)/Box(0.0, 1.0, (5)) |
观察空间形状 |
(18) |
观察值 |
(-inf,inf) |
状态空间形状 |
(54,) |
状态值 |
(-inf,inf) |
此环境包含 N 个智能体和 N 个地标(默认 N=3)。总体而言,智能体必须学会在覆盖所有地标的同时避免碰撞。
更具体地说,所有智能体根据离每个地标最近的智能体的距离(最短距离之和)获得全局奖励。在局部,智能体如果与其他智能体发生碰撞则会受到惩罚(每次碰撞 -1)。这些奖励的相对权重可以通过 local_ratio
参数控制。
智能体观察:[self_vel, self_pos, landmark_rel_positions, other_agent_rel_positions, communication]
智能体动作空间:[no_action, move_left, move_right, move_down, move_up]
参数¶
simple_spread_v3.env(N=3, local_ratio=0.5, max_cycles=25, continuous_actions=False, dynamic_rescaling=False)
N
:智能体和地标的数量
local_ratio
:应用于局部奖励和全局奖励的权重。全局奖励权重始终为 1 - 局部奖励权重。
max_cycles
:游戏终止前的帧数(每个智能体行动一步算一帧)
continuous_actions
:智能体动作空间是离散(默认)还是连续
dynamic_rescaling
:是否根据屏幕尺寸调整智能体和地标的大小
用法¶
AEC¶
from pettingzoo.mpe import simple_spread_v3
env = simple_spread_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()
Parallel¶
from pettingzoo.mpe import simple_spread_v3
env = simple_spread_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()