Algorithm Search⌘K

Proofs: Goldberg-Radzik algorithm

These are the human proofs of Goldberg-Radzik algorithm, at full length.

The Goldberg-Radzik algorithm is correct full

This proof shows: correctness, termination.

Claim. Let GG have real weights and source ss. GOLDBERG-RADZIK ends. It returns NEGATIVE-CYCLE if and only if a negative cycle is reachable from ss. Otherwise it returns d[v]=δ(s,v)d[v] = \delta(s, v) for every vv (+∞+\infty if vv is not reachable), and d[v]=d[π[v]]+w(π[v],v)d[v] = d[\pi[v]] + w(\pi[v], v) for every reachable v≠sv \ne s.

A pass is one iteration of the loop of line L2, numbered from 1. A vertex is scanned when lines L7 to L9 handle it, or when line L3 removes it from BB (which also clears its mark).

Step 1: labels are walk weights. Line L9 changes a label only along a tense edge, so the run relaxes tense edges only, as in the generic relaxation method. As there, each finite label d[v]d[v] is the weight of a walk from ss, labels never increase, and if no negative cycle is reachable, d[v]≥δ(s,v)d[v] \ge \delta(s, v) at all times.

Step 2: the cycle test is sound. The search of line L4 follows only edges (u,v)(u, v) with d[u]<∞d[u] < \infty and wd(u,v)≤0w_d(u, v) \le 0, and labels do not change during the search. If it closes a cycle CC with a tense edge, then ∑(u,v)∈Cwd(u,v)<0\sum_{(u, v) \in C} w_d(u, v) < 0, and the potentials cancel around the cycle, so w(C)=∑wd<0w(C) = \sum w_d < 0. All vertices of CC have finite labels, so they are reachable from ss (Step 1). So a reported cycle is a reachable negative cycle. (The implementation checks the lightest of parallel edges, whose reduced cost is at most that of the edge followed, so the same argument applies.)

Step 3: the labeled set. At the end of each pass, a vertex is labeled if and only if its label dropped after its last scan, or it was never scanned and its label is finite. Indeed, line L1 marks ss, line L9 marks every vertex whose label drops, and a scan unmarks the vertex. Consequently, if uu is not labeled at the end of a pass, then for every edge (u,v)(u, v), d[u]+w(u,v)≥d[v]d[u] + w(u, v) \ge d[v]: at the last scan of uu the edge was either not tense or relaxed (a vertex removed in line L3 has no tense edge at that moment), and since then d[u]d[u] has not changed and d[v]d[v] has not increased.

Step 4: pass property. Assume no negative cycle is reachable from ss. Let vv be reachable and let s=p0,p1,…,pk=vs = p_0, p_1, \ldots, p_k = v be a shortest path with k≤n−1k \le n - 1 edges; every prefix is a shortest path. We show by induction on jj that at the end of pass jj (or at the start, for j=0j = 0), d[pj]=δ(s,pj)d[p_j] = \delta(s, p_j). For j=0j = 0, d[s]=0=δ(s,s)d[s] = 0 = \delta(s, s) (it is at least δ(s,s)=0\delta(s, s) = 0 by Step 1 and starts at 0). Suppose it holds for j−1j - 1, and consider the moment d[pj−1]d[p_{j-1}] became δ(s,pj−1)\delta(s, p_{j-1}), at or before the end of pass j−1j - 1. If pj−1p_{j-1} is scanned after that moment in a pass up to j−1j - 1, the scan leaves d[pj]≤δ(s,pj−1)+w(pj−1,pj)=δ(s,pj)d[p_j] \le \delta(s, p_{j-1}) + w(p_{j-1}, p_j) = \delta(s, p_j) (either the edge is relaxed, or it is not tense; for a removal in line L3, it is not tense). Otherwise pj−1p_{j-1} is labeled at the end of pass j−1j - 1 (Step 3), so it is in BB at the start of pass jj. In pass jj, line L3 either removes it, in which case the edge is not tense and d[pj]≤δ(s,pj)d[p_j] \le \delta(s, p_j) already, or keeps it, in which case it is in AA and is scanned in pass jj with the label δ(s,pj−1)\delta(s, p_{j-1}), which cannot fall further; that scan gives d[pj]≤δ(s,pj)d[p_j] \le \delta(s, p_j). With Step 1, d[pj]=δ(s,pj)d[p_j] = \delta(s, p_j) from then on.

Step 5: no negative cycle. Assume no negative cycle is reachable. By Step 2, the cycle test never fires. By Step 4, at the end of pass n−1n - 1 (if the algorithm runs that long) every reachable vertex has its final label, so no edge out of a reachable vertex is tense; at the start of pass nn line L3 removes every vertex of BB, AA is empty, and the pass-count test does not fire. So NEGATIVE-CYCLE is never returned, and the loop ends after at most nn passes (each pass is finite, since the search and the scans are). When it ends, BB is empty, so no vertex is labeled, and by Step 3 no edge out of a vertex with finite label is tense. Adding d[pi+1]≤d[pi]+w(pi,pi+1)d[p_{i+1}] \le d[p_i] + w(p_i, p_{i+1}) along a shortest path gives d[v]≤δ(s,v)d[v] \le \delta(s, v), so d[v]=δ(s,v)d[v] = \delta(s, v) with Step 1. Unreachable vertices are never relaxed and keep ∞\infty. For v≠sv \ne s reachable, π[v]\pi[v] was set with d[v]d[v] at its last drop, when d[v]=d[π[v]]+w(π[v],v)d[v] = d[\pi[v]] + w(\pi[v], v) with the then label of π[v]\pi[v], which is at least the final one; the edge is not tense at the end, so equality holds.

Step 6: a reachable negative cycle is reported. Assume a negative cycle CC is reachable from ss. Suppose the loop ends with BB empty. By Step 3 no edge out of a vertex with finite label is tense. Every vertex on a path from ss then has a finite label (induction along the path), so d[ci+1]≤d[ci]+w(ci,ci+1)d[c_{i+1}] \le d[c_i] + w(c_i, c_{i+1}) around CC, and adding gives 0≤w(C)<00 \le w(C) < 0, a contradiction. So the loop does not end with BB empty. Each pass is finite, so pass nn is reached unless NEGATIVE-CYCLE is returned earlier; in pass nn the set BB is nonempty, and by the same contradiction some vertex of BB has a tense edge (otherwise line L3 empties BB, and then AA is empty and the next BB is empty). So A≠∅A \ne \emptyset and line L5 returns NEGATIVE-CYCLE. With Step 2, the algorithm returns NEGATIVE-CYCLE exactly when a negative cycle is reachable.

Steps 5 and 6 give the claim, and both show termination. ■\blacksquare

Back to Goldberg-Radzik algorithm