From 7b1d2dca6f2e60d750ef6140b60022a292cfaa1b Mon Sep 17 00:00:00 2001 From: Michael Szell Date: Thu, 3 Sep 2026 16:51:09 +0200 Subject: [PATCH 1/2] Add street name to gap --- fixbikenet/fixbikenet.py | 3 ++- fixbikenet/functions.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/fixbikenet/fixbikenet.py b/fixbikenet/fixbikenet.py index 9957dda..4127483 100644 --- a/fixbikenet/fixbikenet.py +++ b/fixbikenet/fixbikenet.py @@ -161,7 +161,7 @@ def fixbikenet( potential_gaps = find_potential_gaps(contact_nodes, nodes_gdf, maxgap) # add routing for gaps in network - found_gaps, found_gaps_nsp = find_actual_gaps(G, potential_gaps, mingap) + found_gaps, found_gaps_nsp, found_gaps_name = find_actual_gaps(G, potential_gaps, mingap) # calculating local betweenness score dependent on radius ebc = compute_local_betweenness_centrality(G, nodes_gdf, radius) @@ -171,6 +171,7 @@ def fixbikenet( df = pd.DataFrame( { "gap": found_gaps, + "name": found_gaps_name, "benefit": Bs, "nodelist": found_gaps_nsp } diff --git a/fixbikenet/functions.py b/fixbikenet/functions.py index 8e67db0..367dc20 100644 --- a/fixbikenet/functions.py +++ b/fixbikenet/functions.py @@ -388,6 +388,7 @@ def find_actual_gaps(G, potential_gaps, mingap): found_gaps = [] found_gaps_nsp = [] + found_gaps_name = [] for u, v in tqdm( potential_gaps, @@ -420,8 +421,9 @@ def find_actual_gaps(G, potential_gaps, mingap): if valid and nx.shortest_path_length(G, u, v, weight="length") >= mingap: found_gaps.append((u, v)) found_gaps_nsp.append(nodelist) + found_gaps_name.append(G[nodelist[0]][nodelist[1]]["name"]) - return found_gaps, found_gaps_nsp + return found_gaps, found_gaps_nsp, found_gaps_name def compute_local_betweenness_centrality(G, nodes_gdf, radius): """ @@ -671,6 +673,8 @@ def gap_declustering(gaps_df, G, ebc, contact_nodes): result: pd.DataFrame Dataframe with node path for gaps and the newly calculated benefit metric """ + print(gaps_df.head()) + print(gaps_df.loc[gaps_df['gap'] == (576734, 982458401), 'name'][0]) C = nx.Graph() C.graph.update(G.graph) gap_edges = set() @@ -698,6 +702,7 @@ def gap_declustering(gaps_df, G, ebc, contact_nodes): ] selected_paths = [] selected_scores = [] + selected_names = [] for comp in tqdm( components, @@ -744,6 +749,10 @@ def gap_declustering(gaps_df, G, ebc, contact_nodes): # Store selected gap selected_paths.append(best_path) selected_scores.append(best_score) + try: + selected_names.append(gaps_df.loc[gaps_df['gap'] == (best_path[0], best_path[-1]), 'name'].values[0]) + except: + selected_names.append("n/a") # Remove selected path edge_path = list( @@ -757,6 +766,7 @@ def gap_declustering(gaps_df, G, ebc, contact_nodes): { "path": selected_paths, "benefit": selected_scores, + "name": selected_names } ) return result From cf020af6e4f85bf8bf04d44b1d93c03e3a8de7fc Mon Sep 17 00:00:00 2001 From: Michael Szell Date: Thu, 3 Sep 2026 17:27:26 +0200 Subject: [PATCH 2/2] Fix gap naming --- fixbikenet/fixbikenet.py | 3 +-- fixbikenet/functions.py | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/fixbikenet/fixbikenet.py b/fixbikenet/fixbikenet.py index 4127483..9957dda 100644 --- a/fixbikenet/fixbikenet.py +++ b/fixbikenet/fixbikenet.py @@ -161,7 +161,7 @@ def fixbikenet( potential_gaps = find_potential_gaps(contact_nodes, nodes_gdf, maxgap) # add routing for gaps in network - found_gaps, found_gaps_nsp, found_gaps_name = find_actual_gaps(G, potential_gaps, mingap) + found_gaps, found_gaps_nsp = find_actual_gaps(G, potential_gaps, mingap) # calculating local betweenness score dependent on radius ebc = compute_local_betweenness_centrality(G, nodes_gdf, radius) @@ -171,7 +171,6 @@ def fixbikenet( df = pd.DataFrame( { "gap": found_gaps, - "name": found_gaps_name, "benefit": Bs, "nodelist": found_gaps_nsp } diff --git a/fixbikenet/functions.py b/fixbikenet/functions.py index 367dc20..306c218 100644 --- a/fixbikenet/functions.py +++ b/fixbikenet/functions.py @@ -388,7 +388,6 @@ def find_actual_gaps(G, potential_gaps, mingap): found_gaps = [] found_gaps_nsp = [] - found_gaps_name = [] for u, v in tqdm( potential_gaps, @@ -421,9 +420,8 @@ def find_actual_gaps(G, potential_gaps, mingap): if valid and nx.shortest_path_length(G, u, v, weight="length") >= mingap: found_gaps.append((u, v)) found_gaps_nsp.append(nodelist) - found_gaps_name.append(G[nodelist[0]][nodelist[1]]["name"]) - return found_gaps, found_gaps_nsp, found_gaps_name + return found_gaps, found_gaps_nsp def compute_local_betweenness_centrality(G, nodes_gdf, radius): """ @@ -673,8 +671,6 @@ def gap_declustering(gaps_df, G, ebc, contact_nodes): result: pd.DataFrame Dataframe with node path for gaps and the newly calculated benefit metric """ - print(gaps_df.head()) - print(gaps_df.loc[gaps_df['gap'] == (576734, 982458401), 'name'][0]) C = nx.Graph() C.graph.update(G.graph) gap_edges = set() @@ -746,13 +742,23 @@ def gap_declustering(gaps_df, G, ebc, contact_nodes): best_path = path if best_path is None: break + # Store selected gap selected_paths.append(best_path) selected_scores.append(best_score) - try: - selected_names.append(gaps_df.loc[gaps_df['gap'] == (best_path[0], best_path[-1]), 'name'].values[0]) - except: - selected_names.append("n/a") + + # Walk through edges until finding a name + name = "n/a" + for i in [-1]+list(range(len(best_path))): + try: + name = G[best_path[i]][best_path[i+1]]['name'] + except: + pass + if name != "" and name != "n/a": + break + if name == "": + name = "n/a" + selected_names.append(name) # Remove selected path edge_path = list(