Contracting all paths through components of hidden vertices


I am currently filtering a graph. Sometimes hiding the vertices splits the original graph into separate components. Is there an elegant solution to avoid this? Essentially I would like to contract all paths through a component of hidden vertices into a single edge. I have found a solution that works, but it is incredibly slow:

1. Creating a GraphView with only the hidden vertices and label the components in this GraphView
2. For each of the hidden components loop over all vertices in the component and look for vertices that have a different in-degree or out-degree in the hidden GraphView and the original unfiltered graph
3. For each vertex 'I' with a different in-degree label the out-component and check which vertex 'O' with a different out-degree is part of the out-component of 'I'
4. Create an edge between all the in-neighbors of 'I' and all out-neighbors of 'O'

The result is correct, all the vertices that are connected by a path through these hidden components are now connected by a single edge in the filtered graph, but the process is painfully slow on graphs with 600k-5M vertices.

attachment.html (1.55 KB)