iduedu.k_shortest_paths¶
- iduedu.k_shortest_paths(urban_graph, source_node, target_node, k, *, weight='time_min', cutoff=None, max_workers=None)[source]¶
Return up to k shortest loopless paths from source_node to target_node (Yen’s algorithm).
Every next path leaves an earlier one at some node and takes the shortest way on from there that repeats no node of the shared part and no way taken before. The paths are often small variations of one another (another sidewalk, the other side of a square); for routes along other streets use
alternative_paths().- 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 paths, at least 1.weight (
Literal['length_meter','time_min']) – Edge cost column: time_min (minutes) or length_meter (meters).cutoff (
float|None) – Inclusive maximum cost of a path, or None for no limit.max_workers (
int|None) – Worker threads for the searches of each step (default: one per CPU).
- Return type:
- Returns:
DataFrame indexed by
rank(0 is the shortest path) with columnsdist(cost in the units ofweight) andpath(node ids from source_node to target_node), cheapest first. It has fewer than k rows when there are fewer loopless paths within cutoff, and none when the end is not reached.