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.convert_to_dict()) world = scenario.get_world_state() 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 = [] while agent_state is not None: agent_state = lc_config.state(world) if agent_state is not None: agent_behavior = lc_config.behavior_model 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) lc_agents.append(new_agent) # 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 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 = Scenario(map_file_name=self._map_file_name, json_params=self._params.convert_to_dict()) world = scenario.get_world_state() agent_list = [] scenario._agent_list = [] for agent_json_ in self._local_params["Agents"]: agent_json = agent_json_["VehicleModel"].copy() agent_json["map_interface"] = world.map goal_polygon = Polygon2d([0, 0, 0], np.array( agent_json["goal"]["polygon_points"])) goal_polygon = goal_polygon.translate( Point2d(agent_json["goal"]["center_pose"][0], agent_json["goal"]["center_pose"][1])) sequential_goals = [] state_limit_goal = GoalDefinitionStateLimits( goal_polygon, (1.49, 1.65)) for _ in range(self._local_params["goal"]["num_reached", "num", 2]): sequential_goals.append(state_limit_goal) agent_json["goal_definition"] = GoalDefinitionSequential( sequential_goals) agent_state = np.array(agent_json["state"]) if len(np.shape(agent_state)) > 1: agent_state = np.random.uniform(low=agent_state[:, 0], high=agent_state[:, 1]) agent_json["state"] = agent_state.tolist() agent = self._json_converter.agent_from_json( agent_json, param_server=self._local_params) agent.set_agent_id(agent_json["id"]) scenario._agent_list.append(agent) # TODO(@hart): this could be mult. agents scenario._eval_agent_ids = self._local_params[ "controlled_ids", "IDs of agents to be controlled. ", [0]] 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()) 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 = agent_from_trackfile(track_params, self._params, scenario_track_info, id_other) agent_list.append(agent) id_ego = scenario_track_info.GetEgoTrackInfo().GetTrackId() if str(id_ego) in self._behavior_models: track_params["behavior_model"] = self._behavior_models[str(id_ego)] else: track_params["behavior_model"] = None agent = agent_from_trackfile(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() ] return scenario
def create_single_scenario(self): scenario = Scenario(map_file_name=self._map_file_name, json_params=self._params.ConvertToDict()) world = scenario.get_world_state() agent_list = [] # OTHER AGENTS for idx, source in enumerate(self._others_source): connecting_center_line, s_start, s_end = \ self.center_line_between_source_and_sink(world.map, source, self._others_sink[idx]) goal_polygon = Polygon2d([0, 0, 0], [ Point2d(-1.5, 0), Point2d(-1.5, 8), Point2d(1.5, 8), Point2d(1.5, 0) ]) goal_polygon = goal_polygon.Translate( Point2d(self._others_sink[idx][0], self._others_sink[idx][1])) goal_definition = GoalDefinitionPolygon(goal_polygon) agent_list.extend( self.place_agents_along_linestring(world, connecting_center_line, s_start, s_end, self._agent_params, goal_definition)) description = self._params.ConvertToDict() description["ScenarioGenerator"] = "UniformVehicleDistribution" # EGO AGENT ego_agent = None if len(self._ego_route) == 0: # take agent in the middle of list num_agents = len(agent_list) ego_agent = agent_list[math.floor(num_agents / 4)] else: connecting_center_line, s_start, s_end = \ self.center_line_between_source_and_sink(world.map, self._ego_route[0], self._ego_route[1]) sego = self.sample_srange_uniform([s_start, s_end]) xy_point = GetPointAtS(connecting_center_line, sego) angle = GetTangentAngleAtS(connecting_center_line, sego) velocity = self.sample_velocity_uniform(self._ego_velocity_range) agent_state = np.array( [0, xy_point.x(), xy_point.y(), angle, velocity]) agent_params = self._agent_params.copy() agent_params["state"] = agent_state # goal for driving corridor generation goal_polygon = Polygon2d([0, 0, 0], [ Point2d(-1.5, 0), Point2d(-1.5, 8), Point2d(1.5, 8), Point2d(1.5, 0) ]) goal_polygon = goal_polygon.Translate( Point2d(self._ego_route[1][0], self._ego_route[1][1])) goal_definition = GoalDefinitionPolygon(goal_polygon) agent_params["goal_definition"] = goal_definition agent_params["map_interface"] = world.map converter = ModelJsonConversion() ego_agent = converter.agent_from_json(agent_params, self._params["Agent"]) # TODO(@bernhard): ensure that ego agent not collides with others agent_list.append(ego_agent) # EGO Agent Goal Definition if len(self._ego_goal_start) == 0: if len(self._ego_route) == 0: # ego agent is one of the random agents, so the goal definition is # already set pass else: goal_polygon = Polygon2d([0, 0, 0], [ Point2d(-1.5, 0), Point2d(-1.5, 8), Point2d(1.5, 8), Point2d(1.5, 0) ]) goal_polygon = goal_polygon.Translate( Point2d(self._ego_goal_end[0], self._ego_goal_end[1])) ego_agent.goal_definition = GoalDefinitionPolygon(goal_polygon) else: connecting_center_line, s_start, s_end = \ self.center_line_between_source_and_sink(world.map, self._ego_goal_start, self._ego_goal_end) goal_center_line = GetLineFromSInterval(connecting_center_line, s_start, s_end) # build polygon representing state limits lims = self._ego_goal_state_limits goal_limits_left = goal_center_line.Translate( Point2d(-lims[0], -lims[1])) goal_limits_right = goal_center_line.Translate( Point2d(lims[0], lims[1])) goal_limits_right.Reverse() goal_limits_left.AppendLinestring(goal_limits_right) polygon = Polygon2d([0, 0, 0], goal_limits_left) ego_agent.goal_definition = GoalDefinitionStateLimits( polygon, (1.57 - 0.08, 1.57 + 0.08)) # only one agent is ego in the middle of all other agents scenario._agent_list = agent_list scenario._eval_agent_ids = [ego_agent.id] return scenario
def create_single_scenario(self): scenario = Scenario(map_file_name=self._map_file_name, json_params=self._params.ConvertToDict()) world = scenario.get_world_state() collected_sources_sinks_agent_states_geometries = [] collected_sources_sinks_default_param_configs = [] # Loop through each source sink config and first only create state # and geometry information road_corridors = [] kwargs_agent_states_geometry = [] sink_source_default_params = [] for idx, sink_source_config in enumerate(self._sinks_sources): road_corridor = self.get_road_corridor_from_source_sink(sink_source_config, world.map) road_corridors.append(road_corridor) #1) create agent states and geometries for this source args = [road_corridor] agent_states, agent_geometries, kwargs_dict, default_params_state_geometry = \ self.eval_configuration( sink_source_config, "ConfigAgentStatesGeometries", args, {}) kwargs_agent_states_geometry.append(kwargs_dict) # collect default parameters of this config sink_source_default_params.append(sink_source_config) sink_source_default_params[idx]["ConfigAgentStatesGeometries"] = default_params_state_geometry.ConvertToDict() collected_sources_sinks_agent_states_geometries.append((agent_states, agent_geometries)) #2 remove overlapping agent states from different sources and sinks collected_sources_sinks_agent_states_geometries = \ self.resolve_overlaps_in_sources_sinks_agents(collected_sources_sinks_agent_states_geometries) agent_list = [] controlled_agent_ids_all = [] for idx, agent_states_geometries in enumerate( collected_sources_sinks_agent_states_geometries): sink_source_config = self._sinks_sources[idx] agent_states = agent_states_geometries[0] agent_geometries = agent_states_geometries[1] road_corridor = road_corridors[idx] if(len(agent_states)== 0): continue #3) create behavior, execution and dynamic models args_list = [road_corridor, agent_states ] kwargs_dict = {**kwargs_agent_states_geometry[idx]} config_return, kwargs_dict_tmp, default_params_behavior = \ self.eval_configuration( sink_source_config, "ConfigBehaviorModels", args_list, kwargs_dict) behavior_models = config_return sink_source_default_params[idx]["ConfigBehaviorModels"] = default_params_behavior.ConvertToDict() kwargs_dict = {**kwargs_dict, **kwargs_dict_tmp} config_return, kwargs_dict_tmp, default_params_execution = \ self.eval_configuration( sink_source_config, "ConfigExecutionModels", args_list, kwargs_dict) execution_models = config_return sink_source_default_params[idx]["ConfigExecutionModels"] = default_params_execution.ConvertToDict() kwargs_dict = {**kwargs_dict, **kwargs_dict_tmp} config_return, kwargs_dict_tmp, default_params_dynamic = \ self.eval_configuration( sink_source_config, "ConfigDynamicModels", args_list, kwargs_dict) dynamic_models = config_return sink_source_default_params[idx]["ConfigDynamicModels"] = default_params_dynamic.ConvertToDict() kwargs_dict = {**kwargs_dict, **kwargs_dict_tmp} #4 create goal definitions and controlled agents config_return, kwargs_dict_tmp, default_params_controlled_agents = \ self.eval_configuration( sink_source_config, "ConfigControlledAgents", args_list, kwargs_dict) controlled_agent_ids = config_return controlled_agent_ids_all.extend(controlled_agent_ids) sink_source_default_params[idx]["ConfigControlledAgents"] = default_params_controlled_agents.ConvertToDict() kwargs_dict = {**kwargs_dict, **kwargs_dict_tmp} args_list = [*args_list, controlled_agent_ids] config_return, kwargs_dict_tmp, default_params_goals = \ self.eval_configuration( sink_source_config, "ConfigGoalDefinitions", args_list, kwargs_dict) goal_definitions = config_return sink_source_default_params[idx]["ConfigGoalDefinitions"] = default_params_goals.ConvertToDict() #5 Build all agents for this source config agent_params = ParameterServer(json = sink_source_config["AgentParams"]) sink_source_agents = self.create_source_config_agents(agent_states, agent_geometries, behavior_models, execution_models, dynamic_models, goal_definitions, controlled_agent_ids, world, agent_params) sink_source_default_params[idx]["AgentParams"] = agent_params.ConvertToDict() agent_list.extend(sink_source_agents) collected_sources_sinks_default_param_configs.append(sink_source_config) self._sink_source_default_params = sink_source_default_params scenario._agent_list = self.update_agent_ids(agent_list) scenario._eval_agent_ids = [idx for idx, value in enumerate(controlled_agent_ids_all) if value==True] return scenario