Skip to content

383. Traffic density watcher

The vehicle.traffic_density watcher monitors the traffic conditions in the immediate vicinity of a vehicle and emits intervals when traffic density changes across different categories. This watcher provides real-time assessment of traffic conditions in the Ego lane, left lanes, and right lanes, along with an overall traffic density indicator based on established traffic engineering standards.

383.0.1 Start condition

A new interval starts when all the following conditions are met:

  • No active interval exists (data == null)
  • Lane information is available
  • The Ego exists in the simulator
  • The Ego's speed is greater than or equal to min_activation_speed

383.0.2 End condition

An active interval ends when any of the following conditions are met:

1. Category change (with delayed restart):

  • The traffic density category changes from one level to another (e.g., from light to moderate)
  • The previous interval ends immediately at the current sampling time
  • The watcher prevents starting a new interval within the same clock cycle
  • The new interval starts at the next clock cycle in which the conditions are met. This ensures distinct start and end timestamps and prevents overlap.

2. Invalid operating conditions (end without restart):

  • The Ego's speed drops below the min_activation_speed
  • Lane information becomes unavailable
  • The interval ends but does not restart automatically

Note

  • A new interval starts when all start conditions are met again.
  • The check for invalid operating conditions (speed and lane information) runs on every clock tick, not just at sampling intervals. This ensures intervals end promptly when the Ego slows down or leaves the road network, even between sampling times.

383.1 Configuration parameters

The following parameters can be configured to customize the evaluator's behavior.

Parameter Type Description Default Value
detection_range_forward length The forward detection range is the distance from the Ego's current position to the forward detection range. 100m
detection_range_backward length The backward detection range is the distance from the Ego's current position to the backward detection range. 50m
min_vehicle_speed speed The minimum vehicle speed is the minimum speed at which a vehicle is considered to be moving. 5kph
min_activation_speed speed The minimum activation speed is the minimum speed at which the watcher activates. 5kph
moderate_traffic_density_threshold float The moderate traffic density threshold is the threshold for the moderate traffic density category. 19.0
heavy_traffic_density_threshold float The heavy traffic density threshold is the threshold for the heavy traffic density category. 42.0
sampling_frequency time The sampling frequency is the frequency at which the watcher samples the traffic density. 2s
rolling_window_size uint The rolling window size is the size of the rolling window for the traffic density. 5
light_traffic_density_threshold float The light traffic density threshold is the threshold for the light traffic density category. No default

383.2 Metrics

The following metrics are recorded and tracked by the evaluator.

Metric item Unit / Type Description
avg_speed kph Average speed of the Ego during the interval
ego_lane_traffic_density_category enum (no_traffic, light, moderate, heavy, congested, not_available) Traffic density category in the Ego lane
left_lane_traffic_density_category enum (no_traffic, light, moderate, heavy, congested, not_available) Traffic density category in the left adjacent lane
right_lane_traffic_density_category enum (no_traffic, light, moderate, heavy, congested, not_available) Traffic density category in the right adjacent lane
ego_lane_vehicle_count_avg Number of vehicles detected in the Ego lane within the detection range
left_lane_vehicle_count_avg Number of vehicles detected in the left adjacent lane (if available)
right_lane_vehicle_count_avg Number of vehicles detected in the right adjacent lane (if available)
ego_lane_vehicle_count_minimum Minimum number of vehicles detected in the Ego lane within the detection range
left_lane_vehicle_count_minimum Minimum number of vehicles detected in the left adjacent lane (if available)
right_lane_vehicle_count_minimum Minimum number of vehicles detected in the right adjacent lane (if available)
ego_lane_vehicle_count_maximum Maximum number of vehicles detected in the Ego lane within the detection range
left_lane_vehicle_count_maximum Maximum number of vehicles detected in the left adjacent lane (if available)
right_lane_vehicle_count_maximum Maximum number of vehicles detected in the right adjacent lane (if available)
ego_lane_density Spatial traffic density in the Ego lane (vehicles/km/lane)
left_lane_density Spatial traffic density in the left adjacent lane (vehicles/km/lane)
right_lane_density Spatial traffic density in the right adjacent lane (vehicles/km/lane)
traffic_avg_density Mean spatial traffic density across all lanes (vehicles/km/lane)
overall_traffic_density_category enum (no_traffic, light, moderate, heavy, congested, not_available) The overall traffic density category based on average density across all lanes
total_vehicle_count Total number of vehicles detected in the detection range across all lanes
ego_lane_avg_speed kph Mean speed of vehicles traveling in the Ego lane
left_lane_avg_speed kph Mean speed of vehicles traveling in the left adjacent lane
right_lane_avg_speed kph Mean speed of vehicles traveling in the right adjacent lane
traffic_avg_speed kph Mean speed of vehicles across all lanes

383.3 Log and Error Messages

No error messages found.

383.4 Additional information

Custom traffic density interval watcher configuration example

extend top.main:
watcher my_traffic_density_watcher is traffic_density(
vehicle: sut.car,
detection_range_forward: 150m,
detection_range_backward: 75m,
min_vehicle_speed: 10kph,
min_activation_speed: 15kph,
light_traffic_density_threshold: 10.0,
moderate_traffic_density_threshold: 25.0,
heavy_traffic_density_threshold: 50.0,
sampling_frequency: 1s,
rolling_window_size: 3,
log_level: debug_level
)

Traffic density categories

The watcher classifies traffic density into the following five categories based on spatial density of vehicles per kilometer per lane (vehicles/km/lane).

Category Density Range Description Unit
no_traffic 0.0 No vehicles detected in the detection range
light < 8.0 Sparse traffic with minimal vehicle interactions vehicles/km/lane
moderate 8.0 - 19.0 Stable traffic flow with some vehicle interactions vehicles/km/lane
heavy 19.0 - 42.0 Unstable traffic flow where frequent lane changes are difficult due to significant congestion vehicles/km/lane
congested > 42.0 Very heavy traffic, near standstill conditions where breakdowns cause major delays vehicles/km/lane
not_available N/A Lane information unavailable or invalid density calculation