You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Networkx does not compute the connected components for directed graphs. The connected component problem with (multi)digraphs can be solved by
(1) creating first an undirected graph,
(2) getting the components, then
(3) creating digraphs from the edgelist of the undirected components.
Directed graph from the largest connected component (python):
ug = nx.Graph()
ug.add_edges_from(edgetable) # undirected global graph; edgetable is just a list of A->B, A->C, C->D etc.
# largest connected component
if nx.number_connected_components(ug)>1:
lcug = nx.connected_component_subgraphs(ug)[0]
else:
lcug = ug
del ug
dg = nx.DiGraph()
dg.add_edges_from(lcug.edges()) # directed global graph from the largest connected component
IMPORTANT NOTE: G.to_directed() creates edges A->B, B->A from A-B! Don't use it if you want the undirected and directed components to be similar (only difference is the directedness).
G.subgraph() operations could work, but are slower compared to the above solution.
The text was updated successfully, but these errors were encountered:
Networkx does not compute the connected components for directed graphs. The connected component problem with (multi)digraphs can be solved by
(1) creating first an undirected graph,
(2) getting the components, then
(3) creating digraphs from the edgelist of the undirected components.
Directed graph from the largest connected component (python):
IMPORTANT NOTE: G.to_directed() creates edges A->B, B->A from A-B! Don't use it if you want the undirected and directed components to be similar (only difference is the directedness).
G.subgraph() operations could work, but are slower compared to the above solution.
The text was updated successfully, but these errors were encountered: