@graphty/algorithms 1.1.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +820 -235
- package/dist/algorithms.d.ts +42 -2
- package/dist/algorithms.js +11099 -2
- package/dist/algorithms.js.map +1 -1
- package/dist/src/algorithms/centrality/betweenness.d.ts +4 -0
- package/dist/src/algorithms/centrality/betweenness.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/betweenness.js +124 -170
- package/dist/src/algorithms/centrality/betweenness.js.map +1 -1
- package/dist/src/algorithms/centrality/closeness.d.ts +26 -1
- package/dist/src/algorithms/centrality/closeness.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/closeness.js +56 -149
- package/dist/src/algorithms/centrality/closeness.js.map +1 -1
- package/dist/src/algorithms/centrality/degree.js +3 -3
- package/dist/src/algorithms/centrality/degree.js.map +1 -1
- package/dist/src/algorithms/centrality/delta-pagerank-simple.d.ts +39 -0
- package/dist/src/algorithms/centrality/delta-pagerank-simple.d.ts.map +1 -0
- package/dist/src/algorithms/centrality/delta-pagerank-simple.js +286 -0
- package/dist/src/algorithms/centrality/delta-pagerank-simple.js.map +1 -0
- package/dist/src/algorithms/centrality/delta-pagerank.d.ts +80 -0
- package/dist/src/algorithms/centrality/delta-pagerank.d.ts.map +1 -0
- package/dist/src/algorithms/centrality/delta-pagerank.js +294 -0
- package/dist/src/algorithms/centrality/delta-pagerank.js.map +1 -0
- package/dist/src/algorithms/centrality/index.d.ts +2 -0
- package/dist/src/algorithms/centrality/index.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/index.js +1 -0
- package/dist/src/algorithms/centrality/index.js.map +1 -1
- package/dist/src/algorithms/centrality/pagerank.d.ts +17 -0
- package/dist/src/algorithms/centrality/pagerank.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/pagerank.js +45 -0
- package/dist/src/algorithms/centrality/pagerank.js.map +1 -1
- package/dist/src/algorithms/community/girvan-newman.d.ts.map +1 -1
- package/dist/src/algorithms/community/girvan-newman.js +47 -54
- package/dist/src/algorithms/community/girvan-newman.js.map +1 -1
- package/dist/src/algorithms/community/index.d.ts +2 -0
- package/dist/src/algorithms/community/index.d.ts.map +1 -1
- package/dist/src/algorithms/community/index.js.map +1 -1
- package/dist/src/algorithms/community/label-propagation.d.ts +13 -3
- package/dist/src/algorithms/community/label-propagation.d.ts.map +1 -1
- package/dist/src/algorithms/community/label-propagation.js +50 -35
- package/dist/src/algorithms/community/label-propagation.js.map +1 -1
- package/dist/src/algorithms/community/leiden.d.ts +3 -2
- package/dist/src/algorithms/community/leiden.d.ts.map +1 -1
- package/dist/src/algorithms/community/leiden.js +34 -39
- package/dist/src/algorithms/community/leiden.js.map +1 -1
- package/dist/src/algorithms/community/louvain-optimized.d.ts +112 -0
- package/dist/src/algorithms/community/louvain-optimized.d.ts.map +1 -0
- package/dist/src/algorithms/community/louvain-optimized.js +303 -0
- package/dist/src/algorithms/community/louvain-optimized.js.map +1 -0
- package/dist/src/algorithms/community/louvain.d.ts.map +1 -1
- package/dist/src/algorithms/community/louvain.js +17 -76
- package/dist/src/algorithms/community/louvain.js.map +1 -1
- package/dist/src/algorithms/community/modularity-utils.d.ts +59 -0
- package/dist/src/algorithms/community/modularity-utils.d.ts.map +1 -0
- package/dist/src/algorithms/community/modularity-utils.js +112 -0
- package/dist/src/algorithms/community/modularity-utils.js.map +1 -0
- package/dist/src/algorithms/matching/bipartite.d.ts.map +1 -1
- package/dist/src/algorithms/matching/bipartite.js +8 -40
- package/dist/src/algorithms/matching/bipartite.js.map +1 -1
- package/dist/src/algorithms/shortest-path/bellman-ford.d.ts.map +1 -1
- package/dist/src/algorithms/shortest-path/bellman-ford.js +1 -12
- package/dist/src/algorithms/shortest-path/bellman-ford.js.map +1 -1
- package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.d.ts +37 -0
- package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.d.ts.map +1 -0
- package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.js +193 -0
- package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.js.map +1 -0
- package/dist/src/algorithms/shortest-path/dijkstra.d.ts +5 -2
- package/dist/src/algorithms/shortest-path/dijkstra.d.ts.map +1 -1
- package/dist/src/algorithms/shortest-path/dijkstra.js +15 -14
- package/dist/src/algorithms/shortest-path/dijkstra.js.map +1 -1
- package/dist/src/algorithms/traversal/bfs-unified.d.ts +29 -0
- package/dist/src/algorithms/traversal/bfs-unified.d.ts.map +1 -0
- package/dist/src/algorithms/traversal/bfs-unified.js +333 -0
- package/dist/src/algorithms/traversal/bfs-unified.js.map +1 -0
- package/dist/src/algorithms/traversal/bfs-variants.d.ts +54 -0
- package/dist/src/algorithms/traversal/bfs-variants.d.ts.map +1 -0
- package/dist/src/algorithms/traversal/bfs-variants.js +368 -0
- package/dist/src/algorithms/traversal/bfs-variants.js.map +1 -0
- package/dist/src/algorithms/traversal/bfs.d.ts +4 -18
- package/dist/src/algorithms/traversal/bfs.d.ts.map +1 -1
- package/dist/src/algorithms/traversal/bfs.js +5 -182
- package/dist/src/algorithms/traversal/bfs.js.map +1 -1
- package/dist/src/benchmark-all-algorithms.d.ts +23 -0
- package/dist/src/benchmark-all-algorithms.d.ts.map +1 -0
- package/dist/src/benchmark-all-algorithms.js +462 -0
- package/dist/src/benchmark-all-algorithms.js.map +1 -0
- package/dist/src/clustering/hierarchical.d.ts +16 -15
- package/dist/src/clustering/hierarchical.d.ts.map +1 -1
- package/dist/src/clustering/hierarchical.js +209 -223
- package/dist/src/clustering/hierarchical.js.map +1 -1
- package/dist/src/clustering/index.d.ts +4 -2
- package/dist/src/clustering/index.d.ts.map +1 -1
- package/dist/src/clustering/index.js +2 -2
- package/dist/src/clustering/index.js.map +1 -1
- package/dist/src/clustering/k-core.d.ts +16 -15
- package/dist/src/clustering/k-core.d.ts.map +1 -1
- package/dist/src/clustering/k-core.js +57 -21
- package/dist/src/clustering/k-core.js.map +1 -1
- package/dist/src/clustering/spectral.d.ts +8 -0
- package/dist/src/clustering/spectral.d.ts.map +1 -1
- package/dist/src/clustering/spectral.js +158 -35
- package/dist/src/clustering/spectral.js.map +1 -1
- package/dist/src/core/graph.js +4 -4
- package/dist/src/core/graph.js.map +1 -1
- package/dist/src/flow/ford-fulkerson.d.ts +17 -11
- package/dist/src/flow/ford-fulkerson.d.ts.map +1 -1
- package/dist/src/flow/ford-fulkerson.js +141 -217
- package/dist/src/flow/ford-fulkerson.js.map +1 -1
- package/dist/src/flow/min-cut.d.ts +6 -5
- package/dist/src/flow/min-cut.d.ts.map +1 -1
- package/dist/src/flow/min-cut.js +17 -8
- package/dist/src/flow/min-cut.js.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/link-prediction/adamic-adar.d.ts.map +1 -1
- package/dist/src/link-prediction/adamic-adar.js +17 -26
- package/dist/src/link-prediction/adamic-adar.js.map +1 -1
- package/dist/src/link-prediction/common-neighbors.d.ts.map +1 -1
- package/dist/src/link-prediction/common-neighbors.js +7 -11
- package/dist/src/link-prediction/common-neighbors.js.map +1 -1
- package/dist/src/optimized/bit-packed.d.ts +143 -0
- package/dist/src/optimized/bit-packed.d.ts.map +1 -0
- package/dist/src/optimized/bit-packed.js +292 -0
- package/dist/src/optimized/bit-packed.js.map +1 -0
- package/dist/src/optimized/csr-graph.d.ts +86 -0
- package/dist/src/optimized/csr-graph.d.ts.map +1 -0
- package/dist/src/optimized/csr-graph.js +341 -0
- package/dist/src/optimized/csr-graph.js.map +1 -0
- package/dist/src/optimized/direction-optimized-bfs.d.ts +74 -0
- package/dist/src/optimized/direction-optimized-bfs.d.ts.map +1 -0
- package/dist/src/optimized/direction-optimized-bfs.js +223 -0
- package/dist/src/optimized/direction-optimized-bfs.js.map +1 -0
- package/dist/src/optimized/graph-adapter.d.ts +62 -0
- package/dist/src/optimized/graph-adapter.d.ts.map +1 -0
- package/dist/src/optimized/graph-adapter.js +146 -0
- package/dist/src/optimized/graph-adapter.js.map +1 -0
- package/dist/src/optimized/index.d.ts +14 -0
- package/dist/src/optimized/index.d.ts.map +1 -0
- package/dist/src/optimized/index.js +28 -0
- package/dist/src/optimized/index.js.map +1 -0
- package/dist/src/research/grsbm.d.ts +83 -0
- package/dist/src/research/grsbm.d.ts.map +1 -0
- package/dist/src/research/grsbm.js +403 -0
- package/dist/src/research/grsbm.js.map +1 -0
- package/dist/src/research/index.d.ts +12 -0
- package/dist/src/research/index.d.ts.map +1 -0
- package/dist/src/research/index.js +14 -0
- package/dist/src/research/index.js.map +1 -0
- package/dist/src/research/sync.d.ts +49 -0
- package/dist/src/research/sync.d.ts.map +1 -0
- package/dist/src/research/sync.js +316 -0
- package/dist/src/research/sync.js.map +1 -0
- package/dist/src/research/terahac.d.ts +65 -0
- package/dist/src/research/terahac.d.ts.map +1 -0
- package/dist/src/research/terahac.js +379 -0
- package/dist/src/research/terahac.js.map +1 -0
- package/dist/src/types/index.d.ts +8 -0
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/utils/algorithm-utilities.d.ts +2 -0
- package/dist/src/utils/algorithm-utilities.d.ts.map +1 -0
- package/dist/src/utils/algorithm-utilities.js +2 -0
- package/dist/src/utils/algorithm-utilities.js.map +1 -0
- package/dist/src/utils/graph-converters.d.ts +79 -0
- package/dist/src/utils/graph-converters.d.ts.map +1 -0
- package/dist/src/utils/graph-converters.js +196 -0
- package/dist/src/utils/graph-converters.js.map +1 -0
- package/dist/src/utils/graph-utilities.d.ts +62 -0
- package/dist/src/utils/graph-utilities.d.ts.map +1 -0
- package/dist/src/utils/graph-utilities.js +148 -0
- package/dist/src/utils/graph-utilities.js.map +1 -0
- package/dist/src/utils/index.d.ts +5 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/index.js +5 -0
- package/dist/src/utils/index.js.map +1 -0
- package/dist/src/utils/math-utilities.d.ts +52 -0
- package/dist/src/utils/math-utilities.d.ts.map +1 -0
- package/dist/src/utils/math-utilities.js +123 -0
- package/dist/src/utils/math-utilities.js.map +1 -0
- package/dist/src/utils/matrix-utilities.d.ts +2 -0
- package/dist/src/utils/matrix-utilities.d.ts.map +1 -0
- package/dist/src/utils/matrix-utilities.js +2 -0
- package/dist/src/utils/matrix-utilities.js.map +1 -0
- package/dist/src/utils/optimization-helpers.d.ts +33 -0
- package/dist/src/utils/optimization-helpers.d.ts.map +1 -0
- package/dist/src/utils/optimization-helpers.js +47 -0
- package/dist/src/utils/optimization-helpers.js.map +1 -0
- package/package.json +28 -4
- package/src/algorithms/centrality/betweenness.ts +167 -199
- package/src/algorithms/centrality/closeness.ts +73 -191
- package/src/algorithms/centrality/degree.ts +3 -3
- package/src/algorithms/centrality/delta-pagerank-simple.ts +366 -0
- package/src/algorithms/centrality/delta-pagerank.ts +435 -0
- package/src/algorithms/centrality/index.ts +2 -0
- package/src/algorithms/centrality/pagerank.ts +66 -0
- package/src/algorithms/community/girvan-newman.ts +52 -59
- package/src/algorithms/community/index.ts +2 -0
- package/src/algorithms/community/label-propagation.ts +64 -35
- package/src/algorithms/community/leiden.ts +40 -41
- package/src/algorithms/community/louvain-optimized.ts +445 -0
- package/src/algorithms/community/louvain.ts +24 -104
- package/src/algorithms/community/modularity-utils.ts +146 -0
- package/src/algorithms/matching/bipartite.ts +8 -44
- package/src/algorithms/shortest-path/bellman-ford.ts +1 -14
- package/src/algorithms/shortest-path/bidirectional-dijkstra.ts +248 -0
- package/src/algorithms/shortest-path/dijkstra.ts +17 -15
- package/src/algorithms/traversal/bfs-unified.ts +433 -0
- package/src/algorithms/traversal/bfs-variants.ts +496 -0
- package/src/algorithms/traversal/bfs.ts +10 -228
- package/src/benchmark-all-algorithms.ts +548 -0
- package/src/clustering/hierarchical.ts +241 -251
- package/src/clustering/index.ts +4 -2
- package/src/clustering/k-core.ts +87 -39
- package/src/clustering/spectral.ts +185 -34
- package/src/core/graph.ts +4 -4
- package/src/flow/ford-fulkerson.ts +186 -254
- package/src/flow/min-cut.ts +21 -11
- package/src/index.ts +9 -0
- package/src/link-prediction/adamic-adar.ts +17 -30
- package/src/link-prediction/common-neighbors.ts +7 -16
- package/src/optimized/bit-packed.ts +340 -0
- package/src/optimized/csr-graph.ts +455 -0
- package/src/optimized/direction-optimized-bfs.ts +291 -0
- package/src/optimized/graph-adapter.ts +200 -0
- package/src/optimized/index.ts +36 -0
- package/src/research/grsbm.ts +580 -0
- package/src/research/index.ts +17 -0
- package/src/research/sync.ts +440 -0
- package/src/research/terahac.ts +514 -0
- package/src/types/index.ts +8 -0
- package/src/utils/algorithm-utilities.ts +2 -0
- package/src/utils/graph-converters.ts +241 -0
- package/src/utils/graph-utilities.ts +199 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/math-utilities.ts +140 -0
- package/src/utils/matrix-utilities.ts +2 -0
- package/src/utils/optimization-helpers.ts +81 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Graph } from "../core/graph.js";
|
|
2
|
+
import type { NodeId } from "../types/index.js";
|
|
3
|
+
import { CSRGraph, type ReadonlyGraph } from "./csr-graph.js";
|
|
4
|
+
/**
|
|
5
|
+
* Adapter to convert standard Graph to CSR format
|
|
6
|
+
*
|
|
7
|
+
* Provides transparent conversion while maintaining API compatibility
|
|
8
|
+
*/
|
|
9
|
+
export declare class GraphAdapter<TNodeId = NodeId> implements ReadonlyGraph<TNodeId> {
|
|
10
|
+
private csrGraph;
|
|
11
|
+
constructor(graph: Graph | ReadonlyGraph<TNodeId>);
|
|
12
|
+
/**
|
|
13
|
+
* Convert standard graph to CSR format
|
|
14
|
+
*/
|
|
15
|
+
private convertToCSR;
|
|
16
|
+
nodeCount(): number;
|
|
17
|
+
edgeCount(): number;
|
|
18
|
+
hasNode(nodeId: TNodeId): boolean;
|
|
19
|
+
hasEdge(source: TNodeId, target: TNodeId): boolean;
|
|
20
|
+
neighbors(nodeId: TNodeId): IterableIterator<TNodeId>;
|
|
21
|
+
outDegree(nodeId: TNodeId): number;
|
|
22
|
+
nodes(): IterableIterator<TNodeId>;
|
|
23
|
+
/**
|
|
24
|
+
* Get the underlying CSR graph
|
|
25
|
+
*/
|
|
26
|
+
getCSRGraph(): CSRGraph<TNodeId>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Configuration for graph algorithm optimizations
|
|
30
|
+
*/
|
|
31
|
+
export interface GraphAlgorithmConfig {
|
|
32
|
+
useDirectionOptimizedBFS?: boolean;
|
|
33
|
+
useCSRFormat?: boolean;
|
|
34
|
+
useBitPackedStructures?: boolean;
|
|
35
|
+
bfsAlpha?: number;
|
|
36
|
+
bfsBeta?: number;
|
|
37
|
+
preallocateSize?: number;
|
|
38
|
+
enableCaching?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Configure optimizations globally
|
|
42
|
+
* @deprecated This function is a no-op and will be removed in a future version
|
|
43
|
+
*/
|
|
44
|
+
export declare function configureOptimizations(_config: GraphAlgorithmConfig): void;
|
|
45
|
+
/**
|
|
46
|
+
* Get current configuration
|
|
47
|
+
* @deprecated This function returns empty config and will be removed in a future version
|
|
48
|
+
*/
|
|
49
|
+
export declare function getOptimizationConfig(): GraphAlgorithmConfig;
|
|
50
|
+
/**
|
|
51
|
+
* Check if a graph is already in CSR format
|
|
52
|
+
*/
|
|
53
|
+
export declare function isCSRGraph<TNodeId = NodeId>(graph: unknown): graph is CSRGraph<TNodeId>;
|
|
54
|
+
/**
|
|
55
|
+
* Convert any graph to CSR format
|
|
56
|
+
*/
|
|
57
|
+
export declare function toCSRGraph<TNodeId = NodeId>(graph: Graph | ReadonlyGraph<TNodeId> | CSRGraph<TNodeId>): CSRGraph<TNodeId>;
|
|
58
|
+
/**
|
|
59
|
+
* Create an optimized graph from nodes and edges
|
|
60
|
+
*/
|
|
61
|
+
export declare function createOptimizedGraph<TNodeId = NodeId>(nodes: TNodeId[], edges: [TNodeId, TNodeId, number?][]): CSRGraph<TNodeId>;
|
|
62
|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AAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;GAGG;AAEH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAE1E;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,oBAAoB,CAE5D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAG,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAAC,OAAO,CAAC,CAEvF;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAG,MAAM,EACvC,KAAK,EAAE,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,GAC1D,QAAQ,CAAC,OAAO,CAAC,CAOnB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,GAAG,MAAM,EACjD,KAAK,EAAE,OAAO,EAAE,EAChB,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,EAAE,GACrC,QAAQ,CAAC,OAAO,CAAC,CAqBnB"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { CSRGraph } from "./csr-graph.js";
|
|
2
|
+
/**
|
|
3
|
+
* Adapter to convert standard Graph to CSR format
|
|
4
|
+
*
|
|
5
|
+
* Provides transparent conversion while maintaining API compatibility
|
|
6
|
+
*/
|
|
7
|
+
export class GraphAdapter {
|
|
8
|
+
constructor(graph) {
|
|
9
|
+
// Check if already a CSRGraph
|
|
10
|
+
if (graph instanceof CSRGraph) {
|
|
11
|
+
this.csrGraph = graph;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
// Convert to CSR format
|
|
15
|
+
this.csrGraph = this.convertToCSR(graph);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Convert standard graph to CSR format
|
|
20
|
+
*/
|
|
21
|
+
convertToCSR(graph) {
|
|
22
|
+
const adjacencyList = new Map();
|
|
23
|
+
const weights = new Map();
|
|
24
|
+
// Handle both Graph and ReadonlyGraph interfaces
|
|
25
|
+
if ("nodes" in graph && typeof graph.nodes === "function") {
|
|
26
|
+
// Build adjacency list from Graph
|
|
27
|
+
for (const node of graph.nodes()) {
|
|
28
|
+
const nodeId = node.id;
|
|
29
|
+
const neighbors = [];
|
|
30
|
+
const graphTyped = graph;
|
|
31
|
+
for (const neighborId of graphTyped.neighbors(nodeId)) {
|
|
32
|
+
neighbors.push(neighborId);
|
|
33
|
+
// Get edge weight if available
|
|
34
|
+
if ("getEdge" in graph && typeof graph.getEdge === "function") {
|
|
35
|
+
const edge = graphTyped.getEdge(nodeId, neighborId);
|
|
36
|
+
if (edge?.weight !== undefined) {
|
|
37
|
+
weights.set(`${String(nodeId)}-${String(neighborId)}`, edge.weight);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
adjacencyList.set(nodeId, neighbors);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else if ("nodeIds" in graph && typeof graph.nodeIds === "function") {
|
|
45
|
+
const readonlyGraph = graph;
|
|
46
|
+
for (const nodeId of readonlyGraph.nodeIds()) {
|
|
47
|
+
adjacencyList.set(nodeId, []);
|
|
48
|
+
}
|
|
49
|
+
// Build adjacency from edges
|
|
50
|
+
if ("edges" in readonlyGraph && typeof readonlyGraph.edges === "function") {
|
|
51
|
+
for (const edge of readonlyGraph.edges()) {
|
|
52
|
+
const neighbors = adjacencyList.get(edge.source);
|
|
53
|
+
if (neighbors) {
|
|
54
|
+
neighbors.push(edge.target);
|
|
55
|
+
if (edge.weight !== undefined) {
|
|
56
|
+
weights.set(`${String(edge.source)}-${String(edge.target)}`, edge.weight);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return new CSRGraph(adjacencyList, weights.size > 0 ? weights : undefined);
|
|
63
|
+
}
|
|
64
|
+
// Delegate all methods to CSR implementation
|
|
65
|
+
nodeCount() {
|
|
66
|
+
return this.csrGraph.nodeCount();
|
|
67
|
+
}
|
|
68
|
+
edgeCount() {
|
|
69
|
+
return this.csrGraph.edgeCount();
|
|
70
|
+
}
|
|
71
|
+
hasNode(nodeId) {
|
|
72
|
+
return this.csrGraph.hasNode(nodeId);
|
|
73
|
+
}
|
|
74
|
+
hasEdge(source, target) {
|
|
75
|
+
return this.csrGraph.hasEdge(source, target);
|
|
76
|
+
}
|
|
77
|
+
neighbors(nodeId) {
|
|
78
|
+
return this.csrGraph.neighbors(nodeId);
|
|
79
|
+
}
|
|
80
|
+
outDegree(nodeId) {
|
|
81
|
+
return this.csrGraph.outDegree(nodeId);
|
|
82
|
+
}
|
|
83
|
+
nodes() {
|
|
84
|
+
return this.csrGraph.nodes();
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get the underlying CSR graph
|
|
88
|
+
*/
|
|
89
|
+
getCSRGraph() {
|
|
90
|
+
return this.csrGraph;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Configure optimizations globally
|
|
95
|
+
* @deprecated This function is a no-op and will be removed in a future version
|
|
96
|
+
*/
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
98
|
+
export function configureOptimizations(_config) {
|
|
99
|
+
// No-op for backward compatibility
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get current configuration
|
|
103
|
+
* @deprecated This function returns empty config and will be removed in a future version
|
|
104
|
+
*/
|
|
105
|
+
export function getOptimizationConfig() {
|
|
106
|
+
return {};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Check if a graph is already in CSR format
|
|
110
|
+
*/
|
|
111
|
+
export function isCSRGraph(graph) {
|
|
112
|
+
return graph instanceof CSRGraph;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Convert any graph to CSR format
|
|
116
|
+
*/
|
|
117
|
+
export function toCSRGraph(graph) {
|
|
118
|
+
if (isCSRGraph(graph)) {
|
|
119
|
+
return graph;
|
|
120
|
+
}
|
|
121
|
+
const adapter = new GraphAdapter(graph);
|
|
122
|
+
return adapter.getCSRGraph();
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Create an optimized graph from nodes and edges
|
|
126
|
+
*/
|
|
127
|
+
export function createOptimizedGraph(nodes, edges) {
|
|
128
|
+
const adjacencyList = new Map();
|
|
129
|
+
const weights = new Map();
|
|
130
|
+
// Initialize nodes
|
|
131
|
+
for (const node of nodes) {
|
|
132
|
+
adjacencyList.set(node, []);
|
|
133
|
+
}
|
|
134
|
+
// Add edges
|
|
135
|
+
for (const [source, target, weight] of edges) {
|
|
136
|
+
const neighbors = adjacencyList.get(source);
|
|
137
|
+
if (neighbors) {
|
|
138
|
+
neighbors.push(target);
|
|
139
|
+
if (weight !== undefined) {
|
|
140
|
+
weights.set(`${String(source)}-${String(target)}`, weight);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return new CSRGraph(adjacencyList, weights.size > 0 ? weights : undefined);
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=graph-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-adapter.js","sourceRoot":"","sources":["../../../src/optimized/graph-adapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,QAAQ,EAAqB,MAAM,gBAAgB,CAAC;AAE5D;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAGrB,YAAY,KAAqC;QACjD,8BAA8B;QAC1B,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;YAC5B,IAAI,CAAC,QAAQ,GAAG,KAA0B,CAAC;QAC/C,CAAC;aAAM,CAAC;YACJ,wBAAwB;YACxB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAC7C,CAAC;IACL,CAAC;IAED;;KAEC;IACO,YAAY,CAA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EAAE,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QAC3C,MAAM,SAAS,GAAG,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,SAAS,EAAE,CAAC;YACZ,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvB,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACvB,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;YAC/D,CAAC;QACL,CAAC;IACL,CAAC;IAED,OAAO,IAAI,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optimized graph algorithm implementations
|
|
3
|
+
*
|
|
4
|
+
* High-performance implementations using:
|
|
5
|
+
* - Direction-Optimized BFS
|
|
6
|
+
* - Compressed Sparse Row (CSR) format
|
|
7
|
+
* - Bit-packed data structures
|
|
8
|
+
*/
|
|
9
|
+
export { configureOptimizations, getOptimizationConfig, type GraphAlgorithmConfig, } from "./graph-adapter.js";
|
|
10
|
+
export { CompactDistanceArray, GraphBitSet, VisitedBitArray } from "./bit-packed.js";
|
|
11
|
+
export { CSRGraph } from "./csr-graph.js";
|
|
12
|
+
export { DirectionOptimizedBFS } from "./direction-optimized-bfs.js";
|
|
13
|
+
export { createOptimizedGraph, isCSRGraph, toCSRGraph } from "./graph-adapter.js";
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/optimized/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACH,sBAAsB,EACtB,qBAAqB,EACrB,KAAK,oBAAoB,GAC5B,MAAM,oBAAoB,CAAC;AAgB5B,OAAO,EAAC,oBAAoB,EAAE,WAAW,EAAE,eAAe,EAAC,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAC,qBAAqB,EAAC,MAAM,8BAA8B,CAAC;AAGnE,OAAO,EAAC,oBAAoB,EAAE,UAAU,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optimized graph algorithm implementations
|
|
3
|
+
*
|
|
4
|
+
* High-performance implementations using:
|
|
5
|
+
* - Direction-Optimized BFS
|
|
6
|
+
* - Compressed Sparse Row (CSR) format
|
|
7
|
+
* - Bit-packed data structures
|
|
8
|
+
*/
|
|
9
|
+
// Configuration and optimization control
|
|
10
|
+
export { configureOptimizations, getOptimizationConfig, } from "./graph-adapter.js";
|
|
11
|
+
// Note: The main BFS functions in algorithms/traversal/bfs.ts automatically
|
|
12
|
+
// use these optimizations for large graphs (>10k nodes) when optimizations are enabled.
|
|
13
|
+
// No manual configuration needed - just use breadthFirstSearch, shortestPathBFS, etc.
|
|
14
|
+
//
|
|
15
|
+
// The previously exported bfsOptimized, shortestPathBFSOptimized, and
|
|
16
|
+
// singleSourceShortestPathBFSOptimized functions have been removed since they
|
|
17
|
+
// are no longer needed. All optimization happens automatically.
|
|
18
|
+
// BFS optimization functions have been removed. The main BFS functions
|
|
19
|
+
// (breadthFirstSearch, shortestPathBFS, singleSourceShortestPathBFS)
|
|
20
|
+
// in algorithms/traversal/bfs.ts now automatically use optimizations
|
|
21
|
+
// for large graphs without requiring manual configuration.
|
|
22
|
+
// Export data structures for advanced users
|
|
23
|
+
export { CompactDistanceArray, GraphBitSet, VisitedBitArray } from "./bit-packed.js";
|
|
24
|
+
export { CSRGraph } from "./csr-graph.js";
|
|
25
|
+
export { DirectionOptimizedBFS } from "./direction-optimized-bfs.js";
|
|
26
|
+
// Export utilities
|
|
27
|
+
export { createOptimizedGraph, isCSRGraph, toCSRGraph } from "./graph-adapter.js";
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/optimized/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,yCAAyC;AACzC,OAAO,EACH,sBAAsB,EACtB,qBAAqB,GAExB,MAAM,oBAAoB,CAAC;AAE5B,4EAA4E;AAC5E,wFAAwF;AACxF,sFAAsF;AACtF,EAAE;AACF,sEAAsE;AACtE,8EAA8E;AAC9E,gEAAgE;AAEhE,uEAAuE;AACvE,qEAAqE;AACrE,qEAAqE;AACrE,2DAA2D;AAE3D,4CAA4C;AAC5C,OAAO,EAAC,oBAAoB,EAAE,WAAW,EAAE,eAAe,EAAC,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAC,qBAAqB,EAAC,MAAM,8BAA8B,CAAC;AAEnE,mBAAmB;AACnB,OAAO,EAAC,oBAAoB,EAAE,UAAU,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Graph } from "../core/graph.js";
|
|
2
|
+
import type { NodeId } from "../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for the GRSBM (Greedy Recursive Spectral Bisection) algorithm
|
|
5
|
+
*/
|
|
6
|
+
export interface GRSBMConfig {
|
|
7
|
+
/** Maximum depth of recursive bisection */
|
|
8
|
+
maxDepth?: number;
|
|
9
|
+
/** Minimum cluster size to continue splitting */
|
|
10
|
+
minClusterSize?: number;
|
|
11
|
+
/** Number of eigenvectors to use for spectral embedding */
|
|
12
|
+
numEigenvectors?: number;
|
|
13
|
+
/** Convergence tolerance for eigenvalue computation */
|
|
14
|
+
tolerance?: number;
|
|
15
|
+
/** Maximum number of power iterations for eigenvalue computation */
|
|
16
|
+
maxIterations?: number;
|
|
17
|
+
/** Random seed for reproducibility */
|
|
18
|
+
seed?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Represents a cluster in the hierarchical structure
|
|
22
|
+
*/
|
|
23
|
+
export interface GRSBMCluster {
|
|
24
|
+
/** Unique identifier for this cluster */
|
|
25
|
+
id: string;
|
|
26
|
+
/** Node IDs in this cluster */
|
|
27
|
+
members: Set<NodeId>;
|
|
28
|
+
/** Left child cluster (if split) */
|
|
29
|
+
left?: GRSBMCluster;
|
|
30
|
+
/** Right child cluster (if split) */
|
|
31
|
+
right?: GRSBMCluster;
|
|
32
|
+
/** Modularity score of this cluster */
|
|
33
|
+
modularity: number;
|
|
34
|
+
/** Depth in the hierarchy */
|
|
35
|
+
depth: number;
|
|
36
|
+
/** Spectral embedding quality score */
|
|
37
|
+
spectralScore: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Result of the GRSBM clustering algorithm
|
|
41
|
+
*/
|
|
42
|
+
export interface GRSBMResult {
|
|
43
|
+
/** Root of the cluster hierarchy */
|
|
44
|
+
root: GRSBMCluster;
|
|
45
|
+
/** Flat clustering at leaf level */
|
|
46
|
+
clusters: Map<NodeId, number>;
|
|
47
|
+
/** Number of final clusters */
|
|
48
|
+
numClusters: number;
|
|
49
|
+
/** Modularity scores for each level */
|
|
50
|
+
modularityScores: number[];
|
|
51
|
+
/** Explanation of the clustering structure */
|
|
52
|
+
explanation: ClusterExplanation[];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Explanation for a cluster split decision
|
|
56
|
+
*/
|
|
57
|
+
export interface ClusterExplanation {
|
|
58
|
+
/** Cluster that was split */
|
|
59
|
+
clusterId: string;
|
|
60
|
+
/** Reason for the split */
|
|
61
|
+
reason: string;
|
|
62
|
+
/** Modularity improvement from the split */
|
|
63
|
+
modularityImprovement: number;
|
|
64
|
+
/** Key nodes that influenced the split */
|
|
65
|
+
keyNodes: NodeId[];
|
|
66
|
+
/** Spectral embedding values */
|
|
67
|
+
spectralValues: number[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* GRSBM - Greedy Recursive Spectral Bisection with Modularity
|
|
71
|
+
*
|
|
72
|
+
* This algorithm performs hierarchical community detection using spectral
|
|
73
|
+
* bisection guided by modularity optimization. It provides explainable
|
|
74
|
+
* community structure by tracking the reasoning behind each split.
|
|
75
|
+
*
|
|
76
|
+
* Based on: "Explainable Community Detection via Hierarchical Spectral Clustering" (2024)
|
|
77
|
+
*
|
|
78
|
+
* @param graph - Input graph to cluster
|
|
79
|
+
* @param config - Configuration options
|
|
80
|
+
* @returns Hierarchical clustering result with explanations
|
|
81
|
+
*/
|
|
82
|
+
export declare function grsbm(graph: Graph, config?: GRSBMConfig): GRSBMResult;
|
|
83
|
+
//# sourceMappingURL=grsbm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grsbm.d.ts","sourceRoot":"","sources":["../../../src/research/grsbm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AAG9C;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,2DAA2D;IAC3D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oEAAoE;IACpE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sCAAsC;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,yCAAyC;IACzC,EAAE,EAAE,MAAM,CAAC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