GraphIteratorBellmanFord
Guide: /guide/algorithms/graph/iterator-bellman-ford
Signature
ts
const iterator = new GraphIteratorBellmanFord(graph);
createGraphIterator(graph, EnumGraphTraversalType.BELLMAN_FORD);
shortestPath({ graph, from, to, traversalType: EnumGraphTraversalType.BELLMAN_FORD });Params
| Name | Type | Required | Description |
|---|---|---|---|
| graph | IGraph<T> | + | Graph copied at initIterator |
Returns
IGraphIterator<T>
When the path is ready
getPath is available after the walk finishes with no reachable negative cycle. shortestPath drains the iterator and does not stop at the goal. getPath(from, from) is [from] only after that success.
Negative cycles
Any negative cycle reached from the start throws IllegalStateException, including a negative loop when the start is the goal. An entry weight of 1e16 or -1e16 raises that same error, from either vertex on the cycle. A cycle that the walk never reaches does not. The next initIterator may start a new run.