07 Label Correcting Algorithm Rev-1
07 Label Correcting Algorithm Rev-1
A generic algorithm for solving shortest path problems negative costs permitted but no negative cost cycle (at least for now) The use of reduced costs All pair shortest path problem
INPUT G = (N, A) with costs c Node 1 is the source node There is no negative cost cycle We will relax that assumption later
Optimality Conditions
Lemma. Let d*(j) be the shortest path length from node 1 to node j, for each j. Let d( ) be node labels with the following properties: d(j) d(i) + cij for i N for j 1. (1) d(1) = 0. (2) Then d(j) d*(j) for each j. Proof. Let P be any path from node 1 to node j, with length c(P), and suppose P has k arcs. Claim: d(j) c(P). Note: if P is the shortest path from 1 to j, then d(j) c(P) = d*(j), which is what we want to prove.
3
1 P
Optimality Conditions
Theorem. Let d(1), . . . , d(n) satisfy the following properties for a directed graph G = (N,A):
1. d(1) = 0. 2. d(i) is the length of some path from node 1 to node i. 3. d(j) d(i) + cij for all (i,j) A.
Finiteness continued
Proof of Finiteness. At each iteration, d(j) decreases by at least one for some j.
Also d(j) d*(j) > -nC, where C = max (|cij| : (i,j) A).
So, the number of iterations is O(n2C).
Claim: at termination, the distances are all shortest path distances. Proof. At end, d(j) d(i) + cij for all (i,j) A. By the previous theorem, d(j) = d*(j).
More on Finiteness
What happens if data are not required to be integral? The algorithm is still finite, but one needs to use a different proof. What happens if there is a negative cost cycle? The algorithm may no longer be finite. Possibly, d(j) keeps decreasing to - .
But we can stop when d(j) < -nC since this guarantees that there is a negative cost cycle.
10
On computational complexity
Proving finiteness is OK, but .
Can we make the algorithm polynomial time? If so, what is the best running time?
Can we implement it efficiently in practice?
11
Computational issues
Simple Polynomial Time Version (FIFO): We define a pass to consist of scanning all arcs in A, updating distance labels when d(j) > d(i) + cij.
We refer to a pass as performing an update on each arc in A. The algorithm (in this simple version) performs n passes or until no more updates take place, whichever comes first, at which point the algorithm terminates.
12
Theorem. The FIFO label correcting algorithm finds the minimum length path from 1 to j for all j in N in O(nm) steps, or else shows that there is a negative cost cycle. Proof. We want to show that no update takes place in pass n. Let dk(j) be the value d(j) after k passes. Claim dk(j) = d*(j) whenever that shortest path from 1 to j has at most k arcs. It is true for k = 1.
13
Proof. Claim dk(j) = d*(j) whenever that shortest path from 1 to j has at most k arcs.
1
|P| = k-1
15
16
d(j) = d(i) + cij at the end of pass k, and d(i) does not change during pass k.
Create a LIST of nodes j that need to be scanned. Whenever d(j) is decreased, then add j to LIST Major iteration: select a node i from LIST and Procedure Update(i) for each (i, j) A(i) do if d(j) > d(i) + cij then d(j) := d(i) + cij and pred(j) := i and LIST := LIST {j}.
17
18
FIFO Implementation
FIFO. Treat LIST as a Queue. Add nodes to the end of LIST and take nodes from the beginning. LIFO. Treat LIST as a Stack. Add nodes to the top of LIST, and delete the top node of LIST as well. (Efficient in practice, but bad in the worst case.) Theorem. The FIFO modified label correcting algorithm finds the minimum length path from 1 to j for all j in N in O(nm) steps, or else shows that there is a negative cost cycle. Proof. Same as previous theorem.
19
To solve the all pairs shortest path problem we will solve it as one shortest path problem using label correcting n-1 shortest path problems using Dijkstra Technique: transform the problem so that we transform negative arc costs into non-negative costs.
20
Reduced Costs
Suppose that p is any vector of node potentials. p c ij = cij - pi + pj be the reduced cost of arc (i,j) Let For a path P, let c(P) denote the cost (or length) of P. Let cp(P) denote the reduced cost (or length) of P c(P) = (i,j)P cij; cp(P) = (i,j)P c ij
p
2
2 - p4 + p8
8 8
2
2 - p8 + p2
22
5
5 - p2 + pt
t t
22
Proof.
p c ij 0.
0 s
-1
1
1 - ps + p4 4 4
-3
2
2 - p4 + p8 8 8
-5
2
22
-10
5
5 - p2 + pt
23
t t
2 - p8 + p2
25
A Predecessor Graph
Each node except for node 1 has one predecessor. The graph either is an in-tree or it has a directed cycle.
26
A Predecessor Graph
27
A Predecessor Graph
Suppose we Update(4) and pred(4) := 8. Then 4-8-5-4 has negative cost. Prior to Update(4), the following is true: d(5) = d(4) + c45 d(8) = d(5) + c58 d(4) > d(8) + c84
To find negative cost cycles, periodically check the predecessor subgraph to see if it contains a cycle.
28
Summary of Lecture
1. Optimality conditions for the shortest path algorithm. 2. The label correcting algorithm. Excellent in practice. O(nm) in theory, using a FIFO implementation of LIST. 3. All pairs shortest path problem 4. Detecting negative cost cycles.
29