UNPKG

@graphty/algorithms

Version:

Graph algorithms library for browser environments implemented in TypeScript

68 lines 2.29 kB
import type { Graph } from "../../core/graph.js"; import type { NodeId } from "../../types/index.js"; /** * Closeness centrality implementation * * Measures how close a node is to all other nodes in the graph. * Uses BFS to compute shortest path distances efficiently. */ /** * Closeness centrality options */ export interface ClosenessCentralityOptions { /** * Whether to normalize the centrality values (default: false) */ normalized?: boolean; /** * Use harmonic mean instead of reciprocal of sum (default: false) * Better for disconnected graphs */ harmonic?: boolean; /** * Consider only nodes within this distance (default: undefined = all nodes) */ cutoff?: number; /** * Whether to use optimized BFS implementation for large graphs */ optimized?: boolean; } /** * Calculate closeness centrality for all nodes in the graph * * Closeness centrality measures how close a node is to all other nodes * in the graph. It is the reciprocal of the sum of the shortest path * distances to all other reachable nodes. * * @param graph - The input graph * @param options - Algorithm options * @returns Centrality scores for each node * * @example * ```typescript * const graph = new Graph(); * graph.addEdge("A", "B"); * graph.addEdge("B", "C"); * * const centrality = closenessCentrality(graph); * // { A: 0.5, B: 1.0, C: 0.5 } * ``` * * Time Complexity: O(V * (V + E)) for unweighted graphs * Space Complexity: O(V) */ export declare function closenessCentrality(graph: Graph, options?: ClosenessCentralityOptions): Record<string, number>; /** * Calculate closeness centrality for a specific node */ export declare function nodeClosenessCentrality(graph: Graph, node: NodeId, options?: ClosenessCentralityOptions): number; /** * Calculate weighted closeness centrality using Dijkstra's algorithm */ export declare function weightedClosenessCentrality(graph: Graph, options?: ClosenessCentralityOptions): Record<string, number>; /** * Calculate weighted closeness centrality for a specific node using Dijkstra */ export declare function nodeWeightedClosenessCentrality(graph: Graph, node: NodeId, options?: ClosenessCentralityOptions): number; //# sourceMappingURL=closeness.d.ts.map