How traffic-alpha/illm-tsc works
Project Overview and Key Components
• Project Purpose: iLLM-TSC is built to refine RL agent decisions in traffic signal control scenarios using contextual reasoning from an LLM. It leverages simulation environments (based on SUMO via TransSimHub), RL training and evaluation procedures, and an LLM module that provides feedback, explanations, and recommendations.
• Primary Components:
• TSCAssistant: Contains files (tsc_agent_prompt.py and tsc_assistant.py) responsible for interfacing with the LLM. It likely formulates prompts and processes LLM outputs.
• TSCEnvironment: Provides the simulation environment wrappers and utilities (e.g., tsc_env.py, tsc_env_wrapper.py, tsc_rl_wrapper.py) that abstract and encapsulate the SUMO simulation configuration and interactions.
• TSCScenario: Holds configuration details, scenario files, and simulation metadata (e.g., SumoNets folder with XML configuration files for road networks, detectors, and signal programs), which define specific simulation cases and traffic setups.
• RL Training and Evaluation Scripts: Files such as sb3_ppo.py, eval_rl_agent.py, rule_based.py, and rl_llm_tsc.py indicate different modes of operation—training the RL model, evaluating its performance, and integrating RL decisions with LLM guidance.
• Utils: A collection of supporting modules (e.g., custom_models.py, make_tsc_env.py, readConfig.py, tsccn.py) and configuration files (config.yaml) that help manage model parameters, configurations, and environment setups.
• Assets and Logs: Visual assets (images and videos) used for result displays and logs to capture monitor CSV data during simulation runs.
Understanding the Interactions and Data Flow
• The Simulation Environment (TSCEnvironment and TSCScenario) provides state and setup information based on traffic configurations defined in XML files (SUMO networks, detectors, traffic light states).
• The RL Component (from scripts like sb3_ppo.py and eval_rl_agent.py) interacts with the simulated environment using the wrappers provided in TSCEnvironment and utils. It receives the current state and produces an action decision regarding traffic signal control.
• TSCAssistant (LLM integration module) then evaluates these decisions. When an RL action is potentially suboptimal (e.g., in emergency cases), TSCAssistant triggers requests to the LLM. The LLM provides explanations and corrective action recommendations, which are then fed back into the control loop.
• Configuration and external dependencies (e.g., OpenAI API keys in the utils/config.yaml) ensure that the LLM integration is properly authenticating and functioning.
Architectural Patterns and Design Principles
• Modularity: The separation into distinct modules (TSCAssistant, TSCEnvironment, TSCScenario, and utils) indicates a modular design, where each module handles a specific responsibility.
• Layered Architecture:
• Application Layer: Scripts and entry points (sb3_ppo.py, eval_rl_agent.py, rl_llm_tsc.py) that are executed to train and run simulations.
• Domain Layer: Environment and scenario definitions (TSCEnvironment, TSCScenario) capturing traffic simulation details.
• Integration Layer: TSCAssistant integrates LLM decision support with the RL model.
• Use of Wrappers: Wrapper modules (e.g., tsc_env_wrapper.py, tsc_rl_wrapper.py, tsccn.py) abstract low-level simulation details and provide cleaner interfaces for higher-level logic.