UtilityFlowSim is a stochastic, utility-based multi-agent traffic simulation for an urban intersection. It simulates mixed traffic participants:
- vehicles
- pedestrians
- bikes
- drones
Agents choose their next movement by maximizing a utility objective that balances route/heading alignment, speed preference, path adherence (lane/sidewalk/altitude behavior), and collision-risk penalties.
- Builds an intersection environment (including roads, sidewalks, and optional bike-lane setting).
- Spawns initial agents by type based on configuration.
- Optionally generates additional agents during runtime at fixed intervals.
- Advances the world in discrete time steps (
dt) untiltotal_simulation_time. - Runs synchronous decision-making each step so all agents react to the same snapshot.
- Stops updating agents once they reach their destination.
- Produces visualizations, optional animation, and optional CSV trajectory export.
The main inputs are defined in config.py inside the CONFIG dictionary.
environment_setting: selects layout variant (1or2).bike_behavior_mode: bike routing mode ("road"or"sidewalk"; in setting 2 this maps to bike-lane behavior).- Geometry inputs such as
lane_width,sidewalk_width,bike_lane_width, and lane counts. - Drone infrastructure inputs such as
num_drone_stationsanddrone_station_placement_offset.
initial_agent_counts: number of each type spawned at time 0.enable_dynamic_generation: enables ongoing spawning during simulation.dynamic_generation_counts: number of each type spawned per generation event.agent_generation_interval: seconds between spawn events.
dt: simulation step size in seconds.total_simulation_time: total duration in seconds.random_seed: fixed seed for reproducible runs.
- Type-specific size/speed/destination-threshold inputs:
vehicle_*,bike_*,pedestrian_*,drone_*
- Motion limits:
max_acceleration,max_deceleration,max_steering_angle_rad
- Interaction distances:
- safety-distance parameters like
vv_safety_distance,vp_safety_distance,dd_safety_distance, etc.
- safety-distance parameters like
Utility scoring is controlled by weights and shaping parameters such as:
w_c,w_ell,w_ell_droneS_theta,eta_i,S_v,xi_i,S_d,gammabeta,epsilon- collision uncertainty terms (
collision_sigma_x/y/z) - local speed-field terms (
speed_influence_*)
These parameters control tradeoffs between efficiency, comfort/path-following, and collision avoidance.
show_live_simulation: live plot during simulation.create_animation: generate animated output after simulation.plot_trajectories,plot_trajectories_with_ids,plot_individual_trajectoriesenable_trajectory_smoothingexport_to_csvanimation_output_path: output folder for generated files.
From the project root:
python main.pyBefore running, edit config.py to choose:
- environment mode
- number/type of agents
- total duration and step size
- whether to export plots/animation/CSV
Depending on configuration, files are written to animation_output_path (default: ./intersection_plots/), including:
- trajectory plots for ground agents and drones
- optional ID-labeled and individual-agent plots
- optional smoothed trajectory plots
- optional animation
- optional CSV export of trajectories (
full_simulation_trajectories.csv)
- If
show_live_simulationisFalse, the project runs in save/analysis mode and generates configured artifacts after the simulation loop. - Dynamic generation can substantially increase total simulated agent count during long runs.