Reputation: 5582
I'm using Networkx to build a dependency graph. For example I have this struct.
A
+-B
+-C
+-H
AA
+-BB
+-CC
which I build easily with Networkx like that
G = nx.DiGraph()
G.add_edge(A,B)
G.add_edge(A,H)
G.add_edge(B,C)
G.add_edge(AA,BB)
G.add_edge(BB,)
(By the way I didn't know how I could set a root node so i have a root = set() where I have all my roots, in this case root=(A))
My question is how can I get the all hierarchy by specifying a node ? For example if I would do like:
G.successors[A]
It will give me
{A: {B: {C: {} }, H: {} }
But at the moment if I Do
G.successors[A]
It only gives me
{H:{} , B:{} }
Which is correct but where is the rest??? Also If a Do G.successors[B] it returns me
{C:{}}
Which is correct but why don't he put it in when I do G.successors[A] ?
And an other question. Is it possible with Networksx to get the "Path" from a node to another ? For example?
[A,H] or [A,B,C]
Thank you
Upvotes: 0
Views: 710
Reputation: 1862
http://networkx.lanl.gov/reference/algorithms.traversal.html
print nx.dfs_successors(G,'A')
>> {A: [H,B], B:[C]}
I don't how to generate the structure you gave in example though..
Upvotes: 1