iduedu.keep_largest_strongly_connected_component

iduedu.keep_largest_strongly_connected_component(graph, *, top_k_wcc_sizes=5)[source]

Keep only the largest strongly connected component of a directed graph.

Logs the sizes of weakly connected components (WCC) for visibility, then removes all nodes outside the largest strongly connected component (SCC) and returns the pruned copy.

Parameters:
  • graph (nx.DiGraph) – Directed graph to prune (a copy is made).

  • top_k_wcc_sizes (int) – How many largest WCC sizes to show in the warning.

Returns:

Graph restricted to the largest SCC.

Return type:

(nx.DiGraph)

Notes

  • Uses nx.weakly_connected_components for a quick disconnectedness summary.

  • Nodes from all SCCs except the largest are removed.