I am trying to split a directed (acyclic) graph into direction-connected path, relying on connectivity :
When I test weak and strong connectivity subgraphs, here is what I get :
Weak connectivity :
['16', '17'], ['3', '41', '39', '42']
Strong connectivity :
['17'], ['16'], ['39'], ['41'], ['3'], ['42']
I understand the weak connectivity result, but not the strong-connectivity one, as I would expect 3 subgraphs : [16, 17], [42, 39] and [3, 41, 39].
What am I missing here, why those single node lists ? How to get the expected result ?
Here is the code :
import networkx as nx
import matplotlib.pyplot as plt
G = nx.DiGraph()
G.add_edges_from([('16', '17'), ('3', '41'), ('41', '39'), ('42', '39')])
print("Weak connectivity : ")
for subgraph in (G.subgraph(c).copy() for c in nx.weakly_connected_components(G)) :
print(subgraph.nodes)
print("Strong connectivity : ")
for subgraph in (G.subgraph(c).copy() for c in nx.strongly_connected_components(G)) :
print(subgraph.nodes)
nx.draw_networkx(G, pos=nx.circular_layout(G))
plt.show()