### Install TransSimHub with All Dependencies Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/en/installation/index.md Install TransSimHub with all available dependencies to enable all features. This may require significant time and resources. ```bash pip install -U -e ".[all]" ``` -------------------------------- ### Fixed Installation Steps Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Corrected the installation steps in the documentation, changing `cd TransSimHub.git` to `cd TransSimHub`. ```bash Fixed the error of visualization after installing TSHub, `Init.py -> init.py`. ``` -------------------------------- ### Install TransSimHub with Documentation Features Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/en/installation/index.md Install TransSimHub with extra dependencies for documentation editing features, such as Sphinx. ```bash pip install -U -e ".[doc]" ``` -------------------------------- ### Install TransSimHub with Pip Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/en/installation/index.md Install TransSimHub in editable mode using pip after cloning the repository. ```bash pip install -e . ``` -------------------------------- ### Analysis Route Example Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Provides a detailed example for `analysis_route.py` within the sumotool. This script assists in the analysis and visualization of simulation results, specifically route data. ```python from examples.sumo_tools.analysis_output.analysis_route import analysis_route analysis_route() ``` -------------------------------- ### Analysis TLS Program Example Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Presents a detailed example for analyzing traffic light programs using the sumotool. This script aids in the visualization of TLS program data. ```python from examples.sumo_tools.analysis_output.analysis_tls_program import analysis_tls_program analysis_tls_program() ``` -------------------------------- ### Verify TransSimHub Installation Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/en/installation/index.md Check if TransSimHub is installed correctly and print its version using Python. ```python import tshub print(tshub.__version__) ``` -------------------------------- ### Generate Routes Example Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Demonstrates the functionality of `generate_routes.py` for creating different types of vehicles, including controlling acceleration parameters. This is a generated example. ```python from examples.sumo_tools.generate_routes import generate_routes generate_routes() ``` -------------------------------- ### Traffic Light Choose Next Phase (Synchronize) Example Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Provides an example for the 'Choose Next Phase (Synchronize)' action in traffic light control. This action enables synchronized actions for all agents in multi-agent control tasks. ```python from examples.traffic_light.traffic_light_action.tls_choosenextphase_syn import tls_choosenextphase_syn tls_choosenextphase_syn() ``` -------------------------------- ### Start Multi-Agent MAPPO Training Source: https://github.com/traffic-alpha/transsimhub/blob/main/benchmark/traffic_light/README.md Command to start the multi-agent reinforcement learning training using the MAPPO algorithm from PyTorch RL. Model weights and training logs are stored in designated folders. ```shell python train_mappo.py ``` -------------------------------- ### Start Single-Agent PPO Training Source: https://github.com/traffic-alpha/transsimhub/blob/main/benchmark/traffic_light/README.md Command to initiate the training process for a single-agent traffic light control system using the PPO algorithm from Stable Baselines3. Training logs and model weights are saved in specified directories. ```shell python sb3_ppo.py ``` -------------------------------- ### Vehicle Speed Scenario Setup Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Introduced the Vehicle Speed Scenario environment for controlling vehicle speed, located in the benchmark directory. ```python Introduced [Vehicle Speed Scenario](./benchmark/sumo_envs/veh_speed/), which is accomplished by controlling vehicle speed. ``` -------------------------------- ### Aircraft State Example Output Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/zh_CN/object/aircraft.md Example of the state information returned for aircraft, including ID, type, position, speed, heading, and communication range. ```json { "a1": { "id": "a1", "aircraft_type": "drone", "action_type": "horizontal_movement", "position": [ 1496.4644660940673, 1120.606601717798, 100 ], "speed": 5, "heading": [ -0.7071067811865475, 0.7071067811865476, 0 ], "communication_range": 200, "cover_radius": 173.20508075688772, "if_sumo_visualization": true, "img_file": "/home/wmn/TransSimHub/tshub/aircraft/./aircraft.png" }, "a2": { "id": "a2", "aircraft_type": "drone", "action_type": "horizontal_movement", "position": [ 1903.5355339059327, 796.4644660940672, 100 ], "speed": 5, "heading": [ -0.7071067811865477, -0.7071067811865475, 0 ], "communication_range": 200, "cover_radius": 173.20508075688772, "if_sumo_visualization": true, "img_file": "/home/wmn/TransSimHub/tshub/aircraft/./aircraft.png" } } ``` -------------------------------- ### Traffic Light Adjust Cycle Durations Example Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Shows an example of the 'Adjust Cycle Durations' action for traffic lights. This action modifies the duration of each phase within a cycle, allowing for more stable system control. ```python from examples.traffic_light.traffic_light_action.tls_adjustCycleDuration import tls_adjustCycleDuration tls_adjustCycleDuration() ``` -------------------------------- ### Run Unit Tests with Python unittest Source: https://github.com/traffic-alpha/transsimhub/blob/main/README.md Execute all tests in the 'test' directory using Python's built-in unittest module. Ensure the 'tshub' package is installed and its version is greater than 1 for tests to pass. ```shell python -m unittest discover -s test ``` -------------------------------- ### Get Aircraft State Information Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/zh_CN/object/aircraft.md Retrieve the current state information for all initialized aircraft. ```python aircraft_state = scene_aircraft.get_objects_infos() ``` -------------------------------- ### Vehicle Speed Crash Example Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Demonstrates collision detection for vehicles based on speed. This is part of the vehicle collision support features. ```python from examples.vehicles.vehicle_action.vehicle_speed_crash import vehicle_speed_crash vehicle_speed_crash() ``` -------------------------------- ### Get Vehicle Information Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/zh_CN/object/vehicle.md Retrieve detailed information about all vehicles in the simulation scene. This includes properties like position, speed, and emissions. ```python data = scene_vehicles.get_objects_infos() ``` -------------------------------- ### Vehicle Lane Change Crash Example Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Illustrates collision detection for vehicles during lane changes. This feature is available when the vehicle type is 'ego'. ```python from examples.vehicles.vehicle_action.vehicle_laneChange_crash import vehicle_laneChange_crash vehicle_laneChange_crash() ``` -------------------------------- ### Build Aircraft Scene Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/zh_CN/object/aircraft.md Initialize the aircraft builder with a SUMO connection and the defined aircraft initializations. ```python from tshub.aircraft.aircraft_builder import AircraftBuilder scene_aircraft = AircraftBuilder(sumo=conn, aircraft_inits=aircraft_inits) ``` -------------------------------- ### Initialize Vehicle Builder Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/zh_CN/object/vehicle.md Initialize the VehicleBuilder with a SUMO connection and specify the action type for vehicle control. The action type determines the control space available for vehicles. ```python from tshub.vehicle.vehicle_builder import VehicleBuilder scene_vehicles = VehicleBuilder( sumo=conn, action_type='lane' ) ``` -------------------------------- ### 交通灯附加配置文件示例 Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/zh_CN/sumo_tools/tls_addition.md 生成的 .add.xml 配置文件,用于在仿真中保存交通灯状态。可在 .sumocfg 文件中通过 additional-files 指定。 ```xml ``` -------------------------------- ### Render Scene in SUMO-GUI Mode Source: https://github.com/traffic-alpha/transsimhub/blob/main/examples/tshub_env_render/README.md Renders the scene in SUMO-GUI mode and saves the output directly to a specified folder. This mode requires SUMO-GUI to be enabled and the simulation window to be fullscreen for complete output. ```python obs, reward, info, done = tshub_env.step(actions=actions) fig = tshub_env.render( mode='sumo_gui', save_folder=image_save_folder ) ``` -------------------------------- ### RL for Traffic Signal Control Introduction Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Provides an introduction to traffic signal control based on reinforcement learning. ```python Added introduction to traffic signal control based on reinforcement learning, [RL for TSC](./benchmark/traffic_light/). ``` -------------------------------- ### Follow Vehicle Rendering in SUMO-GUI Mode Source: https://github.com/traffic-alpha/transsimhub/blob/main/examples/tshub_env_render/README.md Renders the state around a specific vehicle in SUMO-GUI mode. Set focus_type to 'vehicle' and provide the vehicle's ID to focus_id. focus_distance determines the observation range. ```python obs, reward, info, done = tshub_env.step(actions=actions) fig = tshub_env.render( focus_id='-1105574288#1__0__background.1', focus_type='vehicle', focus_distance=80, mode='sumo_gui', save_folder=image_save_folder ) ``` -------------------------------- ### Highlight Parameter Standardization Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Moved the `highlight` parameter from `control_objects` in `vehicle_builder.py` to `init` for standardization across different objects. ```python Moved the `highlight` parameter from `control_objects` in `vehicle_builder.py` to `init`, standardizing the `control_objects` method for different `objects`. ``` -------------------------------- ### Initialize Aircraft Parameters Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/zh_CN/object/aircraft.md Define initial parameters for aircraft, including their type, action type, position, speed, heading, and communication range. ```python aircraft_inits = { 'a1': { "aircraft_type": "drone", "action_type": "horizontal_movement", "position":(1500,1110,100), "speed":10, "heading":(1,1,0), "communication_range":200, "if_sumo_visualization":True, "img_file":None}, 'a2': { "aircraft_type": "drone", "action_type": "horizontal_movement", "position":(1900,800,100), "speed":10, "heading":(1,1,0), "communication_range":200, "if_sumo_visualization":True, "img_file":None } } ``` -------------------------------- ### 生成交通灯附加文件 Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/zh_CN/sumo_tools/tls_addition.md 使用 `generate_traffic_lights_additions` 函数生成自定义的 .add.xml 文件。需要指定网络文件和输出文件路径。 ```python from tshub.sumo_tools.additional_files.traffic_light_additions import generate_traffic_lights_additions generate_traffic_lights_additions( network_file='xxx.net.xml', output_file='./tls.add.xml' ) ``` -------------------------------- ### Global Rendering in SUMO-GUI Mode Source: https://github.com/traffic-alpha/transsimhub/blob/main/examples/tshub_env_render/README.md Renders the global simulation effect in SUMO-GUI mode. This is achieved by passing only the mode and save_folder parameters to the render method without specifying a focus_id. ```python obs, reward, info, done = tshub_env.step(actions=actions) fig = tshub_env.render( mode='sumo_gui', # 'rgb' save_folder=image_save_folder ) ``` -------------------------------- ### Unified Connection Method Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md The connection method for `from_edge` and `direction` has been unified to the format `f"{from_edge}--{direction}"`. ```python Unified the connection method of `from_edge` and `direction` to `f"{from_edge}--{direction}"`. ``` -------------------------------- ### Execute TSC Environment Check Source: https://github.com/traffic-alpha/transsimhub/blob/main/benchmark/traffic_light/README.md Run this script to verify that the traffic signal control environment is set up correctly and meets expectations before proceeding with model training. ```shell python check_tsc_env.py ``` -------------------------------- ### Multi-Agent Traffic Signal Control Environment Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Introduction of the Multi-Traffic Signal Control environment, featuring 3 traffic signals and supporting multi-agent reinforcement learning algorithms like MAPPO. ```python Introduced environment [Multi-Traffic Signal Control](./benchmark/sumo_envs/multi_junctions_tsc/), which includes $3$ traffic signals. ``` ```python Added multi-traffic signal control environment in `TsHub`, see [Multi-Agent TSC Env](./benchmark/traffic_light/multi_agents/env_utils/). ``` ```python Provided examples of `MAPPO` algorithm, controlling multiple traffic signals. Detailed algorithm can be found at [MAPPO Traffic Signal Control](./benchmark/traffic_light/multi_agents/mappo_models/). ``` -------------------------------- ### Highlight Parameter Addition Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Added a `highlight` parameter in `tshub.py`. ```python Added a `highlight` parameter in `tshub.py`. ``` -------------------------------- ### Clone TransSimHub Repository Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/en/installation/index.md Clone the official TransSimHub GitHub repository to your local machine. ```bash git clone https://github.com/Traffic-Alpha/TransSimHub.git cd TransSimHub ``` -------------------------------- ### Local Intersection Rendering in SUMO-GUI Mode Source: https://github.com/traffic-alpha/transsimhub/blob/main/examples/tshub_env_render/README.md Renders a local intersection view in SUMO-GUI mode. Specify 'node' as focus_type, provide a node ID for focus_id, and set focus_distance to define the observation range. ```python obs, reward, info, done = tshub_env.step(actions=actions) fig = tshub_env.render( focus_id='25663429', focus_type='node', focus_distance=80, mode='sumo_gui', save_folder=image_save_folder ) ``` -------------------------------- ### Define TSC Environment Wrappers Source: https://github.com/traffic-alpha/transsimhub/blob/main/benchmark/traffic_light/README.md Implement state, reward, and info wrappers for traffic signal control environments. The state wrapper captures movement occupancy, and the reward wrapper calculates average queue length. ```python def state_wrapper(self, state): """Returns the occupancy of each movement at the current moment. """ pass def reward_wrapper(self, states) -> float: """Returns the average queue length at the intersection. """ pass def info_wrapper(self, infos, occupancy): """Adds the occupancy rate of each phase to info. """ pass ``` -------------------------------- ### Vehicle Speed Scenario Default Actions Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Updates to veh_wrapper.py to generate default actions for all vehicles, setting speed to -1 and lane to 0. Subsequent parameters only affect the ego vehicle's speed. ```python Updated [veh_wrapper.py](./benchmark/vehicle/utils/veh_wrapper.py) with `__get_actions` and `__update_actions` methods to generate default actions for all vehicles (speed=-1, lane=0), meaning no lane changes or speed alterations. Subsequent parameters only affect the `speed` of the `ego` vehicle. ``` -------------------------------- ### Vehicle Control Strategy Update Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Updated control parameters: `lane_change=-1` now uses SUMO's lane-changing strategy, and `speed=-1` uses SUMO's speed strategy. Corresponding documentation has been updated. ```python In control, `lane_change=-1` now uses SUMO's lane-changing strategy, and `speed=-1` uses SUMO's speed strategy. ``` ```python Updated corresponding documentation. ``` -------------------------------- ### Define Vehicle Types and Instances Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/zh_CN/object/vehicle.md Define custom vehicle types with specific attributes and then create vehicle instances with routes and departure times. These are typically defined in a simulation configuration file. ```xml ``` -------------------------------- ### TLS Switches 输出格式 Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/zh_CN/sumo_tools/tls_addition.md 记录每一个 connection 绿灯的信息,包括交通灯ID、程序ID、fromLane、toLane、开始时间、结束时间和持续时间。 ```xml ... ``` -------------------------------- ### Traffic Light State Update Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Updated the documentation description for the new traffic light state, `fromEdge_toEdge`. ```python Updated doc description about the new state of traffic light, `fromEdge_toEdge`. ``` -------------------------------- ### Rule-Based Method Adaptation Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Updated the rule-based method in single agent to adapt to the new connection method of `from_edge` and `direction`. ```python Updated the rule-based method in single agent to adapt to the new connection method of `from_edge` and `direction`. ``` -------------------------------- ### Scenario Configuration for Special Events Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Defines parameters for a simulation scenario, including base settings, accident configurations, and special vehicle deployments. Use this to set up complex traffic events. ```python SCENARIO_CONFIGS = { "Hongkong_YMT_NORMAL": { # ================== Base Scenario Parameters ================== "SCENARIO_NAME": "Hongkong_YMT", # Scenario directory name "SUMOCFG": "ymt_normal.sumocfg", # Combines route & network configs "NETFILE": "./env_normal/YMT.net.xml", # Network file for map data "JUNCTION_NAME": "J1", "NUM_SECONDS": 500, "PHASE_NUMBER": 3, # Number of traffic light phases "MOVEMENT_NUMBER": 6, "CENTER_COORDINATES": (172, 201, 60), "SENSOR_INDEX_2_PHASE_INDEX": {0: 2, 1: 3, 2: 0, 3: 1}, # ==================== Incident Configuration ==================== "ACCIDENTS": [ { "id": "accident_01", # Unique incident identifier "depart_time": 20, # Simulation trigger time (seconds) "edge_id": "30658263#0", # Target road segment ID "lane_index": 0, # Affected lane index "position": 99, # Location on lane (meters), lane_length-1 "duration": 50, # Duration (seconds), 0=permanent }, { "id": "accident_02", "depart_time": 100, "edge_id": "30658263#0", "lane_index": 1, "position": 99, "duration": 20, }, ], # ================== Special Vehicle Configuration ================== "SPECIAL_VEHICLES": [ { "id": "ambulance_01", # Unique vehicle ID "type": "emergency", # Vehicle class "depart_time": 10, # Departure time (sim seconds) "route": ["960661806#0", "102640426#0"], # Path edge sequence }, { "id": "police_01", "type": "police", "depart_time": 100, "route": ["102454134#0", "102640432#0"], } ] }, } ``` -------------------------------- ### Control Ego Vehicles Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/zh_CN/object/vehicle.md Continuously simulate steps, retrieve vehicle information, identify ego vehicles, generate random actions (lane change and speed), and apply these actions to control the ego vehicles. ```python import numpy as np while conn.simulation.getMinExpectedNumber() > 0: # 获得车辆的信息 data = scene_vehicles.get_objects_infos() # 控制部分车辆, 分别是 lane_change, speed ego_vehicles = filter_ego_id(data) actions = {_veh_id:(np.random.randint(4), None) for _veh_id in ego_vehicles} scene_vehicles.control_objects(actions) conn.simulationStep() ``` -------------------------------- ### Plot Reward Curves Utility Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md The `plot_reward_curves.py` script is available in the utils directory for plotting reward curves with standard deviation from log files. ```python Added [plot_reward_curves.py](./tshub/utils/plot_reward_curves.py) in utils, for plotting reward curve with standard deviation from log files. ``` -------------------------------- ### TLS States 输出格式 Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/zh_CN/sumo_tools/tls_addition.md 记录仿真每一步的交通灯状态,包括时间、ID、程序ID、相位和状态。 ```xml ... ``` -------------------------------- ### Vehicle Lane Change Behavior Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Fixed the issue where vehicles did not stay in the current lane when lane changes were not possible. ```python Fixed the problem where the vehicle did not stay in the current lane when it could not change lanes [base_vehicle_action.py](./tshub/vehicle/vehicle_type/base_vehicle_action.py). ``` -------------------------------- ### LaneWithContinuousSpeedAction Speed Maintenance Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Updated `LaneWithContinuousSpeedAction` to maintain the original speed when the target speed is set to -1. ```python Updated `LaneWithContinuousSpeedAction` to maintain the original speed when the target speed is set to -1. ``` -------------------------------- ### Render Scene in RGB Mode Source: https://github.com/traffic-alpha/transsimhub/blob/main/examples/tshub_env_render/README.md Renders the scene in RGB mode and converts the Matplotlib figure to a NumPy array using plt2arr. Requires importing plt2arr from tshub.utils.plt_to_array. ```python from tshub.utils.plt_to_array import plt2arr obs, reward, info, done = tshub_env.step(actions=actions) fig = tshub_env.render(mode='rgb') fig_array = plt2arr(fig) # convert fig to array ``` -------------------------------- ### Vehicle Information Structure Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/zh_CN/object/vehicle.md The returned vehicle information is a dictionary where keys are vehicle IDs and values are dictionaries containing detailed attributes of each vehicle. ```json "gsndj_n7__1.0": { "id": "gsndj_n7__1.0", "action_type": "lane", "vehicle_type": "car_2", "length": 5.0, "width": 1.8, "heading": 307.80342137935276, "position": [ 2328.0809235224924, 523.075053998435 ], "speed": 8.775783075718211, "road_id": "gsndj_n7", "lane_id": "gsndj_n7_0", "lane_index": 0, "edges": [ "gsndj_n7", "gsndj_n6" ], "waiting_time": 0.0, "accumulated_waiting_time": 0.0, "distance": 26.36442383383401, "co2_emission": 5280.710440252024, "fuel_consumption": 1684.3056844797748, "speed_without_traci": 8.775783075718211, "leader": null, "next_tls": [ [ "htddj_gsndj", 8, 666.575576166166, "r" ] ] } ``` -------------------------------- ### Vehicle Lane Change Logic Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Fixed the problem of vehicle lane change direction error, where the direction was calculated based on the size of the lane index. ```python Fixed the problem of vehicle lane change direction error, where the direction of lane change is calculated based on the size of the lane index. ``` -------------------------------- ### Vehicle Speed Scenario Modifications Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Prevented direct lane changes for all vehicles to mitigate queuing at bottlenecks by adjusting speeds. Regenerated road network and traffic flow files. ```python Prevented direct lane changes for all vehicles to mitigate queuing at bottlenecks by adjusting speeds. ``` ```python Regenerated road network and traffic flow files. Refer to [Vehicle Speed Scenario](./benchmark/sumo_envs/veh_speed/). ``` -------------------------------- ### Enhanced Vehicle Environment Attributes Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md New attributes added to the vehicle environment include accumulated waiting time, distance traveled, leader information, and visualization-related attributes like width, length, and heading angle. ```python Enhanced the `vehicle` environment with new attributes: - `accumulated_waiting_time`: Accumulated waiting time of the vehicle. - `distance`: Distance traveled by the vehicle. - `leader`: Information about the vehicle ahead, including (vehicle id, distance). - `width`, `length`, and `heading_angle`: Attributes for visualizing vehicles in the environment. ``` -------------------------------- ### Control Aircraft Movement Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/zh_CN/object/aircraft.md Issue control commands to aircraft for horizontal movement, specifying speed and heading index. Ensure 'np' is imported for random number generation. ```python import numpy as np actions = { "a1": (5, np.random.randint(8)), "a2": (5, np.random.randint(8)), } scene_aircraft.control_objects(actions) ``` -------------------------------- ### Vehicle Feature Extraction Enhancements Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Added CO2 emissions, fuel consumption, and speed without traci to the vehicle feature extraction. Speed without traci returns the speed the vehicle would drive without speed-influencing commands. ```python In feature extraction, added CO2 emissions (mg/s), fuel consumption (mg/s), and speed without traci (returns the speed the vehicle would drive if no speed-influencing command such as `setSpeed` or `slowDown` was given). ``` -------------------------------- ### Pedestrian Module Modifications Source: https://github.com/traffic-alpha/transsimhub/blob/main/CHANGELOG.md Modified connection judgment in tls_connections.py to exclude pedestrian crossings and added a testing environment and state representation for pedestrians. ```python Modified the connection judgment in [tls_connections.py](./tshub/sumo_tools/sumo_infos/tls_connections.py#76), excluding pedestrian crossings. ``` ```python Added a testing environment for pedestrians. ``` ```python Included pedestrian state representation. ``` -------------------------------- ### Custom Model for Traffic Light Control Source: https://github.com/traffic-alpha/transsimhub/blob/main/benchmark/traffic_light/README.md Defines a custom feature extractor model using Linear and LSTM layers for embedding intersection information and encoding time-series data. This model is suitable for single-agent reinforcement learning tasks. ```python class CustomModel(BaseFeaturesExtractor): def __init__(self, observation_space: gym.Space, features_dim: int = 16): """Feature Extract """ super().__init__(observation_space, features_dim) net_shape = observation_space.shape[-1] # 12 self.embedding = nn.Sequential( nn.Linear(net_shape, 32), nn.ReLU(), ) # 5*12 -> 5*32 self.lstm = nn.LSTM( input_size=32, hidden_size=64, num_layers=1, batch_first=True ) self.relu = nn.ReLU() self.output = nn.Sequential( nn.Linear(64, 32), nn.ReLU(), nn.Linear(32, features_dim) ) def forward(self, observations): embedding = self.embedding(observations) output, (hn, cn) = self.lstm(embedding) hn = hn.view(-1, 64) hn = self.relu(hn) output = self.output(hn) return output ``` -------------------------------- ### Filter Ego Vehicles Source: https://github.com/traffic-alpha/transsimhub/blob/main/docs/source/locales/zh_CN/object/vehicle.md A utility function to filter out vehicle IDs that are designated as 'ego' vehicles from a given vehicle data dictionary. This is useful for applying specific controls only to autonomous or controlled vehicles. ```python def filter_ego_id(vehicle_data): ego_ids = [] for _veh_id, _veh_info in vehicle_data.items(): if _veh_info['vehicle_type'] == 'ego': ego_ids.append(_veh_id) return ego_ids ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.