pub fn condensation<G>(graph: &G) -> CondensedGraphExpand description
Condenses a directed graph into its SCC DAG.
Each strongly connected component (SCC) is collapsed into a single super-node. The resulting graph is always a DAG — any cycle that existed in the original graph is now internal to a single super-node.
Uses tarjan_scc() internally to compute the SCCs.
§Returns
A CondensedGraph where:
components[i]lists the original nodes that form super-nodei.edges[i]lists which super-nodes super-nodeihas edges to.
§Complexity
O(V + E) — dominated by the SCC computation.
§Examples
use graph_core::{AdjacencyList, Graph};
use graph_advanced::condensation;
// 0 ↔ 1 (one SCC), 2 is a singleton, edge 0→2.
let mut g: AdjacencyList<()> = AdjacencyList::directed();
let n: Vec<_> = (0..3).map(|_| g.add_node(())).collect();
g.add_edge(n[0], n[1], 1.0).unwrap();
g.add_edge(n[1], n[0], 1.0).unwrap();
g.add_edge(n[0], n[2], 1.0).unwrap();
let cg = condensation(&g);
assert_eq!(cg.node_count(), 2); // two SCCs
// There must be exactly one inter-SCC edge.
let total_edges: usize = cg.edges.iter().map(|e| e.len()).sum();
assert_eq!(total_edges, 1);