Road

A Road is composed of a RoadNetwork and a list of Vehicle.

The RoadNetwork describes the topology of the road infrastructure as a graph, where edges represent lanes and nodes represent intersections. It contains a graph dictionary which stores the AbstractLane geometries by their LaneIndex. A LaneIndex is a tuple containing:

  • a string identifier of a starting position

  • a string identifier of an ending position

  • an integer giving the index of the described lane, in the (unique) road from the starting to the ending position

For instance, the geometry of the second lane in the road going from the "lab" to the "pub" can be obtained by:

lane = road.road_network.graph["lab"]["pub"][1]

The actual positions of the lab and the pub are defined in the ``lane```geometry object.

API

class highway_env.road.road.RoadNetwork[source]
__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

graph: Dict[str, Dict[str, List[AbstractLane]]] = None
add_lane(_from: str, _to: str, lane: highway_env.road.lane.AbstractLane) → None[source]

A lane is encoded as an edge in the road network.

Parameters
  • _from – the node at which the lane starts.

  • _to – the node at which the lane ends.

  • lane (AbstractLane) – the lane geometry.

get_lane(index: Tuple[str, str, int]) → highway_env.road.lane.AbstractLane[source]

Get the lane geometry corresponding to a given index in the road network.

Parameters

index – a tuple (origin node, destination node, lane id on the road).

Returns

the corresponding lane geometry.

get_closest_lane_index(position: numpy.ndarray) → Tuple[str, str, int][source]

Get the index of the lane closest to a world position.

Parameters

position – a world position [m].

Returns

the index of the closest lane.

next_lane(current_index: Tuple[str, str, int], route: List[Tuple[str, str, int]] = None, position: numpy.ndarray = None, np_random: numpy.random.mtrand.RandomState = <module 'numpy.random' from '/usr/local/lib/python3.8/site-packages/numpy/random/__init__.py'>) → Tuple[str, str, int][source]

Get the index of the next lane that should be followed after finishing the current lane.

  • If a plan is available and matches with current lane, follow it.

  • Else, pick next road randomly.

  • If it has the same number of lanes as current road, stay in the same lane.

  • Else, pick next road’s closest lane.

Parameters
  • current_index – the index of the current lane.

  • route – the planned route, if any.

  • position – the vehicle position.

  • np_random – a source of randomness.

Returns

the index of the next lane to be followed when current lane is finished.

bfs_paths(start: str, goal: str) → List[List[str]][source]

Breadth-first search of all routes from start to goal.

Parameters
  • start – starting node

  • goal – goal node

Returns

list of paths from start to goal.

shortest_path(start: str, goal: str) → List[str][source]

Breadth-first search of shortest path from start to goal.

Parameters
  • start – starting node

  • goal – goal node

Returns

shortest path from start to goal.

all_side_lanes(lane_index: Tuple[str, str, int]) → List[Tuple[str, str, int]][source]
Parameters

lane_index – the index of a lane.

Returns

all lanes belonging to the same road.

side_lanes(lane_index: Tuple[str, str, int]) → List[Tuple[str, str, int]][source]
Parameters

lane_index – the index of a lane.

Returns

indexes of lanes next to a an input lane, to its right or left.

static is_same_road(lane_index_1: Tuple[str, str, int], lane_index_2: Tuple[str, str, int], same_lane: bool = False) → bool[source]

Is lane 1 in the same road as lane 2?

static is_leading_to_road(lane_index_1: Tuple[str, str, int], lane_index_2: Tuple[str, str, int], same_lane: bool = False) → bool[source]

Is lane 1 leading to of lane 2?

is_connected_road(lane_index_1: Tuple[str, str, int], lane_index_2: Tuple[str, str, int], route: List[Tuple[str, str, int]] = None, same_lane: bool = False, depth: int = 0) → bool[source]

Is the lane 2 leading to a road within lane 1’s route?

Vehicles on these lanes must be considered for collisions. :param lane_index_1: origin lane :param lane_index_2: target lane :param route: route from origin lane, if any :param same_lane: compare lane id :param depth: search depth from lane 1 along its route :return: whether the roads are connected

lanes_list() → List[highway_env.road.lane.AbstractLane][source]
static straight_road_network(lanes: int = 4, length: float = 10000, angle: float = 0) → highway_env.road.road.RoadNetwork[source]
position_heading_along_route(route: List[Tuple[str, str, int]], longitudinal: float, lateral: float) → Tuple[numpy.ndarray, float][source]

Get the absolute position and heading along a route composed of several lanes at some local coordinates.

Parameters
  • route – a planned route, list of lane indexes

  • longitudinal – longitudinal position

  • lateral – : lateral position

Returns

position, heading

__annotations__ = {'graph': typing.Dict[str, typing.Dict[str, typing.List[highway_env.road.lane.AbstractLane]]]}
__dict__ = mappingproxy({'__module__': 'highway_env.road.road', '__annotations__': {'graph': typing.Dict[str, typing.Dict[str, typing.List[highway_env.road.lane.AbstractLane]]]}, '__init__': <function RoadNetwork.__init__>, 'add_lane': <function RoadNetwork.add_lane>, 'get_lane': <function RoadNetwork.get_lane>, 'get_closest_lane_index': <function RoadNetwork.get_closest_lane_index>, 'next_lane': <function RoadNetwork.next_lane>, 'bfs_paths': <function RoadNetwork.bfs_paths>, 'shortest_path': <function RoadNetwork.shortest_path>, 'all_side_lanes': <function RoadNetwork.all_side_lanes>, 'side_lanes': <function RoadNetwork.side_lanes>, 'is_same_road': <staticmethod object>, 'is_leading_to_road': <staticmethod object>, 'is_connected_road': <function RoadNetwork.is_connected_road>, 'lanes_list': <function RoadNetwork.lanes_list>, 'straight_road_network': <staticmethod object>, 'position_heading_along_route': <function RoadNetwork.position_heading_along_route>, '__dict__': <attribute '__dict__' of 'RoadNetwork' objects>, '__weakref__': <attribute '__weakref__' of 'RoadNetwork' objects>, '__doc__': None})
__module__ = 'highway_env.road.road'
__weakref__

list of weak references to the object (if defined)

class highway_env.road.road.Road(network: highway_env.road.road.RoadNetwork = None, vehicles: List[kinematics.Vehicle] = None, road_objects: List[objects.RoadObject] = None, np_random: numpy.random.mtrand.RandomState = None, record_history: bool = False)[source]

A road is a set of lanes, and a set of vehicles driving on these lanes.

__init__(network: highway_env.road.road.RoadNetwork = None, vehicles: List[kinematics.Vehicle] = None, road_objects: List[objects.RoadObject] = None, np_random: numpy.random.mtrand.RandomState = None, record_history: bool = False) → None[source]

New road.

Parameters
  • network – the road network describing the lanes

  • vehicles – the vehicles driving on the road

  • road_objects – the objects on the road including obstacles and landmarks

  • np_random (np.random.RandomState) – a random number generator for vehicle behaviour

  • record_history – whether the recent trajectories of vehicles should be recorded for display

close_vehicles_to(vehicle: kinematics.Vehicle, distance: float, count: int = None, see_behind: bool = True) → object[source]
act() → None[source]

Decide the actions of each entity on the road.

step(dt: float) → None[source]

Step the dynamics of each entity on the road.

Parameters

dt – timestep [s]

neighbour_vehicles(vehicle: kinematics.Vehicle, lane_index: Tuple[str, str, int] = None) → Tuple[Optional[kinematics.Vehicle], Optional[kinematics.Vehicle]][source]

Find the preceding and following vehicles of a given vehicle.

Parameters
  • vehicle – the vehicle whose neighbours must be found

  • lane_index – the lane on which to look for preceding and following vehicles. It doesn’t have to be the current vehicle lane but can also be another lane, in which case the vehicle is projected on it considering its local coordinates in the lane.

Returns

its preceding vehicle, its following vehicle

dump() → None[source]

Dump the data of all entities on the road.

get_log() → pandas.core.frame.DataFrame[source]

Concatenate the logs of all entities on the road.

Returns

the concatenated log.

__module__ = 'highway_env.road.road'
__repr__()[source]

Return repr(self).