예제 #1
0
    def _airlock_social_vehicle_with_social_agent(
        self,
        vehicle_id: str,
        social_agent_actor: SocialAgentActor,
    ) -> str:
        """When airlocked. The social agent will receive observations and execute
        its policy, however it won't actually operate the vehicle's controller.
        """
        self._log.debug(
            f"Airlocked vehicle={vehicle_id} with actor={social_agent_actor}")

        sim = self._sim
        agent_id = BubbleManager._make_social_agent_id(vehicle_id,
                                                       social_agent_actor)

        if agent_id in sim.agent_manager.social_agent_ids:
            # E.g. if agent is a boid and was being re-used
            interface = sim.agent_manager.agent_interface_for_agent_id(
                agent_id)
        else:
            social_agent = make_social_agent(
                locator=social_agent_actor.agent_locator,
                **social_agent_actor.policy_kwargs,
            )
            interface = social_agent.interface

        mission_planner = MissionPlanner(sim.scenario.waypoints,
                                         sim.scenario.road_network)
        is_boid = isinstance(social_agent_actor, BoidAgentActor)
        vehicle = sim.vehicle_index.prepare_for_agent_control(sim,
                                                              vehicle_id,
                                                              agent_id,
                                                              interface,
                                                              mission_planner,
                                                              boid=is_boid)

        # Setup mission (also used for observations)
        route = sim.traffic_sim.vehicle_route(vehicle_id=vehicle.id)
        mission = Mission(
            start=Start(vehicle.position[:2], vehicle.heading),
            goal=PositionalGoal.fromedge(route[-1], sim.scenario.road_network),
        )
        mission_planner.plan(mission=mission)

        if agent_id not in sim.agent_manager.social_agent_ids:
            social_agent_data_model = SocialAgent(
                id=SocialAgentId.new(social_agent_actor.name),
                name=social_agent_actor.name,
                mission=mission,
                agent_locator=social_agent_actor.agent_locator,
                policy_kwargs=social_agent_actor.policy_kwargs,
                initial_speed=social_agent_actor.initial_speed,
            )
            sim.agent_manager.start_social_agent(agent_id, social_agent,
                                                 social_agent_data_model)

        return agent_id
예제 #2
0
    def _airlock_social_vehicle_with_social_agent(
        self, sim, vehicle_id: str, social_agent_actor: SocialAgentActor, bubble: Bubble
    ) -> str:
        """When airlocked. The social agent will receive observations and execute
        its policy, however it won't actually operate the vehicle's controller.
        """
        self._log.debug(
            f"Airlocked vehicle={vehicle_id} with actor={social_agent_actor}"
        )

        if bubble.is_boid:
            agent_id = BubbleManager._make_boid_social_agent_id(social_agent_actor)
        else:
            agent_id = BubbleManager._make_social_agent_id(vehicle_id)

        social_agent = None
        if (
            bubble.is_boid
            and bubble.keep_alive
            or agent_id in sim.agent_manager.social_agent_ids
        ):
            # E.g. if agent is a boid and was being re-used
            interface = sim.agent_manager.agent_interface_for_agent_id(agent_id)
        else:
            social_agent = make_social_agent(
                locator=social_agent_actor.agent_locator,
                **social_agent_actor.policy_kwargs,
            )
            interface = social_agent.interface

        self._prepare_sensors_for_agent_control(
            sim, vehicle_id, agent_id, interface, bubble
        )

        if social_agent is None:
            return

        self._start_social_agent(
            sim, agent_id, social_agent, social_agent_actor, bubble
        )
예제 #3
0
    def start_keep_alive_boid_agents(self, sim):
        for bubble in filter(
            lambda b: b.is_boid and b.keep_alive, sim.scenario.bubbles
        ):
            actor = bubble.actor
            agent_id = BubbleManager._make_boid_social_agent_id(actor)

            social_agent = make_social_agent(
                locator=actor.agent_locator, **actor.policy_kwargs,
            )

            actor = bubble.actor
            social_agent_data_model = SocialAgent(
                id=SocialAgentId.new(actor.name),
                name=actor.name,
                is_boid=True,
                is_boid_keep_alive=True,
                agent_locator=actor.agent_locator,
                policy_kwargs=actor.policy_kwargs,
                initial_speed=actor.initial_speed,
            )
            self.start_social_agent(agent_id, social_agent, social_agent_data_model)