Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a sub-graph from one node in NetworkX

Context

This is the first time I have to work with NetworkX so either I can't read correctly the documentation, or I simply do not use the right vocabulary.

Problem

I am working with a DiGraph, and I want to get a list of every nodes accessible starting from a specified node.

I thought of making a sub-graph containing the nodes I just described, and I would siply have to iterate over that specific sub-graph. Unfortunately, I didn't find a way to create automatically a sub-graph with the condition I mentioned.

It feels like an obvious feature. What am I missing ?

like image 574
superpg Avatar asked Jun 05 '18 10:06

superpg


1 Answers

You are looking for the nx.descendants method:

descendants(G, source)

Return all nodes reachable from (source) in G.

Parameters : G : NetworkX DiGraph

source : node in G

Returns : des : set()

The descendants of source in G

like image 143
hilberts_drinking_problem Avatar answered Nov 07 '22 14:11

hilberts_drinking_problem