iduedu.alternative_paths¶
- iduedu.alternative_paths(urban_graph, source_node, target_node, k=3, *, weight='time_min', penalty=1.5, max_overlap=0.7, max_cost_ratio=1.4, cutoff=None)[source]¶
Return up to k distinct routes from source_node to target_node by the penalty method.
The shortest route comes first. Then the costs of the edges it uses are multiplied by
penaltyin both directions and the search runs again, so the next route leaves those streets wherever a detour exists; every route found is penalised in turn. A route is kept when its real cost is at mostmax_cost_ratiotimes the shortest one and at mostmax_overlapof that cost runs on the streets of a route kept earlier. Unlikek_shortest_paths(), whose routes on a street graph often differ by a sidewalk, the routes differ by whole streets. Streets are graph edges: on a walk graph the sidewalk on the other side of an avenue is another street.- Parameters:
urban_graph (
UrbanGraph) – Urban graph to search.source_node (
Any) – Graph id of the start node.target_node (
Any) – Graph id of the end node.k (
int) – Maximum number of routes, at least 1. At most4 * ksearches run.weight (
Literal['length_meter','time_min']) – Edge cost column: time_min (minutes) or length_meter (meters).penalty (
float) – Factor applied to the edges of every route found, above 1.max_overlap (
float) – Largest share of a route’s cost on the streets of an earlier route, from 0 (nothing shared) to 1 (no limit).max_cost_ratio (
float) – Largest cost of a route relative to the shortest one, at least 1.cutoff (
float|None) – Inclusive maximum cost of a route, or None for no limit.
- Return type:
- Returns:
DataFrame indexed by
rank(0 is the shortest route, then by cost) with columnsdist(real cost in the units ofweight),overlap(the largest share of it on the streets of another route of the table) andpath(node ids from source_node to target_node). It has fewer than k rows when no more routes meet the limits, and none when the end is not reached.