1

我正在尝试为交通灯控制制作 3x3 网格 (grid0) 的多代理实现。在该get_state功能中,我想在此功能中发送给 RL 代理的信息有所不同。因此,代理 1 仅获得在边缘上行驶至交叉口 1 的车辆的信息。

据我了解,每个代理都会调用 `get_state 函数。

如何区分代理?有可能做这样的事情吗?

agent_id = get_agent_id()
    if agent_id =0
        #return 'all info of vehicles on edges heading to traffic light1
    if agent_id =1
        ...

有没有像这样的方法或功能(代理列表或其他东西)来区分get_state功能中的不同代理?

其次,agent_id 是否与红绿灯 id(intersection_id)相同?(以及如何为每个路口分配不同的代理?现在我只是使用默认grid0场景,但我喜欢使用多代理环境)。

提前致谢!

4

1 回答 1

1

1- 在 Flow 中,为了处理多智能体的情况,在某些方法(例如 in get_state())中,我们不是将单个智能体的状态信息作为 annp.array返回,而是返回一个状态字典(agent_id作为键和agent_state作为字典的值) .

所以你可以做这样的事情:

    def get_state(self):

        agent_state_dict = {}
        i = 0
        for intersection, edges in self.scenario.get_node_mapping():
            i = i + 1
            agent_id = self.agent_name_prefix + str(i) # self.agent_name_prefix is defined as string "intersection"

            speeds = []
            dist_to_intersec = []
            traffic_light_states = []

            ..... code .....

            # construct the state (observation) for each agent
            observation = np.array(
                np.concatenate([
                    speeds, dist_to_intersec, traffic_light_states  

            # each intersection is an agent, so we will make a dictionary that maps form "self.agent_name_prefix+'i'" to the state of that agent.
            agent_state_dict.update({agent_id: observation})

        return agent_state_dict

Theagent_state_dict是映射agent_id到“观察”(即状态)的字典

2- 现在回答您的第二个问题,将交叉口定义为代理(因此您将拥有多代理场景),您需要做的就是为交叉口定义相应的 RLlib 函数(get_stateaction_spaceobservation_spacecompute_reward_apply_rl_actions)。如果你这样做,你将拥有一个完整的多代理环境。

于 2019-07-02T22:15:06.003 回答