@statelyai/graph 0.8.0 → 0.9.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.
@@ -1,647 +1,2 @@
1
- import { A as TraversalOptions, O as SinglePathOptions, S as MSTOptions, T as PathOptions, _ as GraphNode, n as AllPairsShortestPathsOptions, t as AStarOptions, u as Graph, y as GraphPath } from "./types-BzckPChi.mjs";
2
-
3
- //#region src/algorithms.d.ts
4
-
5
- /**
6
- * Breadth-first traversal generator yielding nodes level by level.
7
- *
8
- * **O(V + E)** time, **O(V)** space.
9
- *
10
- * @example
11
- * ```ts
12
- * import { createGraph, bfs } from '@statelyai/graph';
13
- *
14
- * const graph = createGraph({
15
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
16
- * edges: [{ id: 'ab', sourceId: 'a', targetId: 'b' }, { id: 'bc', sourceId: 'b', targetId: 'c' }],
17
- * });
18
- *
19
- * for (const node of bfs(graph, 'a')) {
20
- * console.log(node.id); // 'a', 'b', 'c'
21
- * }
22
- * ```
23
- */
24
- declare function bfs<N>(graph: Graph<N>, startId: string): Generator<GraphNode<N>>;
25
- /**
26
- * Depth-first traversal generator yielding nodes as visited.
27
- *
28
- * **O(V + E)** time, **O(V)** space.
29
- *
30
- * @example
31
- * ```ts
32
- * import { createGraph, dfs } from '@statelyai/graph';
33
- *
34
- * const graph = createGraph({
35
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
36
- * edges: [{ id: 'ab', sourceId: 'a', targetId: 'b' }, { id: 'bc', sourceId: 'b', targetId: 'c' }],
37
- * });
38
- *
39
- * for (const node of dfs(graph, 'a')) {
40
- * console.log(node.id); // 'a', 'b', 'c'
41
- * }
42
- * ```
43
- */
44
- declare function dfs<N>(graph: Graph<N>, startId: string): Generator<GraphNode<N>>;
45
- /**
46
- * Checks whether the graph contains no cycles.
47
- *
48
- * **O(V + E)** time.
49
- *
50
- * @example
51
- * ```ts
52
- * import { createGraph, isAcyclic } from '@statelyai/graph';
53
- *
54
- * const dag = createGraph({
55
- * nodes: [{ id: 'a' }, { id: 'b' }],
56
- * edges: [{ id: 'ab', sourceId: 'a', targetId: 'b' }],
57
- * });
58
- *
59
- * isAcyclic(dag); // true
60
- * ```
61
- */
62
- declare function isAcyclic(graph: Graph): boolean;
63
- /**
64
- * Returns connected components as arrays of nodes.
65
- * Treats all edges as undirected for connectivity.
66
- *
67
- * **O(V + E)** time.
68
- *
69
- * @example
70
- * ```ts
71
- * import { createGraph, getConnectedComponents } from '@statelyai/graph';
72
- *
73
- * const graph = createGraph({
74
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
75
- * edges: [{ id: 'ab', sourceId: 'a', targetId: 'b' }],
76
- * });
77
- *
78
- * const components = getConnectedComponents(graph);
79
- * // [[nodeA, nodeB], [nodeC]]
80
- * ```
81
- */
82
- declare function getConnectedComponents<N>(graph: Graph<N>): GraphNode<N>[][];
83
- /**
84
- * Returns a topological ordering of nodes, or `null` if the graph is cyclic.
85
- *
86
- * **O(V + E)** time (Kahn's algorithm).
87
- *
88
- * @example
89
- * ```ts
90
- * import { createGraph, getTopologicalSort } from '@statelyai/graph';
91
- *
92
- * const graph = createGraph({
93
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
94
- * edges: [
95
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
96
- * { id: 'bc', sourceId: 'b', targetId: 'c' },
97
- * ],
98
- * });
99
- *
100
- * const sorted = getTopologicalSort(graph);
101
- * // [nodeA, nodeB, nodeC]
102
- * ```
103
- */
104
- declare function getTopologicalSort<N>(graph: Graph<N>): GraphNode<N>[] | null;
105
- /**
106
- * Checks whether a path exists between two nodes.
107
- *
108
- * **O(V + E)** time (BFS) or **O((V + E) log V)** (Dijkstra when weighted).
109
- *
110
- * @example
111
- * ```ts
112
- * import { createGraph, hasPath } from '@statelyai/graph';
113
- *
114
- * const graph = createGraph({
115
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
116
- * edges: [{ id: 'ab', sourceId: 'a', targetId: 'b' }],
117
- * });
118
- *
119
- * hasPath(graph, 'a', 'b'); // true
120
- * hasPath(graph, 'a', 'c'); // false
121
- * ```
122
- */
123
- declare function hasPath(graph: Graph, sourceId: string, targetId: string): boolean;
124
- /**
125
- * Checks whether the graph is connected (all nodes reachable from any node).
126
- *
127
- * **O(V + E)** time.
128
- *
129
- * @example
130
- * ```ts
131
- * import { createGraph, isConnected } from '@statelyai/graph';
132
- *
133
- * const graph = createGraph({
134
- * nodes: [{ id: 'a' }, { id: 'b' }],
135
- * edges: [{ id: 'ab', sourceId: 'a', targetId: 'b' }],
136
- * });
137
- *
138
- * isConnected(graph); // true
139
- * ```
140
- */
141
- declare function isConnected(graph: Graph): boolean;
142
- /**
143
- * Checks whether the graph is a tree (connected and acyclic).
144
- *
145
- * **O(V + E)** time.
146
- *
147
- * @example
148
- * ```ts
149
- * import { createGraph, isTree } from '@statelyai/graph';
150
- *
151
- * const tree = createGraph({
152
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
153
- * edges: [
154
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
155
- * { id: 'ac', sourceId: 'a', targetId: 'c' },
156
- * ],
157
- * });
158
- *
159
- * isTree(tree); // true
160
- * ```
161
- */
162
- declare function isTree(graph: Graph): boolean;
163
- /**
164
- * Lazily yields all shortest paths from a source node.
165
- * Use `getShortestPaths` for the full array.
166
- *
167
- * **O(V + E)** time (BFS) or **O((V + E) log V)** (Dijkstra when weighted),
168
- * plus **O(P)** per path yielded where P is the path length.
169
- *
170
- * @example
171
- * ```ts
172
- * import { createGraph, genShortestPaths } from '@statelyai/graph';
173
- *
174
- * const graph = createGraph({
175
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
176
- * edges: [
177
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
178
- * { id: 'bc', sourceId: 'b', targetId: 'c' },
179
- * ],
180
- * initialNodeId: 'a',
181
- * });
182
- *
183
- * for (const path of genShortestPaths(graph)) {
184
- * console.log(path.steps.map(s => s.node.id));
185
- * }
186
- * ```
187
- */
188
- declare function genShortestPaths<N, E>(graph: Graph<N, E>, opts?: PathOptions<E>): Generator<GraphPath<N, E>>;
189
- /**
190
- * Returns all shortest paths from a source node as an array.
191
- * Delegates to `genShortestPaths` internally.
192
- *
193
- * **O(V + E)** time (BFS) or **O((V + E) log V)** (Dijkstra when weighted).
194
- *
195
- * @example
196
- * ```ts
197
- * import { createGraph, getShortestPaths } from '@statelyai/graph';
198
- *
199
- * const graph = createGraph({
200
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
201
- * edges: [
202
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
203
- * { id: 'bc', sourceId: 'b', targetId: 'c' },
204
- * ],
205
- * initialNodeId: 'a',
206
- * });
207
- *
208
- * const paths = getShortestPaths(graph);
209
- * // paths to 'b' and 'c' from 'a'
210
- * ```
211
- */
212
- declare function getShortestPaths<N, E>(graph: Graph<N, E>, opts?: PathOptions<E>): GraphPath<N, E>[];
213
- /**
214
- * Returns a single shortest path from source to target, or `undefined` if unreachable.
215
- *
216
- * **O(V + E)** time (BFS) or **O((V + E) log V)** (Dijkstra when weighted).
217
- *
218
- * @example
219
- * ```ts
220
- * import { createGraph, getShortestPath } from '@statelyai/graph';
221
- *
222
- * const graph = createGraph({
223
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
224
- * edges: [
225
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
226
- * { id: 'bc', sourceId: 'b', targetId: 'c' },
227
- * ],
228
- * initialNodeId: 'a',
229
- * });
230
- *
231
- * const path = getShortestPath(graph, { to: 'c' });
232
- * // path.steps -> [{node: nodeB, edge: ...}, {node: nodeC, edge: ...}]
233
- * ```
234
- */
235
- declare function getShortestPath<N, E>(graph: Graph<N, E>, opts: SinglePathOptions<E>): GraphPath<N, E> | undefined;
236
- /**
237
- * Returns all simple (acyclic) paths from a source node as an array.
238
- * Delegates to `genSimplePaths` internally.
239
- *
240
- * **O(V!)** worst-case (exponential in dense graphs).
241
- *
242
- * @example
243
- * ```ts
244
- * import { createGraph, getSimplePaths } from '@statelyai/graph';
245
- *
246
- * const graph = createGraph({
247
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
248
- * edges: [
249
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
250
- * { id: 'bc', sourceId: 'b', targetId: 'c' },
251
- * { id: 'ac', sourceId: 'a', targetId: 'c' },
252
- * ],
253
- * initialNodeId: 'a',
254
- * });
255
- *
256
- * const paths = getSimplePaths(graph, { to: 'c' });
257
- * // two paths: a->b->c and a->c
258
- * ```
259
- */
260
- declare function getSimplePaths<N, E>(graph: Graph<N, E>, opts?: PathOptions<E>): GraphPath<N, E>[];
261
- /**
262
- * Lazily yields all simple (acyclic) paths from a source node via DFS backtracking.
263
- * Use `getSimplePaths` for the full array.
264
- *
265
- * **O(V!)** worst-case (exponential in dense graphs).
266
- *
267
- * @example
268
- * ```ts
269
- * import { createGraph, genSimplePaths } from '@statelyai/graph';
270
- *
271
- * const graph = createGraph({
272
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
273
- * edges: [
274
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
275
- * { id: 'bc', sourceId: 'b', targetId: 'c' },
276
- * { id: 'ac', sourceId: 'a', targetId: 'c' },
277
- * ],
278
- * initialNodeId: 'a',
279
- * });
280
- *
281
- * for (const path of genSimplePaths(graph, { to: 'c' })) {
282
- * console.log(path.steps.map(s => s.node.id));
283
- * // ['b', 'c'] or ['c']
284
- * }
285
- * ```
286
- */
287
- declare function genSimplePaths<N, E>(graph: Graph<N, E>, opts?: PathOptions<E>): Generator<GraphPath<N, E>>;
288
- /**
289
- * Returns a single simple (acyclic) path from source to target, or `undefined` if unreachable.
290
- *
291
- * **O(V + E)** typical, **O(V!)** worst-case.
292
- *
293
- * @example
294
- * ```ts
295
- * import { createGraph, getSimplePath } from '@statelyai/graph';
296
- *
297
- * const graph = createGraph({
298
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
299
- * edges: [
300
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
301
- * { id: 'bc', sourceId: 'b', targetId: 'c' },
302
- * ],
303
- * initialNodeId: 'a',
304
- * });
305
- *
306
- * const path = getSimplePath(graph, { to: 'c' });
307
- * // path.steps -> [{node: nodeB, edge: ...}, {node: nodeC, edge: ...}]
308
- * ```
309
- */
310
- declare function getSimplePath<N, E>(graph: Graph<N, E>, opts: SinglePathOptions<E>): GraphPath<N, E> | undefined;
311
- /**
312
- * Returns strongly connected components using Tarjan's algorithm.
313
- * Only meaningful for directed graphs.
314
- *
315
- * **O(V + E)** time.
316
- *
317
- * @example
318
- * ```ts
319
- * import { createGraph, getStronglyConnectedComponents } from '@statelyai/graph';
320
- *
321
- * const graph = createGraph({
322
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
323
- * edges: [
324
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
325
- * { id: 'ba', sourceId: 'b', targetId: 'a' },
326
- * { id: 'bc', sourceId: 'b', targetId: 'c' },
327
- * ],
328
- * });
329
- *
330
- * const sccs = getStronglyConnectedComponents(graph);
331
- * // [[nodeA, nodeB], [nodeC]]
332
- * ```
333
- */
334
- declare function getStronglyConnectedComponents<N>(graph: Graph<N>): GraphNode<N>[][];
335
- /**
336
- * Returns all elementary cycles as an array of paths.
337
- * Delegates to `genCycles` internally.
338
- *
339
- * **O((V + E) · C)** where C is the number of elementary cycles (can be exponential).
340
- *
341
- * @example
342
- * ```ts
343
- * import { createGraph, getCycles } from '@statelyai/graph';
344
- *
345
- * const graph = createGraph({
346
- * nodes: [{ id: 'a' }, { id: 'b' }],
347
- * edges: [
348
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
349
- * { id: 'ba', sourceId: 'b', targetId: 'a' },
350
- * ],
351
- * });
352
- *
353
- * const cycles = getCycles(graph);
354
- * // one cycle: a -> b -> a
355
- * ```
356
- */
357
- declare function getCycles<N, E>(graph: Graph<N, E>): GraphPath<N, E>[];
358
- /**
359
- * Lazily yields elementary cycles one at a time.
360
- * Use `getCycles` for the full array.
361
- *
362
- * **O((V + E) · C)** where C is the number of elementary cycles (can be exponential).
363
- *
364
- * @example
365
- * ```ts
366
- * import { createGraph, genCycles } from '@statelyai/graph';
367
- *
368
- * const graph = createGraph({
369
- * nodes: [{ id: 'a' }, { id: 'b' }],
370
- * edges: [
371
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
372
- * { id: 'ba', sourceId: 'b', targetId: 'a' },
373
- * ],
374
- * });
375
- *
376
- * for (const cycle of genCycles(graph)) {
377
- * console.log(cycle.steps.map(s => s.node.id)); // ['b', 'a']
378
- * }
379
- * ```
380
- */
381
- declare function genCycles<N, E>(graph: Graph<N, E>): Generator<GraphPath<N, E>>;
382
- /**
383
- * Returns a single canonical preorder (DFS visit-order) sequence.
384
- * Visits neighbors in the order they appear in the adjacency list.
385
- *
386
- * **O(V + E)** time.
387
- *
388
- * @example
389
- * ```ts
390
- * import { createGraph, getPreorder } from '@statelyai/graph';
391
- *
392
- * const graph = createGraph({
393
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
394
- * edges: [
395
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
396
- * { id: 'bc', sourceId: 'b', targetId: 'c' },
397
- * ],
398
- * initialNodeId: 'a',
399
- * });
400
- *
401
- * const order = getPreorder(graph);
402
- * // [nodeA, nodeB, nodeC]
403
- * ```
404
- */
405
- declare function getPreorder<N>(graph: Graph<N>, opts?: TraversalOptions): GraphNode<N>[];
406
- /**
407
- * Returns a single canonical postorder (DFS finish-order) sequence.
408
- * Visits neighbors in the order they appear in the adjacency list.
409
- *
410
- * **O(V + E)** time.
411
- *
412
- * @example
413
- * ```ts
414
- * import { createGraph, getPostorder } from '@statelyai/graph';
415
- *
416
- * const graph = createGraph({
417
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
418
- * edges: [
419
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
420
- * { id: 'bc', sourceId: 'b', targetId: 'c' },
421
- * ],
422
- * initialNodeId: 'a',
423
- * });
424
- *
425
- * const order = getPostorder(graph);
426
- * // [nodeC, nodeB, nodeA]
427
- * ```
428
- */
429
- declare function getPostorder<N>(graph: Graph<N>, opts?: TraversalOptions): GraphNode<N>[];
430
- /**
431
- * Returns all possible preorder sequences as an array. Can be exponential -- prefer `genPreorders`.
432
- *
433
- * **O(V! · V)** worst-case (exponential).
434
- *
435
- * @example
436
- * ```ts
437
- * import { createGraph, getPreorders } from '@statelyai/graph';
438
- *
439
- * const graph = createGraph({
440
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
441
- * edges: [
442
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
443
- * { id: 'ac', sourceId: 'a', targetId: 'c' },
444
- * ],
445
- * initialNodeId: 'a',
446
- * });
447
- *
448
- * const allOrders = getPreorders(graph);
449
- * // [[nodeA, nodeB, nodeC], [nodeA, nodeC, nodeB]]
450
- * ```
451
- */
452
- declare function getPreorders<N>(graph: Graph<N>, opts?: TraversalOptions): GraphNode<N>[][];
453
- /**
454
- * Returns all possible postorder sequences as an array. Can be exponential -- prefer `genPostorders`.
455
- *
456
- * **O(V! · V)** worst-case (exponential).
457
- *
458
- * @example
459
- * ```ts
460
- * import { createGraph, getPostorders } from '@statelyai/graph';
461
- *
462
- * const graph = createGraph({
463
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
464
- * edges: [
465
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
466
- * { id: 'ac', sourceId: 'a', targetId: 'c' },
467
- * ],
468
- * initialNodeId: 'a',
469
- * });
470
- *
471
- * const allOrders = getPostorders(graph);
472
- * // [[nodeB, nodeC, nodeA], [nodeC, nodeB, nodeA]]
473
- * ```
474
- */
475
- declare function getPostorders<N>(graph: Graph<N>, opts?: TraversalOptions): GraphNode<N>[][];
476
- /**
477
- * Lazily yields all possible preorder (DFS visit-order) sequences.
478
- * Different neighbor exploration orders yield different sequences.
479
- * Use `getPreorder()` for a single canonical ordering.
480
- *
481
- * **O(V! · V)** worst-case (exponential).
482
- *
483
- * @example
484
- * ```ts
485
- * import { createGraph, genPreorders } from '@statelyai/graph';
486
- *
487
- * const graph = createGraph({
488
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
489
- * edges: [
490
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
491
- * { id: 'ac', sourceId: 'a', targetId: 'c' },
492
- * ],
493
- * initialNodeId: 'a',
494
- * });
495
- *
496
- * for (const order of genPreorders(graph)) {
497
- * console.log(order.map(n => n.id));
498
- * // ['a', 'b', 'c'] or ['a', 'c', 'b']
499
- * }
500
- * ```
501
- */
502
- declare function genPreorders<N>(graph: Graph<N>, opts?: TraversalOptions): Generator<GraphNode<N>[]>;
503
- /**
504
- * Lazily yields all possible postorder (DFS finish-order) sequences.
505
- * Different neighbor exploration orders yield different sequences.
506
- * Use `getPostorder()` for a single canonical ordering.
507
- *
508
- * **O(V! · V)** worst-case (exponential).
509
- *
510
- * @example
511
- * ```ts
512
- * import { createGraph, genPostorders } from '@statelyai/graph';
513
- *
514
- * const graph = createGraph({
515
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
516
- * edges: [
517
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
518
- * { id: 'ac', sourceId: 'a', targetId: 'c' },
519
- * ],
520
- * initialNodeId: 'a',
521
- * });
522
- *
523
- * for (const order of genPostorders(graph)) {
524
- * console.log(order.map(n => n.id));
525
- * // ['b', 'c', 'a'] or ['c', 'b', 'a']
526
- * }
527
- * ```
528
- */
529
- declare function genPostorders<N>(graph: Graph<N>, opts?: TraversalOptions): Generator<GraphNode<N>[]>;
530
- /**
531
- * Returns a minimum spanning tree of the graph.
532
- * Only meaningful for connected undirected graphs (or the component reachable
533
- * from an arbitrary start node in directed graphs).
534
- *
535
- * **O(E log E)** using either edge sorting (Kruskal) or a min-heap (Prim).
536
- *
537
- * @example
538
- * ```ts
539
- * import { createGraph, getMinimumSpanningTree } from '@statelyai/graph';
540
- *
541
- * const graph = createGraph({
542
- * type: 'undirected',
543
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
544
- * edges: [
545
- * { id: 'ab', sourceId: 'a', targetId: 'b', data: { weight: 1 } },
546
- * { id: 'bc', sourceId: 'b', targetId: 'c', data: { weight: 2 } },
547
- * { id: 'ac', sourceId: 'a', targetId: 'c', data: { weight: 3 } },
548
- * ],
549
- * });
550
- *
551
- * const mst = getMinimumSpanningTree(graph, {
552
- * getWeight: (e) => e.data.weight,
553
- * });
554
- * // mst has edges 'ab' and 'bc' (total weight 3)
555
- * ```
556
- */
557
- declare function getMinimumSpanningTree<N, E>(graph: Graph<N, E>, opts?: MSTOptions<E>): Graph<N, E>;
558
- /**
559
- * Returns shortest paths between all pairs of nodes.
560
- * Algorithm 'dijkstra' (default): runs getShortestPaths per source node.
561
- * Algorithm 'floyd-warshall': classic dynamic programming.
562
- *
563
- * **O(V · (V + E) log V)** (Dijkstra) or **O(V³)** (Floyd-Warshall).
564
- *
565
- * @example
566
- * ```ts
567
- * import { createGraph, getAllPairsShortestPaths } from '@statelyai/graph';
568
- *
569
- * const graph = createGraph({
570
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
571
- * edges: [
572
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
573
- * { id: 'bc', sourceId: 'b', targetId: 'c' },
574
- * ],
575
- * });
576
- *
577
- * const allPaths = getAllPairsShortestPaths(graph);
578
- * // paths for every reachable (source, target) pair
579
- * ```
580
- */
581
- declare function getAllPairsShortestPaths<N, E>(graph: Graph<N, E>, opts?: AllPairsShortestPathsOptions<E>): GraphPath<N, E>[];
582
- /**
583
- * Returns a shortest path using A* search with an admissible heuristic.
584
- * More efficient than Dijkstra when a good heuristic is available.
585
- *
586
- * **O((V + E) log V)** time with a good heuristic; degrades to Dijkstra
587
- * with `heuristic: () => 0`.
588
- *
589
- * @example
590
- * ```ts
591
- * import { createGraph, getAStarPath } from '@statelyai/graph';
592
- *
593
- * const graph = createGraph({
594
- * nodes: [
595
- * { id: 'a', x: 0, y: 0 },
596
- * { id: 'b', x: 1, y: 0 },
597
- * { id: 'c', x: 1, y: 1 },
598
- * ],
599
- * edges: [
600
- * { id: 'ab', sourceId: 'a', targetId: 'b', weight: 1 },
601
- * { id: 'bc', sourceId: 'b', targetId: 'c', weight: 1 },
602
- * { id: 'ac', sourceId: 'a', targetId: 'c', weight: 3 },
603
- * ],
604
- * });
605
- *
606
- * const path = getAStarPath(graph, {
607
- * from: 'a',
608
- * to: 'c',
609
- * heuristic: (nodeId) => {
610
- * const node = graph.nodes.find(n => n.id === nodeId)!;
611
- * const target = graph.nodes.find(n => n.id === 'c')!;
612
- * return Math.abs(node.x! - target.x!) + Math.abs(node.y! - target.y!);
613
- * },
614
- * });
615
- * // path: a -> b -> c (weight 2, cheaper than direct a -> c)
616
- * ```
617
- */
618
- declare function getAStarPath<N, E>(graph: Graph<N, E>, opts: AStarOptions<E>): GraphPath<N, E> | undefined;
619
- /**
620
- * Joins two paths end-to-end. The last node of the head path must equal
621
- * the source of the tail path (the overlap node).
622
- *
623
- * Steps are concatenated: head.steps ++ tail.steps (tail already starts
624
- * from the overlap node, so no slicing is needed).
625
- *
626
- * @example
627
- * ```ts
628
- * import { createGraph, getShortestPath, joinPaths } from '@statelyai/graph';
629
- *
630
- * const graph = createGraph({
631
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
632
- * edges: [
633
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
634
- * { id: 'bc', sourceId: 'b', targetId: 'c' },
635
- * ],
636
- * initialNodeId: 'a',
637
- * });
638
- *
639
- * const ab = getShortestPath(graph, { to: 'b' })!;
640
- * const bc = getShortestPath(graph, { from: 'b', to: 'c' })!;
641
- * const ac = joinPaths(ab, bc);
642
- * // ac: a -> b -> c
643
- * ```
644
- */
645
- declare function joinPaths<N, E>(headPath: GraphPath<N, E>, tailPath: GraphPath<N, E>): GraphPath<N, E>;
646
- //#endregion
647
- export { bfs, dfs, genCycles, genPostorders, genPreorders, genShortestPaths, genSimplePaths, getAStarPath, getAllPairsShortestPaths, getConnectedComponents, getCycles, getMinimumSpanningTree, getPostorder, getPostorders, getPreorder, getPreorders, getShortestPath, getShortestPaths, getSimplePath, getSimplePaths, getStronglyConnectedComponents, getTopologicalSort, hasPath, isAcyclic, isConnected, isTree, joinPaths };
1
+ import { A as getArticulationPoints, B as HITSResult, C as hasPath, D as joinPaths, E as isTree, F as genGirvanNewmanCommunities, G as getEigenvectorCentrality, H as getBetweennessCentrality, I as getGirvanNewmanCommunities, J as getOutDegreeCentrality, K as getHITS, L as getGreedyModularityCommunities, M as getBridges, N as GirvanNewmanOptions, O as IsomorphismOptions, P as LabelPropagationOptions, R as getLabelPropagationCommunities, S as getTopologicalSort, T as isConnected, U as getClosenessCentrality, V as IterativeCentralityOptions, W as getDegreeCentrality, Y as getPageRank, _ as getShortestPath, a as genPreorders, b as getSimplePaths, c as getAStarPath, d as getCycles, f as getMinimumSpanningTree, g as getPreorders, h as getPreorder, i as genPostorders, j as getBiconnectedComponents, k as isIsomorphic, l as getAllPairsShortestPaths, m as getPostorders, n as dfs, o as genShortestPaths, p as getPostorder, q as getInDegreeCentrality, r as genCycles, s as genSimplePaths, t as bfs, u as getConnectedComponents, v as getShortestPaths, w as isAcyclic, x as getStronglyConnectedComponents, y as getSimplePath, z as getModularity } from "./algorithms-g2uWmPrb.mjs";
2
+ export { GirvanNewmanOptions, HITSResult, IsomorphismOptions, IterativeCentralityOptions, LabelPropagationOptions, bfs, dfs, genCycles, genGirvanNewmanCommunities, genPostorders, genPreorders, genShortestPaths, genSimplePaths, getAStarPath, getAllPairsShortestPaths, getArticulationPoints, getBetweennessCentrality, getBiconnectedComponents, getBridges, getClosenessCentrality, getConnectedComponents, getCycles, getDegreeCentrality, getEigenvectorCentrality, getGirvanNewmanCommunities, getGreedyModularityCommunities, getHITS, getInDegreeCentrality, getLabelPropagationCommunities, getMinimumSpanningTree, getModularity, getOutDegreeCentrality, getPageRank, getPostorder, getPostorders, getPreorder, getPreorders, getShortestPath, getShortestPaths, getSimplePath, getSimplePaths, getStronglyConnectedComponents, getTopologicalSort, hasPath, isAcyclic, isConnected, isIsomorphic, isTree, joinPaths };
@@ -1,3 +1,3 @@
1
- import { C as hasPath, D as joinPaths, E as isTree, S as getTopologicalSort, T as isConnected, _ as getShortestPath, a as genPreorders, b as getSimplePaths, c as getAStarPath, d as getCycles, f as getMinimumSpanningTree, g as getPreorders, h as getPreorder, i as genPostorders, l as getAllPairsShortestPaths, m as getPostorders, n as dfs, o as genShortestPaths, p as getPostorder, r as genCycles, s as genSimplePaths, t as bfs, u as getConnectedComponents, v as getShortestPaths, w as isAcyclic, x as getStronglyConnectedComponents, y as getSimplePath } from "./algorithms-Pbj9dJB1.mjs";
1
+ import { A as getBiconnectedComponents, B as getEigenvectorCentrality, C as hasPath, D as joinPaths, E as isTree, F as getLabelPropagationCommunities, H as getInDegreeCentrality, I as getModularity, L as getBetweennessCentrality, M as genGirvanNewmanCommunities, N as getGirvanNewmanCommunities, O as isIsomorphic, P as getGreedyModularityCommunities, R as getClosenessCentrality, S as getTopologicalSort, T as isConnected, U as getOutDegreeCentrality, V as getHITS, W as getPageRank, _ as getShortestPath, a as genPreorders, b as getSimplePaths, c as getAStarPath, d as getCycles, f as getMinimumSpanningTree, g as getPreorders, h as getPreorder, i as genPostorders, j as getBridges, k as getArticulationPoints, l as getAllPairsShortestPaths, m as getPostorders, n as dfs, o as genShortestPaths, p as getPostorder, r as genCycles, s as genSimplePaths, t as bfs, u as getConnectedComponents, v as getShortestPaths, w as isAcyclic, x as getStronglyConnectedComponents, y as getSimplePath, z as getDegreeCentrality } from "./algorithms-3xvCxHzo.mjs";
2
2
 
