Skip to content

dfs_/bfs_predecessors does not work correctly for DiGraphs (migrated from Trac #724) #710

Closed

Description

@networkx-trac

Original ticket https://networkx.lanl.gov/trac/ticket/724
Reported 2012-05-11 by teemu.rytkonen, assigned to @hagberg.

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.

Activity

  1. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Attachment in Trac by teemu.rytkonen, 2012-05-11: predecessor_fix.diff

  2. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    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?

  3. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @hagberg, 2012-05-26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions