Keep the original all-to-one orientation of the Bellman inequalities: concerns routes from to a fixed sink , and belongs to the original directed edge . Initialize and for . The synchronous dynamic programming recurrence is
It prepends the first edge of a route instead of appending the last: is the minimum cost of a directed walk from to using at most edges. In particular, improving can improve labels on incoming directed edges . The same original directed edge therefore updates its tail in this convention, whereas single-source edge relaxation updates its head.
If no negative-cost directed cycle can reach , rounds suffice for every distance to , and automatically. This hypothesis concerns directed paths from the cycle to the sink, not paths from the sink to the cycle. In the base example with its original arrows and sink , the distances in order are . Once of weight is added, instead have distance to , while keeps distance and keeps .
More generally, precisely when can reach a negative-cost directed cycle that can reach . Thus the affected vertices are the ancestors of such a directed cycle. A negative-cost directed cycle unable to reach is irrelevant. Reversing all arrows makes a single source, turns these ancestors into descendants, and makes the detection and forward graph search above directly applicable. The right panel of the figure uses that reversal with sink ; its distances to equal the left panel's distances from .
Do not force the root to remain zero outside the hypothesis. Consider the two directed edges of cost and of cost , with sink . The recurrence gives and : the latter records one lap of a negative-cost directed cycle through . Repetition makes both unrestricted distances . Clamping at zero and omitting its update would instead leave the stationary labels , concealing that behaviour. Initialization specifies the cost of the empty directed walk; it does not forbid cheaper nonempty returns to the root. Cycle detection must test every relevant directed edge, including those whose relaxation updates the root.

Articles by others on the same topic (0)

There are currently no matching articles.