@graphty/algorithms 2.1.1 → 2.2.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 +139 -50
- package/dist/algorithms.js +15260 -10390
- package/dist/algorithms.js.map +1 -1
- package/dist/algorithms.standalone.js +26675 -21542
- package/dist/algorithms.standalone.js.map +1 -1
- package/dist/src/algorithms/centrality/betweenness.d.ts +18 -0
- package/dist/src/algorithms/centrality/betweenness.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/betweenness.js +40 -1
- package/dist/src/algorithms/centrality/betweenness.js.map +1 -1
- package/dist/src/algorithms/centrality/closeness.d.ts +20 -0
- package/dist/src/algorithms/centrality/closeness.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/closeness.js +93 -8
- package/dist/src/algorithms/centrality/closeness.js.map +1 -1
- package/dist/src/algorithms/centrality/degree.d.ts +9 -0
- package/dist/src/algorithms/centrality/degree.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/degree.js +18 -0
- package/dist/src/algorithms/centrality/degree.js.map +1 -1
- package/dist/src/algorithms/centrality/eigenvector.d.ts +10 -0
- package/dist/src/algorithms/centrality/eigenvector.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/eigenvector.js +29 -0
- package/dist/src/algorithms/centrality/eigenvector.js.map +1 -1
- package/dist/src/algorithms/centrality/hits.d.ts +9 -0
- package/dist/src/algorithms/centrality/hits.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/hits.js +23 -0
- package/dist/src/algorithms/centrality/hits.js.map +1 -1
- package/dist/src/algorithms/centrality/katz.d.ts +9 -0
- package/dist/src/algorithms/centrality/katz.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/katz.js +31 -0
- package/dist/src/algorithms/centrality/katz.js.map +1 -1
- package/dist/src/algorithms/centrality/pagerank.d.ts +13 -13
- package/dist/src/algorithms/centrality/pagerank.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/pagerank.js +47 -10
- package/dist/src/algorithms/centrality/pagerank.js.map +1 -1
- package/dist/src/algorithms/community/girvan-newman-legacy.d.ts +27 -0
- package/dist/src/algorithms/community/girvan-newman-legacy.d.ts.map +1 -0
- package/dist/src/algorithms/community/girvan-newman-legacy.js +335 -0
- package/dist/src/algorithms/community/girvan-newman-legacy.js.map +1 -0
- package/dist/src/algorithms/community/girvan-newman.d.ts +5 -3
- package/dist/src/algorithms/community/girvan-newman.d.ts.map +1 -1
- package/dist/src/algorithms/community/girvan-newman.js +34 -308
- package/dist/src/algorithms/community/girvan-newman.js.map +1 -1
- package/dist/src/algorithms/community/label-propagation.d.ts +9 -6
- package/dist/src/algorithms/community/label-propagation.d.ts.map +1 -1
- package/dist/src/algorithms/community/label-propagation.js +24 -110
- package/dist/src/algorithms/community/label-propagation.js.map +1 -1
- package/dist/src/algorithms/components/connected.d.ts.map +1 -1
- package/dist/src/algorithms/components/connected.js +28 -77
- package/dist/src/algorithms/components/connected.js.map +1 -1
- package/dist/src/algorithms/mst/kruskal.d.ts.map +1 -1
- package/dist/src/algorithms/mst/kruskal.js +59 -3
- package/dist/src/algorithms/mst/kruskal.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 +46 -0
- package/dist/src/algorithms/shortest-path/bellman-ford.js.map +1 -1
- package/dist/src/algorithms/shortest-path/dijkstra.d.ts.map +1 -1
- package/dist/src/algorithms/shortest-path/dijkstra.js +27 -0
- package/dist/src/algorithms/shortest-path/dijkstra.js.map +1 -1
- package/dist/src/algorithms/shortest-path/floyd-warshall.d.ts +15 -5
- package/dist/src/algorithms/shortest-path/floyd-warshall.d.ts.map +1 -1
- package/dist/src/algorithms/shortest-path/floyd-warshall.js +97 -107
- package/dist/src/algorithms/shortest-path/floyd-warshall.js.map +1 -1
- package/dist/src/algorithms/traversal/bfs-unified.d.ts +2 -12
- package/dist/src/algorithms/traversal/bfs-unified.d.ts.map +1 -1
- package/dist/src/algorithms/traversal/bfs-unified.js +47 -308
- package/dist/src/algorithms/traversal/bfs-unified.js.map +1 -1
- package/dist/src/algorithms/traversal/bfs-variants.d.ts.map +1 -1
- package/dist/src/algorithms/traversal/bfs-variants.js +5 -25
- package/dist/src/algorithms/traversal/bfs-variants.js.map +1 -1
- package/dist/src/algorithms/traversal/bfs.d.ts +0 -3
- package/dist/src/algorithms/traversal/bfs.d.ts.map +1 -1
- package/dist/src/algorithms/traversal/bfs.js +0 -4
- package/dist/src/algorithms/traversal/bfs.js.map +1 -1
- package/dist/src/algorithms/traversal/dfs.d.ts.map +1 -1
- package/dist/src/algorithms/traversal/dfs.js +33 -154
- package/dist/src/algorithms/traversal/dfs.js.map +1 -1
- package/dist/src/clustering/hierarchical-legacy.d.ts +56 -0
- package/dist/src/clustering/hierarchical-legacy.d.ts.map +1 -0
- package/dist/src/clustering/hierarchical-legacy.js +441 -0
- package/dist/src/clustering/hierarchical-legacy.js.map +1 -0
- package/dist/src/clustering/hierarchical.d.ts +7 -39
- package/dist/src/clustering/hierarchical.d.ts.map +1 -1
- package/dist/src/clustering/hierarchical.js +56 -417
- package/dist/src/clustering/hierarchical.js.map +1 -1
- package/dist/src/clustering/k-core-legacy.d.ts +30 -0
- package/dist/src/clustering/k-core-legacy.d.ts.map +1 -0
- package/dist/src/clustering/k-core-legacy.js +191 -0
- package/dist/src/clustering/k-core-legacy.js.map +1 -0
- package/dist/src/clustering/k-core.d.ts +8 -7
- package/dist/src/clustering/k-core.d.ts.map +1 -1
- package/dist/src/clustering/k-core.js +33 -174
- package/dist/src/clustering/k-core.js.map +1 -1
- package/dist/src/clustering/mcl-legacy.d.ts +42 -0
- package/dist/src/clustering/mcl-legacy.d.ts.map +1 -0
- package/dist/src/clustering/mcl-legacy.js +386 -0
- package/dist/src/clustering/mcl-legacy.js.map +1 -0
- package/dist/src/clustering/mcl.d.ts +9 -32
- package/dist/src/clustering/mcl.d.ts.map +1 -1
- package/dist/src/clustering/mcl.js +48 -374
- package/dist/src/clustering/mcl.js.map +1 -1
- package/dist/src/index.d.ts +29 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/indexed/accelerator.d.ts +141 -11
- package/dist/src/indexed/accelerator.d.ts.map +1 -1
- package/dist/src/indexed/accelerator.js +319 -5
- package/dist/src/indexed/accelerator.js.map +1 -1
- package/dist/src/indexed/all-pairs.d.ts +59 -0
- package/dist/src/indexed/all-pairs.d.ts.map +1 -0
- package/dist/src/indexed/all-pairs.js +274 -0
- package/dist/src/indexed/all-pairs.js.map +1 -0
- package/dist/src/indexed/bellman-ford.d.ts +25 -0
- package/dist/src/indexed/bellman-ford.d.ts.map +1 -0
- package/dist/src/indexed/bellman-ford.js +59 -0
- package/dist/src/indexed/bellman-ford.js.map +1 -0
- package/dist/src/indexed/betweenness.d.ts +85 -0
- package/dist/src/indexed/betweenness.d.ts.map +1 -0
- package/dist/src/indexed/betweenness.js +188 -0
- package/dist/src/indexed/betweenness.js.map +1 -0
- package/dist/src/indexed/bfs.d.ts +69 -2
- package/dist/src/indexed/bfs.d.ts.map +1 -1
- package/dist/src/indexed/bfs.js +148 -1
- package/dist/src/indexed/bfs.js.map +1 -1
- package/dist/src/indexed/bipartite.d.ts +37 -0
- package/dist/src/indexed/bipartite.d.ts.map +1 -0
- package/dist/src/indexed/bipartite.js +54 -0
- package/dist/src/indexed/bipartite.js.map +1 -0
- package/dist/src/indexed/closeness.d.ts +49 -0
- package/dist/src/indexed/closeness.d.ts.map +1 -0
- package/dist/src/indexed/closeness.js +127 -0
- package/dist/src/indexed/closeness.js.map +1 -0
- package/dist/src/indexed/common-neighbors.d.ts +14 -1
- package/dist/src/indexed/common-neighbors.d.ts.map +1 -1
- package/dist/src/indexed/common-neighbors.js +24 -14
- package/dist/src/indexed/common-neighbors.js.map +1 -1
- package/dist/src/indexed/degree.d.ts +19 -0
- package/dist/src/indexed/degree.d.ts.map +1 -0
- package/dist/src/indexed/degree.js +45 -0
- package/dist/src/indexed/degree.js.map +1 -0
- package/dist/src/indexed/delta-pagerank.d.ts +145 -0
- package/dist/src/indexed/delta-pagerank.d.ts.map +1 -0
- package/dist/src/indexed/delta-pagerank.js +428 -0
- package/dist/src/indexed/delta-pagerank.js.map +1 -0
- package/dist/src/indexed/dfs.d.ts +55 -0
- package/dist/src/indexed/dfs.d.ts.map +1 -0
- package/dist/src/indexed/dfs.js +146 -0
- package/dist/src/indexed/dfs.js.map +1 -0
- package/dist/src/indexed/eigenvector.d.ts +48 -0
- package/dist/src/indexed/eigenvector.d.ts.map +1 -0
- package/dist/src/indexed/eigenvector.js +162 -0
- package/dist/src/indexed/eigenvector.js.map +1 -0
- package/dist/src/indexed/facade.d.ts +109 -0
- package/dist/src/indexed/facade.d.ts.map +1 -0
- package/dist/src/indexed/facade.js +204 -0
- package/dist/src/indexed/facade.js.map +1 -0
- package/dist/src/indexed/flow.d.ts +120 -0
- package/dist/src/indexed/flow.d.ts.map +1 -0
- package/dist/src/indexed/flow.js +377 -0
- package/dist/src/indexed/flow.js.map +1 -0
- package/dist/src/indexed/girvan-newman.d.ts +42 -0
- package/dist/src/indexed/girvan-newman.d.ts.map +1 -0
- package/dist/src/indexed/girvan-newman.js +90 -0
- package/dist/src/indexed/girvan-newman.js.map +1 -0
- package/dist/src/indexed/grsbm.d.ts +85 -0
- package/dist/src/indexed/grsbm.d.ts.map +1 -0
- package/dist/src/indexed/grsbm.js +287 -0
- package/dist/src/indexed/grsbm.js.map +1 -0
- package/dist/src/indexed/hierarchical.d.ts +69 -0
- package/dist/src/indexed/hierarchical.d.ts.map +1 -0
- package/dist/src/indexed/hierarchical.js +245 -0
- package/dist/src/indexed/hierarchical.js.map +1 -0
- package/dist/src/indexed/index.d.ts +29 -3
- package/dist/src/indexed/index.d.ts.map +1 -1
- package/dist/src/indexed/index.js +29 -3
- package/dist/src/indexed/index.js.map +1 -1
- package/dist/src/indexed/isomorphism.d.ts +42 -0
- package/dist/src/indexed/isomorphism.d.ts.map +1 -0
- package/dist/src/indexed/isomorphism.js +269 -0
- package/dist/src/indexed/isomorphism.js.map +1 -0
- package/dist/src/indexed/label-propagation.d.ts +134 -0
- package/dist/src/indexed/label-propagation.d.ts.map +1 -0
- package/dist/src/indexed/label-propagation.js +486 -0
- package/dist/src/indexed/label-propagation.js.map +1 -0
- package/dist/src/indexed/leiden.d.ts +52 -0
- package/dist/src/indexed/leiden.d.ts.map +1 -0
- package/dist/src/indexed/leiden.js +384 -0
- package/dist/src/indexed/leiden.js.map +1 -0
- package/dist/src/indexed/link-prediction.d.ts +147 -0
- package/dist/src/indexed/link-prediction.d.ts.map +1 -0
- package/dist/src/indexed/link-prediction.js +317 -0
- package/dist/src/indexed/link-prediction.js.map +1 -0
- package/dist/src/indexed/markov.d.ts +54 -0
- package/dist/src/indexed/markov.d.ts.map +1 -0
- package/dist/src/indexed/markov.js +284 -0
- package/dist/src/indexed/markov.js.map +1 -0
- package/dist/src/indexed/matching.d.ts +53 -0
- package/dist/src/indexed/matching.d.ts.map +1 -0
- package/dist/src/indexed/matching.js +139 -0
- package/dist/src/indexed/matching.js.map +1 -0
- package/dist/src/indexed/min-cut.d.ts +48 -0
- package/dist/src/indexed/min-cut.d.ts.map +1 -0
- package/dist/src/indexed/min-cut.js +175 -0
- package/dist/src/indexed/min-cut.js.map +1 -0
- package/dist/src/indexed/modularity.d.ts +34 -0
- package/dist/src/indexed/modularity.d.ts.map +1 -0
- package/dist/src/indexed/modularity.js +74 -0
- package/dist/src/indexed/modularity.js.map +1 -0
- package/dist/src/indexed/mst.d.ts +29 -1
- package/dist/src/indexed/mst.d.ts.map +1 -1
- package/dist/src/indexed/mst.js +62 -0
- package/dist/src/indexed/mst.js.map +1 -1
- package/dist/src/indexed/pagerank.d.ts +29 -6
- package/dist/src/indexed/pagerank.d.ts.map +1 -1
- package/dist/src/indexed/pagerank.js +107 -11
- package/dist/src/indexed/pagerank.js.map +1 -1
- package/dist/src/indexed/point-to-point.d.ts +53 -0
- package/dist/src/indexed/point-to-point.d.ts.map +1 -0
- package/dist/src/indexed/point-to-point.js +173 -0
- package/dist/src/indexed/point-to-point.js.map +1 -0
- package/dist/src/indexed/scc.d.ts +53 -0
- package/dist/src/indexed/scc.d.ts.map +1 -0
- package/dist/src/indexed/scc.js +110 -0
- package/dist/src/indexed/scc.js.map +1 -0
- package/dist/src/indexed/spectral.d.ts +61 -0
- package/dist/src/indexed/spectral.d.ts.map +1 -0
- package/dist/src/indexed/spectral.js +476 -0
- package/dist/src/indexed/spectral.js.map +1 -0
- package/dist/src/indexed/structures/bit-set.d.ts +45 -0
- package/dist/src/indexed/structures/bit-set.d.ts.map +1 -0
- package/dist/src/indexed/structures/bit-set.js +57 -0
- package/dist/src/indexed/structures/bit-set.js.map +1 -0
- package/dist/src/indexed/structures/max-heap.d.ts +52 -0
- package/dist/src/indexed/structures/max-heap.d.ts.map +1 -0
- package/dist/src/indexed/structures/max-heap.js +66 -0
- package/dist/src/indexed/structures/max-heap.js.map +1 -0
- package/dist/src/indexed/structures/min-heap.d.ts +30 -1
- package/dist/src/indexed/structures/min-heap.d.ts.map +1 -1
- package/dist/src/indexed/structures/min-heap.js +46 -6
- package/dist/src/indexed/structures/min-heap.js.map +1 -1
- package/dist/src/indexed/structures/ring-queue.d.ts +41 -0
- package/dist/src/indexed/structures/ring-queue.d.ts.map +1 -0
- package/dist/src/indexed/structures/ring-queue.js +64 -0
- package/dist/src/indexed/structures/ring-queue.js.map +1 -0
- package/dist/src/indexed/sync.d.ts +50 -0
- package/dist/src/indexed/sync.d.ts.map +1 -0
- package/dist/src/indexed/sync.js +175 -0
- package/dist/src/indexed/sync.js.map +1 -0
- package/dist/src/indexed/terahac.d.ts +58 -0
- package/dist/src/indexed/terahac.d.ts.map +1 -0
- package/dist/src/indexed/terahac.js +244 -0
- package/dist/src/indexed/terahac.js.map +1 -0
- package/dist/src/indexed/to-snapshot.d.ts +45 -2
- package/dist/src/indexed/to-snapshot.d.ts.map +1 -1
- package/dist/src/indexed/to-snapshot.js +140 -6
- package/dist/src/indexed/to-snapshot.js.map +1 -1
- package/dist/src/link-prediction/common-neighbors-legacy.d.ts +71 -0
- package/dist/src/link-prediction/common-neighbors-legacy.d.ts.map +1 -0
- package/dist/src/link-prediction/common-neighbors-legacy.js +172 -0
- package/dist/src/link-prediction/common-neighbors-legacy.js.map +1 -0
- package/dist/src/link-prediction/common-neighbors.d.ts +11 -19
- package/dist/src/link-prediction/common-neighbors.d.ts.map +1 -1
- package/dist/src/link-prediction/common-neighbors.js +56 -123
- package/dist/src/link-prediction/common-neighbors.js.map +1 -1
- package/dist/src/optimized/direction-optimized-bfs.d.ts +6 -0
- package/dist/src/optimized/direction-optimized-bfs.d.ts.map +1 -1
- package/dist/src/optimized/direction-optimized-bfs.js +6 -0
- package/dist/src/optimized/direction-optimized-bfs.js.map +1 -1
- package/dist/src/research/grsbm-legacy.d.ts +82 -0
- package/dist/src/research/grsbm-legacy.d.ts.map +1 -0
- package/dist/src/research/grsbm-legacy.js +416 -0
- package/dist/src/research/grsbm-legacy.js.map +1 -0
- package/dist/src/research/grsbm.d.ts +9 -66
- package/dist/src/research/grsbm.d.ts.map +1 -1
- package/dist/src/research/grsbm.js +67 -391
- package/dist/src/research/grsbm.js.map +1 -1
- package/dist/src/research/sync-legacy.d.ts +48 -0
- package/dist/src/research/sync-legacy.d.ts.map +1 -0
- package/dist/src/research/sync-legacy.js +337 -0
- package/dist/src/research/sync-legacy.js.map +1 -0
- package/dist/src/research/sync.d.ts +10 -32
- package/dist/src/research/sync.d.ts.map +1 -1
- package/dist/src/research/sync.js +28 -316
- package/dist/src/research/sync.js.map +1 -1
- package/package.json +4 -3
- package/src/algorithms/centrality/betweenness.ts +51 -1
- package/src/algorithms/centrality/closeness.ts +112 -12
- package/src/algorithms/centrality/degree.ts +19 -0
- package/src/algorithms/centrality/eigenvector.ts +34 -0
- package/src/algorithms/centrality/hits.ts +24 -0
- package/src/algorithms/centrality/katz.ts +32 -0
- package/src/algorithms/centrality/pagerank.ts +53 -13
- package/src/algorithms/community/girvan-newman-legacy.ts +414 -0
- package/src/algorithms/community/girvan-newman.ts +36 -386
- package/src/algorithms/community/label-propagation.ts +24 -133
- package/src/algorithms/components/connected.ts +28 -95
- package/src/algorithms/mst/kruskal.ts +65 -4
- package/src/algorithms/shortest-path/bellman-ford.ts +49 -0
- package/src/algorithms/shortest-path/dijkstra.ts +29 -0
- package/src/algorithms/shortest-path/floyd-warshall.ts +106 -136
- package/src/algorithms/traversal/bfs-unified.ts +52 -366
- package/src/algorithms/traversal/bfs-variants.ts +5 -28
- package/src/algorithms/traversal/bfs.ts +0 -4
- package/src/algorithms/traversal/dfs.ts +39 -182
- package/src/clustering/hierarchical-legacy.ts +551 -0
- package/src/clustering/hierarchical.ts +64 -520
- package/src/clustering/k-core-legacy.ts +229 -0
- package/src/clustering/k-core.ts +38 -209
- package/src/clustering/mcl-legacy.ts +498 -0
- package/src/clustering/mcl.ts +46 -479
- package/src/index.ts +90 -3
- package/src/indexed/accelerator.ts +502 -16
- package/src/indexed/all-pairs.ts +342 -0
- package/src/indexed/bellman-ford.ts +72 -0
- package/src/indexed/betweenness.ts +258 -0
- package/src/indexed/bfs.ts +189 -3
- package/src/indexed/bipartite.ts +77 -0
- package/src/indexed/closeness.ts +160 -0
- package/src/indexed/common-neighbors.ts +31 -14
- package/src/indexed/degree.ts +55 -0
- package/src/indexed/delta-pagerank.ts +513 -0
- package/src/indexed/dfs.ts +189 -0
- package/src/indexed/eigenvector.ts +202 -0
- package/src/indexed/facade.ts +229 -0
- package/src/indexed/flow.ts +500 -0
- package/src/indexed/girvan-newman.ts +120 -0
- package/src/indexed/grsbm.ts +390 -0
- package/src/indexed/hierarchical.ts +295 -0
- package/src/indexed/index.ts +94 -3
- package/src/indexed/isomorphism.ts +305 -0
- package/src/indexed/label-propagation.ts +582 -0
- package/src/indexed/leiden.ts +436 -0
- package/src/indexed/link-prediction.ts +399 -0
- package/src/indexed/markov.ts +324 -0
- package/src/indexed/matching.ts +192 -0
- package/src/indexed/min-cut.ts +201 -0
- package/src/indexed/modularity.ts +81 -0
- package/src/indexed/mst.ts +79 -1
- package/src/indexed/pagerank.ts +128 -15
- package/src/indexed/point-to-point.ts +220 -0
- package/src/indexed/scc.ts +132 -0
- package/src/indexed/spectral.ts +550 -0
- package/src/indexed/structures/bit-set.ts +65 -0
- package/src/indexed/structures/max-heap.ts +74 -0
- package/src/indexed/structures/min-heap.ts +51 -6
- package/src/indexed/structures/ring-queue.ts +70 -0
- package/src/indexed/sync.ts +229 -0
- package/src/indexed/terahac.ts +290 -0
- package/src/indexed/to-snapshot.ts +156 -6
- package/src/link-prediction/common-neighbors-legacy.ts +252 -0
- package/src/link-prediction/common-neighbors.ts +65 -168
- package/src/optimized/direction-optimized-bfs.ts +6 -1
- package/src/research/grsbm-legacy.ts +586 -0
- package/src/research/grsbm.ts +76 -555
- package/src/research/sync-legacy.ts +456 -0
- package/src/research/sync.ts +30 -431
|
@@ -1,145 +1,135 @@
|
|
|
1
|
+
import { INVALID_INDEX } from "@graphty/graph-format";
|
|
2
|
+
import { allPairsShortestPath } from "../../indexed/all-pairs.js";
|
|
3
|
+
import { exactArcWeights } from "../../indexed/facade.js";
|
|
4
|
+
import { toSnapshot } from "../../indexed/to-snapshot.js";
|
|
1
5
|
/**
|
|
2
|
-
*
|
|
6
|
+
* The graph without its +Infinity edges, which the port refuses and which never shortened a path
|
|
7
|
+
* (`x + Infinity < d` is false), and those edges. A NaN or -Infinity weight has no such reading, so it
|
|
8
|
+
* throws.
|
|
9
|
+
* @param graph - The legacy graph
|
|
10
|
+
* @param name - The calling function, for the error message
|
|
11
|
+
* @returns The graph to run on (the input itself when every weight is finite) and the removed edges,
|
|
12
|
+
* each in both orientations on an undirected graph
|
|
13
|
+
* @throws RangeError on a NaN or -Infinity edge weight
|
|
14
|
+
*/
|
|
15
|
+
function withoutInfinite(graph, name) {
|
|
16
|
+
const removed = [];
|
|
17
|
+
for (const e of graph.edges()) {
|
|
18
|
+
const w = e.weight ?? 1;
|
|
19
|
+
if (Number.isNaN(w) || w === -Infinity) {
|
|
20
|
+
throw new RangeError(`${name}: the edge ${String(e.source)} -> ${String(e.target)} has weight ${String(w)}; weights must be numbers or +Infinity (no edge)`);
|
|
21
|
+
}
|
|
22
|
+
if (w === Infinity) {
|
|
23
|
+
removed.push(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (removed.length === 0) {
|
|
27
|
+
return { finite: graph, removed };
|
|
28
|
+
}
|
|
29
|
+
const finite = graph.clone();
|
|
30
|
+
for (const e of removed) {
|
|
31
|
+
finite.removeEdge(e.source, e.target);
|
|
32
|
+
}
|
|
33
|
+
const reversed = graph.isDirected ? [] : removed.map((e) => ({ ...e, source: e.target, target: e.source }));
|
|
34
|
+
return { finite, removed: [...removed, ...reversed] };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Computes all-pairs shortest paths using the Floyd-Warshall algorithm: the port's sweep in node order
|
|
38
|
+
* over the exact f64 weights, with no node bound. A self-loop never changes a node's distance to itself
|
|
39
|
+
* (0); its predecessor on the diagonal is the node. Under a negative cycle (a negative undirected edge is
|
|
40
|
+
* one) every distance is NaN and every predecessor null. An infinite edge weight counts as no edge
|
|
41
|
+
* (its predecessor entry is its source while nothing reaches the target); a NaN weight leaves its own
|
|
42
|
+
* entry NaN and shortens nothing.
|
|
3
43
|
* @param graph - The graph to compute shortest paths for
|
|
4
44
|
* @returns The distances, predecessors, and negative cycle detection result
|
|
45
|
+
* @throws RangeError on a NaN or -Infinity edge weight
|
|
5
46
|
*/
|
|
6
47
|
export function floydWarshall(graph) {
|
|
7
|
-
const
|
|
48
|
+
const { finite, removed } = withoutInfinite(graph, "floydWarshall");
|
|
49
|
+
const s = toSnapshot(finite);
|
|
50
|
+
const { dist, n, predArc, hasNegativeCycle } = allPairsShortestPath(s, {
|
|
51
|
+
weights: exactArcWeights(s),
|
|
52
|
+
method: "floyd-warshall",
|
|
53
|
+
paths: true,
|
|
54
|
+
maxNodes: Infinity,
|
|
55
|
+
});
|
|
8
56
|
const distances = new Map();
|
|
9
57
|
const predecessors = new Map();
|
|
10
|
-
for (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
nodeDistances.set(other, 0);
|
|
21
|
-
nodePredecessors.set(other, null);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
nodeDistances.set(other, Infinity);
|
|
25
|
-
nodePredecessors.set(other, null);
|
|
26
|
-
}
|
|
58
|
+
for (let i = 0; i < n; i++) {
|
|
59
|
+
const row = new Map();
|
|
60
|
+
const predRow = new Map();
|
|
61
|
+
for (let j = 0; j < n; j++) {
|
|
62
|
+
const id = s.ids.idOf(j);
|
|
63
|
+
row.set(id, dist[i * n + j]);
|
|
64
|
+
const arc = predArc?.[i * n + j];
|
|
65
|
+
predRow.set(id, hasNegativeCycle || arc === undefined || i === j || dist[i * n + j] === Infinity
|
|
66
|
+
? null
|
|
67
|
+
: s.ids.idOf(s.arcSource(arc)));
|
|
27
68
|
}
|
|
69
|
+
distances.set(s.ids.idOf(i), row);
|
|
70
|
+
predecessors.set(s.ids.idOf(i), predRow);
|
|
28
71
|
}
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (sourceDistances && sourcePredecessors) {
|
|
34
|
-
sourceDistances.set(edge.target, weight);
|
|
35
|
-
sourcePredecessors.set(edge.target, edge.source);
|
|
36
|
-
}
|
|
37
|
-
if (!graph.isDirected) {
|
|
38
|
-
const targetDistances = distances.get(edge.target);
|
|
39
|
-
const targetPredecessors = predecessors.get(edge.target);
|
|
40
|
-
if (targetDistances && targetPredecessors) {
|
|
41
|
-
targetDistances.set(edge.source, weight);
|
|
42
|
-
targetPredecessors.set(edge.source, edge.target);
|
|
72
|
+
if (!hasNegativeCycle) {
|
|
73
|
+
for (const e of graph.edges()) {
|
|
74
|
+
if (e.source === e.target) {
|
|
75
|
+
predecessors.get(e.source)?.set(e.source, e.source);
|
|
43
76
|
}
|
|
44
77
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
for (const j of nodes) {
|
|
49
|
-
const distancesI = distances.get(i);
|
|
50
|
-
const distancesK = distances.get(k);
|
|
51
|
-
const predecessorsI = predecessors.get(i);
|
|
52
|
-
const predecessorsK = predecessors.get(k);
|
|
53
|
-
if (!distancesI || !distancesK || !predecessorsI || !predecessorsK) {
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
const distIK = distancesI.get(k);
|
|
57
|
-
const distKJ = distancesK.get(j);
|
|
58
|
-
const distIJ = distancesI.get(j);
|
|
59
|
-
if (distIK === undefined || distKJ === undefined || distIJ === undefined) {
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
if (distIK + distKJ < distIJ) {
|
|
63
|
-
distancesI.set(j, distIK + distKJ);
|
|
64
|
-
const predKJ = predecessorsK.get(j);
|
|
65
|
-
predecessorsI.set(j, predKJ ?? null);
|
|
66
|
-
}
|
|
78
|
+
for (const { source, target } of removed) {
|
|
79
|
+
if (distances.get(source)?.get(target) === Infinity) {
|
|
80
|
+
predecessors.get(source)?.set(target, source);
|
|
67
81
|
}
|
|
68
82
|
}
|
|
69
83
|
}
|
|
70
|
-
|
|
71
|
-
for (const node of nodes) {
|
|
72
|
-
const nodeDistances = distances.get(node);
|
|
73
|
-
if (!nodeDistances) {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
const selfDistance = nodeDistances.get(node);
|
|
77
|
-
if (selfDistance !== undefined && selfDistance < 0) {
|
|
78
|
-
hasNegativeCycle = true;
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
distances,
|
|
84
|
-
predecessors,
|
|
85
|
-
hasNegativeCycle,
|
|
86
|
-
};
|
|
84
|
+
return { distances, predecessors, hasNegativeCycle };
|
|
87
85
|
}
|
|
88
86
|
/**
|
|
89
87
|
* Finds the shortest path between two nodes using Floyd-Warshall
|
|
90
88
|
* @param graph - The graph to search
|
|
91
89
|
* @param source - The starting node for the path
|
|
92
90
|
* @param target - The destination node for the path
|
|
93
|
-
* @returns The path and distance or null if no path exists
|
|
91
|
+
* @returns The path and distance, or null if either node is missing, no path exists, or the graph
|
|
92
|
+
* has a negative cycle
|
|
93
|
+
* @throws RangeError on a NaN or -Infinity edge weight
|
|
94
94
|
*/
|
|
95
95
|
export function floydWarshallPath(graph, source, target) {
|
|
96
|
-
const
|
|
97
|
-
|
|
96
|
+
const s = toSnapshot(withoutInfinite(graph, "floydWarshallPath").finite);
|
|
97
|
+
const i = s.ids.indexOf(source);
|
|
98
|
+
const j = s.ids.indexOf(target);
|
|
99
|
+
if (i === INVALID_INDEX || j === INVALID_INDEX) {
|
|
98
100
|
return null;
|
|
99
101
|
}
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
+
const result = allPairsShortestPath(s, {
|
|
103
|
+
weights: exactArcWeights(s),
|
|
104
|
+
method: "floyd-warshall",
|
|
105
|
+
paths: true,
|
|
106
|
+
maxNodes: Infinity,
|
|
107
|
+
});
|
|
108
|
+
const distance = result.dist[i * result.n + j];
|
|
109
|
+
if (result.hasNegativeCycle || distance === Infinity) {
|
|
102
110
|
return null;
|
|
103
111
|
}
|
|
104
|
-
|
|
105
|
-
if (distance === undefined || distance === Infinity) {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
const path = [];
|
|
109
|
-
let current = target;
|
|
110
|
-
while (current !== null && current !== source) {
|
|
111
|
-
path.unshift(current);
|
|
112
|
-
const sourcePredecessors = result.predecessors.get(source);
|
|
113
|
-
if (!sourcePredecessors) {
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
current = sourcePredecessors.get(current) ?? null;
|
|
117
|
-
if (path.length > graph.nodeCount) {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (current === source) {
|
|
122
|
-
path.unshift(source);
|
|
123
|
-
return { path, distance };
|
|
124
|
-
}
|
|
125
|
-
return null;
|
|
112
|
+
return { path: Array.from(result.pathTo(i, j), (k) => s.ids.idOf(k)), distance };
|
|
126
113
|
}
|
|
127
114
|
/**
|
|
128
|
-
* Computes the transitive closure of a graph
|
|
115
|
+
* Computes the transitive closure of a graph: one breadth-first search per node, edge weights
|
|
116
|
+
* ignored except that a +Infinity edge counts as no edge.
|
|
129
117
|
* @param graph - The graph to compute transitive closure for
|
|
130
|
-
* @returns A map of each node to the set of nodes reachable from it
|
|
118
|
+
* @returns A map of each node to the set of nodes reachable from it, itself included, in node order
|
|
119
|
+
* @throws RangeError on a NaN or -Infinity edge weight
|
|
131
120
|
*/
|
|
132
121
|
export function transitiveClosure(graph) {
|
|
133
|
-
const
|
|
122
|
+
const s = toSnapshot(withoutInfinite(graph, "transitiveClosure").finite);
|
|
123
|
+
const { dist, n } = allPairsShortestPath(s, { weighted: false, maxNodes: Infinity });
|
|
134
124
|
const closure = new Map();
|
|
135
|
-
for (
|
|
125
|
+
for (let i = 0; i < n; i++) {
|
|
136
126
|
const reachable = new Set();
|
|
137
|
-
for (
|
|
138
|
-
if (
|
|
139
|
-
reachable.add(
|
|
127
|
+
for (let j = 0; j < n; j++) {
|
|
128
|
+
if (dist[i * n + j] < Infinity) {
|
|
129
|
+
reachable.add(s.ids.idOf(j));
|
|
140
130
|
}
|
|
141
131
|
}
|
|
142
|
-
closure.set(
|
|
132
|
+
closure.set(s.ids.idOf(i), reachable);
|
|
143
133
|
}
|
|
144
134
|
return closure;
|
|
145
135
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"floyd-warshall.js","sourceRoot":"","sources":["../../../../src/algorithms/shortest-path/floyd-warshall.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"floyd-warshall.js","sourceRoot":"","sources":["../../../../src/algorithms/shortest-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;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAY;IAC1C,MAAM,CAAC,GAAG,UAAU,CAAC,eAAe,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;IACzE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,oBAAoB,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;IACrF,MAAM,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACzB,MAAM,SAAS,GAAG,IAAI,GAAG,EAAU,CAAC;QACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YACzB,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,EAAE,CAAC;gBAC7B,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YACjC,CAAC;QACL,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,OAAO,CAAC;AACnB,CAAC"}
|
|
@@ -2,9 +2,6 @@ import type { Graph } from "../../core/graph.js";
|
|
|
2
2
|
import type { NodeId, ShortestPathResult, TraversalOptions, TraversalResult } from "../../types/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Perform breadth-first search starting from a given node
|
|
5
|
-
*
|
|
6
|
-
* Automatically uses the most optimized implementation based on graph size.
|
|
7
|
-
* No configuration needed - just call this function for the best performance.
|
|
8
5
|
* @param graph - The input graph to traverse
|
|
9
6
|
* @param startNode - The node to start the BFS from
|
|
10
7
|
* @param options - Traversal options (callbacks, target node, etc.)
|
|
@@ -13,8 +10,6 @@ import type { NodeId, ShortestPathResult, TraversalOptions, TraversalResult } fr
|
|
|
13
10
|
export declare function breadthFirstSearch(graph: Graph, startNode: NodeId, options?: TraversalOptions): TraversalResult;
|
|
14
11
|
/**
|
|
15
12
|
* Find shortest path between two nodes using BFS
|
|
16
|
-
*
|
|
17
|
-
* Automatically optimized for large graphs. Returns null if no path exists.
|
|
18
13
|
* @param graph - The input graph to search
|
|
19
14
|
* @param source - The source node ID
|
|
20
15
|
* @param target - The target node ID
|
|
@@ -23,18 +18,13 @@ export declare function breadthFirstSearch(graph: Graph, startNode: NodeId, opti
|
|
|
23
18
|
export declare function shortestPathBFS(graph: Graph, source: NodeId, target: NodeId): ShortestPathResult | null;
|
|
24
19
|
/**
|
|
25
20
|
* Find shortest paths from source to all reachable nodes
|
|
26
|
-
*
|
|
27
|
-
* Automatically optimized for large graphs.
|
|
28
21
|
* @param graph - The input graph to search
|
|
29
22
|
* @param source - The source node ID to compute shortest paths from
|
|
30
|
-
* @returns Map of node IDs to their shortest path results
|
|
23
|
+
* @returns Map of node IDs to their shortest path results, every entry sharing one predecessor map
|
|
31
24
|
*/
|
|
32
25
|
export declare function singleSourceShortestPathBFS(graph: Graph, source: NodeId): Map<NodeId, ShortestPathResult>;
|
|
33
26
|
/**
|
|
34
|
-
* Check if the graph is bipartite
|
|
35
|
-
*
|
|
36
|
-
* Note: This function does not use Direction-Optimized BFS as the
|
|
37
|
-
* coloring logic is specific and doesn't benefit from the optimization.
|
|
27
|
+
* Check if the graph is bipartite
|
|
38
28
|
* @param graph - The undirected graph to check
|
|
39
29
|
* @returns True if the graph is bipartite, false otherwise
|
|
40
30
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bfs-unified.d.ts","sourceRoot":"","sources":["../../../../src/algorithms/traversal/bfs-unified.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bfs-unified.d.ts","sourceRoot":"","sources":["../../../../src/algorithms/traversal/bfs-unified.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAKjD,OAAO,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AA2B1G;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,eAAe,CAiBnH;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI,CAuBvG;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAYzG;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAKjD"}
|