1- import pandas as pd
2- import geopandas as gpd
3- import osmnx as ox
4- import networkx as nx
5- from shapely .geometry import LineString
6- from shapely .ops import linemerge , unary_union
71import math
82
93# single-global-graph approach; per-row cached graphs removed
104import multiprocessing as mp
11- from typing import Tuple , Any
5+ from typing import Any , Tuple
126
7+ import geopandas as gpd
8+ import networkx as nx
9+ import osmnx as ox
10+ import pandas as pd
11+ from shapely .geometry import LineString
12+ from shapely .ops import linemerge , unary_union
1313
1414# Optionally hold a single pre-fetched graph for the whole study area.
1515GLOBAL_GRAPH = None
1616
1717
18- # Note: per-row cached graph fetch removed. This module now requires a single
19- # pre-fetched study-area graph assigned to GLOBAL_GRAPH (via bbox in
20- # `add_deadhead_trips`) and all routing workers use that graph.
21-
22-
2318def _parallel_map (
2419 func : Any , iterable : Any , n_processes : int | None , chunksize : int = 8
2520) -> list [Any ]:
@@ -32,6 +27,7 @@ def _parallel_map(
3227 results .append (item )
3328 return results
3429
30+
3531def _haversine_km (lat1 : Any , lon1 : Any , lat2 : Any , lon2 : Any ) -> float :
3632 """Get the haversine distance between two points in kilometers."""
3733 R = 6371.0
@@ -153,7 +149,7 @@ def _process_deadhead_trip_row(args: Tuple[Any, ...]) -> list[Any]:
153149 return []
154150
155151
156- def add_deadhead_trips (
152+ def create_deadhead_shapes (
157153 df : gpd .GeoDataFrame ,
158154 o_col : str = "geometry_origin" ,
159155 d_col : str = "geometry_destination" ,
@@ -171,9 +167,7 @@ def add_deadhead_trips(
171167 global GLOBAL_GRAPH
172168
173169 # Create bounding box around for osmnx graph based on O/D geometry
174- all_points = pd .concat (
175- [df ["geometry_origin" ], df ["geometry_destination" ]]
176- )
170+ all_points = pd .concat ([df ["geometry_origin" ], df ["geometry_destination" ]])
177171 lons = all_points .apply (lambda p : p .x )
178172 lats = all_points .apply (lambda p : p .y )
179173 min_lon , max_lon = lons .min (), lons .max () # Bounding box
0 commit comments