Point-to-point routing on a RoadGraph (shortest = metres, fastest =
seconds with the urban speed table), matching the Julia server's
shortest_route/fastest_route semantics.
route_vertices(
graph: RoadGraph,
from_vertex: int,
to_vertex: int,
metric: str,
) -> list[int] | None
Vertex-index path for one edge of a route, or None when unreachable.
Source code in MAMUT-routing-tools/src/mamut_routing_tools/roadgraph/router.py
| def route_vertices(
graph: RoadGraph,
from_vertex: int,
to_vertex: int,
metric: str,
) -> list[int] | None:
"""Vertex-index path for one edge of a route, or None when unreachable."""
if metric == "fastest":
def weight(edge_index: int) -> float:
return graph.time_weight(edge_index, SPEED_ROADS_URBAN)
elif metric == "shortest":
def weight(edge_index: int) -> float:
return graph.edge_weight[edge_index]
else:
raise ValueError(f"Unsupported road metric '{metric}'")
paths = rx.dijkstra_shortest_paths(graph.graph, from_vertex, target=to_vertex, weight_fn=weight)
if to_vertex not in paths:
return None if from_vertex != to_vertex else [from_vertex]
return list(paths[to_vertex])
|