Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Algorithm to get IN and OUT component of a directed graph #4969

Closed
wants to merge 3 commits into from

Conversation

salfaris
Copy link

@salfaris salfaris commented Jul 9, 2021

I have added functions to extract the IN and OUT components of a directed graph (that contains a strongly connected component) using a simple random-start BFS. The IN and OUT components are those as described in this paper by Broder et al.

This is my first PR in NetworkX, so I apologize beforehand if my code is badly written. In particular, I was having a lot of thoughts on how to properly refactor the in_component and out_component as their code content share a lot of similar lines. I look forward to hearing from the community on how to do this correctly as I am here to learn.

Some future work that I am considering are:

  1. Add more tests.
  2. Algorithm to compute TENDRILS and TUBE (refer to Broder et al.).
  3. Uniting these components under a single Bow-tie diagram (defined by these IN, OUT, TENDRILS, TUBE components) function.

Copy link
Contributor

@rossbar rossbar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be misunderstanding something, so please correct me where I'm wrong!

From the paper, the definition of the IN component is "the set of nodes that can reach the SCC but can't be reached by it". This sounds like it's directly translatable to NX without the need for extra machinery like random and bfs. For example, assuming you have a DiGraph G and a set of nodes scc corresponding to the strongly-connected component of interest:

>>> others = G.nodes() - scc
>>> in_component = frozenset(
...     u for u in others if set(G.successors(u)) & scc and not
...     set(G.predecessors(u)) & scc
... )

Out-component then follows the same pattern, but with predecessors and successors switched.

Assuming I've understood correctly, I would argue that it's straightforward to construct the in and out components this way and so adding dedicated functions to do so would be unnecessary.

@rossbar
Copy link
Contributor

rossbar commented Mar 5, 2024

This one has been stale for quite awhile so I will go ahead and close it. @salfaris if you're interested in picking this up again, please feel free to do so - the last comment re: a (proposed) simpler way of producing the components would be a good starting point to re-kindle the discussion!

@rossbar rossbar closed this Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants