Edge relaxation tests whether extending a recorded route by one directed edge improves a tentative distance. For a single source and an original directed edge of weight , form the candidate . If is finite and , replace by and record the shortest-path predecessor . Otherwise leave both unchanged. The minimum formula in the header gives the resulting label in either case. The authored implementation uses this strict comparison and records the incoming directed edge.[ref]
https://raw.githubusercontent.com/kevin-wayne/algs4/master/src/main/java/edu/princeton/cs/algs4/DijkstraSP.java. Sedgewick and Wayne, DijkstraSP.java, relax method
The table lists labels after each specified operation, keeping throughout this constructed acyclic graph. Relaxing first offers . Relaxing then offers , lowering from to ; revisiting now offers . Finally offers , so the label stays. Changing a label can make a previously checked outgoing directed edge worth checking again. This trace illustrates the operation itself, with a deliberately specified order, rather than a run of the Dijkstra algorithm.
A single edge relaxation does not require nonnegative weights: its candidate is the cost of a real extended directed walk, even when the last directed edge has negative weight. Nonnegative weights are needed by the Dijkstra algorithm to make its selected minimum tentative distance permanent. The Bellman-Ford algorithm permits negative weights and revisits labels; its authored implementation also checks for reachable negative-cost directed cycles.[ref]
https://raw.githubusercontent.com/kevin-wayne/algs4/master/src/main/java/edu/princeton/cs/algs4/DijkstraSP.java. Sedgewick and Wayne, DijkstraSP.java, nonnegative-weight precondition
[ref]https://raw.githubusercontent.com/kevin-wayne/algs4/master/src/main/java/edu/princeton/cs/algs4/BellmanFordSP.java. Sedgewick and Wayne, BellmanFordSP.java, signed weights and cycle detection
For the all-to-one convention of the Bellman inequalities, relax the same original directed edge by . This prepends to a discovered route from to , and improves the tail label , not the head label . Skip the operation when . In exact arithmetic, a full pass over all relevant directed edges with no improvement establishes all their Bellman inequalities; combined with the discovered-route upper bounds, this certifies finite distances. One unsuccessful operation establishes only that this particular candidate did not improve its label at that moment.
Articles by others on the same topic
There are currently no matching articles.
