Skip to content

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 ​

NameTypeRequiredDescription
graphIGraph<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.

Throws ​

IsNotFoundException when the start, or a path vertex, is not in the snapshot ​

IllegalArgumentException when a weight is not finite, or a sum overflows or is not exact. Later calls keep failing until initIterator ​

IllegalStateException when the search is unfinished, the goal was not reached, or a reachable negative cycle exists ​

MIT Licensed