Spaces:
Build error
Build error
Download node_modules/dagre-d3-es/src/graphlib/alg/prim.js from Biomimicry-AI/Nexus: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/spaces/Biomimicry-AI/Nexus/resolve/main/node_modules/dagre-d3-es/src/graphlib/alg/prim.js
- Command line
-
hf download hf://spaces/Biomimicry-AI/Nexus/node_modules/dagre-d3-es/src/graphlib/alg/prim.js
-
curl -L -o prim.js https://huggingface.co/spaces/Biomimicry-AI/Nexus/resolve/main/node_modules/dagre-d3-es/src/graphlib/alg/prim.js
1.11 kB
| import * as _ from 'lodash-es'; | |
| import { PriorityQueue } from '../data/priority-queue.js'; | |
| import { Graph } from '../graph.js'; | |
| export { prim }; | |
| function prim(g, weightFunc) { | |
| var result = new Graph(); | |
| var parents = {}; | |
| var pq = new PriorityQueue(); | |
| var v; | |
| function updateNeighbors(edge) { | |
| var w = edge.v === v ? edge.w : edge.v; | |
| var pri = pq.priority(w); | |
| if (pri !== undefined) { | |
| var edgeWeight = weightFunc(edge); | |
| if (edgeWeight < pri) { | |
| parents[w] = v; | |
| pq.decrease(w, edgeWeight); | |
| } | |
| } | |
| } | |
| if (g.nodeCount() === 0) { | |
| return result; | |
| } | |
| _.each(g.nodes(), function (v) { | |
| pq.add(v, Number.POSITIVE_INFINITY); | |
| result.setNode(v); | |
| }); | |
| // Start from an arbitrary node | |
| pq.decrease(g.nodes()[0], 0); | |
| var init = false; | |
| while (pq.size() > 0) { | |
| v = pq.removeMin(); | |
| if (_.has(parents, v)) { | |
| result.setEdge(v, parents[v]); | |
| } else if (init) { | |
| throw new Error('Input graph is not connected: ' + g); | |
| } else { | |
| init = true; | |
| } | |
| g.nodeEdges(v).forEach(updateNeighbors); | |
| } | |
| return result; | |
| } | |