1 / 84

Network Optimization

Network Optimization. Chapter 3 Shortest Path Problems. 3 .1 Shortest paths from a single source. In a weighted digraph , a path of minimum weight from vertex v to vertex w is called a shortest path (SP) from v to w, and its length is called the shortest distance (SD) from v to w.

Download Presentation

Network Optimization

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Network Optimization Chapter 3 Shortest Path Problems

  2. 3.1 Shortest paths from a single source • In a weighted digraph, a path of minimum weight from vertex v to vertex w is called a shortest path (SP) from v to w, and its length is called the shortest distance (SD) from v to w. • For undirected graph, we can define SP and SD between two vertices. • The shortest path problem can be treated as a transshipment problem.

  3. 3.1 Shortest paths from a single source • (a) If we want to find SP and SD from v to w, then: • let v be the only source with a supply of 1 unit; • let w be the only sink with a demand of 1 unit; • let other vertices be intermediate vertices; • let the cost of sending one unit of the commodity from i to j be the weight of the arc (i , j); • we now use the network simplex method to solve this transshipment problem. A 0-1 solution x* will be obtained, and the arcs (i , j) with =1 form a shortest path from v to w.

  4. 3.1 Shortest paths from a single source • (b) if we want to find shortest paths from a given vertex v to each of the other n-1 vertices in the digraph, then: • let v be the only source with a supply of n-1 units; • let every other vertex be a sink with a demand of 1 unit; • let the cost of sending one unit of commodity from i to j be the weight of the arc (i , j); • then the shortest path problem is transformed to a transshipment problem, and hence can be solved by the network simplex method.

  5. 3.1 Shortest paths from a single source • We study other two algorithms: • Dijkstra’s algorithm to find a SP and the SD from a specified vertex to every other vertex; • Floyd and Warshall algorithm for all-pairs shortest path problem.

  6. Main idea about the Dijkstra’s method • Suppose the 5 nearest vertices to v1 are v1,v3,v5,v7 and v9. • Then finding the sixth nearest vertex is easy. • Assume the sixth nearest vertex is v6 and the shortest path is (v1,…v?, v6). • Then v? must be one the 5 nearest vertices. Can you see why?

  7. Another important idea!! • Suppose 1356 is the SP from 1 to 6. Then, for sure, 135 is the SP from 1 to 5. Can you see why? • As a result, to save the SP from 1 to 6, I just need to write down 5 and the SP from 1 to 5.

  8. 3.1 Shortest paths from a single source • Dijkstra’s algorithm • Let the network G = (V, E), V = {1, 2, …, n}, and the weight of the arc (i , j) be a(i , j). • If there is no arc from i to j (i j), then a(i , j) is taken as a large positive number M. • We want to find the SD and SP from vertex 1 to all other vertices.

  9. 3.1 Shortest paths from a single source • In the Dijkstra’s algorithm, each vertex i is assigned a label which is either permanent, or tentative. • The permanent label L(i) of i is the SD from 1 to i; • The tentative label L’(i) of i is an upper bound for the SD from 1 to i. • At each stage of the procedure, V is partitioned to two sets: P and T, whereP is the set of vertices with permanent labels, and T = V \ P is the set of vertices with tentative labels.

  10. 3.1 Shortest paths from a single source • We also need to use an index V(i) to record the vertex immediately before i . This index may be updated after each iteration, and when we complete computation, it shows the vertex immediately before vertex i in the shortest path from vertex 1 to i. • Dijkstra’s algorithm • Step 0 (initial step) • Set L(1) = 0. • Set L’(j) = a(1, j) and V(j)=1 for j = 2, 3, …, n. • Set P = {1}, T = {2, 3, …, n}.

  11. 3.1 Shortest paths from a single source • Step 1 (Designation of a permanent label) • Find kT such that Declare vertex k to be permanently labeled: • Set T = T - k, P = P + k, L(k) = L’(k). • If T = Ø (i.e. P = V), stop; the computation is completed.

  12. 3.1 Shortest paths from a single source • Step 2 (Revision of tentative labels) • Set L’(j) = min {L’(j), L(k) + a(k, j)} for all jT, and if now L’(j) = L(k) + a(k, j), then update V(j) as V(j)=k. • Go to step 1.

  13. Informal steps • L’(1)=0, V’(1)=1, P = {1}, T = {2,…} • For all v in T, L(v)=M, V(v)=1, • For any v is still in T and adjacent to v*, Update L’(v), V’(v) • Find v*, s.t. L’(v*)  L(v), v in T. • L(v*) = L’(v*) and V(v*) = V’(v*) • Move v* from T to P.

  14. 3.1 Shortest paths from a single source • In each step 1 → step 2 → step 1 iteration, a vertex is moved from T to P. • So, we need to have n-1 iterations to complete computation, and for all j=2,3,…n, the indexes V(2), …, V(n) gives us n-1 arcs which together with all n vertices form a subgraph H of G(V, E).

  15. 3.1 Shortest paths from a single source • If there exists a path from vertex 1 to any other vertex, then H must be connected. H is acyclic because if V(k)=i, arc (i, k) is in the shortest path from 1 to k, and i must enter P earlier than k does. • So, H is a spanning tree rooted at vertex1. And H is a shortest distance tree which includes the shortest paths from vertex 1 to other vertices.

  16. 3.1 Shortest paths from a single source • Example 3.1 • Obtain the SD from 1 to the remaining vertices in the directed network shown below, using Dijkstra’s algorithm.

  17. 3.1 Shortest paths from a single source Iteration 1 Step 1. • P = {1} • L(1)=0 T = {2, 3, 4, 5, 6, 7} L’(2) = 4, L’(3) = 6, L’(4) = 8, L’(5) = L’(6) = L’(7) = M. V(2)=V(3)=V(4)=V(5)=V(6)=V(7)=1. Vertex 2 is assigned a permanent label.

  18. 3.1 Shortest paths from a single source Step 2. • P = {1, 2} • L(2) = 4 • Record arc (1,2) T = {3, 4, 5, 6, 7} L’(3) = min {6, L(2) + a(2, 3)}=5 L’(4) = min {8, L(2) + a(2, 4)}=8 L’(5) = min {M, L(2) + a(2, 5)}=11 L’(6) = min {M, L(2) + a(2, 6)}=M L’(7) = min {M, L(2) + a(2, 7)}=M V(3)=2, V(5)=2.

  19. 3.1 Shortest paths from a single source Iteration 2 Step1. • P={1,2} • L(1) = 0 • L(2) = 4 T = {3, 4, 5, 6, 7} Min{L’(i) | i in T}= L’(3) Vertex 3 is assigned a permanent label.

  20. 3.1 Shortest paths from a single source Step 2 • P = {1, 2, 3} • L(3) = 5 T = {4, 5, 6, 7} L’(4) = min {8, L(3) + a(3, 4)}=7 L’(5) = min {11, L(3) + a(3, 5)}=10 L’(6) = min {M, L(3) + a(3, 6)}=9 L’(7) = min {M, L(3) + a(3, 7)}=M V(4)=3, V(5)=3, V(6)=3.

  21. 3.1 Shortest paths from a single source Iteration 3 Step 1. • P = {1, 2, 3} • L(1) = 0 • L(2) = 4 • L(3) = 5 T = {4, 5, 6, 7} Min {L’(i) | i in T} = L’(4) Vertex 4 is assigned a permanent label.

  22. 3.1 Shortest paths from a single source • Step 2 • P = {1, 2, 3, 4} • L(4) = 7 T = {5, 6, 7} L’(5) = min {10, L(4) + a(4, 5)}=10 L’(6) = min {9, L(4) + a(4, 6)}=9 L’(7) = min {M, L(4) + a(4, 7)}=M

  23. 3.1 Shortest paths from a single source Iteration 4 Step 1 • P = {1, 2, 3, 4} • L(1) = 0, • L(2) = 4, • L(3) = 5, • L(4) = 7 T = {5, 6, 7} Min {L’(i) | i in T} =L’(6) Vertex 6 is assigned a permanent label.

  24. 3.1 Shortest paths from a single source Step 2. • P = {1, 2, 3, 4, 6} • L(6) = 9 T = {5, 7} L’(5) = min {10, L(6) + a(6, 5)}=10 L’(7) = min {M, L(6) + a(6, 7)}=17 V(7)=6.

  25. 3.1 Shortest paths from a single source Iteration 5 Step 1 • P = {1, 2, 3, 4, 6} • L(1) = 0, • L(2) = 4, • L(3) = 5, • L(4) = 7, • L(6) = 9 T = {5,7} Min {L’(i) | i in T} = L’(5) Vertex 5 is assigned a permanent label.

  26. 3.1 Shortest paths from a single source Step 2 • P = {1, 2, 3, 4,6, 5} • L(5) = 10 T = {7} L’(7) = min {17, L(5) + a(5, 7)}=16 V(7)=5

  27. 3.1 Shortest paths from a single source Iteration 6 Step 1. • P = {1, 2, 3, 4, 6, 5} • L(1) = 0, L(2) = 4, • L(3) = 5, L(4) = 7, • L(6) = 9, L(5) = 10. T = {7} L’(7) = 16 Vertex 7 gets a permanent label.

  28. 3.1 Shortest paths from a single source • Step 2. • P = {1, 2, 3, 4, 6, 5, 7} • L(7) = 16 T is empty

  29. 3.1 Shortest paths from a single source • Thus L(1) = 0, L(2) = 4, L(3) = 5, L(4) = 7, L(6) = 9, L(5) = 10 and L(7) = 16, giving the SD from 1 to each vertex. • The indexes V(2)=1, V(3)=2, V(4)=3, V(5)=3, V(6)=3, V(7)=5 show that arcs (1, 2), (2, 3), (3, 4), (3, 5), (3, 6) and (5, 7) constitute a shortest distance tree in the given network as shown below, giving the SP from vertex 1 to every other vertex.

  30. 3.1 Shortest paths from a single source • The shortest distance tree: Question: is this a minimum weight spanning tree? No, in MST, (6,5) replaces (3,6)

  31. You answer should consist • Sequence of arcs. (according to the order the arcs are moved to P) • Tree (Draw it!!). • Total weight.

  32. 3.1 Shortest paths from a single source Theorem 3.1 Dijkstra’s algorithm finds the SD from vertex 1 to every other vertex i (i = 2, …, n). Proof.We prove the theorem by induction on the cardinality of P. We will show that for each P generated in the algorithm, (1)for every i P,L(i) is the SD from 1 to i. (2)for every j T, L’(j) is the length of an SP from 1 to j under the restriction that every intermediate vertex is in P.

  33. 3.1 Shortest paths from a single source • First, when |P| = 1, i.e. P = {1}, T = {2, 3, …, n}, the two conclusions hold obviously. • We now show that if conclusions (i) and (ii) are true when |P| = k-1, then they also hold if |P| = k. shore shore

  34. 3.1 Shortest paths from a single source • Without loss of generality, assume P = {1, 2, …, k-1}, T = {k, …, n}. • By the assumption, (i)for i P, L(i) is the SD from 1 to i; (ii)for jT, L’(j) is the SD from 1 to j under the restriction that every intermediate vertex is in P.

  35. 3.1 Shortest paths from a single source • Also assume that in the current iteration, vertex k moves to P, i.e. • So, L(k) = L’(k), and (△)

  36. 3.1 Shortest paths from a single source • We need to show that (i)L(k) is the SD from 1 to k. • If it is not true, let d be the SD from 1 to k. So, d < L(k) = L’(k). As L’(k) is the SD from 1 to k provided that every intermediate vertex of the SP is in P, it means that along any SP from 1 to k, there must be at least one vertex in T. Let v be the first vertex in T along the SP from 1 to k.

  37. 3.1 Shortest paths from a single source • Let the SD from 1 to v be d’. Then d’ = L’(v) and d’d < L’(k). • So, L’(v) < L’(k), which contradicts (*). • Therefore, L(k) must be the SD from 1 to k.

  38. 3.1 Shortest paths from a single source (ii) We need to show that for each j = {k+1, …, n}, ’(j) is the SD from 1 to j under the restriction that all intermediate vertices are in . • Let be the SD from 1 to j when all intermediate vertices are in . The corresponding SP may have two possibilities:

  39. 3.1 Shortest paths from a single source (a) The SP does not go through vertex k. In this case, is the SD from 1 to j under the restriction that every intermediate vertex is in P = {1, …, k-1}. So, = L’(j).

  40. 3.1 Shortest paths from a single source (b)The SP includes vertex k. • In this case, k must be the last vertex before j in the SP. If not, the SP arrives at k, then reaches a qP, and at last comes to j. • It means the shortest path from 1 to qmust pass through k, which is impossiblebecause q enters P before k does, i.e. the SP from 1 to q need not to pass k. • Now since k is the last vertex in the SP before reaching j, the SD from 1 to j must be the SD from 1 to k plus a(k, j): L’(k) + a(k, j).

  41. 3.1 Shortest paths from a single source • Combining the two cases (a) and (b), = min {L’(j), L’(k) +a(k, j)}. • So, by the formula (△),’(j) = , i.e. ’(j) is the SD from 1 to j under the restriction that every intermediate vertex of SP is in . So, the proof is completed. (△)

  42. 3.2 All shortest path algorithm • Let G = (V, A) be a directed network. V = {1, 2, …, n}. • Let auvbe the weight of the arc (u, v). (in the method we allow some negative auv) • We want to calculate the SD from every vertex u to every other vertex v. • We will use The Floyd - Warshall Method

  43. The main idea used • Suppose v5 is the second vertex in the shortest path from v1 to v9. • That is, the shortest path from v1 to v9 is (v1, v5, ???, v9). • Besides, suppose (v5, v6, v7, v8, v9) is the shortest path from v5 to v9. • Then, we can assure the shortest path from v1 to v9 is (v1, v5, v6, v7, v8, v9).

  44. 3.2 All shortest path algorithm • Let A = [auv] be the n n weight matrix; P = [Puv] be the n n matrix with Puv = v, i.e. • The F&W method is an iterative method which needs to have n iterations. In the j-th iteration, we will have two n n matrices A(j) = [auv(j)] and P(j)=[Puv(j)] (j = 1, …, n). A(0)=A and P(0)=P.

  45. 3.2 All shortest path algorithm • In A(j), auv (j) shall be the SD from u to v with intermediate vertices in the vertex set {1, 2, …, j}, and the corresponding element puv(j) in P(j) gives the vertex immediately after u in the path to attain the above SD auv(j).

  46. 3.2 All shortest path algorithm • The algorithm is as follows. • Step 0 Let j = 1, A(0) = A and P(0) = P. • Step 1for all (u,v), If auv (j-1) < auj (j-1) + ajv (j-1),then auv (j) = auv (j-1) and puv(j) = puv (j-1),otherwise auv (j) = auj (j-1) + ajv (j-1) and puv (j) = puj (j-1).

  47. 3.2 All shortest path algorithm • Step 2If in matrix A(j), one diagonal element is negative, stop, the problem has a negative cycle, and some SD from a vertex to another vertex are unbounded. • If j = n, go to step 3; otherwise let j ← j+1 and return to Step 1.

  48. 3.2 All shortest path algorithm • Step 3 Each element auv(n) of the matrix A(n) gives the SD from vertex u to vertex v. • To find the SP from u to v, if puv (n) = j1, then the first arc of the SP is (u, j1). If j1v, we continue by checking pj1v(n). If pj1v(n)=j2, then the second arc is (j1, j2). Repeat the procedure until we reach vertex v. Then the SP is u → j1 → j2 → …. → v.

  49. 3.2 All shortest path algorithm • We use an example to explain the algorithm. • Example 3.2 • Obtain the SD matrix and the SP matrix in the directed network as shown below.

  50. 3.2 All shortest path algorithm • We begin with the following matrices:

More Related