def create_single_scenario(self): """Creates one scenario using the defined LaneCorridorConfig Returns: Scenario -- Returns a BARK scenario """ scenario = Scenario(map_file_name=self._map_file_name, json_params=self._params.ConvertToDict()) # as we always use the same world, we can create the MapIntf. once if self._map_interface is None: scenario.CreateMapInterface(self._map_file_name) else: scenario.map_interface = self._map_interface self._map_interface = scenario.map_interface world = scenario.GetWorldState() map_interface = world.map # fill agent list of the BARK world and set agents that are controlled scenario._agent_list = [] scenario._eval_agent_ids = [] for lc_config in self._lane_corridor_configs: agent_state = True lc_agents = [] if lc_config._source_pos is not None and lc_config._sink_pos is not None: lc_config.InferRoadIdsAndLaneCorr(world) while agent_state is not None: agent_state = lc_config.state(world) if agent_state is not None: agent_behavior = lc_config.behavior_model(world) agent_dyn = lc_config.dynamic_model agent_exec = lc_config.execution_model agent_polygon = lc_config.shape agent_params = self._params.AddChild("agent") agent_goal = lc_config.goal(world) new_agent = Agent( agent_state, agent_behavior, agent_dyn, agent_exec, agent_polygon, agent_params, agent_goal, map_interface) new_agent.road_corridor = lc_config._road_corridor lc_agents.append(new_agent) # set the road corridor # handle controlled agents controlled_agent_ids = [] for controlled_agent in lc_config.controlled_ids(lc_agents): controlled_agent.goal_definition = lc_config.controlled_goal(world) controlled_agent.behavior_model = \ lc_config.controlled_behavior_model(world) controlled_agent_ids.append(controlled_agent.id) scenario._eval_agent_ids.extend(controlled_agent_ids) scenario._agent_list.extend(lc_agents) lc_config.reset() return scenario
def __create_single_scenario__(self, scenario_track_info): scenario_track_info.TimeSanityCheck() scenario = Scenario(map_file_name=self._map_file_name, json_params=self._params.ConvertToDict()) # as we always use the same world, we can create the MapIntf. once if self._map_interface is None: scenario.CreateMapInterface(self._map_file_name) print("Creating New Map Interface for Scenario!") else: scenario.map_interface = self._map_interface self._map_interface = scenario.map_interface world = scenario.GetWorldState() track_params = ParameterServer() track_params["execution_model"] = 'ExecutionModelInterpolate' track_params["dynamic_model"] = 'SingleTrackModel' track_params["map_interface"] = world.map all_track_ids = list(scenario_track_info.GetOtherTrackInfos().keys()) # also add ego id ego_track_id = scenario_track_info.GetEgoTrackInfo().GetTrackId() all_track_ids.append(ego_track_id) agent_list = [] model_converter = ModelJsonConversion() for track_id in all_track_ids: if self._behavior_model and track_id != ego_track_id: behavior_params = self.__fill_agent_params( scenario_track_info.GetEgoTrackInfo(), scenario_track_info.GetOtherTrackInfos()[track_id]) behavior_model_name = self._behavior_model track_params["behavior_model"] = model_converter.convert_model( behavior_model_name, behavior_params) # behavior_params.Save("/tmp/agent_prams_{}.json".format(track_id)) else: track_params["behavior_model"] = None agent = self.interaction_ds_reader.AgentFromTrackfile( track_params, self._params, scenario_track_info, track_id) agent.first_valid_timestamp = scenario_track_info.GetOffsetOfAgentMillisec( track_id) agent_list.append(agent) scenario._agent_list = agent_list # must contain all agents! scenario._eval_agent_ids = [ scenario_track_info.GetEgoTrackInfo().GetTrackId() ] scenario.json_params[ "track_file"] = scenario_track_info.GetTrackFilename() return scenario
def __create_single_scenario__(self, scenario_track_info): scenario_track_info.TimeSanityCheck() scenario = Scenario(map_file_name=self._map_file_name, json_params=self._params.ConvertToDict()) # as we always use the same world, we can create the MapIntf. once if self._map_interface is None: scenario.CreateMapInterface(self._map_file_name) print("Creating New Map Interface for Scenario!") else: scenario.map_interface = self._map_interface self._map_interface = scenario.map_interface world = scenario.GetWorldState() agent_list = [] track_params = ParameterServer() track_params["execution_model"] = 'ExecutionModelInterpolate' track_params["dynamic_model"] = 'SingleTrackModel' track_params["map_interface"] = world.map for id_other in scenario_track_info.GetOtherTrackInfos().keys(): if str(id_other) in self._behavior_models: track_params["behavior_model"] = self._behavior_models[str( id_other)] else: track_params["behavior_model"] = None agent = self.interaction_ds_reader.AgentFromTrackfile( track_params, self._params, scenario_track_info, id_other) agent_list.append(agent) id_ego = scenario_track_info.GetEgoTrackInfo().GetTrackId() if "ego" in self._behavior_models: # Always set this behavior to the ego agent, regardless of agent's ID track_params["behavior_model"] = self._behavior_models["ego"] elif str(id_ego) in self._behavior_models: track_params["behavior_model"] = self._behavior_models[str(id_ego)] else: track_params["behavior_model"] = None agent = self.interaction_ds_reader.AgentFromTrackfile( track_params, self._params, scenario_track_info, id_ego) agent_list.append(agent) scenario._agent_list = agent_list # must contain all agents! scenario._eval_agent_ids = [ scenario_track_info.GetEgoTrackInfo().GetTrackId() ] scenario.json_params[ "track_file"] = scenario_track_info.GetTrackFilename() return scenario