Planning & Search in Rust
Esc

Loading…

↑↓ move ↵ open Esc close
Colour theme
All algorithms

Bellman-Ford

Also known as Bellman-Ford algorithm, STN consistency

validation temporal-control

Bellman-Ford finds shortest paths from one source in a graph whose edge weights can be negative. It relaxes every edge in passes: an edge u → v of weight w lowers the distance of v to d(u) + w when that is smaller. With n vertices, all distances are final after n − 1 passes, so a change in pass n proves a negative cycle (a cycle whose weights add up to less than zero). A simple temporal network (STN) turns each constraint lo ≤ t_j − t_i ≤ hi into two such edges, and it is consistent (some schedule meets every constraint) exactly when this graph has no negative cycle. temporal-control starts all distances at zero and returns either the distances as a valid schedule or the negative cycle as a list of constraint bounds.

Pseudocode

algorithm Bellman-Ford(V, E)input: time points V, distance-graph edges E, each (u, v, w) meaning t_v − t_u ≤ woutput: a schedule that meets every constraint, or a negative cyclefor each v in V dod[v] ← 0                               ▷ a virtual source with a zero edge to every pointpred[v] ← nilfor pass in 1, …, |V| dolast ← nilfor each (u, v, w) in E doif d[u] + w < d[v] thend[v] ← d[u] + wpred[v] ← (u, v, w)last ← vif last = nil thenreturn d                             ▷ consistent: d is a schedulereturn extract-cycle(pred, last)         ▷ a change in pass |V| proves a negative cyclefunction extract-cycle(pred, x)for i in 1, …, |V| dox ← tail(pred[x])                      ▷ after |V| steps back, x lies on the cycleC ← ⟨⟩y ← xrepeatprepend(C, pred[y])y ← tail(pred[y])until y = xreturn C                                 ▷ its constraint bounds add up to less than zero

In the crates

Lineage

Comes from

Nothing on this site.

Led to

FPTAS for constrained shortest path builds on it

Incremental STN consistency builds on it

RUL⁻ builds on it

Papers

  1. On a routing problem Richard Bellman · 1958· Quarterly of Applied Mathematics introduces doi 10.1090/qam/102435
  2. Temporal constraint networks Rina Dechter, Itay Meiri, Judea Pearl · 1991· Artificial Intelligence applies doi 10.1016/0004-3702(91)90006-6