code
stringlengths 26
870k
| docstring
stringlengths 1
65.6k
| func_name
stringlengths 1
194
| language
stringclasses 1
value | repo
stringlengths 8
68
| path
stringlengths 5
194
| url
stringlengths 46
254
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
def waypoint_paths(
self,
pose: Pose,
lookahead: int,
within_radius: float = 5,
route: RoadMap.Route = None,
) -> List[List[Waypoint]]:
"""Computes equally-spaced Waypoints for all lane paths
up to `lookahead` waypoints ahead, starting on the Road containing
the nearest Lane aligned with the vehicle's pose within within_radius meters.
Constrains paths to the supplied route if specified."""
raise NotImplementedError() | Computes equally-spaced Waypoints for all lane paths
up to `lookahead` waypoints ahead, starting on the Road containing
the nearest Lane aligned with the vehicle's pose within within_radius meters.
Constrains paths to the supplied route if specified. | waypoint_paths | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def surface_id(self) -> str:
"""The unique identifier for a surface."""
raise NotImplementedError() | The unique identifier for a surface. | surface_id | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def is_drivable(self) -> bool:
"""Returns true if this surface is legally and physically drivable."""
raise NotImplementedError() | Returns true if this surface is legally and physically drivable. | is_drivable | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def entry_surfaces(self) -> List[RoadMap.Surface]:
"""Surfaces by which one might enter this surface."""
raise NotImplementedError() | Surfaces by which one might enter this surface. | entry_surfaces | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def exit_surfaces(self) -> List[RoadMap.Surface]:
"""Surfaces by which one might exit this surface."""
raise NotImplementedError() | Surfaces by which one might exit this surface. | exit_surfaces | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def features(self) -> List[RoadMap.Feature]:
"""The features that this surface contains."""
return [] | The features that this surface contains. | features | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def features_near(self, pose: Pose, radius: float) -> List[RoadMap.Feature]:
"""The features on this surface near the given pose."""
raise NotImplementedError() | The features on this surface near the given pose. | features_near | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def shape(
self, buffer_width: float = 0.0, default_width: Optional[float] = None
) -> Polygon:
"""Returns a convex polygon representing this surface, buffered by buffered_width (which must be non-negative),
where buffer_width is a buffer around the perimeter of the polygon. In some situations, it may be desirable to
also specify a `default_width`, in which case the returned polygon should have a convex shape where the
distance across it is no less than buffered_width + default_width at any point.
"""
raise NotImplementedError() | Returns a convex polygon representing this surface, buffered by buffered_width (which must be non-negative),
where buffer_width is a buffer around the perimeter of the polygon. In some situations, it may be desirable to
also specify a `default_width`, in which case the returned polygon should have a convex shape where the
distance across it is no less than buffered_width + default_width at any point. | shape | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def contains_point(self, point: Point) -> bool:
"""Returns True if this point is fully contained by this surface.
For some regions of some maps, it may not be possible to determine this.
In such indeterminate cases, it is recommended to return True."""
raise NotImplementedError() | Returns True if this point is fully contained by this surface.
For some regions of some maps, it may not be possible to determine this.
In such indeterminate cases, it is recommended to return True. | contains_point | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def __hash__(self) -> int:
"""Derived classes must implement a suitable hash function
so that Lane objects may be used deterministically in sets."""
raise NotImplementedError() | Derived classes must implement a suitable hash function
so that Lane objects may be used deterministically in sets. | __hash__ | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def __eq__(self, other) -> bool:
"""Required for set usage; derived classes may override this."""
return self.__class__ == other.__class__ and hash(self) == hash(other) | Required for set usage; derived classes may override this. | __eq__ | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def bounding_box(self):
"""Gets the lane bounding box."""
raise NotImplementedError() | Gets the lane bounding box. | bounding_box | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def lane_id(self) -> str:
"""Unique identifier for this Lane."""
raise NotImplementedError() | Unique identifier for this Lane. | lane_id | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def road(self) -> RoadMap.Road:
"""The road that this lane is a part of."""
raise NotImplementedError() | The road that this lane is a part of. | road | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def composite_lane(self) -> RoadMap.Lane:
"""Return an abstract Lane composed of one or more RoadMap.Lane segments
(including this one) that has been inferred to correspond to one
continuous real-world lane. May return same object as self."""
return self | Return an abstract Lane composed of one or more RoadMap.Lane segments
(including this one) that has been inferred to correspond to one
continuous real-world lane. May return same object as self. | composite_lane | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def is_composite(self) -> bool:
"""Return True if this Lane object was inferred
and composed out of subordinate Lane objects."""
return False | Return True if this Lane object was inferred
and composed out of subordinate Lane objects. | is_composite | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def speed_limit(self) -> Optional[float]:
"""The speed limit on this lane. May be None if not defined."""
raise NotImplementedError() | The speed limit on this lane. May be None if not defined. | speed_limit | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def length(self) -> float:
"""The length of this lane."""
raise NotImplementedError() | The length of this lane. | length | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def in_junction(self) -> bool:
"""If this lane is a part of a junction (usually an intersection.)"""
raise NotImplementedError() | If this lane is a part of a junction (usually an intersection.) | in_junction | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def index(self) -> int:
"""when not in_junction, 0 is outer / right-most (relative to lane heading) lane on road.
otherwise, index scheme is implementation-dependent, but must be deterministic.
"""
# TAI: UK roads
raise NotImplementedError() | when not in_junction, 0 is outer / right-most (relative to lane heading) lane on road.
otherwise, index scheme is implementation-dependent, but must be deterministic. | index | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def lanes_in_same_direction(self) -> List[RoadMap.Lane]:
"""returns all other lanes on this road where traffic goes
in the same direction. it is currently assumed these will be
adjacent to one another. In junctions, diverging lanes
should not be included."""
raise NotImplementedError() | returns all other lanes on this road where traffic goes
in the same direction. it is currently assumed these will be
adjacent to one another. In junctions, diverging lanes
should not be included. | lanes_in_same_direction | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def lane_to_left(self) -> Tuple[RoadMap.Lane, bool]:
"""Get the parallel lane to the left side of the direction this current lane.
.. note::
Left is defined as 90 degrees clockwise relative to the lane heading.
(I.e., positive `t` in the RefLine coordinate system.)
Second result is True if lane is in the same direction as this one
In junctions, diverging lanes should not be included.
"""
raise NotImplementedError() | Get the parallel lane to the left side of the direction this current lane.
.. note::
Left is defined as 90 degrees clockwise relative to the lane heading.
(I.e., positive `t` in the RefLine coordinate system.)
Second result is True if lane is in the same direction as this one
In junctions, diverging lanes should not be included. | lane_to_left | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def lane_to_right(self) -> Tuple[RoadMap.Lane, bool]:
"""Get the parallel lane to the right side of the direction this current lane.
.. note::
Right is defined as 90 degrees counter-clockwise relative to the lane heading.
(I.e., negative `t` in the RefLine coordinate system.)
Second result is True if lane is in the same direction as this one.
In junctions, diverging lanes should not be included.
"""
raise NotImplementedError() | Get the parallel lane to the right side of the direction this current lane.
.. note::
Right is defined as 90 degrees counter-clockwise relative to the lane heading.
(I.e., negative `t` in the RefLine coordinate system.)
Second result is True if lane is in the same direction as this one.
In junctions, diverging lanes should not be included. | lane_to_right | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def incoming_lanes(self) -> List[RoadMap.Lane]:
"""Lanes leading into this lane."""
raise NotImplementedError() | Lanes leading into this lane. | incoming_lanes | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def outgoing_lanes(self) -> List[RoadMap.Lane]:
"""Lanes leading out of this lane."""
raise NotImplementedError() | Lanes leading out of this lane. | outgoing_lanes | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def oncoming_lanes_at_offset(self, offset: float) -> List[RoadMap.Lane]:
"""Returns a list of nearby lanes at offset that are (roughly)
parallel to this one but go in the opposite direction."""
raise NotImplementedError() | Returns a list of nearby lanes at offset that are (roughly)
parallel to this one but go in the opposite direction. | oncoming_lanes_at_offset | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def foes(self) -> List[RoadMap.Lane]:
"""All lanes that in some ways intersect with (cross) this one,
including those that have the same outgoing lane as this one,
and so might require right-of-way rules. This should only
ever happen in junctions."""
raise NotImplementedError() | All lanes that in some ways intersect with (cross) this one,
including those that have the same outgoing lane as this one,
and so might require right-of-way rules. This should only
ever happen in junctions. | foes | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def waypoint_paths_for_pose(
self, pose: Pose, lookahead: int, route: RoadMap.Route = None
) -> List[List[Waypoint]]:
"""Computes equally-spaced Waypoints for all lane paths
up to `lookahead` waypoints ahead, starting in this lane at pose.
Constrains paths to the supplied route if specified."""
raise NotImplementedError() | Computes equally-spaced Waypoints for all lane paths
up to `lookahead` waypoints ahead, starting in this lane at pose.
Constrains paths to the supplied route if specified. | waypoint_paths_for_pose | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def waypoint_paths_at_offset(
self, offset: float, lookahead: int = 30, route: RoadMap.Route = None
) -> List[List[Waypoint]]:
"""Computes equally-spaced Waypoints for all lane paths
up to `lookahead` waypoints ahead, starting offset into this lane.
Constrains paths to the supplied route if specified."""
raise NotImplementedError() | Computes equally-spaced Waypoints for all lane paths
up to `lookahead` waypoints ahead, starting offset into this lane.
Constrains paths to the supplied route if specified. | waypoint_paths_at_offset | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def offset_along_lane(self, world_point: Point) -> float:
"""Get the offset of the given point imposed on this lane."""
raise NotImplementedError() | Get the offset of the given point imposed on this lane. | offset_along_lane | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def width_at_offset(self, offset: float) -> Tuple[float, float]:
"""Get the width of the lane at the given offset as well as
a measure of certainty in this width between 0 and 1.0, where
1 indicates that the width is exact and certain, and 0 indicates
a width estimate with no confidence."""
raise NotImplementedError() | Get the width of the lane at the given offset as well as
a measure of certainty in this width between 0 and 1.0, where
1 indicates that the width is exact and certain, and 0 indicates
a width estimate with no confidence. | width_at_offset | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def project_along(
self, start_offset: float, distance: float
) -> Set[Tuple[RoadMap.Lane, float]]:
"""Starting at start_offset along the lane, project locations (lane, offset tuples)
reachable within distance, not including lane changes."""
result = set()
path_stack = {(self, self.length - start_offset)}
for lane in self.lanes_in_same_direction:
path_stack.add((lane, lane.length - start_offset))
while len(path_stack):
new_stack = set()
for lane, dist in path_stack:
if dist > distance:
offset = lane.length + (distance - dist)
result.add((lane, offset))
continue
for out_lane in lane.outgoing_lanes:
new_stack.add((out_lane, dist + out_lane.length))
for adj_lane in out_lane.lanes_in_same_direction:
new_stack.add((adj_lane, dist + adj_lane.length))
path_stack = new_stack
return result | Starting at start_offset along the lane, project locations (lane, offset tuples)
reachable within distance, not including lane changes. | project_along | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def from_lane_coord(self, lane_point: RefLinePoint) -> Point:
"""Get a world point on the lane from the given lane coordinate point."""
raise NotImplementedError() | Get a world point on the lane from the given lane coordinate point. | from_lane_coord | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def to_lane_coord(self, world_point: Point) -> RefLinePoint:
"""Convert from the given world coordinate to a lane coordinate point."""
s = self.offset_along_lane(world_point)
vector = self.vector_at_offset(s)
normal = np.array([-vector[1], vector[0], 0])
center_at_s = self.from_lane_coord(RefLinePoint(s=s))
offcenter_vector = world_point.as_np_array - center_at_s.as_np_array
t_sign = np.sign(np.dot(offcenter_vector, normal))
t = np.linalg.norm(offcenter_vector) * t_sign
return RefLinePoint(s=s, t=t) | Convert from the given world coordinate to a lane coordinate point. | to_lane_coord | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def center_at_point(self, point: Point) -> Point:
"""Get the 'center' of the lane closest to the given world coordinate."""
offset = self.offset_along_lane(point)
return self.from_lane_coord(RefLinePoint(s=offset)) | Get the 'center' of the lane closest to the given world coordinate. | center_at_point | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def vector_at_offset(self, start_offset: float) -> np.ndarray:
"""The lane direction vector at the given offset (not normalized)."""
if start_offset >= self.length:
s_offset = self.length - 1
end_offset = self.length
else:
s_offset = start_offset
end_offset = start_offset + 1 # a little further down the lane
s_offset = max(s_offset, 0)
p1 = self.from_lane_coord(RefLinePoint(s=s_offset))
p2 = self.from_lane_coord(RefLinePoint(s=end_offset))
return p2.as_np_array - p1.as_np_array | The lane direction vector at the given offset (not normalized). | vector_at_offset | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def center_pose_at_point(self, point: Point) -> Pose:
"""The pose at the center of the lane closest to the given point."""
offset = self.offset_along_lane(point)
position = self.from_lane_coord(RefLinePoint(s=offset))
desired_vector = self.vector_at_offset(offset)
orientation = fast_quaternion_from_angle(vec_to_radians(desired_vector[:2]))
return Pose(position=position.as_np_array, orientation=orientation) | The pose at the center of the lane closest to the given point. | center_pose_at_point | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def curvature_radius_at_offset(
self, offset: float, lookahead: int = 5
) -> float:
"""`lookahead` (in meters) is the size of the window to use
to compute the curvature, which must be at least 1 to make sense.
This may return math.inf if the lane is straight."""
assert lookahead > 0
prev_heading_rad = None
heading_deltas = 0.0
lane = self
for i in range(lookahead + 1):
if offset + i > lane.length:
if len(lane.outgoing_lanes) != 1:
break
lane = lane.outgoing_lanes[0]
offset = -i
vec = lane.vector_at_offset(offset + i)[:2]
heading_rad = vec_to_radians(vec[:2])
if prev_heading_rad is not None:
# XXX: things like S curves can cancel out here
heading_deltas += min_angles_difference_signed(
heading_rad, prev_heading_rad
)
prev_heading_rad = heading_rad
return i / heading_deltas if heading_deltas else math.inf | `lookahead` (in meters) is the size of the window to use
to compute the curvature, which must be at least 1 to make sense.
This may return math.inf if the lane is straight. | curvature_radius_at_offset | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def __hash__(self) -> int:
"""Derived classes must implement a suitable hash function
so that Road objects may be used deterministically in sets."""
raise NotImplementedError() | Derived classes must implement a suitable hash function
so that Road objects may be used deterministically in sets. | __hash__ | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def __eq__(self, other) -> bool:
"""Required for set usage; derived classes may override this."""
return self.__class__ == other.__class__ and hash(self) == hash(other) | Required for set usage; derived classes may override this. | __eq__ | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def road_id(self) -> str:
"""The identifier for this road."""
raise NotImplementedError() | The identifier for this road. | road_id | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def type(self) -> int:
"""The type of this road."""
raise NotImplementedError() | The type of this road. | type | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def type_as_str(self) -> str:
"""The type of this road."""
raise NotImplementedError() | The type of this road. | type_as_str | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def composite_road(self) -> RoadMap.Road:
"""Return an abstract Road composed of one or more RoadMap.Road segments
(including this one) that has been inferred to correspond to one continuous
real-world road. May return same object as self."""
return self | Return an abstract Road composed of one or more RoadMap.Road segments
(including this one) that has been inferred to correspond to one continuous
real-world road. May return same object as self. | composite_road | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def is_composite(self) -> bool:
"""Returns True if this Road object was inferred
and composed out of subordinate Road objects."""
return False | Returns True if this Road object was inferred
and composed out of subordinate Road objects. | is_composite | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def is_junction(self) -> bool:
"""Note that a junction can be an intersection ('+') or a 'T', 'Y', 'L', etc."""
raise NotImplementedError() | Note that a junction can be an intersection ('+') or a 'T', 'Y', 'L', etc. | is_junction | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def length(self) -> float:
"""The length of this road."""
raise NotImplementedError() | The length of this road. | length | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def incoming_roads(self) -> List[RoadMap.Road]:
"""All roads that lead into this road."""
raise NotImplementedError() | All roads that lead into this road. | incoming_roads | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def outgoing_roads(self) -> List[RoadMap.Road]:
"""All roads that lead out of this road."""
raise NotImplementedError() | All roads that lead out of this road. | outgoing_roads | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def oncoming_roads_at_point(self, point: Point) -> List[RoadMap.Road]:
"""Returns a list of nearby roads to point that are (roughly)
parallel to this one but have lanes that go in the opposite direction."""
raise NotImplementedError() | Returns a list of nearby roads to point that are (roughly)
parallel to this one but have lanes that go in the opposite direction. | oncoming_roads_at_point | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def parallel_roads(self) -> List[RoadMap.Road]:
"""Returns roads that start and end at the same
point as this one."""
raise NotImplementedError() | Returns roads that start and end at the same
point as this one. | parallel_roads | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def lanes(self) -> List[RoadMap.Lane]:
"""The lanes contained in this road."""
raise NotImplementedError() | The lanes contained in this road. | lanes | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def lane_at_index(self, index: int) -> RoadMap.Lane:
"""Gets the lane with the given index."""
raise NotImplementedError() | Gets the lane with the given index. | lane_at_index | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def feature_id(self) -> str:
"""The identifier for this feature."""
raise NotImplementedError() | The identifier for this feature. | feature_id | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def type(self) -> RoadMap.FeatureType:
"""The type of this feature."""
raise NotImplementedError() | The type of this feature. | type | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def type_as_str(self) -> str:
"""The type of this feature as a string.
This is useful for resolving CUSTOM feature types."""
raise NotImplementedError() | The type of this feature as a string.
This is useful for resolving CUSTOM feature types. | type_as_str | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def geometry(self) -> List[Point]:
"""The geometry that represents this feature."""
raise NotImplementedError() | The geometry that represents this feature. | geometry | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def is_dynamic(self) -> bool:
"""True if this feature has dynamic state (such as a traffic light); False otherwise."""
# this may be overridden in the case of custom feature types
return self.type == RoadMap.FeatureType.FIXED_LOC_SIGNAL | True if this feature has dynamic state (such as a traffic light); False otherwise. | is_dynamic | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def type_specific_info(self) -> Optional[Any]:
"""Can be anything specific to the feature type; defaults to None."""
return None | Can be anything specific to the feature type; defaults to None. | type_specific_info | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def min_dist_from(self, point: Point) -> float:
"""Returns the euclidean (as-the-crow-flies) distance
between point and the nearest part of this feature."""
raise NotImplementedError() | Returns the euclidean (as-the-crow-flies) distance
between point and the nearest part of this feature. | min_dist_from | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def __hash__(self) -> int:
"""Derived classes must implement a suitable hash function
so that Route objects may be used deterministically in sets."""
raise NotImplementedError() | Derived classes must implement a suitable hash function
so that Route objects may be used deterministically in sets. | __hash__ | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def __eq__(self, other) -> bool:
"""Required for set usage; derived classes may override this."""
return self.__class__ == other.__class__ and hash(self) == hash(other) | Required for set usage; derived classes may override this. | __eq__ | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def roads(self) -> List[RoadMap.Road]:
"""A possibly-unordered list of roads that this route covers"""
return [] | A possibly-unordered list of roads that this route covers | roads | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def road_ids(self) -> List[str]:
"""A possibly-unordered list of road-ids that this route covers"""
return [] | A possibly-unordered list of road-ids that this route covers | road_ids | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def road_length(self) -> float:
"""The total road length of this route."""
return 0 | The total road length of this route. | road_length | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def geometry(self) -> Sequence[Sequence[Tuple[float, float]]]:
"""A sequence of polygon vertices describing the shape of each road on the route"""
return [] | A sequence of polygon vertices describing the shape of each road on the route | geometry | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def distance_between(self, start: RoutePoint, end: RoutePoint) -> float:
"""Distance along route between two points."""
raise NotImplementedError() | Distance along route between two points. | distance_between | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def project_along(
self, start: RoutePoint, distance: float
) -> Set[Tuple[RoadMap.Lane, float]]:
"""Starting at point on the route, returns a set of possible
locations (lane and offset pairs) further along the route that
are distance away, not including lane changes."""
raise NotImplementedError() | Starting at point on the route, returns a set of possible
locations (lane and offset pairs) further along the route that
are distance away, not including lane changes. | project_along | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def distance_from(
self, cur_lane: RouteLane, route_road: Optional[RoadMap.Road] = None
) -> Optional[float]:
"""Returns the distance along the route from the beginning of the current lane
to the beginning of the next occurrence of route_road, or if route_road is None,
then to the end of the route."""
raise NotImplementedError() | Returns the distance along the route from the beginning of the current lane
to the beginning of the next occurrence of route_road, or if route_road is None,
then to the end of the route. | distance_from | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def next_junction(
self, cur_lane: RouteLane, offset: float
) -> Tuple[Optional[RoadMap.Lane], float]:
"""Returns a lane within the next junction along the route from beginning
of the current lane to the returned lane it connects with in the junction,
and the distance to it from this offset, or (None, inf) if there aren't any.
"""
raise NotImplementedError() | Returns a lane within the next junction along the route from beginning
of the current lane to the returned lane it connects with in the junction,
and the distance to it from this offset, or (None, inf) if there aren't any. | next_junction | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def relative_heading(self, h: Heading) -> Heading:
"""Computes relative heading between the given angle and the waypoint heading
Returns:
float: Relative heading in [-pi, pi].
"""
assert isinstance(
h, Heading
), "Heading h ({}) must be an instance of smarts.core.coordinates.Heading".format(
type(h)
)
return self.heading.relative_to(h) | Computes relative heading between the given angle and the waypoint heading
Returns:
float: Relative heading in [-pi, pi]. | relative_heading | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def position(self):
"""The position of the waypoint."""
return self.pos | The position of the waypoint. | position | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def signed_lateral_error(self, p) -> float:
"""Returns the signed lateral distance from the given point to the
line formed by the waypoint position and the waypoint heading.
Negative signals right of line and Positive left of line.
"""
return signed_dist_to_line(p, self.pos, self.heading.direction_vector()) | Returns the signed lateral distance from the given point to the
line formed by the waypoint position and the waypoint heading.
Negative signals right of line and Positive left of line. | signed_lateral_error | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def dist_to(self, p) -> float:
"""Calculates straight line distance to the given 2D point"""
return np.linalg.norm(self.pos - p[: len(self.pos)]) | Calculates straight line distance to the given 2D point | dist_to | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def interpolate_waypoints(
first_waypoint: Waypoint,
second_waypoint: Waypoint,
start_relative_offset: float,
interval: float,
) -> Tuple[List[Waypoint], float]:
"""Generate intermediary waypoints between the given waypoints.
Args:
first_waypoint (Waypoint): The initial start waypoint.
second_waypoint (Waypoint): The initial end waypoint.
start_relative_offset (float): The starting offset to generate the first waypoint.
interval (float): The interval to generate the waypoints at.
Returns:
Tuple[List[Waypoint], float]: The resulting waypoints and the used offset
"""
assert interval > 0, f"Instead got {interval =}"
assert start_relative_offset >= 0, f"Instead got {start_relative_offset =}"
base_waypoint_offset_delta = abs(
second_waypoint.lane_offset - first_waypoint.lane_offset
)
accumulated_relative_offset = 0
out_waypoints: List[Waypoint] = []
normalize_factor = 1 / base_waypoint_offset_delta
while (
accumulated_relative_offset + start_relative_offset
<= base_waypoint_offset_delta
):
normalized_relative_offset = (
accumulated_relative_offset + start_relative_offset
) * normalize_factor
out_waypoints.append(
Waypoint(
pos=lerp(
first_waypoint.pos, second_waypoint.pos, normalized_relative_offset
),
heading=Heading(
lerp(
first_waypoint.heading,
second_waypoint.heading,
normalized_relative_offset,
)
),
lane_id=first_waypoint.lane_id,
lane_width=lerp(
first_waypoint.lane_width,
second_waypoint.lane_width,
normalized_relative_offset,
),
speed_limit=lerp(
first_waypoint.lane_width,
second_waypoint.lane_width,
normalized_relative_offset,
),
lane_index=first_waypoint.lane_index,
lane_offset=lerp(
first_waypoint.lane_offset,
second_waypoint.lane_offset,
normalized_relative_offset,
),
)
)
accumulated_relative_offset += interval
used = base_waypoint_offset_delta
return out_waypoints, used | Generate intermediary waypoints between the given waypoints.
Args:
first_waypoint (Waypoint): The initial start waypoint.
second_waypoint (Waypoint): The initial end waypoint.
start_relative_offset (float): The starting offset to generate the first waypoint.
interval (float): The interval to generate the waypoints at.
Returns:
Tuple[List[Waypoint], float]: The resulting waypoints and the used offset | interpolate_waypoints | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def center_polyline(self) -> List[Point]:
"""Should return a list of the points along the center-line
of the lane, in the order they will be encountered in the
direction of travel.
Note: not all map types will be able to implement this method,
so use with care. This was added to support those that wish
to make use of the SegmentCache class below."""
raise NotImplementedError() | Should return a list of the points along the center-line
of the lane, in the order they will be encountered in the
direction of travel.
Note: not all map types will be able to implement this method,
so use with care. This was added to support those that wish
to make use of the SegmentCache class below. | center_polyline | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def dist_to_next(self) -> float:
"""returns the distance to the next point in the polyline."""
return np.linalg.norm((self.dx, self.dy)) | returns the distance to the next point in the polyline. | dist_to_next | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def from_lane_coord(self, lane_pt: RefLinePoint) -> Point:
"""For a reference-line point in/along this segment, converts it to a world point."""
offset = lane_pt.s - self.offset
return Point(
self.x
+ (offset * self.dx - lane_pt.t * self.dy) / self.dist_to_next,
self.y
+ (offset * self.dy + lane_pt.t * self.dx) / self.dist_to_next,
) | For a reference-line point in/along this segment, converts it to a world point. | from_lane_coord | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def clear(self):
"""Reset this SegmentCache."""
self._lane_cache = dict() | Reset this SegmentCache. | clear | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def segment_for_offset(
self, lane: RoadMapWithCaches.Lane, offset: float
) -> RoadMapWithCaches._SegmentCache.Segment:
"""Given an offset along a Lane, returns the nearest Segment to it."""
# Note: we could use Shapely's "interpolate()" for a LineString here,
# but profiling and testing showed that (unlike Shapely's "project()")
# this was significantly slower than doing our own version here...
# TODO: consider using pygeos' line_interpolate_point() here.
segs = self._cache_lane_info(lane)
assert segs
segi = bisect(self.__class__._OffsetWrapper(segs), offset)
if segi > 0:
segi -= 1
return segs[segi] | Given an offset along a Lane, returns the nearest Segment to it. | segment_for_offset | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def seg(
self, pt1: Point, pt2: Point
) -> RoadMapWithCaches._SegmentCache.Segment:
"""Create a Segment for a successive pair of polyline points."""
# TAI: include lane width sometimes?
rval = RoadMapWithCaches._SegmentCache.Segment(
x=pt1.x,
y=pt1.y,
dx=pt2.x - pt1.x,
dy=pt2.y - pt1.y,
offset=self.offset,
)
self.offset += rval.dist_to_next
return rval | Create a Segment for a successive pair of polyline points. | _cache_lane_info.seg | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def _cache_lane_info(
self, lane: RoadMapWithCaches.Lane
) -> List[RoadMapWithCaches._SegmentCache.Segment]:
segs = self._lane_cache.get(lane.lane_id)
if segs is not None:
return segs
class _AccumulateSegs:
def __init__(self):
self.offset = 0
def seg(
self, pt1: Point, pt2: Point
) -> RoadMapWithCaches._SegmentCache.Segment:
"""Create a Segment for a successive pair of polyline points."""
# TAI: include lane width sometimes?
rval = RoadMapWithCaches._SegmentCache.Segment(
x=pt1.x,
y=pt1.y,
dx=pt2.x - pt1.x,
dy=pt2.y - pt1.y,
offset=self.offset,
)
self.offset += rval.dist_to_next
return rval
points = lane.center_polyline
assert len(points) >= 2
accum = _AccumulateSegs()
segs = [accum.seg(pt1, pt2) for pt1, pt2 in zip(points[:-1], points[1:])]
self._lane_cache[lane.lane_id] = segs
return segs | Create a Segment for a successive pair of polyline points. | _cache_lane_info | python | huawei-noah/SMARTS | smarts/core/road_map.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py | MIT |
def identity(cls):
"""Returns an empty identity index."""
return cls() | Returns an empty identity index. | identity | python | huawei-noah/SMARTS | smarts/core/vehicle_index.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_index.py | MIT |
def vehicle_ids(self) -> Set[str]:
"""A set of all unique vehicles ids in the index."""
vehicle_ids = self._controlled_by["vehicle_id"]
return {self._2id_to_id[id_] for id_ in vehicle_ids} | A set of all unique vehicles ids in the index. | vehicle_ids | python | huawei-noah/SMARTS | smarts/core/vehicle_index.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_index.py | MIT |
def agent_vehicle_ids(self) -> Set[str]:
"""A set of vehicle ids associated with an agent."""
vehicle_ids = self._controlled_by[
(self._controlled_by["role"] == ActorRole.EgoAgent)
| (self._controlled_by["role"] == ActorRole.SocialAgent)
]["vehicle_id"]
return {self._2id_to_id[id_] for id_ in vehicle_ids} | A set of vehicle ids associated with an agent. | agent_vehicle_ids | python | huawei-noah/SMARTS | smarts/core/vehicle_index.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_index.py | MIT |
def social_vehicle_ids(
self, vehicle_types: Optional[FrozenSet[str]] = None
) -> Set[str]:
"""A set of vehicle ids associated with traffic vehicles."""
vehicle_ids = self._controlled_by[
self._controlled_by["role"] == ActorRole.Social
]["vehicle_id"]
return {
self._2id_to_id[id_]
for id_ in vehicle_ids
if not vehicle_types or self._vehicles[id_].vehicle_type in vehicle_types
} | A set of vehicle ids associated with traffic vehicles. | social_vehicle_ids | python | huawei-noah/SMARTS | smarts/core/vehicle_index.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_index.py | MIT |
def vehicle_is_hijacked_or_shadowed(self, vehicle_id: str) -> Tuple[bool, bool]:
"""Determine if a vehicle is either taken over by an owner or watched."""
b_vehicle_id = _2id(vehicle_id)
v_index = self._controlled_by["vehicle_id"] == b_vehicle_id
if not np.any(v_index):
return False, False
vehicle = self._controlled_by[v_index]
assert len(vehicle) == 1
vehicle = vehicle[0]
return bool(vehicle["is_hijacked"]), bool(vehicle["shadower_id"]) | Determine if a vehicle is either taken over by an owner or watched. | vehicle_is_hijacked_or_shadowed | python | huawei-noah/SMARTS | smarts/core/vehicle_index.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_index.py | MIT |
def vehicle_ids_by_owner_id(
self, owner_id: str, include_shadowers: bool = False
) -> List[str]:
"""Returns all vehicles for the given owner ID as a list. This is most
applicable when an agent is controlling multiple vehicles (e.g. with boids).
"""
b_owner_id = _2id(owner_id)
v_index = self._controlled_by["owner_id"] == b_owner_id
if include_shadowers:
v_index = v_index | (self._controlled_by["shadower_id"] == b_owner_id)
b_vehicle_ids = self._controlled_by[v_index]["vehicle_id"]
return [self._2id_to_id[id_] for id_ in b_vehicle_ids] | Returns all vehicles for the given owner ID as a list. This is most
applicable when an agent is controlling multiple vehicles (e.g. with boids). | vehicle_ids_by_owner_id | python | huawei-noah/SMARTS | smarts/core/vehicle_index.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_index.py | MIT |
def owner_id_from_vehicle_id(self, vehicle_id: str) -> Optional[str]:
"""Find the owner id associated with the given vehicle."""
b_vehicle_id = _2id(vehicle_id)
owner_ids = self._controlled_by[
self._controlled_by["vehicle_id"] == b_vehicle_id
]["owner_id"]
if owner_ids:
return self._2id_to_id[owner_ids[0]]
return None | Find the owner id associated with the given vehicle. | owner_id_from_vehicle_id | python | huawei-noah/SMARTS | smarts/core/vehicle_index.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_index.py | MIT |
def shadower_id_from_vehicle_id(self, vehicle_id: str) -> Optional[str]:
"""Find the first shadowing entity watching a vehicle."""
b_vehicle_id = _2id(vehicle_id)
shadower_ids = self._controlled_by[
self._controlled_by["vehicle_id"] == b_vehicle_id
]["shadower_id"]
if shadower_ids:
return self._2id_to_id[shadower_ids[0]]
return None | Find the first shadowing entity watching a vehicle. | shadower_id_from_vehicle_id | python | huawei-noah/SMARTS | smarts/core/vehicle_index.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_index.py | MIT |
def shadower_ids(self) -> Set[str]:
"""Get all current shadowing entity IDs."""
return set(
self._2id_to_id[sa_id]
for sa_id in self._controlled_by["shadower_id"]
if sa_id not in (b"", None)
) | Get all current shadowing entity IDs. | shadower_ids | python | huawei-noah/SMARTS | smarts/core/vehicle_index.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_index.py | MIT |
def vehicle_position(self, vehicle_id: str):
"""Find the position of the given vehicle."""
b_vehicle_id = _2id(vehicle_id)
positions = self._controlled_by[
self._controlled_by["vehicle_id"] == b_vehicle_id
]["position"]
return positions[0] if len(positions) > 0 else None | Find the position of the given vehicle. | vehicle_position | python | huawei-noah/SMARTS | smarts/core/vehicle_index.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_index.py | MIT |
def vehicles_by_owner_id(self, owner_id: str, include_shadowers: bool = False):
"""Find vehicles associated with the given owner id.
Args:
owner_id:
The owner id to find all associated vehicle ids.
include_shadowers:
If to include vehicles that the owner is only watching.
Returns:
A list of associated vehicles.
"""
vehicle_ids = self.vehicle_ids_by_owner_id(owner_id, include_shadowers)
return [self._vehicles[_2id(id_)] for id_ in vehicle_ids] | Find vehicles associated with the given owner id.
Args:
owner_id:
The owner id to find all associated vehicle ids.
include_shadowers:
If to include vehicles that the owner is only watching.
Returns:
A list of associated vehicles. | vehicles_by_owner_id | python | huawei-noah/SMARTS | smarts/core/vehicle_index.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_index.py | MIT |
def vehicle_is_hijacked(self, vehicle_id: str) -> bool:
"""Determine if a vehicle is controlled by an owner."""
is_hijacked, _ = self.vehicle_is_hijacked_or_shadowed(vehicle_id)
return is_hijacked | Determine if a vehicle is controlled by an owner. | vehicle_is_hijacked | python | huawei-noah/SMARTS | smarts/core/vehicle_index.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_index.py | MIT |
def vehicle_is_shadowed(self, vehicle_id: str) -> bool:
"""Determine if a vehicle is watched by an owner."""
_, is_shadowed = self.vehicle_is_hijacked_or_shadowed(vehicle_id)
return is_shadowed | Determine if a vehicle is watched by an owner. | vehicle_is_shadowed | python | huawei-noah/SMARTS | smarts/core/vehicle_index.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_index.py | MIT |
def vehicles(self) -> List[Vehicle]:
"""A list of all existing vehicles."""
return list(self._vehicles.values()) | A list of all existing vehicles. | vehicles | python | huawei-noah/SMARTS | smarts/core/vehicle_index.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_index.py | MIT |
def vehicleitems(self) -> Iterator[Tuple[str, Vehicle]]:
"""A list of all vehicle IDs paired with their vehicle."""
return map(lambda x: (self._2id_to_id[x[0]], x[1]), self._vehicles.items()) | A list of all vehicle IDs paired with their vehicle. | vehicleitems | python | huawei-noah/SMARTS | smarts/core/vehicle_index.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_index.py | MIT |
def vehicle_by_id(
self,
vehicle_id: str,
default: Optional[Union[Vehicle, Ellipsis.__class__]] = ...,
):
"""Get a vehicle by its id."""
b_vehicle_id = _2id(vehicle_id)
if default is ...:
return self._vehicles[b_vehicle_id]
return self._vehicles.get(b_vehicle_id, default) | Get a vehicle by its id. | vehicle_by_id | python | huawei-noah/SMARTS | smarts/core/vehicle_index.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_index.py | MIT |
def teardown_vehicles_by_vehicle_ids(
self, vehicle_ids: Sequence[str], renderer: Optional[RendererBase]
):
"""Terminate and remove a vehicle from the index using its id."""
self._log.debug("Tearing down vehicle ids: %s", vehicle_ids)
b_vehicle_ids = [_2id(id_) for id_ in vehicle_ids]
if len(b_vehicle_ids) == 0:
return
for b_vehicle_id in b_vehicle_ids:
vehicle = self._vehicles.pop(b_vehicle_id, None)
if vehicle is not None:
vehicle.teardown(renderer=renderer)
# popping since sensor_states/controller_states may not include the
# vehicle if it's not being controlled by an agent
self._controller_states.pop(b_vehicle_id, None)
# TODO: This stores agents as well; those aren't being cleaned-up
self._2id_to_id.pop(b_vehicle_id, None)
remove_vehicle_indices = np.isin(
self._controlled_by["vehicle_id"], b_vehicle_ids, assume_unique=True
)
self._controlled_by = self._controlled_by[~remove_vehicle_indices] | Terminate and remove a vehicle from the index using its id. | teardown_vehicles_by_vehicle_ids | python | huawei-noah/SMARTS | smarts/core/vehicle_index.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_index.py | MIT |
def teardown_vehicles_by_owner_ids(
self,
owner_ids: Iterable[str],
renderer: RendererBase,
include_shadowing: bool = True,
) -> List[str]:
"""Terminate and remove all vehicles associated with an owner id."""
vehicle_ids: List[str] = []
for owner_id in owner_ids:
vehicle_ids.extend(
[v.id for v in self.vehicles_by_owner_id(owner_id, include_shadowing)]
)
self.teardown_vehicles_by_vehicle_ids(vehicle_ids, renderer)
return vehicle_ids | Terminate and remove all vehicles associated with an owner id. | teardown_vehicles_by_owner_ids | python | huawei-noah/SMARTS | smarts/core/vehicle_index.py | https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/vehicle_index.py | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.