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.
Neighbour vehicles¶
Each Road exposes
neighbour_vehicles() to find the preceding and following vehicles
on a lane. By default, the search is limited to the current lane segment; when
neighbour_vehicles_connected_lanes is enabled, connected next
and previous segments are included. See Neighbour vehicles for the full description,
environment version mapping, and a visual comparison.
API¶
- class highway_env.road.road.Road(network: RoadNetwork = None, vehicles: list[kinematics.Vehicle] = None, road_objects: list[objects.RoadObject] = None, np_random: np.random.RandomState = None, record_history: bool = False, neighbour_vehicles_connected_lanes: bool = False)[source]¶
A road is a set of lanes, and a set of vehicles driving on these lanes.
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
neighbour_vehicles_connected_lanes – whether to search connected lane segments for neighbours
- 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: LaneIndex = None) tuple[kinematics.Vehicle | None, kinematics.Vehicle | None][source]¶
Find the preceding and following vehicles of a given vehicle.
When
neighbour_vehicles_connected_lanesis enabled, connected next/previous lane segments are also searched so vehicles near segment boundaries are detected.- 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