/** * Graph Coloring, Cliques, Community Detection, Katz Centrality, Isomorphism * * Complements the existing traversal/shortest-path/centrality/optimization * graph functions (`typed/graph.ts`, `graph/traversal-centrality.ts`, * `graph/optimization.ts`) with: * * - `graphColoring`: greedy proper vertex coloring (Welsh-Powell: largest * degree first). * - `maxClique`: a maximum clique via Bron-Kerbosch with pivoting. * - `louvainCommunities`: Louvain modularity community detection. * - `katzCentrality`: Katz centrality (matches `networkx.katz_centrality_numpy`). * - `isIsomorphic`: graph isomorphism test via backtracking with * degree-sequence pruning. * * Input format: adjacency matrix as `number[][]`, matching the convention * used elsewhere in this directory. Structural functions (`graphColoring`, * `maxClique`, `isIsomorphic`) treat any finite, nonzero `adj[i][j]` as an * edge; `graphColoring`/`maxClique` read the graph as undirected (an edge * i-j exists if either `adj[i][j]` or `adj[j][i]` is a finite nonzero * value), while `isIsomorphic` reads directed (matching the bfs/dfs/ * floydWarshall convention — pass a symmetric matrix for undirected graphs). * `louvainCommunities`/`katzCentrality` treat `adj[i][j]` as an edge weight * (0 = no edge) and require a symmetric (undirected) matrix. * * @packageDocumentation */ /** * Greedy proper vertex coloring using the Welsh-Powell heuristic: vertices * are processed in descending order of (undirected) degree, each assigned * the smallest color index not already used by an already-colored neighbor. * Ties in degree are broken by ascending vertex index (deterministic). * * Not guaranteed to use the chromatic number of colors (graph coloring is * NP-hard in general) — this is a fast heuristic upper bound, but the * result is always a *proper* coloring (no edge connects two same-colored * vertices). * * @param adj - Adjacency matrix (undirected reading: `adj[i][j]` or * `adj[j][i]` nonzero means an edge) * @returns Color index (0-based) for each vertex, length = n * * @example * const adj = [[0,1,1],[1,0,1],[1,1,0]]; // triangle K3 * graphColoring(adj) // => [0, 1, 2] (needs 3 colors) */ export declare function graphColoring(adj: number[][]): number[]; /** * Find a maximum clique (largest set of mutually adjacent vertices) via the * Bron-Kerbosch algorithm with pivoting, exploring all maximal cliques and * keeping the largest. Exact (not a heuristic), but exponential worst-case — * intended for small-to-moderate graphs. * * @param adj - Adjacency matrix (undirected reading) * @returns Vertex indices of a maximum clique, ascending order * * @example * // triangle 0-1-2 plus a pendant 3 attached only to 0 * const adj = [[0,1,1,1],[1,0,1,0],[1,1,0,0],[1,0,0,0]]; * maxClique(adj) // => [0, 1, 2] */ export declare function maxClique(adj: number[][]): number[]; /** * Louvain modularity-maximization community detection. * * Alternates a local-moving phase (greedily move each node into the * neighboring community that most increases modularity, deterministic * tie-break per `_louvainLocalMoving`) with an aggregation phase (collapse * each found community into a super-node) until a local-moving pass leaves * every node in its own singleton community (no further merge possible). * * Heuristic and **not** guaranteed to find the globally optimal partition, * but deterministic — no random seed is used, so the same graph always * produces the same partition. * * @param adj - Weighted undirected adjacency matrix (symmetric; `adj[i][j]` * = edge weight, 0 = no edge) * @returns Partition as an array of vertex-index groups (every vertex * appears in exactly one group) * * @example * // Two triangles 0-1-2 and 3-4-5 joined by a single bridge edge 2-3 * louvainCommunities(adj) // => [[0,1,2],[3,4,5]] (two communities) */ export declare function louvainCommunities(adj: number[][]): number[][]; /** * Katz centrality: `x = alpha * A^T * x + beta`, solved directly via * `x = (I - alpha*A^T)^-1 * (beta * 1)`, then normalized so * `sign(sum(x)) * ||x||_2 = 1` — matching `networkx.katz_centrality_numpy`'s * convention exactly (including its "use A^T so directed graphs measure * in-edges" default). For an undirected (symmetric) `adj`, `A^T = A`. * * `alpha` must be strictly less than `1 / λ_max(A)` (the reciprocal of the * adjacency matrix's largest eigenvalue) for the system to be well-posed; * an ill-conditioned/singular system throws. * * @param adj - Adjacency matrix (directed reading; weighted or unweighted) * @param alpha - Attenuation factor (must satisfy `alpha < 1/λ_max`) * @param beta - Constant added at every node (default 1) * @returns L2-normalized Katz centrality score per vertex * * @example * const adj = [[0,1,1],[1,0,1],[1,1,0]]; // triangle K3 * katzCentrality(adj, 0.1) // all three equal (symmetric graph) */ export declare function katzCentrality(adj: number[][], alpha: number, beta?: number): number[]; /** * Test whether two graphs are isomorphic: does there exist a bijection * `f` between their vertices such that `i -> j` is an edge in `graphA` iff * `f(i) -> f(j)` is an edge in `graphB`? * * Sound and complete backtracking search (not a heuristic): a quick reject * compares sorted (out-degree, in-degree) sequences, then a permutation * search builds the bijection incrementally, checking edge-consistency * against every previously-mapped vertex at each step. Exponential * worst-case (graph isomorphism has no known polynomial algorithm in * general) — intended for small-to-moderate graphs. * * @param graphA - Adjacency matrix (directed reading) * @param graphB - Adjacency matrix (directed reading) * @returns Whether the two graphs are isomorphic * * @example * const k3 = [[0,1,1],[1,0,1],[1,1,0]]; * const c3 = [[0,1,1],[1,0,1],[1,1,0]]; // C3 === K3 for n=3 * isIsomorphic(k3, c3) // => true */ export declare function isIsomorphic(graphA: number[][], graphB: number[][]): boolean; //# sourceMappingURL=community-coloring.d.ts.map