Intent-Aware Data Collection
HighwayEnv setup and rule-based dataset workflow · 2026-11-19
Environment and vehicles
CustomEnv is defined in src/cooperative_driving/environments/customEnv.py.
By default the ego starts in any lane from 0 through 3, chosen per episode. Background traffic types are shuffled at reset, and lead-vehicle offsets are randomly assigned to lanes.
Every vehicle receives a stable ID:
vehicle.vehicle_id = self.next_vehicle_id
self.next_vehicle_id += 1
self.vehicles_by_id[vehicle_id] = vehicle
self.vehicle_types[vehicle_id] = vehicle_type
Visible neighbors
scripts/data_collection/show_visible_neighbors.py considers the ego lane and its immediate left and right lanes. It keeps the closest vehicle in each slot within 60 m.
| Lane | Front | Beside | Rear |
|---|---|---|---|
| Left | 1 | 1 | 1 |
| Ego lane | 1 | — | 1 |
| Right | 1 | 1 | 1 |
The theoretical maximum is eight visible vehicles, although the actual number can be zero through eight. A vehicle is classified as beside the ego within a 10 m longitudinal side window.
.venv/bin/python -m scripts.data_collection.show_visible_neighbors
State and intent messages
get_vehicle_state(vehicle) returns the vehicle's current ID, behavior type, position, velocity, speed, heading, current lane, target lane, target speed, acceleration, steering, and crash status.
preview_next_action(vehicle_id) deep-copies the road and calculates the neighbor's next controller action without changing the real environment.
{
"vehicle_id": ..., // stable ID
"behavior_type": ..., // aggressive, defensive, or idm
"crashed": ..., // crash status
"target_lane": ..., // predicted target lane
"target_speed": ..., // desired speed
"acceleration": ..., // predicted acceleration
"steering": ..., // predicted steering
}
The current state describes what the vehicle is doing now. The preview describes what its controller would do next.
.venv/bin/python -m scripts.data_collection.smoke_test_messages
.venv/bin/python -m scripts.data_collection.compare_neighbor_state_action
Rule-based informed ego action
scripts/policy/intent_aware_policy.py combines geometry with requested messages. It checks distance, closing speed, time to collision, beside vehicles, lane-entry intentions, braking front vehicles, and accelerating aggressive rear vehicles.
It supports all five discrete actions:
LANE_LEFT, IDLE, LANE_RIGHT, FASTER, SLOWER
- When a front vehicle enters the caution range, choose a safe adjacent lane.
- If neither adjacent lane is safe, choose
SLOWER. - If the lane is clear and the ego is below target speed, choose
FASTER. - Otherwise choose
IDLE.
.venv/bin/python -m scripts.policy.intent_aware_policy --steps 10
Request-subset scenarios
scripts/data_collection/enumerate_message_requests.py evaluates every non-empty subset of visible vehicles. For n visible vehicles, there are 2^n - 1 scenarios. Use --include-none to add the no-request case.
Each subset uses only the messages requested in that subset. Unrequested vehicles contribute observable geometry but not private intent. Each scenario is evaluated on a deep-copied environment.
Dataset collection flow
state + requested messages + ego action → next state + reward + terminated/truncatedThe real rollout advances separately using the action chosen with all currently visible messages. The dataset records counterfactual one-step outcomes for every request subset.
.venv/bin/python -m scripts.data_collection.collect_intent_aware_dataset \
--episodes 1000 \
--include-none \
--experiment 3
Corrected records use message_slot_encoding: spatial_v1. The eight visible_vehicle_slots preserve empty positions with null, so messages use the same spatial indices in training and planning. The adapter rejects ambiguous legacy packed informed records. No-message records encode as all zeros.
Crash metrics
- Counterfactual scenario crash rate: crashes among request/action combinations evaluated on copied environments.
- Actual rollout crash rate: crashes from the real rollout using all currently visible messages. This is the metric for judging policy safety.
Each request subset is a separate counterfactual transition, so record counts and truncations can exceed the number of real episode endings. See the dataset dashboard for per-experiment totals and rollout statistics.
Uninformed random-action baseline
scripts/data_collection/collect_random_no_message_dataset.py collects a separate baseline in which the ego requests no vehicles and chooses a random action. It records the same transition fields, including messages=None, and preserves crash transitions instead of stopping data collection globally.
.venv/bin/python -m scripts.data_collection.collect_random_no_message_dataset \
--episodes 1000 \
--experiment 3
This dataset gives the World Model uninformed examples of both safe and unsafe actions, including the outcomes that lead to crashes.
Combining datasets
The two JSONL datasets can be merged while preserving provenance. Each merged record contains dataset_source, source_episode, global_episode, and a unique record_id.
.venv/bin/python -m scripts.data_collection.merge_world_model_datasets \
--experiment 3 \
--random data/experiment_2/random_no_message_dataset.jsonl
Experiment 3 reused the Experiment 2 no-message baseline, which remains compatible with the corrected encoding. To use a newly collected Experiment 3 random baseline instead, omit --random. Choose one route; rerunning collectors overwrites their default files.
Per-experiment counts, action/message distributions, and source provenance live on the dataset dashboard. Follow the training run guide for subsequent steps.