dgl.traversal.bfs_nodes_generator

dgl.traversal.bfs_nodes_generator(graph, source, reversed=False)[source]

Node frontiers generator using breadth-first search.

Parameters:
  • graph (DGLGraph) – The graph object.
  • source (list, tensor of nodes) – Source nodes.
  • reversed (bool, default False) – If True, traverse following the in-edge direction.
Returns:

Each node frontier is a list or tensor of node ids.

Return type:

list of node frontiers

Examples

Given a graph (directed, edges from small node id to large):

      2 - 4
     / \
0 - 1 - 3 - 5
>>> g = dgl.DGLGraph([(0, 1), (1, 2), (1, 3), (2, 3), (2, 4), (3, 5)])
>>> list(dgl.bfs_nodes_generator(g, 0))
[tensor([0]), tensor([1]), tensor([2, 3]), tensor([4, 5])]