File size: 2,465 Bytes
40d7073
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
 * Graph Algorithms - MinCut, Spectral Clustering, Community Detection
 *
 * Provides graph partitioning and clustering algorithms for:
 * - Code module detection
 * - Dependency clustering
 * - Architecture analysis
 * - Refactoring suggestions
 */
export interface Graph {
    nodes: string[];
    edges: Array<{
        from: string;
        to: string;
        weight?: number;
    }>;
    adjacency: Map<string, Map<string, number>>;
}
export interface Partition {
    groups: string[][];
    cutWeight: number;
    modularity: number;
}
export interface SpectralResult {
    clusters: Map<string, number>;
    eigenvalues: number[];
    coordinates: Map<string, number[]>;
}
/**
 * Build adjacency representation from edges
 */
export declare function buildGraph(nodes: string[], edges: Array<{
    from: string;
    to: string;
    weight?: number;
}>): Graph;
/**
 * Minimum Cut (Stoer-Wagner algorithm)
 *
 * Finds the minimum weight cut that partitions the graph into two parts.
 * Useful for finding loosely coupled module boundaries.
 */
export declare function minCut(graph: Graph): Partition;
/**
 * Spectral Clustering (using power iteration)
 *
 * Uses graph Laplacian eigenvectors for clustering.
 * Good for finding natural clusters in code dependencies.
 */
export declare function spectralClustering(graph: Graph, k?: number): SpectralResult;
/**
 * Louvain Community Detection
 *
 * Greedy modularity optimization for finding communities.
 * Good for detecting natural module boundaries.
 */
export declare function louvainCommunities(graph: Graph): Map<string, number>;
/**
 * Calculate modularity of a partition
 */
export declare function calculateModularity(graph: Graph, partition: string[][]): number;
/**
 * Find bridges (edges whose removal disconnects components)
 */
export declare function findBridges(graph: Graph): Array<{
    from: string;
    to: string;
}>;
/**
 * Find articulation points (nodes whose removal disconnects components)
 */
export declare function findArticulationPoints(graph: Graph): string[];
declare const _default: {
    buildGraph: typeof buildGraph;
    minCut: typeof minCut;
    spectralClustering: typeof spectralClustering;
    louvainCommunities: typeof louvainCommunities;
    calculateModularity: typeof calculateModularity;
    findBridges: typeof findBridges;
    findArticulationPoints: typeof findArticulationPoints;
};
export default _default;
//# sourceMappingURL=graph-algorithms.d.ts.map