我无法为多智能体健身房环境选择随机动作。
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我找不到一个修复,因为没有足够的讨论这些多代理环境。
发布于 2018-11-15 12:46:30
在回答我自己的问题时,让我们考虑一下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.])]
(视环境而定)
https://stackoverflow.com/questions/53304915
复制相似问题