Hi,

I need to find a way to label all reachable nodes in a directed graph starting 
at a specific node. Is there a short way to do this?

Currently I use this:

```
graph = get_graph()
is_reachable = graph.new_vp("bool")
start_vertex = get_start_vertex()

tc = gt.transitive_closure(graph)
is_reachable[start_vertex] = True
for node in tc.vertex(start_vertex).out_neighbors():
    is_reachable[graph.vertex(node)] = True
```

This works, but seems quite inefficient, since I don't need the full transitive 
closure (although I have multiple such start vertexes).
Another possibility should be a raw DFS but this needs far more LOC, since it 
needs to stop when it backtracks and therefore needs a custom visitor.

Gerion

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
graph-tool mailing list
graph-tool@skewed.de
https://lists.skewed.de/mailman/listinfo/graph-tool

Reply via email to