ferrobus.find_routes_one_to_many#
- ferrobus.find_routes_one_to_many(transit_model, start_point, end_points, departure_time, max_transfers=3)#
Find routes from one point to multiple destinations
Efficiently calculates routes from a single starting point to multiple destination points in a single operation. This is significantly faster than performing separate routing calculations for each destination.
- Parameters:
transit_model (TransitModel) – The transit model to use for routing.
start_point (TransitPoint) – Starting location for all routes.
end_points (list[TransitPoint]) – List of destination points.
departure_time (int) – Time of departure in seconds since midnight.
max_transfers (int, default=3) – Maximum number of transfers allowed in route planning.
- Returns:
List of routing results in the same order as the input end_points. Each result is either a dictionary with route details or None if the destination is unreachable.
- Return type:
list[dict or None]
Notes
The one-to-many nature of this function allows us to scan multiple possible egress stops for each destination, so the results may be more accurate than individual route calculations using
find_route().Example
# Create a transit model model = ferrobus.create_transit_model( gtfs_dirs=["path/to/you_feed"], osm_path="path/to/street_network.osm.pbf" ) start_point = ferrobus.create_transit_point( lat=52.5200, lon=13.4050, transit_model=model, max_walking_time=900, max_nearest_stops=5 ) end_point1 = ferrobus.create_transit_point( lat=52.5300, lon=13.4100, transit_model=model, max_walking_time=900, max_nearest_stops=5 ) end_point2 = ferrobus.create_transit_point( lat=52.5400, lon=13.4200, transit_model=model, max_walking_time=900, max_nearest_stops=5 ) # Find routes results = ferrobus.find_routes_one_to_many( model, start_point, [end_point1, end_point2], departure_time=3600, max_transfers = 3 ) for result in results: if result is not None: print(result) # Example output for one destination: # [{ # "travel_time_seconds": 1800, # "walking_time_seconds": 300, # "transit_time_seconds": 1500, # "transfers": 1, # "used_transit": True # }, # { # "travel_time_seconds": 2100, # "walking_time_seconds": 300, # "transit_time_seconds": 1800, # "transfers": 2, # "used_transit": True # }] else: print("No route found")
- Raises:
RuntimeError – If the batch routing calculation fails.
Notes
This function releases the GIL during computation to allow other Python threads to run.