Skip to content

Traffic junction#2

Open
lucaschoii wants to merge 9 commits intomainfrom
traffic_junction
Open

Traffic junction#2
lucaschoii wants to merge 9 commits intomainfrom
traffic_junction

Conversation

@lucaschoii
Copy link

Description

This PR adds the Traffic Junction environment to JaxMARL, a fully JAX-compatible port of the classic multi-agent traffic control task.

This implementation features a scalable grid size, dynamic spawning logic, and a custom Matplotlib visualizer for evaluating agent behaviors.

Key Features

  • Scalable Environment: The TrafficJunction class supports variable grid_size (default: 14), automatically adjusting lane positions (mid_low, mid_high) and spawn points.
  • Right-Hand Drive (RHD) Logic: Implements correct pivot logic for RHD turns, preventing head-on collisions and ensuring realistic traffic flow.
  • Observation Space: Agents receive a local view (view_size x view_size) centered on themselves, padded with -1 for off-grid areas.
  • Visualization: Includes tj_visualizer.py with:
    • Dynamic marker scaling based on grid_size.
    • Directional triangle markers for moving agents.
    • Octagon markers for stopped agents (Stop Signs).
    • Collision and active agent counters.

Files Added

  • jaxmarl/environments/traffic_junction/traffic_junction.py: Core environment logic.
  • jaxmarl/environments/traffic_junction/tj_visualizer.py: Visualization tool.
  • jaxmarl/environments/traffic_junction/test_tj.py: Sanity check / test script.

Verification

  • Verified zero-collision spawning with off-grid buffers.
  • Verified correct turning logic for all 4 directions (Right, Down, Left, Up).
  • Verified visualizer scaling for different grid sizes.

Copilot AI review requested due to automatic review settings February 8, 2026 05:10
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Traffic Junction multi-agent environment to JaxMARL (JAX-native), along with a Matplotlib-based visualizer and a small runnable sanity-check script.

Changes:

  • Introduces TrafficJunction environment with grid-size-dependent lane/spawn logic, turning rules, and local observations.
  • Adds TrafficVisualizer to animate recorded state sequences.
  • Adds test_tj.py as a manual simulation/visualization driver.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.

File Description
jaxmarl/environments/traffic_junction/traffic_junction.py Core environment implementation: state, stepping (movement/spawn), rewards, and observations.
jaxmarl/environments/traffic_junction/tj_visualizer.py Matplotlib animation utility for inspecting state sequences over time.
jaxmarl/environments/traffic_junction/test_tj.py Manual script to run random actions, track collisions, and launch the visualizer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants