// Compute single-source shortest paths with Bellman–Ford
eles.bellmanFord(options?: BellmanFordOptions): BellmanFordResultCompute single-source shortest paths with Bellman–Ford. Unlike dijkstra(), this algorithm supports negative edge weights and reports reachable negative-weight cycles. Undirected, every edge is both arcs, so a negative edge reachable from the root is itself a negative cycle .
| Name | Description |
|---|---|
options: BellmanFordOptions? |
|
Fields of options
| Name | Description |
|---|---|
root: Collection | null? | |
weight: WeightFn? | |
directed: boolean? | |
findNegativeWeightCycles: boolean? |
BellmanFordResultdistance and path accessors, hasNegativeWeightCycle, and negativeWeightCycles (collections describing detected cycles); unreachable nodes have infinite distance and an empty path
Example
const result = eles.bellmanFord({ root: cy.getElementById('a'), weight: edge => edge.data('weight') });console.log(result.distanceTo(cy.getElementById('c'))); // 5if root is missing or does not contain a node