From d634da952b793dd85f5c8169c9a9a71ceb4b384f Mon Sep 17 00:00:00 2001 From: Renata Imai Date: Wed, 5 Jun 2024 11:29:11 -0300 Subject: [PATCH] update graph discount --- aequilibrae/transit/gtfs_loader.py | 4 ++-- aequilibrae/transit/lib_gtfs.py | 5 ----- .../transit/transit_elements/pattern.py | 20 +++++++------------ 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/aequilibrae/transit/gtfs_loader.py b/aequilibrae/transit/gtfs_loader.py index e5fd82cd3..f841acdcc 100644 --- a/aequilibrae/transit/gtfs_loader.py +++ b/aequilibrae/transit/gtfs_loader.py @@ -271,14 +271,14 @@ def __load_shapes_table(self): self.signal.emit(["start", "secondary", len(all_shape_ids), msg_txt, self.__mt]) self.data_arrays[shapestxt] = shapes - lons, lats = self.transformer.transform(shapes[:]["shape_pt_lat"], shapes[:]["shape_pt_lon"]) + lats, lons = self.transformer.transform(shapes[:]["shape_pt_lat"], shapes[:]["shape_pt_lon"]) shapes[:]["shape_pt_lat"][:] = lats[:] shapes[:]["shape_pt_lon"][:] = lons[:] for i, shape_id in enumerate(all_shape_ids): self.signal.emit(["update", "secondary", i + 1, msg_txt, self.__mt]) items = shapes[shapes["shape_id"] == shape_id] items = items[np.argsort(items["shape_pt_sequence"])] - shape = LineString(list(zip(items["shape_pt_lat"], items["shape_pt_lon"]))) + shape = LineString(list(zip(items["shape_pt_lon"], items["shape_pt_lat"]))) self.shapes[shape_id] = shape def __load_trips_table(self): diff --git a/aequilibrae/transit/lib_gtfs.py b/aequilibrae/transit/lib_gtfs.py index 56f042025..0a9a81a4c 100644 --- a/aequilibrae/transit/lib_gtfs.py +++ b/aequilibrae/transit/lib_gtfs.py @@ -70,11 +70,6 @@ def __init__(self, network, agency_identifier, file_path, day="", description="" links = self.project.network.links.data self.geo_links = gpd.GeoDataFrame(links, geometry=links.geometry, crs="EPSG:4326") - self.reprojected_links = self.geo_links.to_crs(3857) - self.reprojected_links["repr_length"] = self.reprojected_links["geometry"].length - # Approximately 40 meter buffer - # buff_geo = self.geo_links.to_crs(3857).buffer(40).geometry - # self.geo_links_buffer = gpd.GeoDataFrame(links, geometry=buff_geo.to_crs(4326), crs="EPSG:4326") def set_capacities(self, capacities: dict): """Sets default capacities for modes/vehicles. diff --git a/aequilibrae/transit/transit_elements/pattern.py b/aequilibrae/transit/transit_elements/pattern.py index 436944a38..50eed8c93 100644 --- a/aequilibrae/transit/transit_elements/pattern.py +++ b/aequilibrae/transit/transit_elements/pattern.py @@ -43,8 +43,6 @@ def __init__(self, route_id, gtfs_feed) -> None: self.total_capacity = None self.__srid = get_srid() self.__geolinks = gtfs_feed.geo_links - # self.__geolinks_buffer = gtfs_feed.geo_links_buffer - self.__reprojected_links = gtfs_feed.reprojected_links self.__logger = logger self.__feed = gtfs_feed @@ -156,14 +154,15 @@ def map_match(self): self.__build_pattern_mapping() logger.info(f"Map-matched pattern {self.pattern_id}") + # TODO: consider improving the link selection for discount applying an overlay and use a cost proportional to the + # link length in the route (raw_shape) buffer. def __graph_discount(self): buff = gpd.GeoSeries(self.raw_shape, crs="EPSG:4326").to_crs(3857).buffer(20).geometry - gdf = gpd.GeoDataFrame(geometry=buff, crs=self.__reprojected_links.crs) - gdf = self.__reprojected_links.overlay(gdf, how="intersection") + gdf = gpd.GeoDataFrame(geometry=buff.to_crs(4326), crs=self.__geolinks.crs) + gdf = self.__geolinks.overlay(gdf, how="intersection") - gdf = gdf[gdf.modes.str.contains(mode_correspondence[self.route_type])] - gdf.loc[:, "intersect"] = 1 / (gdf["geometry"].length / gdf["repr_length"]) - return gdf + gdf = gdf.loc[gdf.modes.str.contains(mode_correspondence[self.route_type])] + return gdf.link_id.tolist() def __map_matching_complete_path_building(self): mode_ = mode_correspondence[self.route_type] @@ -202,12 +201,7 @@ def __map_matching_complete_path_building(self): graph.cost = np.array(graph.graph.distance) likely_links = self.__graph_discount() - lnks = likely_links.link_id.tolist() - links_in_graph = graph.graph.original_id.abs().isin(lnks) - g = graph.graph[links_in_graph] - g.loc[:, "abs_id"] = g["original_id"].abs() - g = g.merge(likely_links[["link_id", "intersect"]], left_on="abs_id", right_on="link_id") - graph.cost[links_in_graph] *= g["intersect"] * 0.1 + graph.cost[graph.graph.original_id.abs().isin(likely_links)] *= 0.1 fstop = connected_stops[0]