Search code examples
pythongraphnetworkxdepth-first-searchmicrosoft-distributed-file-system

Does networkx support dfs traversal by label


The networkx dfs_edges() function will iterate over child nodes. As far as I can tell, the http://networkx.lanl.gov/ documentation does not specify a parameter into dfs_edges() to only traverse if edges have a specific label.

Also, I looked at dfs_labeled_edges() but that only tells you the traversal direction while iterating over a graph with DFS.


Solution

  • I have an approach which is working for me. Thanks @Aric for the inspiration.

    It is at https://github.com/namoopsoo/networkx/blob/master/networkx/algorithms/traversal/depth_first_search.py

    It is a new function called dfs_edges_by_label() . And given a label as an input, it only traverses edges matching the label.