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
{{ message }}
Repository navigation
dfs_/bfs_predecessors does not work correctly for DiGraphs (migrated from Trac #724) #710
To me it would seem that the predecessor search methods do not work correctly for directed graphs, because the algorithm always traverses the dfs_edges or bfs_edges from the successors dictionary.
I attach here a patch with tests and a fix proposal that to me is the problem and a fix for that problem.
The traversals use the successors so in a directed graph you only follow the out edges.
This creates a directed tree.
The result that is returned by dfs_predeccessors and bfs_predecessors is a dictionary with the tree nodes as keys and predecessors of the tree nodes as values.
e.g.
'''
In [1]: import networkx as nx
In [2]: G=nx.Graph()
In [3]: G=nx.DiGraph()
In [4]: G.add_edge(1,2)
In [5]: G.add_edge(2,3)
In [6]: nx.bfs_predecessors(G,1)
Out[6]: {2: 1, 3: 2}
'''
Activity
networkx-trac commentedon Jul 20, 2012
Attachment in Trac by teemu.rytkonen, 2012-05-11: predecessor_fix.diff
networkx-trac commentedon Jul 20, 2012
Comment in Trac by @hagberg, 2012-05-11
The traversals use the successors so in a directed graph you only follow the out edges.
This creates a directed tree.
The result that is returned by dfs_predeccessors and bfs_predecessors is a dictionary with the tree nodes as keys and predecessors of the tree nodes as values.
e.g.
'''
In [1]: import networkx as nx
In [2]: G=nx.Graph()
In [3]: G=nx.DiGraph()
In [4]: G.add_edge(1,2)
In [5]: G.add_edge(2,3)
In [6]: nx.bfs_predecessors(G,1)
Out[6]: {2: 1, 3: 2}
'''
Is there still a bug there?
networkx-trac commentedon Jul 20, 2012
Comment in Trac by @hagberg, 2012-05-26
Reorganized flow functions following the discussion of #710