From 6b46c78bcff78117fbfdef7f4a9f9f21315a4c94 Mon Sep 17 00:00:00 2001 From: Tomasini Luca Date: Mon, 20 Jan 2025 09:21:45 +0100 Subject: [PATCH] Add get_all_edge_data 2 --- src/networkx_function.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/networkx_function.py b/src/networkx_function.py index b7b88de..c3e2a0e 100644 --- a/src/networkx_function.py +++ b/src/networkx_function.py @@ -246,3 +246,27 @@ def generate_and_connect_segment_from_linestring_list(linestring_list: list[Line ) segment_list.append(LineString(new_segment_points)) return segment_list + +def generate_bfs_tree_with_edge_data(graph: nx.Graph, source): + """ + Create a BFS tree from a graph while retaining edge data. + + Parameters: + graph (nx.Graph): The input graph. + source (node): The starting node for BFS. + + Returns: + nx.DiGraph: A directed BFS tree with edge data preserved. + """ + # Create an empty directed graph for the BFS tree + bfs_tree = nx.DiGraph() + + # Add nodes to the BFS tree + + # Add edges to the BFS tree with preserved edge data + for u, v in nx.bfs_edges(graph, source): + + edge_data = graph.get_edge_data(u, v) + bfs_tree.add_edge(u, v, **edge_data) + + return bfs_tree \ No newline at end of file