iduedu.od_matrix¶
- iduedu.od_matrix(urban_graph, *, gdf_origins=None, gdf_destinations=None, origins_nodes=None, destination_nodes=None, graph_node_column='graph_node_id', weight='time_min', dtype=<class 'numpy.float32'>, threshold=None, max_workers=None, cutoff=None, output='distances', path_storage='eager', mode='all_to_all', batch_size=None, method='auto', distance_format='frame')[source]¶
Compute OD distances, node routes, or both with one search per unique source.
- Parameters:
urban_graph (
UrbanGraph) – Urban graph to search.gdf_origins (
DataFrame|None) – Origin objects, using graph_node_column or nearest geometries.gdf_destinations (
DataFrame|None) – Destination objects, with the same input conventions.origins_nodes (
Optional[Iterable[Any]]) – Origin graph ids, as an alternative to gdf_origins.destination_nodes (
Optional[Iterable[Any]]) – Destination graph ids, instead of gdf_destinations.graph_node_column (
str) – Explicit graph node id column in object tables.weight (
Literal['length_meter','time_min']) – Edge cost column: time_min (minutes) or length_meter (meters).dtype (
dtype) – Returned distance dtype; kernel arithmetic remains float32.threshold (
float|None) – Compatible alias for cutoff. Passing both is an error.max_workers (
int|None) – Worker threads (default: one per CPU).cutoff (
float|None) – Inclusive maximum total cost, or None for no limit.output (
Literal['distances','paths','both']) – distances (default, preserving existing calls), paths, or both.path_storage (
Literal['eager','lazy']) – eager or lazy. Lazy requires output=both and retains compact predecessor trees. result.get_path(origin, destination) reconstructs one path; result.paths materializes and caches the entire path table.mode (
Literal['all_to_all','pairwise']) – all_to_all creates matrices; pairwise matches inputs by position and returns a MultiIndex table with one dist or path column.batch_size (
int|None) – Maximum searches per batch. This limits working memory, not the full returned table or retained lazy trees. Use iter_od_matrix to consume bounded blocks of origin rows instead.method (
Literal['auto','bidirectional','astar','dijkstra']) – Search of pairwise tables.dijkstraruns one search per unique origin that stops at its destinations;bidirectional,astarandaltrun one point-to-point search per pair (seeshortest_path()).auto(default) picksbidirectionalwhen most origins occur once anddijkstraotherwise. All-to-all tables always usedijkstra.distance_format (
Literal['frame','dense','sparse']) –"frame"(default) uses a pandas table. Withoutput="distances"or"both","dense"uses a NumPy array withnp.inffor unreachable or out-of-cutoff pairs."sparse"uses a SciPy CSR array for all-to-all mode. An absent entry means unreachable. Explicit zero costs are stored, so never calleliminate_zeros. Use.tocoo()to get therow,colanddataarrays.
- Return type:
Series|DataFrame|ShortestPathResult|ndarray|csr_array- Returns:
A sparse DataFrame, ShortestPathResult or distance array. Array axes follow input order and preserve duplicate inputs. Pairwise dense output has one dimension with one value per input pair. With
output="both", the paths remain a pandas table with the same labels and positions. Searches use the smaller unique input side when possible, stop once requested targets settle, and restore original directed route order.