/** * Graph Traversal, All-Pairs Shortest Paths, and Distance-Based Centrality * * Complements the existing single-source Dijkstra `shortestPath` / * `graphDistance` (see `../typed/graph.ts`) with: * * - `bfs` / `dfs`: visitation-order traversal (directed reading; neighbors * visited in ascending index order). * - `floydWarshall`: all-pairs shortest-path distances (handles negative * edge weights, not negative cycles). * - `bellmanFord`: single-source shortest paths, negative-weight-aware, * with negative-cycle detection. * - `closenessCentrality` / `harmonicCentrality`: distance-based centrality * measures (networkx-compatible conventions), built on `floydWarshall`. * * Input format: adjacency matrix as `number[][]` where `adj[i][j]` is the * weight of the directed edge i -> j. Both `Infinity` and `0` (off the * diagonal) are treated as "no edge" by the weighted routines * (`floydWarshall`, `bellmanFord`, and the centrality functions). `bfs`/`dfs` * instead treat any finite, nonzero off-diagonal entry as an edge. Graphs * are read as directed (adjacency is never symmetrized). * * @packageDocumentation */ /** * Breadth-first traversal order starting from `start`. * * A directed edge i -> j exists when `adj[i][j]` is finite and nonzero. * Neighbors are visited in ascending index order. * * @param adj - Adjacency matrix (directed reading; not symmetrized) * @param start - Source node index * @returns Node indices in BFS visitation order * * @example * const adj = [[0,1,Infinity],[1,0,1],[Infinity,1,0]]; * bfs(adj, 0) // => [0, 1, 2] */ export declare function bfs(adj: number[][], start: number): number[]; /** * Depth-first traversal order starting from `start` (iterative, preserves * ascending-neighbor-order visitation as if implemented recursively). * * A directed edge i -> j exists when `adj[i][j]` is finite and nonzero. * * @param adj - Adjacency matrix (directed reading; not symmetrized) * @param start - Source node index * @returns Node indices in DFS visitation order * * @example * const adj = [[0,1,Infinity],[1,0,1],[Infinity,1,0]]; * dfs(adj, 0) // => [0, 1, 2] */ export declare function dfs(adj: number[][], start: number): number[]; /** * All-pairs shortest-path distances via the Floyd-Warshall algorithm. * * `d[i][j]` = 0 if i === j, else `adj[i][j]` when it is a finite nonzero * edge, else `Infinity`. Handles negative edge weights. A negative value * remaining on the diagonal after the triple loop indicates a negative * cycle reachable through that node (not flagged by this function — use * `bellmanFord` for explicit negative-cycle detection). * * Time complexity: O(V^3). * * @param adj - Adjacency matrix (directed reading) * @returns n x n matrix of shortest-path distances * * @example * const adj = [[0,1,Infinity],[1,0,1],[Infinity,1,0]]; * floydWarshall(adj)[0][2] // => 2 */ export declare function floydWarshall(adj: number[][]): number[][]; /** Result of `bellmanFord`. */ export interface BellmanFordResult { /** Shortest-path distance from source to each node (Infinity if unreachable). */ dist: number[]; /** True if a negative-weight cycle is reachable from the source. */ hasNegativeCycle: boolean; } /** * Single-source shortest paths via the Bellman-Ford algorithm. * * Handles negative edge weights and detects a negative-weight cycle * reachable from `source`: relaxes all edges |V|-1 times, then performs one * additional pass — any edge that can still be relaxed indicates a * reachable negative cycle. * * Time complexity: O(V*E) (O(V^3) on a dense adjacency matrix). * * @param adj - Adjacency matrix (directed reading) * @param source - Source node index * @returns `{ dist, hasNegativeCycle }` * * @example * const adj = [[0,1,Infinity],[1,0,1],[Infinity,1,0]]; * bellmanFord(adj, 0) // => { dist: [0, 1, 2], hasNegativeCycle: false } */ export declare function bellmanFord(adj: number[][], source: number): BellmanFordResult; /** * Closeness centrality for each node, using the networkx (Wasserman & * Faust) convention for possibly-disconnected graphs: * * `C(u) = ((r-1)/(n-1)) * ((r-1)/sum(d))` * * where `r` is the number of nodes that can reach `u` (including `u`) and * `sum(d)` is the sum of shortest-path distances from those nodes to `u`. * For a graph where every node reaches all others (`r === n`), this reduces * to `(n-1)/sum(d)`. Isolated nodes (`r === 1`) score 0. * * **Direction note (matches networkx default):** closeness uses the * *incoming* distance to `u` for directed graphs — how reachable `u` is * *from* the rest of the graph, not how far `u` can reach. This mirrors * `networkx.closeness_centrality`'s documented default ("the closeness * distance function computes the incoming distance to u for directed * graphs"). For undirected graphs (symmetric `adj`) direction is moot. * * @param adj - Adjacency matrix (directed reading) * @returns Closeness centrality score for each node (length = n) * * @example * const adj = [[0,1,Infinity],[1,0,1],[Infinity,1,0]]; * closenessCentrality(adj) // middle node scores highest */ export declare function closenessCentrality(adj: number[][]): number[]; /** * Harmonic centrality for each node: * * `H(u) = sum_{v != u} 1/d(v,u)` * * Unreachable nodes contribute 0 (1/Infinity), so this remains well-defined * for disconnected graphs without normalization. * * **Direction note (matches networkx default):** like closeness, harmonic * centrality sums *incoming* distances (`d(v,u)`, from other nodes to `u`), * matching `networkx.harmonic_centrality`'s directed-graph default. For * undirected graphs (symmetric `adj`) direction is moot. * * @param adj - Adjacency matrix (directed reading) * @returns Harmonic centrality score for each node (length = n) * * @example * const adj = [[0,1,Infinity],[1,0,1],[Infinity,1,0]]; * harmonicCentrality(adj) // => [1.5, 2, 1.5] (middle node reaches both neighbors at distance 1) */ export declare function harmonicCentrality(adj: number[][]): number[]; //# sourceMappingURL=traversal-centrality.d.ts.map