我无法为多主体体育馆环境选择随机动作。
def make_env(scenario_name, benchmark=False):
from multiagent.environment import MultiAgentEnv
import multiagent.scenarios as scenarios
# load scenario from script
scenario = scenarios.load(scenario_name + ".py").Scenario()
# create world
world = scenario.make_world()
# create multiagent environment
if benchmark:
env = MultiAgentEnv(world, scenario.reset_world, scenario.reward, scenario.observation, scenario.benchmark_data)
else:
env = MultiAgentEnv(world, scenario.reset_world, scenario.reward, scenario.observation)
return env
env = make_env('simple_tag')
env.reset()
for i in range(100):
env.render()
actions = [action_space.sample() for action_space in env.action_space]
env.step(actions)
上面的代码抛出此错误:
Traceback (most recent call last):
File "hello.py", line 22, in <module>
env.step(actions)
File "c:\multiagent-particle-envs\multiagent\environment.py", line 88, in step
self._set_action(action_n[i], agent, self.action_space[i])
File "c:\multiagent-particle-envs\multiagent\environment.py", line 174, in _set_action
agent.action.u[0] += action[0][1] - action[0][2]
TypeError: 'int' object is not subscriptable
我找不到解决方法,因为关于这些多代理环境的讨论还不够多。
最佳答案
回答我自己的问题,让我们考虑simple_tag环境。
此环境的env.action_space
提供:[Discrete(5), Discrete(5), Discrete(5), Discrete(5)]
(4个代理)
这就是我发现的误导。我认为这些动作必须是4个元素的列表,例如:[0, 3, 4, 1]
,但它期望的是所有4个代理的一个热向量(5个元素)。
因此,对动作进行编码的正确方法是:[array([1., 0., 0., 0., 0.]), array([0., 0., 1., 0., 0.]), array([0., 0., 0., 0., 1.]), array([0., 0., 0., 1., 0.])]
(取决于环境)
关于python - 多主体健身房环境中的随机主体,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53304915/