@statelyai/graph 1.0.0 → 2.1.0
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 +121 -44
- package/dist/{adjacency-list-VsUaH9SJ.mjs → adjacency-list-DQ32Mmhx.mjs} +3 -1
- package/dist/algorithms-D1cgly0g.d.mts +452 -0
- package/dist/algorithms-DBpH74hR.mjs +3309 -0
- package/dist/algorithms.d.mts +2 -2
- package/dist/algorithms.mjs +2 -2
- package/dist/config-Dt5u1gSf.mjs +793 -0
- package/dist/{converter-udLITX36.mjs → converter-DB6Rg6Vd.mjs} +2 -2
- package/dist/format-support.mjs +38 -11
- package/dist/formats/adjacency-list/index.d.mts +1 -1
- package/dist/formats/adjacency-list/index.mjs +1 -1
- package/dist/formats/converter/index.d.mts +1 -1
- package/dist/formats/converter/index.mjs +1 -1
- package/dist/formats/cytoscape/index.d.mts +4 -4
- package/dist/formats/cytoscape/index.mjs +10 -4
- package/dist/formats/d2/index.d.mts +1 -1
- package/dist/formats/d2/index.mjs +26 -12
- package/dist/formats/d3/index.d.mts +4 -4
- package/dist/formats/d3/index.mjs +10 -4
- package/dist/formats/dot/index.d.mts +1 -1
- package/dist/formats/dot/index.mjs +22 -6
- package/dist/formats/edge-list/index.d.mts +1 -1
- package/dist/formats/edge-list/index.mjs +1 -1
- package/dist/formats/elk/index.d.mts +1 -1
- package/dist/formats/elk/index.mjs +63 -24
- package/dist/formats/gexf/index.d.mts +1 -1
- package/dist/formats/gexf/index.mjs +43 -16
- package/dist/formats/gml/index.d.mts +4 -4
- package/dist/formats/gml/index.mjs +28 -15
- package/dist/formats/graphml/index.d.mts +1 -1
- package/dist/formats/graphml/index.mjs +96 -23
- package/dist/formats/jgf/index.d.mts +4 -4
- package/dist/formats/jgf/index.mjs +12 -5
- package/dist/formats/mermaid/index.d.mts +1 -1
- package/dist/formats/mermaid/index.mjs +49 -12
- package/dist/formats/tgf/index.d.mts +4 -4
- package/dist/formats/tgf/index.mjs +4 -4
- package/dist/formats/xyflow/index.d.mts +12 -6
- package/dist/formats/xyflow/index.mjs +42 -10
- package/dist/{index-D9Kj6Fe3.d.mts → index-BlbSWUvH.d.mts} +1 -1
- package/dist/{index-CHoriXZD.d.mts → index-CNvqxPLJ.d.mts} +157 -30
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +290 -307
- package/dist/layout/cytoscape.d.mts +66 -0
- package/dist/layout/cytoscape.mjs +114 -0
- package/dist/layout/d3-force.d.mts +52 -0
- package/dist/layout/d3-force.mjs +127 -0
- package/dist/layout/d3-hierarchy.d.mts +39 -0
- package/dist/layout/d3-hierarchy.mjs +135 -0
- package/dist/layout/dagre.d.mts +32 -0
- package/dist/layout/dagre.mjs +99 -0
- package/dist/layout/elk.d.mts +47 -0
- package/dist/layout/elk.mjs +73 -0
- package/dist/layout/forceatlas2.d.mts +48 -0
- package/dist/layout/forceatlas2.mjs +100 -0
- package/dist/layout/graphviz.d.mts +50 -0
- package/dist/layout/graphviz.mjs +179 -0
- package/dist/layout/index.d.mts +185 -0
- package/dist/layout/index.mjs +181 -0
- package/dist/layout/webcola.d.mts +40 -0
- package/dist/layout/webcola.mjs +104 -0
- package/dist/{queries-BlkA1HAN.d.mts → queries-B6quF529.d.mts} +43 -12
- package/dist/queries-BMM0XAv_.mjs +986 -0
- package/dist/queries.d.mts +1 -1
- package/dist/queries.mjs +1 -768
- package/dist/schemas.d.mts +19 -1
- package/dist/schemas.mjs +32 -84
- package/dist/{types-3-FS9NV2.d.mts → types-BAEQTwK_.d.mts} +99 -7
- package/dist/validate-BsfSOv0S.mjs +190 -0
- package/package.json +59 -7
- package/schemas/edge.schema.json +27 -0
- package/schemas/graph.schema.json +27 -0
- package/dist/algorithms-Ba7o7niK.mjs +0 -2394
- package/dist/algorithms-fTqmvhzP.d.mts +0 -178
- package/dist/indexing-DR8M1vBy.mjs +0 -137
- /package/dist/{edge-list-DP4otyPU.mjs → edge-list-CA9UTvn2.mjs} +0 -0
- /package/dist/{mode-D8OnHFBk.mjs → mode-gu_mhKKs.mjs} +0 -0
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import { M as SinglePathOptions, O as PathOptions, P as TraversalOptions, f as Graph, h as GraphEdge, n as AllPairsShortestPathsOptions, t as AStarOptions, w as MSTOptions, x as GraphPath, y as GraphNode } from "./types-BAEQTwK_.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/algorithms/traversal.d.ts
|
|
4
|
+
declare function genBFS<N>(graph: Graph<N>, startId: string): Generator<GraphNode<N>>;
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Use {@link genBFS}.
|
|
7
|
+
*/
|
|
8
|
+
declare function bfs<N>(graph: Graph<N>, startId: string): Generator<GraphNode<N>>;
|
|
9
|
+
declare function genDFS<N>(graph: Graph<N>, startId: string): Generator<GraphNode<N>>;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use {@link genDFS}.
|
|
12
|
+
*/
|
|
13
|
+
declare function dfs<N>(graph: Graph<N>, startId: string): Generator<GraphNode<N>>;
|
|
14
|
+
declare function isAcyclic(graph: Graph): boolean;
|
|
15
|
+
declare function getConnectedComponents<N>(graph: Graph<N>): GraphNode<N>[][];
|
|
16
|
+
/**
|
|
17
|
+
* Returns a topological ordering of the graph's nodes, or `null` if no such
|
|
18
|
+
* ordering exists.
|
|
19
|
+
*
|
|
20
|
+
* Any edge whose effective mode (per {@link getEdgeMode}) is not `'directed'`
|
|
21
|
+
* makes ordering impossible — an undirected/bidirectional edge is mutual
|
|
22
|
+
* precedence, i.e. a 2-cycle — so the function returns `null`.
|
|
23
|
+
*/
|
|
24
|
+
declare function getTopologicalSort<N>(graph: Graph<N>): GraphNode<N>[] | null;
|
|
25
|
+
declare function hasPath(graph: Graph, sourceId: string, targetId: string): boolean;
|
|
26
|
+
declare function isConnected(graph: Graph): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Returns whether the graph is a tree: connected, acyclic, and with exactly
|
|
29
|
+
* `nodes.length - 1` edges (so directed diamonds and parallel edges are not
|
|
30
|
+
* trees). Empty and single-node graphs are considered trees.
|
|
31
|
+
*/
|
|
32
|
+
declare function isTree(graph: Graph): boolean;
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/algorithms/paths.d.ts
|
|
35
|
+
declare function genShortestPaths<N, E>(graph: Graph<N, E>, opts?: PathOptions<E>): Generator<GraphPath<N, E>>;
|
|
36
|
+
declare function getShortestPaths<N, E>(graph: Graph<N, E>, opts?: PathOptions<E>): GraphPath<N, E>[];
|
|
37
|
+
declare function getShortestPath<N, E>(graph: Graph<N, E>, opts: SinglePathOptions<E>): GraphPath<N, E> | undefined;
|
|
38
|
+
declare function getSimplePaths<N, E>(graph: Graph<N, E>, opts?: PathOptions<E>): GraphPath<N, E>[];
|
|
39
|
+
declare function genSimplePaths<N, E>(graph: Graph<N, E>, opts?: PathOptions<E>): Generator<GraphPath<N, E>>;
|
|
40
|
+
declare function getSimplePath<N, E>(graph: Graph<N, E>, opts: SinglePathOptions<E>): GraphPath<N, E> | undefined;
|
|
41
|
+
declare function getStronglyConnectedComponents<N>(graph: Graph<N>): GraphNode<N>[][];
|
|
42
|
+
declare function getCycles<N, E>(graph: Graph<N, E>): GraphPath<N, E>[];
|
|
43
|
+
declare function genCycles<N, E>(graph: Graph<N, E>): Generator<GraphPath<N, E>>;
|
|
44
|
+
declare function getAllPairsShortestPaths<N, E>(graph: Graph<N, E>, opts?: AllPairsShortestPathsOptions<E>): GraphPath<N, E>[];
|
|
45
|
+
declare function getAStarPath<N, E>(graph: Graph<N, E>, opts: AStarOptions<E>): GraphPath<N, E> | undefined;
|
|
46
|
+
declare function getJoinedPath<N, E>(headPath: GraphPath<N, E>, tailPath: GraphPath<N, E>): GraphPath<N, E>;
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated Use {@link getJoinedPath}.
|
|
49
|
+
*/
|
|
50
|
+
declare function joinPaths<N, E>(headPath: GraphPath<N, E>, tailPath: GraphPath<N, E>): GraphPath<N, E>;
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/algorithms/ordering.d.ts
|
|
53
|
+
declare function getPreorder<N>(graph: Graph<N>, opts?: TraversalOptions): GraphNode<N>[];
|
|
54
|
+
declare function getPostorder<N>(graph: Graph<N>, opts?: TraversalOptions): GraphNode<N>[];
|
|
55
|
+
declare function getPreorders<N>(graph: Graph<N>, opts?: TraversalOptions): GraphNode<N>[][];
|
|
56
|
+
declare function getPostorders<N>(graph: Graph<N>, opts?: TraversalOptions): GraphNode<N>[][];
|
|
57
|
+
declare function genPreorders<N>(graph: Graph<N>, opts?: TraversalOptions): Generator<GraphNode<N>[]>;
|
|
58
|
+
declare function genPostorders<N>(graph: Graph<N>, opts?: TraversalOptions): Generator<GraphNode<N>[]>;
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/algorithms/spanning-tree.d.ts
|
|
61
|
+
declare function getMinimumSpanningTree<N, E>(graph: Graph<N, E>, opts?: MSTOptions<E>): Graph<N, E>;
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/algorithms/centrality.d.ts
|
|
64
|
+
interface IterativeCentralityOptions {
|
|
65
|
+
alpha?: number;
|
|
66
|
+
maxIterations?: number;
|
|
67
|
+
tolerance?: number;
|
|
68
|
+
}
|
|
69
|
+
interface EigenvectorCentralityOptions<E = any> extends IterativeCentralityOptions {
|
|
70
|
+
/** Edge weight accessor. Defaults to unweighted (every edge counts 1). */
|
|
71
|
+
getWeight?: (edge: GraphEdge<E>) => number;
|
|
72
|
+
}
|
|
73
|
+
interface KatzCentralityOptions<E = any> extends IterativeCentralityOptions {
|
|
74
|
+
/** Constant added to every node each iteration. Defaults to `1`. */
|
|
75
|
+
beta?: number;
|
|
76
|
+
/** Edge weight accessor. Defaults to unweighted (every edge counts 1). */
|
|
77
|
+
getWeight?: (edge: GraphEdge<E>) => number;
|
|
78
|
+
}
|
|
79
|
+
interface HITSResult {
|
|
80
|
+
hubs: Record<string, number>;
|
|
81
|
+
authorities: Record<string, number>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns degree centrality scores for all nodes.
|
|
85
|
+
*
|
|
86
|
+
* Degree centrality is the node degree normalized by `n - 1`.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const scores = getDegreeCentrality(graph);
|
|
91
|
+
* console.log(scores.a); // 0.5
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
declare function getDegreeCentrality(graph: Graph): Record<string, number>;
|
|
95
|
+
/**
|
|
96
|
+
* Returns in-degree centrality scores for all nodes.
|
|
97
|
+
*
|
|
98
|
+
* In-degree centrality is the incoming degree normalized by `n - 1`.
|
|
99
|
+
*/
|
|
100
|
+
declare function getInDegreeCentrality(graph: Graph): Record<string, number>;
|
|
101
|
+
/**
|
|
102
|
+
* Returns out-degree centrality scores for all nodes.
|
|
103
|
+
*
|
|
104
|
+
* Out-degree centrality is the outgoing degree normalized by `n - 1`.
|
|
105
|
+
*/
|
|
106
|
+
declare function getOutDegreeCentrality(graph: Graph): Record<string, number>;
|
|
107
|
+
/**
|
|
108
|
+
* Returns closeness centrality scores for all nodes.
|
|
109
|
+
*
|
|
110
|
+
* Distances are computed over unweighted shortest paths using the graph's
|
|
111
|
+
* existing directed or undirected edge semantics.
|
|
112
|
+
*/
|
|
113
|
+
declare function getClosenessCentrality(graph: Graph): Record<string, number>;
|
|
114
|
+
/**
|
|
115
|
+
* Returns betweenness centrality scores for all nodes.
|
|
116
|
+
*
|
|
117
|
+
* Uses Brandes' algorithm over unweighted shortest paths and returns
|
|
118
|
+
* normalized scores.
|
|
119
|
+
*/
|
|
120
|
+
declare function getBetweennessCentrality(graph: Graph): Record<string, number>;
|
|
121
|
+
/**
|
|
122
|
+
* Returns PageRank scores for all nodes.
|
|
123
|
+
*
|
|
124
|
+
* Uses power iteration with damping factor `alpha`.
|
|
125
|
+
*/
|
|
126
|
+
declare function getPageRank(graph: Graph, options?: IterativeCentralityOptions): Record<string, number>;
|
|
127
|
+
/**
|
|
128
|
+
* Returns HITS hub and authority scores for all nodes.
|
|
129
|
+
*
|
|
130
|
+
* Uses power iteration and L2 normalization per iteration.
|
|
131
|
+
*/
|
|
132
|
+
declare function getHITS(graph: Graph, options?: IterativeCentralityOptions): HITSResult;
|
|
133
|
+
/**
|
|
134
|
+
* Returns eigenvector centrality scores for all nodes.
|
|
135
|
+
*
|
|
136
|
+
* Power iteration with the `A + I` shift (same scheme as graphology and
|
|
137
|
+
* networkx, so bipartite structures converge instead of oscillating).
|
|
138
|
+
* Scores flow along edge direction: a node's score is fed by its incoming
|
|
139
|
+
* neighbors; undirected edges feed both endpoints. The result vector is
|
|
140
|
+
* Euclidean (L2) normalized.
|
|
141
|
+
*
|
|
142
|
+
* Throws when the iteration has not converged (L1 error < `n × tolerance`)
|
|
143
|
+
* within `maxIterations`.
|
|
144
|
+
*/
|
|
145
|
+
declare function getEigenvectorCentrality<N, E>(graph: Graph<N, E>, options?: EigenvectorCentralityOptions<E>): Record<string, number>;
|
|
146
|
+
/**
|
|
147
|
+
* Returns Katz centrality scores for all nodes.
|
|
148
|
+
*
|
|
149
|
+
* Iterates `x' = alpha · Aᵀx + beta` to its fixed point (networkx-style),
|
|
150
|
+
* then Euclidean (L2) normalizes the result. Scores flow along edge
|
|
151
|
+
* direction: a node's score is fed by its incoming neighbors; undirected
|
|
152
|
+
* edges feed both endpoints.
|
|
153
|
+
*
|
|
154
|
+
* Converges only when `alpha` is below the reciprocal of the largest
|
|
155
|
+
* eigenvalue of the adjacency matrix; throws when the iteration has not
|
|
156
|
+
* converged (L1 error < `n × tolerance`) within `maxIterations`.
|
|
157
|
+
*/
|
|
158
|
+
declare function getKatzCentrality<N, E>(graph: Graph<N, E>, options?: KatzCentralityOptions<E>): Record<string, number>;
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/algorithms/cores.d.ts
|
|
161
|
+
/**
|
|
162
|
+
* Returns the core number of every node (largest `k` such that the node
|
|
163
|
+
* belongs to the k-core).
|
|
164
|
+
*
|
|
165
|
+
* Uses Batagelj–Zaveršnik bucket peeling — O(m). Edges are treated as
|
|
166
|
+
* undirected (the standard k-core definition); self-loops are ignored.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* const cores = getCoreNumbers(graph);
|
|
171
|
+
* console.log(cores.a); // 3
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
declare function getCoreNumbers(graph: Graph): Record<string, number>;
|
|
175
|
+
/**
|
|
176
|
+
* Returns the ids of all nodes in the k-core: the maximal subgraph in which
|
|
177
|
+
* every node has at least `k` neighbors (edges treated as undirected).
|
|
178
|
+
*
|
|
179
|
+
* Node order follows `graph.nodes`. `k <= 0` returns every node id.
|
|
180
|
+
*/
|
|
181
|
+
declare function getKCore(graph: Graph, k: number): string[];
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region src/algorithms/bipartite.d.ts
|
|
184
|
+
interface BipartiteMatch {
|
|
185
|
+
/** Source node id of the matched edge (as stored on the edge). */
|
|
186
|
+
sourceId: string;
|
|
187
|
+
/** Target node id of the matched edge (as stored on the edge). */
|
|
188
|
+
targetId: string;
|
|
189
|
+
/** Id of the edge realizing the match. */
|
|
190
|
+
edgeId: string;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Returns whether the graph is bipartite (2-colorable).
|
|
194
|
+
*
|
|
195
|
+
* Edges are treated as undirected; self-loops make a graph non-bipartite.
|
|
196
|
+
* Runs a BFS 2-coloring per connected component — O(n + m).
|
|
197
|
+
*/
|
|
198
|
+
declare function isBipartite(graph: Graph): boolean;
|
|
199
|
+
/**
|
|
200
|
+
* Returns a maximum-cardinality matching of a bipartite graph using
|
|
201
|
+
* Hopcroft–Karp — O(m·√n).
|
|
202
|
+
*
|
|
203
|
+
* The bipartition is derived by 2-coloring (edges treated as undirected).
|
|
204
|
+
* Each match reports the realizing edge with its stored `sourceId`/
|
|
205
|
+
* `targetId` orientation; for parallel edges between a matched pair, the
|
|
206
|
+
* first edge used by the algorithm is reported.
|
|
207
|
+
*
|
|
208
|
+
* Throws if the graph is not bipartite, naming the offending edge.
|
|
209
|
+
*/
|
|
210
|
+
declare function getMaximumBipartiteMatching(graph: Graph): BipartiteMatch[];
|
|
211
|
+
//#endregion
|
|
212
|
+
//#region src/algorithms/community.d.ts
|
|
213
|
+
interface GirvanNewmanOptions {
|
|
214
|
+
level?: number;
|
|
215
|
+
maxLevels?: number;
|
|
216
|
+
}
|
|
217
|
+
interface LabelPropagationOptions {
|
|
218
|
+
maxIterations?: number;
|
|
219
|
+
/**
|
|
220
|
+
* When provided, runs *asynchronous* label propagation with a shuffled
|
|
221
|
+
* node order per round and random tie-breaking, seeded with mulberry32 —
|
|
222
|
+
* deterministic per seed. Without a seed, ties break lexicographically.
|
|
223
|
+
*/
|
|
224
|
+
seed?: number;
|
|
225
|
+
}
|
|
226
|
+
type Community<N = any> = GraphNode<N>[];
|
|
227
|
+
/**
|
|
228
|
+
* Returns label-propagation communities for the graph.
|
|
229
|
+
*
|
|
230
|
+
* The implementation is deterministic: ties are broken by lexicographic label
|
|
231
|
+
* order so test results remain stable. Pass `options.seed` for the classic
|
|
232
|
+
* asynchronous variant (shuffled node order per round, random tie-breaking)
|
|
233
|
+
* — still deterministic per seed.
|
|
234
|
+
*/
|
|
235
|
+
declare function getLabelPropagationCommunities<N>(graph: Graph<N>, options?: LabelPropagationOptions): Community<N>[];
|
|
236
|
+
/**
|
|
237
|
+
* Lazily yields Girvan-Newman community splits as edge betweenness removes
|
|
238
|
+
* bridge-like edges from the graph.
|
|
239
|
+
*/
|
|
240
|
+
declare function genGirvanNewmanCommunities<N>(graph: Graph<N>, options?: GirvanNewmanOptions): Generator<Community<N>[]>;
|
|
241
|
+
/**
|
|
242
|
+
* Returns the requested Girvan-Newman split level eagerly.
|
|
243
|
+
*
|
|
244
|
+
* `level: 1` returns the first split yielded by `genGirvanNewmanCommunities`.
|
|
245
|
+
*/
|
|
246
|
+
declare function getGirvanNewmanCommunities<N>(graph: Graph<N>, options?: GirvanNewmanOptions): Community<N>[];
|
|
247
|
+
/**
|
|
248
|
+
* Returns the modularity score for a partition of communities.
|
|
249
|
+
*
|
|
250
|
+
* Community algorithms in this module treat the graph as undirected.
|
|
251
|
+
*/
|
|
252
|
+
declare function getModularity<N>(graph: Graph<N>, communities: Community<N>[]): number;
|
|
253
|
+
/**
|
|
254
|
+
* Returns communities found by greedily merging partitions that improve
|
|
255
|
+
* modularity the most at each step.
|
|
256
|
+
*/
|
|
257
|
+
declare function getGreedyModularityCommunities<N>(graph: Graph<N>): Community<N>[];
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/algorithms/connectivity.d.ts
|
|
260
|
+
/**
|
|
261
|
+
* Returns bridge edges whose removal disconnects the graph.
|
|
262
|
+
*
|
|
263
|
+
* Connectivity algorithms in this module treat the graph as undirected.
|
|
264
|
+
*/
|
|
265
|
+
declare function getBridges<N, E>(graph: Graph<N, E>): GraphEdge<E>[];
|
|
266
|
+
/**
|
|
267
|
+
* Returns articulation points (cut vertices) for the graph.
|
|
268
|
+
*
|
|
269
|
+
* Connectivity algorithms in this module treat the graph as undirected.
|
|
270
|
+
*/
|
|
271
|
+
declare function getArticulationPoints<N, E>(graph: Graph<N, E>): GraphNode<N>[];
|
|
272
|
+
/**
|
|
273
|
+
* Returns biconnected components as arrays of nodes.
|
|
274
|
+
*
|
|
275
|
+
* Articulation points may appear in multiple returned components.
|
|
276
|
+
*/
|
|
277
|
+
declare function getBiconnectedComponents<N, E>(graph: Graph<N, E>): GraphNode<N>[][];
|
|
278
|
+
//#endregion
|
|
279
|
+
//#region src/algorithms/isomorphism.d.ts
|
|
280
|
+
interface IsomorphismOptions<N = any, E = any> {
|
|
281
|
+
nodeMatch?: (a: GraphNode<N>, b: GraphNode<N>) => boolean;
|
|
282
|
+
edgeMatch?: (a: GraphEdge<E>, b: GraphEdge<E>) => boolean;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Returns whether two graphs are structurally isomorphic.
|
|
286
|
+
*
|
|
287
|
+
* Optional `nodeMatch` and `edgeMatch` predicates can refine the match using
|
|
288
|
+
* node and edge payloads.
|
|
289
|
+
*/
|
|
290
|
+
declare function isIsomorphic<N, E>(graphA: Graph<N, E>, graphB: Graph<N, E>, options?: IsomorphismOptions<N, E>): boolean;
|
|
291
|
+
//#endregion
|
|
292
|
+
//#region src/algorithms/louvain.d.ts
|
|
293
|
+
interface LouvainOptions<E = any> {
|
|
294
|
+
/** Edge weight accessor. Defaults to `edge.weight ?? 1`. */
|
|
295
|
+
getWeight?: (edge: GraphEdge<E>) => number;
|
|
296
|
+
/** Resolution parameter γ. Values > 1 favor smaller communities. Default 1. */
|
|
297
|
+
resolution?: number;
|
|
298
|
+
/** Maximum number of two-phase (local move + aggregation) passes. Default 10. */
|
|
299
|
+
maxPasses?: number;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Returns communities found by the classic two-phase Louvain modularity
|
|
303
|
+
* optimization (local moving + community aggregation).
|
|
304
|
+
*
|
|
305
|
+
* Like the other community algorithms in this library, the graph is treated
|
|
306
|
+
* as undirected regardless of `graph.mode` or per-edge modes. Parallel edges
|
|
307
|
+
* have their weights summed; self-loops contribute to a community's internal
|
|
308
|
+
* weight.
|
|
309
|
+
*
|
|
310
|
+
* The implementation is deterministic: nodes are visited in `graph.nodes`
|
|
311
|
+
* array order and there is no random shuffling, so tie-breaking is
|
|
312
|
+
* order-dependent but stable across runs.
|
|
313
|
+
*
|
|
314
|
+
* Returns communities of node ids, each community sorted lexicographically
|
|
315
|
+
* and communities sorted by their first id.
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* ```ts
|
|
319
|
+
* const communities = getLouvainCommunities(graph);
|
|
320
|
+
* // [['a', 'b', 'c'], ['d', 'e', 'f']]
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
declare function getLouvainCommunities<N, E>(graph: Graph<N, E>, options?: LouvainOptions<E>): string[][];
|
|
324
|
+
//#endregion
|
|
325
|
+
//#region src/algorithms/flow.d.ts
|
|
326
|
+
interface MaxFlowOptions<E = any> {
|
|
327
|
+
/** Source node id. */
|
|
328
|
+
from: string;
|
|
329
|
+
/** Sink node id. */
|
|
330
|
+
to: string;
|
|
331
|
+
/** Edge capacity accessor. Defaults to `edge.weight ?? 1`. */
|
|
332
|
+
getCapacity?: (edge: GraphEdge<E>) => number;
|
|
333
|
+
}
|
|
334
|
+
interface MaxFlowResult<E = any> {
|
|
335
|
+
/** Maximum flow value from source to sink. */
|
|
336
|
+
value: number;
|
|
337
|
+
/** Net flow per edge id (positive means source→target direction). */
|
|
338
|
+
flows: Record<string, number>;
|
|
339
|
+
/** Edges in the minimum cut (max-flow-min-cut theorem). */
|
|
340
|
+
cutEdges: GraphEdge<E>[];
|
|
341
|
+
}
|
|
342
|
+
interface MinCutOptions<E = any> {
|
|
343
|
+
/** Source node id. */
|
|
344
|
+
source: string;
|
|
345
|
+
/** Sink node id. */
|
|
346
|
+
sink: string;
|
|
347
|
+
/** Edge capacity accessor. Defaults to `edge.weight ?? 1`. */
|
|
348
|
+
getCapacity?: (edge: GraphEdge<E>) => number;
|
|
349
|
+
}
|
|
350
|
+
interface MinCutResult {
|
|
351
|
+
/** Total capacity of the cut (equals the max-flow value). */
|
|
352
|
+
value: number;
|
|
353
|
+
/** Ids of the edges crossing the cut. */
|
|
354
|
+
cutEdges: string[];
|
|
355
|
+
/** Node ids on each side of the cut, in `graph.nodes` order. */
|
|
356
|
+
partition: {
|
|
357
|
+
source: string[];
|
|
358
|
+
sink: string[];
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Returns the maximum flow from `from` to `to` using the Edmonds-Karp
|
|
363
|
+
* algorithm (BFS augmenting paths).
|
|
364
|
+
*
|
|
365
|
+
* Directed edges carry capacity from source to target only. Edges whose
|
|
366
|
+
* effective mode is not `'directed'` (undirected/bidirectional) are modeled
|
|
367
|
+
* as two independent opposite arcs, each with the edge's full capacity.
|
|
368
|
+
*
|
|
369
|
+
* The returned `flows` record maps every edge id to its net flow (positive
|
|
370
|
+
* in the source→target direction). `cutEdges` is a minimum s-t cut: the
|
|
371
|
+
* edges crossing from the source side to the sink side of the final
|
|
372
|
+
* residual graph; the sum of their capacities equals `value`.
|
|
373
|
+
*
|
|
374
|
+
* @example
|
|
375
|
+
* ```ts
|
|
376
|
+
* const { value, cutEdges } = getMaxFlow(graph, { from: 's', to: 't' });
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
declare function getMaxFlow<N, E>(graph: Graph<N, E>, options: MaxFlowOptions<E>): MaxFlowResult<E>;
|
|
380
|
+
/**
|
|
381
|
+
* Returns a minimum s-t cut between `source` and `sink` via the max-flow
|
|
382
|
+
* min-cut theorem: runs the same Edmonds-Karp solver as {@link getMaxFlow},
|
|
383
|
+
* then splits the nodes by residual reachability from the source.
|
|
384
|
+
*
|
|
385
|
+
* `partition.source` holds every node reachable from `source` in the final
|
|
386
|
+
* residual graph; `partition.sink` holds the rest (both in `graph.nodes`
|
|
387
|
+
* order). `cutEdges` are the ids of the edges crossing the cut, and their
|
|
388
|
+
* total capacity equals `value` (the max-flow value).
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```ts
|
|
392
|
+
* const { value, cutEdges, partition } = getMinCut(graph, {
|
|
393
|
+
* source: 's',
|
|
394
|
+
* sink: 't',
|
|
395
|
+
* });
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
declare function getMinCut<N, E>(graph: Graph<N, E>, options: MinCutOptions<E>): MinCutResult;
|
|
399
|
+
//#endregion
|
|
400
|
+
//#region src/algorithms/dominators.d.ts
|
|
401
|
+
interface DominatorTreeOptions {
|
|
402
|
+
/**
|
|
403
|
+
* Root node id. Defaults to `graph.initialNodeId`, then to the unique
|
|
404
|
+
* zero-in-degree node.
|
|
405
|
+
*/
|
|
406
|
+
from?: string;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Returns the dominator tree of the graph rooted at `from`, computed with
|
|
410
|
+
* the Cooper–Harvey–Kennedy iterative algorithm.
|
|
411
|
+
*
|
|
412
|
+
* Each reachable node maps to its immediate dominator's id; the root maps
|
|
413
|
+
* to `null`. Unreachable nodes are omitted. Traversal is mode-aware:
|
|
414
|
+
* undirected/bidirectional edges are traversable both ways.
|
|
415
|
+
*
|
|
416
|
+
* For statecharts this answers "which states must every path from the
|
|
417
|
+
* initial state pass through to reach this state?" — node `d` dominates
|
|
418
|
+
* node `n` when every path from the initial state to `n` goes through `d`.
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```ts
|
|
422
|
+
* // a→b, a→c, b→d, c→d (diamond)
|
|
423
|
+
* getDominatorTree(graph, { from: 'a' });
|
|
424
|
+
* // { a: null, b: 'a', c: 'a', d: 'a' }
|
|
425
|
+
* ```
|
|
426
|
+
*/
|
|
427
|
+
declare function getDominatorTree(graph: Graph, options?: DominatorTreeOptions): Record<string, string | null>;
|
|
428
|
+
//#endregion
|
|
429
|
+
//#region src/algorithms/reduction.d.ts
|
|
430
|
+
/**
|
|
431
|
+
* Returns a new graph with all transitively-redundant edges removed (the
|
|
432
|
+
* transitive reduction). The input graph is not mutated; nodes and surviving
|
|
433
|
+
* edges keep all of their fields.
|
|
434
|
+
*
|
|
435
|
+
* An edge u→v is removed when v is also reachable from u via a path of
|
|
436
|
+
* length ≥ 2. Exact-duplicate parallel edges u→v collapse to the first one
|
|
437
|
+
* in `graph.edges` order (a duplicate adds no reachability, so at most one
|
|
438
|
+
* edge per (u, v) pair survives).
|
|
439
|
+
*
|
|
440
|
+
* DAG-only: throws when the graph contains a cycle or any edge whose
|
|
441
|
+
* effective mode is not `'directed'`.
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* ```ts
|
|
445
|
+
* // a→b, b→c, a→c
|
|
446
|
+
* const reduced = getTransitiveReduction(graph);
|
|
447
|
+
* // a→c removed; edges: a→b, b→c
|
|
448
|
+
* ```
|
|
449
|
+
*/
|
|
450
|
+
declare function getTransitiveReduction<N, E, G, P>(graph: Graph<N, E, G, P>): Graph<N, E, G, P>;
|
|
451
|
+
//#endregion
|
|
452
|
+
export { getAllPairsShortestPaths as $, HITSResult as A, getOutDegreeCentrality as B, getModularity as C, getCoreNumbers as D, isBipartite as E, getDegreeCentrality as F, getPostorder as G, getMinimumSpanningTree as H, getEigenvectorCentrality as I, getPreorders as J, getPostorders as K, getHITS as L, KatzCentralityOptions as M, getBetweennessCentrality as N, getKCore as O, getClosenessCentrality as P, getAStarPath as Q, getInDegreeCentrality as R, getLabelPropagationCommunities as S, getMaximumBipartiteMatching as T, genPostorders as U, getPageRank as V, genPreorders as W, genShortestPaths as X, genCycles as Y, genSimplePaths as Z, GirvanNewmanOptions as _, isTree as _t, MaxFlowResult as a, getSimplePaths as at, getGirvanNewmanCommunities as b, getMaxFlow as c, bfs as ct, getLouvainCommunities as d, genDFS as dt, getCycles as et, IsomorphismOptions as f, getConnectedComponents as ft, getBridges as g, isConnected as gt, getBiconnectedComponents as h, isAcyclic as ht, MaxFlowOptions as i, getSimplePath as it, IterativeCentralityOptions as j, EigenvectorCentralityOptions as k, getMinCut as l, dfs as lt, getArticulationPoints as m, hasPath as mt, DominatorTreeOptions as n, getShortestPath as nt, MinCutOptions as o, getStronglyConnectedComponents as ot, isIsomorphic as p, getTopologicalSort as pt, getPreorder as q, getDominatorTree as r, getShortestPaths as rt, MinCutResult as s, joinPaths as st, getTransitiveReduction as t, getJoinedPath as tt, LouvainOptions as u, genBFS as ut, LabelPropagationOptions as v, BipartiteMatch as w, getGreedyModularityCommunities as x, genGirvanNewmanCommunities as y, getKatzCentrality as z };
|