3
- export { bfs, dfs, genCycles, genPostorders, genPreorders, genShortestPaths, genSimplePaths, getAStarPath, getAllPairsShortestPaths, getConnectedComponents, getCycles, getMinimumSpanningTree, getPostorder, getPostorders, getPreorder, getPreorders, getShortestPath, getShortestPaths, getSimplePath, getSimplePaths, getStronglyConnectedComponents, getTopologicalSort, hasPath, isAcyclic, isConnected, isTree, joinPaths };
3
+ export { bfs, dfs, genCycles, genGirvanNewmanCommunities, genPostorders, genPreorders, genShortestPaths, genSimplePaths, getAStarPath, getAllPairsShortestPaths, getArticulationPoints, getBetweennessCentrality, getBiconnectedComponents, getBridges, getClosenessCentrality, getConnectedComponents, getCycles, getDegreeCentrality, getEigenvectorCentrality, getGirvanNewmanCommunities, getGreedyModularityCommunities, getHITS, getInDegreeCentrality, getLabelPropagationCommunities, getMinimumSpanningTree, getModularity, getOutDegreeCentrality, getPageRank, getPostorder, getPostorders, getPreorder, getPreorders, getShortestPath, getShortestPaths, getSimplePath, getSimplePaths, getStronglyConnectedComponents, getTopologicalSort, hasPath, isAcyclic, isConnected, isIsomorphic, isTree, joinPaths };