Skip to content

Commit

Permalink
update graph discount
Browse files Browse the repository at this point in the history
  • Loading branch information
r-akemii committed Jun 5, 2024
1 parent 802f609 commit d634da9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
4 changes: 2 additions & 2 deletions aequilibrae/transit/gtfs_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 0 additions & 5 deletions aequilibrae/transit/lib_gtfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 7 additions & 13 deletions aequilibrae/transit/transit_elements/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]

Expand Down

0 comments on commit d634da9

Please sign in to comment.