๐งญ Trips Generator ๐ฆ
This module converts Sevilla traffic counts into SUMO trips and routes (.rou.xml) using a configurable
mapping and time-of-day distributions. It complements the Traffic Profile Analysis by turning demand estimates into
simulation-ready inputs.
Author: Code โ Raquel Blanco ยท Docs โ Belรฉn Lรณpez Salamanca
Date: 07/2025
Version: 1.0.0
- ๐ Project Overview
- ๐งฐ Inputs
- ๐งช Environment
- ๐งผ Pre-processing
- โ๏ธ Generation Logic
- ๐ Vehicle Route Docstrings
- ๐ค Outputs
- ๐ฎ Next Steps
- ๐ Notes & References
๐ Project Overview¶
The trips generator reads cleaned interval counts for Sevilla routes, as prepared in
Traffic Data. Route identifiers are manually mapped to SUMO edge IDs in
rutas_edges_v1.json. With those inputs, the Python script (randomTrips_v7) produces a SUMO route file (.rou.xml)
that follows the observed temporal distribution of vehicles.
๐งฐ Inputs¶
CSV with route vehicle counts¶
- Path: In Sanevec-docs:
traffic_profiling/trips/datos_combinados_1.csv - Description: See Traffic Data.
- Expected columns:
- RUTAS: integer route identifiers (e.g., 1, 2, 3, โฆ).
- Hour columns: per-route counts for each time window (e.g.,
07:00-08:00,08:00-09:00, โฆ). - Optional
Totalcolumn: may be present; ignored.
JSON with route edges¶
- Path: In Sanevec-docs:
traffic_profiling/trips/rutas_edges_v1.json - Description: Manually curated mapping that links each route (
RUTA_n) to one or more SUMO edge IDs from the Sevilla network. - Structure: Values are comma-separated SUMO edge IDs used as candidate source edges for each route.
{ "RUTA_1": "edgeA, edgeB, edgeC", "RUTA_2": "edgeX, edgeY" }
SUMO network¶
- Path:
osm.net.xml - Description: Map of Seville obtained with the OSM Web Wizard.
- Usage: Compute shortest paths and filter target edges (
allows("passenger")andnot edge.is_fringe()).
๐งช Environment¶
SUMO_HOMEset sosumolibtools are available.- MPI environment available for
mpi4py(hours distributed across ranks).
๐ค Outputs¶
- Route file for SUMO:
generated_routes.rou.xml
Contains<vehicle id="..." depart="..."><route edges="..."/></vehicle>entries, sorted bydeparttime. - Console logs: Per-route/hour generation stats and final totals.
๐งผ Pre-processing¶
- Load vehicle counts from CSV. Treat all columns except
RUTASandTotalas hour bins. - Load edges mapping from JSON. For each
RUTA_n, split by comma and trim whitespace. - Build per-hour objects:
- For each hour, create
Route(route_id=f"{RUTA}_{hour}", total_vehicles=n, edges=[...]). - Store
(routes_for_hour, total_vehicles_in_hour)under the hour key. - Read the SUMO network and filter target edges: non-fringe and passenger-allowed.
โ๏ธ Generation Logic¶
Per MPI rank: 1. Distribute hours across ranks (even split; remainder on lower ranks). 2. For each local hour:
- Uniform depart spacing across the hour:
3600 / total_vehicles_in_hour. -
For each
Route:- Pre-assign overlapped vehicles (shared edges with previously generated routes in the same hour) to reduce new generation.
- While the route still needs vehicles:
- Sample a depart time, a source edge from the route, and a target edge from global valid targets.
- Compute shortest path (source โ target). If none, retry.
- Create
Vehicle(id, depart_time, path_edges). - Penalize the routeโs edges (inflate first-lane length) to discourage re-use in subsequent shortest-path calls (heuristic).
- Record overlap so remaining routes can pre-assign accordingly.
- Gather all vehicles at rank 0 and write the
.rou.xmlfile.
๐ Vehicle Route Generation โ Docstrings Extracted¶
Module¶
Vehicle route generation module for SUMO traffic simulations.
This module generates vehicles routes based on input data
Classes¶
Vehicle¶
Class Docstring¶
Represents a vehicle with its route an departure time
Vehicle.__init__(id, depart_time, edges)¶
Initialize a Vehicle instance
Args:
route_id: unique identifier for the vehicle
depart_time: Simulation time when the vehicle departs (seconds)
edges: List of edge IDs that form the vehicle's route
Vehicle.__repr__()¶
Return a string representation of the Vehicle.
Route¶
Class docstring: None provided.
Route.__init__(route_id, total_vehicles, edges)¶
Initialize a Route instance
Args:
route_id: unique identifier for the route
total_vehicles: number of vehicles assigned to this route
edges: list of edges ids that form the route
Route.add_vehicles(id_vh_list)¶
Add vehicles to the processed vehicles list.
Args:
vehicles: List of Vehicle objects to add
Route.processed()¶
Docstring: None provided.
Route.__repr__()¶
Docstring: None provided.
Functions¶
load_route_data(route_vehicles_file_path, route_edges_file_path) -> List[Route]¶
Load route data from CSV and JSON files.
Args:
route_vehicles_file_path: Path to CSV file with vehicle counts per route and hour
route_edges_file_path: Path to JSON file with edge sequences for each route
Returns:
Dictionary mapping hours to tuples of (routes, total_vehicles)
find_routes_by_edge(routes, current_id, vehicles, update_routes: dict)¶
Find routes that share edges with the given vehicles.
Args:
routes: List of all Route objects
current_id: ID of the current route being processed
vehicles: List of Vehicle objects to check
update_routes: Dictionary to accumulate route updates
Returns:
Updated dictionary mapping route IDs to lists of vehicle IDs
generate_vehicles_for_hour(start_time, net: Net, target_edges, routes: List[Route], total_vh, start_id: int) -> List[Vehicle]¶
Generate vehicles for a specific hour.
Args:
start_time: Starting time for this hour (seconds)
net: SUMO network object
target_edges: List of valid target edges for vehicles
routes: List of Route objects for this hour
total_vh: Total number of vehicles to generate for this hour
start_id: Starting ID for vehicle numbering
Returns:
Tuple of (list of generated vehicles, next available vehicle ID)
create_route_file(vehicles: List[Vehicle], filename="generated_routes.rou.xml")¶
Create a SUMO route file from a list of Vehicle objects.
Args:
vehicles: List of Vehicle objects to include in the file
filename: Name of the output file
๐ฎ Next Steps¶
- Integrate directionality and multi-class vehicle types.
- Add OD matrices or downstream edge selection for longer routes.
- Validate against
--edgedata-outputmetrics and refine distributions.
๐ Notes & References¶
- Data preparation: Traffic Profile Analysis