I don't know if this is a weird question. Like in the title, is there a way to find semi-connected( unilaterally connected ) components in a directed graph with networkX? I do read the document of networkX but it just has is_semiconnected to check if a di-graph is connected or not, i don't see any other option( am I missing anything?). What I want is something like nx.connected_components. For example I have a graph like this :
I want the result to be : [A,B,C], [A,E,F], [X] and [Y]. The output data should be in the order, because in my case, A->B mean A happen before B,B->C mean B happen before C, so I want to keep the order as it is in the graph. Is there a way to do this? If a node is not connected to any other node, it should be considered semi-connected too( for my case that i'm working ). Like in the example, if I have another standalone node called X, then X should be in the final answer too. I know this is kinda weird for directed graph, but need it for my data and output. It's like finding maximal semi-connected components.
Also i can make sure that my graph won't have cycles in it.
Here is a bruteforce function which will yield all maximally semiconnected subgraphs.
This uses a function
maximal_subsets(seq, pred)to yield all maximal subsets of a sequenceseqfor a predicatepred.You can find an explanation for that function in an answer to this related question:
Testing: