Пример #1
0
    def __init__(
        self,
        scenario_root: str,
        route: str = None,
        missions: Dict[str, Mission] = None,
        social_agents: Dict[str, SocialAgent] = None,
        log_dir: str = None,
        surface_patches: list = None,
        traffic_history: str = None,
    ):

        self._logger = logging.getLogger(self.__class__.__name__)
        self._root = scenario_root
        self._route = route
        self._missions = missions or {}
        self._bubbles = Scenario._discover_bubbles(scenario_root)
        self._social_agents = social_agents or {}
        self._surface_patches = surface_patches
        self._log_dir = self._resolve_log_dir(log_dir)
        self._validate_assets_exist()

        if traffic_history:
            self._traffic_history = TrafficHistory(traffic_history)
            default_lane_width = self.traffic_history.lane_width
        else:
            self._traffic_history = None
            default_lane_width = None

        net_file = os.path.join(self._root, "map.net.xml")
        self._road_network = SumoRoadNetwork.from_file(
            net_file, default_lane_width=default_lane_width, lanepoint_spacing=1.0
        )
        self._net_file_hash = file_md5_hash(self._road_network.net_file)
        self._scenario_hash = path2hash(str(Path(self.root_filepath).resolve()))
Пример #2
0
    def __init__(
        self,
        scenario_root: str,
        route: str = None,
        missions: Dict[str, Mission] = None,
        social_agents: Dict[str, SocialAgent] = None,
        log_dir: str = None,
        surface_patches: list = None,
        traffic_history: str = None,
    ):

        self._logger = logging.getLogger(self.__class__.__name__)
        self._root = scenario_root
        self._route = route
        self._missions = missions or {}
        self._bubbles = Scenario._discover_bubbles(scenario_root)
        self._social_agents = social_agents or {}
        self._surface_patches = surface_patches
        self._log_dir = self._resolve_log_dir(log_dir)

        self._validate_assets_exist()
        self._road_network = SumoRoadNetwork.from_file(self.net_filepath)
        self._net_file_hash = file_md5_hash(self.net_filepath)
        self._waypoints = Waypoints(self._road_network, spacing=1.0)
        self._scenario_hash = path2hash(str(
            Path(self.root_filepath).resolve()))
        self._traffic_history_service = Traffic_history_service(
            traffic_history)
Пример #3
0
def get_road_map(map_spec) -> Tuple[Optional[RoadMap], Optional[str]]:
    """@return a RoadMap object and a hash
    that uniquely identifies it. Changes to the hash
    should signify that the map is different enough
    that map-related caches should be reloaded.
    If possible, the RoadMap object may be cached here
    and re-used.
    """
    assert map_spec, "A road map spec must be specified"
    assert map_spec.source, "A road map source must be specified"

    if os.path.isdir(map_spec.source):
        map_type, map_source = _find_mapfile_in_dir(map_spec.source)
    else:
        map_type = _UNKNOWN_MAP
        map_source = map_spec.source
        if map_source.endswith(".net.xml"):
            map_type = _SUMO_MAP
        elif map_source.endswith(".xodr"):
            map_type = _OPENDRIVE_MAP

    if map_type == _SUMO_MAP:
        from smarts.core.sumo_road_network import SumoRoadNetwork

        map_class = SumoRoadNetwork

    elif map_type == _OPENDRIVE_MAP:
        from smarts.core.opendrive_road_network import OpenDriveRoadNetwork

        map_class = OpenDriveRoadNetwork

    else:
        return None, None

    if _existing_map:
        if isinstance(_existing_map.obj,
                      map_class) and _existing_map.obj.is_same_map(map_spec):
            return _existing_map.obj, _existing_map.map_hash
        _clear_cache()

    road_map = map_class.from_spec(map_spec)
    if os.path.isfile(road_map.source):
        road_map_hash = file_md5_hash(road_map.source)
    else:
        road_map_hash = path2hash(road_map.source)
    _cache_result(map_spec, road_map, road_map_hash)

    return road_map, road_map_hash
Пример #4
0
    def __init__(
        self,
        scenario_root: str,
        route: Optional[str] = None,
        missions: Optional[Dict[str, Mission]] = None,
        social_agents: Optional[Dict[str, SocialAgent]] = None,
        log_dir: Optional[str] = None,
        surface_patches: Optional[Sequence[Dict[str, Any]]] = None,
        traffic_history: Optional[str] = None,
        map_spec: Optional[MapSpec] = None,
    ):

        self._logger = logging.getLogger(self.__class__.__name__)
        self._root = scenario_root
        self._route = route
        self._missions = missions or {}
        self._bubbles = Scenario._discover_bubbles(scenario_root)
        self._social_agents = social_agents or {}
        self._surface_patches = surface_patches
        self._log_dir = self._resolve_log_dir(log_dir)

        if traffic_history:
            self._traffic_history = TrafficHistory(traffic_history)
            default_lane_width = self.traffic_history.lane_width
        else:
            self._traffic_history = None
            default_lane_width = None

        # XXX: using a map builder_fn supplied by users is a security risk
        # as SMARTS will be executing the code "as is".  We are currently
        # trusting our users to not try to sabotage their own simulations.
        # In the future, this may need to be revisited if SMARTS is ever
        # shared in a multi-user mode.
        if not map_spec:
            map_spec = Scenario.discover_map(self._root, 1.0,
                                             default_lane_width)
        self._road_map, self._road_map_hash = map_spec.builder_fn(map_spec)
        self._scenario_hash = path2hash(str(
            Path(self.root_filepath).resolve()))

        os.makedirs(self._log_dir, exist_ok=True)