#eles.dijkstra(options)
// Compute single-source shortest paths from a root over this collection's subgraph using Dijkstra's algorithm
eles.dijkstra(options: DijkstraOptions): DijkstraResultCompute single-source shortest paths from a root over this collection's subgraph using Dijkstra's algorithm. The caller is responsible for using non-negative edge weights; the library does not validate the weight function's mathematical properties.
| Name | Description |
|---|---|
options: DijkstraOptions |
|
Fields of options
| Name | Description |
|---|---|
root: Collection | null? | Starting node in this collection; required at runtime. |
weight: WeightFn? | Non-negative edge cost; defaults to 1 for each edge. |
directed: boolean? | Follow outgoing edges only when true; defaults to false. |
DijkstraResult{ distanceTo, pathTo }; an unreachable node has infinite distance and its pathTo() collection contains that node alone. A node outside this subgraph has undefined distance and an empty path.
Example
const result = eles.dijkstra({ root: cy.getElementById('a'), directed: true, weight: edge => edge.data('weight') });console.log(result.distanceTo(cy.getElementById('c'))); // 5if root is missing or is not a node in this collection
#eles.dijkstra(root, weight?, directed?)
// Compute shortest paths with positional arguments
eles.dijkstra(root: Collection, weight?: WeightFn, directed?: boolean): DijkstraResultCompute shortest paths with positional arguments. Use non-negative weights.
| Name | Description |
|---|---|
root: Collection | a node in this collection |
weight: WeightFn? | the edge cost function; defaults to a cost of 1 |
directed: boolean? | true to follow outgoing edges only; defaults to false |
DijkstraResultshortest-path distanceTo() and pathTo() functions; unreachable nodes have infinite distance, nodes outside this subgraph have undefined distance
Example
const result = eles.dijkstra(cy.getElementById('a'), edge => edge.data('weight'), true);console.log(result.distanceTo(cy.getElementById('c'))); // 5if root is missing or is not a node in this collection