HPC module
METS-R HPC is used to control multiple simulation instances that can run and exchange data through WebSocket connects. Apache Kafka is used to explicitly model the data stream. The overall HPC framework is shown in the figure below, note this framework allows us to separate the logics of modeling data processing, decision generation, traffic simulation, and potentially cyber attacks.
HPC framework
Code structure
Four types of classes are used:
Clientfor interfacing the data communication between simulators and other components.Runnerfor defining different types of experiments.Modelfor implementing operational algorithms.Configfor storing the configuration templates.
Besides these, we provide the example scripts:
interactive_example.ipynb, cosim_example.py.
Interactive APIs
The following APIs are implemented to interact with the METS-R SIM,
here sim_client is an instance of METSRClient.
STEP
Name |
Description |
Examples |
Return |
|---|---|---|---|
tick |
Move the simulation one tick forward |
|
QUERY
If an agent ID is provided, a query would return the information of the specific agent, otherwise, it will return a list containing the ID of all agents.
Name |
Description |
Examples |
Return |
|---|---|---|---|
|
Get the information of one or more vehicles. By default, queries public vehicles. Set |
|
x, y, speed, acceleration, bearing, origin zone, destination zone, vehicle state |
|
Get the information of one or more EV taxis. |
|
x, y, passenger number, vehicle state, origin zone, destination zone |
|
Get the information of one or more EV buses. |
|
battery state, route ID, current stop, passenger number |
|
Get the information of one or more roads. |
|
speed limit, number of on-road vehicles, average travel time, road length (m), energy consumed, road type |
|
Get the centerline geometry of a specific lane on a road. Set |
|
list of (x, y) coordinate pairs along the lane centerline |
|
Get the information of one or more demand zones. |
|
vehicle stock, taxi demand, bus demand, x, y, zone type |
|
Get the information of one or more traffic signals. |
|
current phase, next phase, next update time |
|
Get the signal group information for a given signal controller ID, including all phases and their durations. |
|
signal group ID, phase list, phase durations |
|
Query the signal controlling the connection between two consecutive roads. |
|
signal ID, current phase, next update time |
|
Get the information of one or more EV charging stations. |
|
x, y, number of available chargers |
|
Get the vehicle IDs currently located on the co-simulation road. |
|
list of vehicle IDs on the co-sim road |
|
Query the shortest route between two coordinate-specified locations. Set |
|
ordered list of road IDs forming the route |
|
Query the shortest route between two road IDs. |
|
ordered list of road IDs forming the route |
|
Query the current edge weights (travel time or energy cost) used for routing. Returns weights for all roads if no ID is specified. |
|
road ID, current weight value |
|
Get the stop sequence and road path for a named bus route. |
|
route name, stop zone IDs, road path |
|
Get all active buses currently assigned to a specific route. |
|
list of bus IDs on the route |
CONTROL
Name |
Description |
Examples |
Inputs |
|---|---|---|---|
|
Generate a vehicle trip between origin and destination zones. |
|
vehID, origin zone ID, destination zone ID |
|
Generate a vehicle trip between origin and destination roads. |
|
vehID, origin road ID, destination road ID |
|
Set one or more roads for co-simulation. Vehicles on these roads will be controlled externally. |
|
roadID |
|
Release one or more co-simulation roads, returning vehicle control to the simulator. |
|
roadID |
|
Teleport a co-simulation vehicle to a specified coordinate with a given heading. Set |
|
vehID, x, y, bearing (degrees), private_veh, transform_coords |
|
Teleport a vehicle to a position specified by road ID, lane index, and distance from the downstream junction. |
|
vehID, roadID, laneID, dist, private_veh |
|
Move a co-simulation vehicle onto the next road in its planned route. |
|
vehID, private_veh |
|
Signal that a co-simulation vehicle has reached its destination and should be removed from the network. |
|
vehID, private_veh |
|
Directly override the acceleration of a vehicle for the current tick. |
|
vehID, acc (m/s²), private_veh |
|
Change the sensor type of a vehicle (e.g., for V2X data stream configuration). |
|
vehID, sensorType, private_veh |
|
Override the planned route of a vehicle with a new ordered list of road IDs. |
|
vehID, route (list of road IDs), private_veh |
|
Dispatch a specific taxi to serve a passenger request between two zones. |
|
vehID, origin zone ID, destination zone ID, num passengers |
|
Dispatch a specific taxi to serve a request between two road-specified locations. |
|
vehID, origin road ID, destination road ID, num passengers |
|
Inject a taxi passenger request at a zone, to be fulfilled by the simulator’s dispatch logic. |
|
origin zone ID, destination zone ID, num passengers |
|
Inject a road-based taxi request from one road to another. |
|
origin road ID, destination road ID, num passengers |
|
Assign a passenger request directly to a specific bus. |
|
vehID, origin zone ID, destination zone ID, num passengers |
|
Inject a bus passenger request at a zone for a specific route. |
|
origin zone ID, destination zone ID, route name, num passengers |
|
Define a new bus route by specifying its stop zones and road path. If |
|
route name, list of zone IDs, list of road IDs, optional paths |
|
Schedule a new bus departure on an existing route at a specified simulation time (in ticks). |
|
route name, departure time (ticks) |
|
Dynamically insert a new stop into an active bus route at a given index. |
|
bus ID, route name, zone ID, road name, stop index |
|
Remove a stop from an active bus route at a given index. |
|
bus ID, route name, stop index |
|
Update the routing weight (e.g., travel time or energy cost) for a road segment. |
|
roadID, new weight value |
|
Update the per-kWh charging price at a specific station. |
|
station ID, charger type, price ($/kWh) |
|
Force a traffic signal to switch to a target phase, lasting the specified duration (in ticks). |
|
signal ID, target phase index, phase duration (ticks) |
|
Update the fixed-time cycle durations (in ticks) of a traffic signal. |
|
signal ID, green ticks, yellow ticks, red ticks |
|
Set a complete signal phase plan using durations in seconds. |
|
signal ID, green time (s), yellow time (s), red time (s), start phase, phase offset (s) |
|
Set a complete signal phase plan using durations in simulation ticks. |
|
signal ID, green ticks, yellow ticks, red ticks, start phase, tick offset |
|
Save a full snapshot of the current simulation state to a file, enabling reproducible replay. |
|
filename |
|
Restore the simulation to a previously saved state. |
|
filename |
|
Reset the simulation to its initial state using the current configuration. |
|
|
|
Fully terminate the simulation process. |
|
|
|
Close the client connection while leaving the simulation running. |
|