ferrobus.find_route#
- ferrobus.find_route(transit_model, start_point, end_point, departure_time, max_transfers=3)#
Find an optimal route between two points in a transit network
Calculates the fastest route between two points using a multimodal approach that combines walking and public transit. The algorithm considers all possible transit connections as well as direct walking paths.
- Parameters:
transit_model (TransitModel) – The transit model to use for routing.
start_point (TransitPoint) – Starting location for the route.
end_point (TransitPoint) – Destination location for the route.
departure_time (int) – Time of departure in seconds since midnight.
max_transfers (int, default=3) – Maximum number of transfers allowed in route planning.
- Returns:
A dictionary containing route details including: - travel_time_seconds: Total travel time - walking_time_seconds: Total walking time - transit_time_seconds: Time spent on transit (if used) - transfers: Number of transfers made (if transit used) - used_transit: Whether transit was used or just walking Returns None if the destination is unreachable.
- Return type:
dict or None
Notes
This function uses aggressive early pruning, and scans fewer possible egress stops compared to
find_routes_one_to_many(). As a result, the route found may not always be the absolute fastest possible, especially in complex transit networks with multiple transfer options. If you require the most accurate and optimal results, prefer usingfind_routes_one_to_many(), which performs a more exhaustive search for each destination.- Raises:
RuntimeError – If the route calculation fails.
Example
result = ferrobus.find_route(model, start_point, end_point, departure_time, max_transfers) if result is not None: print(result) # Example output: # { # "travel_time_seconds": 1800, # "walking_time_seconds": 300, # "transit_time_seconds": 1500, # "transfers": 1, # "used_transit": True # } else: print("No route found")