ox_k_shortest_paths: k shortest paths between two nodes

View source: R/routing.R

ox_k_shortest_pathsR Documentation

k shortest paths between two nodes

Description

Computes up to k loopless shortest paths from from to to using Yen's algorithm in the Rust core. Useful for route alternatives.

Usage

ox_k_shortest_paths(g, from, to, k = 3, weight = "length")

Arguments

g

An osm_graph.

from, to

Node osmids.

k

Number of paths to return. Default 3.

weight

Edge column used as weight. Default "length".

Value

A tibble with one row per path: rank, cost and a list-column path of node osmids, ordered by increasing cost. Fewer than k rows are returned when fewer distinct paths exist.

Examples

g <- example_osm_graph()
from <- ox_nearest_nodes(g, 0, 0)
to <- ox_nearest_nodes(g, 200, 200)
ox_k_shortest_paths(g, from, to, k = 3)

osmnxr documentation built on Oct. 20, 2026, 1:07 a.m.