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 have real weights and source . GOLDBERG-RADZIK ends. It returns NEGATIVE-CYCLE if and only if a negative cycle is reachable from . Otherwise it returns for every ( if is not reachable), and for every reachable .
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 (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 is the weight of a walk from , labels never increase, and if no negative cycle is reachable, at all times.
Step 2: the cycle test is sound. The search of line L4 follows only edges with and , and labels do not change during the search. If it closes a cycle with a tense edge, then , and the potentials cancel around the cycle, so . All vertices of have finite labels, so they are reachable from (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 , line L9 marks every vertex whose label drops, and a scan unmarks the vertex. Consequently, if is not labeled at the end of a pass, then for every edge , : at the last scan of the edge was either not tense or relaxed (a vertex removed in line L3 has no tense edge at that moment), and since then has not changed and has not increased.
Step 4: pass property. Assume no negative cycle is reachable from . Let be reachable and let be a shortest path with edges; every prefix is a shortest path. We show by induction on that at the end of pass (or at the start, for ), . For , (it is at least by Step 1 and starts at 0). Suppose it holds for , and consider the moment became , at or before the end of pass . If is scanned after that moment in a pass up to , the scan leaves (either the edge is relaxed, or it is not tense; for a removal in line L3, it is not tense). Otherwise is labeled at the end of pass (Step 3), so it is in at the start of pass . In pass , line L3 either removes it, in which case the edge is not tense and already, or keeps it, in which case it is in and is scanned in pass with the label , which cannot fall further; that scan gives . With Step 1, 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 (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 line L3 removes every vertex of , is empty, and the pass-count test does not fire. So NEGATIVE-CYCLE is never returned, and the loop ends after at most passes (each pass is finite, since the search and the scans are). When it ends, is empty, so no vertex is labeled, and by Step 3 no edge out of a vertex with finite label is tense. Adding along a shortest path gives , so with Step 1. Unreachable vertices are never relaxed and keep . For reachable, was set with at its last drop, when with the then label of , 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 is reachable from . Suppose the loop ends with empty. By Step 3 no edge out of a vertex with finite label is tense. Every vertex on a path from then has a finite label (induction along the path), so around , and adding gives , a contradiction. So the loop does not end with empty. Each pass is finite, so pass is reached unless NEGATIVE-CYCLE is returned earlier; in pass the set is nonempty, and by the same contradiction some vertex of has a tense edge (otherwise line L3 empties , and then is empty and the next is empty). So 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.