Network Optimization

of 84 /84
1 Network Optimization Chapter 3 Shortest Path Problems

Embed Size (px)

description

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. - PowerPoint PPT Presentation

Transcript of Network Optimization

  • Network OptimizationChapter 3Shortest 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.For undirected graph, we can define SP and SD between two vertices.The shortest path problem can be treated as a transshipment problem.

  • 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.

  • 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.

  • 3.1 Shortest paths from a single sourceWe study other two algorithms:Dijkstras 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.

  • Main idea about the Dijkstras 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?

  • 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.

  • 3.1 Shortest paths from a single sourceDijkstras algorithmLet 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.

  • 3.1 Shortest paths from a single sourceIn the Dijkstras 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, where P is the set of vertices with permanent labels, and T = V \ P is the set of vertices with tentative labels.

  • 3.1 Shortest paths from a single sourceWe 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. Dijkstras algorithmStep 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}.

  • 3.1 Shortest paths from a single sourceStep 1 (Designation of a permanent label)Find k T 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.

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

  • Informal stepsL(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.

  • 3.1 Shortest paths from a single sourceIn 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).

  • 3.1 Shortest paths from a single sourceIf 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 vertex 1. And H is a shortest distance tree which includes the shortest paths from vertex 1 to other vertices.

  • 3.1 Shortest paths from a single sourceExample 3.1Obtain the SD from 1 to the remaining vertices in the directed network shown below, using Dijkstras algorithm.

  • 3.1 Shortest paths from a single sourceIteration 1Step 1.P = {1}L(1)=0T = {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.

  • 3.1 Shortest paths from a single sourceStep 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)}=5L(4) = min {8, L(2) + a(2, 4)}=8L(5) = min {M, L(2) + a(2, 5)}=11L(6) = min {M, L(2) + a(2, 6)}=ML(7) = min {M, L(2) + a(2, 7)}=MV(3)=2, V(5)=2.

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

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

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

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

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

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

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

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

  • 3.1 Shortest paths from a single sourceIteration 6Step 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) = 16Vertex 7 gets a permanent label.

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

  • 3.1 Shortest paths from a single sourceThus 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.

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

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

  • 3.1 Shortest paths from a single source Theorem 3.1 Dijkstras 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.

  • 3.1 Shortest paths from a single sourceFirst, 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

  • 3.1 Shortest paths from a single sourceWithout 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 j T, L(j) is the SD from 1 to j under the restriction that every intermediate vertex is in P.

  • 3.1 Shortest paths from a single sourceAlso assume that in the current iteration, vertex k moves to P, i.e.

    So, L(k) = L(k), and ()

  • 3.1 Shortest paths from a single sourceWe 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.

  • 3.1 Shortest paths from a single sourceLet 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.

  • 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:

  • 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).

  • 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 q P, and at last comes to j. It means the shortest path from 1 to q must pass through k, which is impossible because 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).

  • 3.1 Shortest paths from a single sourceCombining 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. ()

  • 3.2 All shortest path algorithmLet G = (V, A) be a directed network. V = {1, 2, , n}.Let auv be 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

  • The main idea usedSuppose 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).

  • 3.2 All shortest path algorithmLet 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.

  • 3.2 All shortest path algorithmIn 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).

  • 3.2 All shortest path algorithmThe algorithm is as follows.Step 0Let 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).

  • 3.2 All shortest path algorithmStep 2 If 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.

  • 3.2 All shortest path algorithmStep 3Each 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 j1 v, 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.

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

  • 3.2 All shortest path algorithmWe begin with the following matrices:

  • 3.2 All shortest path algorithm Iteration 1, based on vertex 1 (j = 1) at the end of the first iteration we have the following matrices:

  • 3.2 All shortest path algorithmMatrix A(1) is obtained from A(0) by the following triangle operation:Draw two lines on row k and column k respectively (here k=1, and when we calculate A(2), k=2, ).In A(0), for each element which is neither in row k, nor in column k, find its two projections on the two lines. For example for element , its two projections are and respectively.Compare the sum of the two values at the projections with the value at the element. (e.g., compare with ). Then we use the rule in the F-W method to obtain A(1) and P(1).

  • 3.2 All shortest path algorithm Iteration 2, based on vertex 2 (j=2)It begins with A(1) and P(1). The triangle operations are carried out as in the previous operation (but now k=2) at this stage the auv(2) = min{auv(1), au2(1) + a2v(1)}. At the end of this iteration we have the following matrices:

  • 3.2 All shortest path algorithmIteration 2, based on vertex 2 (j=2)

  • 3.2 All shortest path algorithm Iteration 3, based at vertex 3 (j=3)It begins with A(2) and P(2). Applying the triangle operation (let k=3), we obtain the following matrices:

  • 3.2 All shortest path algorithm Iteration 4, based on vertex 4 (j=4)It begins with A(3) and P(3). Applying the triangle operation (let k=4) , we get the following matrices:

  • 3.2 All shortest path algorithmAt this stage we have the SD from every vertex to every other vertex in the network, which can be obtained readily from A(4).The various shortest paths are obtained as follows:From 1 to 2: p12(4)=2. So the SP is 12, i.e., the arc (1, 2).From 1 to 3: p13(4) = 3. So the SP from 1 to 3 is the arc (1, 3).

  • 3.2 All shortest path algorithmFrom 1 to 4: p14(4) = 3. So take the arc (1, 3) and join it to the SP from 3 to 4. We have p34 (4) = 4. So the SP from 3 to 4 is the arc (3, 4). Thus the SP is 134.From 2 to 1: the SP is the arc (2, 1).From 2 to 3: the SP is the arc (2, 3).From 2 to 4: the SP is 234.From 3 to 1: the SP is 3421.From 3 to 2: the SP is 342.From 3 to 4: the SP is the arc (3, 4).From 4 to 1: the SP is 421.From 4 to 2: the SP is the arc (4, 2).From 4 to 3: the SP is 423.

  • 3.2 All shortest path algorithmLocating negative cyclesConsider a network for which the weight matrix is as follows:

  • 3.2 All shortest path algorithmAt the end of the second iteration we have the following matrices:

  • 3.2 All shortest path algorithmIn A(2), the diagonal element a44(2)= -1
  • 3.2 All shortest path algorithmTheorem 3.2 If the network contains no negative cycle, then in using the Floyd-Warshall algorithm, auv(n), the (u, v)th element in A(n), is equal to the SD from u to v. Proof Suppose the algorithm works until obtaining A(n) and P(n), and there is no negative cycle.

  • 3.2 All shortest path algorithmWe use the induction method to show that for j =1, , n, auv(j) is the SD from u to v with each intermediate vertex w j.For j=1, as auv(1)= ,

    obviously auv(1) is the SD from u to v if only vertex 1 can be a possible intermediate vertex.

  • 3.2 All shortest path algorithmSuppose auv(j-1) is the SD from u to v with each intermediate vertex w j-1. Let Quv(j) be the SP from u to v with every intermediate vertex w j.It has two possibilities: (1) Quv(j) does not take j as an intermediate vertex. Then Quv(j) = Quv(j-1) and hence auv(j) = auv(j-1).(a)

  • 3.2 All shortest path algorithm(2) Quv(j) has vertex j as an intermediate vertex.

    Then the part of Quv(j) from u to j must be the SP from u to j with every intermediate vertex w j-1, i.e., it is Quj(j-1), and the part of Quv(j) from j to v must be Qjv(j-1). So, auv(j) = auj(j-1) + ajv(j-1).(b)

  • 3.2 All shortest path algorithmCombining (a) and (b), we know that the SD from u to v with each intermediate vertex w j is auv(j) = min{auv(j-1), auj(j-1) + ajv(j-1)}, which is just the formula in step 1.Therefore we proved that the conclusion is true for j, and the induction proof is completed.

  • 3.2 All shortest path algorithmAn exercise for F-W method. For the network shown on the next page, when we use F-W method to obtain all pairs of shortest distances, the final matrices A(6) and P(6) are:

  • 3.2 All shortest path algorithmGraph of the exercise

  • 3.2 All shortest path algorithma. Using matrix P(6), show the shortest paths from vertex 3 to all other vertices and the shortest paths from vertex 4 to all other vertices.b. Using matrix A(6) to verify your answer for question a.

  • 3.3 Medians and centersLocation ProblemIn a network, we need to find a vertex such that the distances to other vertices meet some optimality criterion.Suppose G=(V,E), V = {1, 2, n}. The following two criteria (Minsum Problems & Minmax Problems) are often used.

  • 3.3 Medians and centers1. Minsum ProblemsFind a vertex j such that the sum of the distances from j to all other vertices is as small as possible.Let d(j, k) be the shortest distance from j to k ( d( j, j )=0 ), then the Minsum problem is

  • 3.3 Medians and centersThis problem is also called l1 norm location problem as for the non-negative vector dj = (d (j,1), d (j,2), , d (j,n)), the l1 norm ||dj||1 = , (if all d(j,k) are non-negative) and the location problem is to find

  • 3.3 Medians and centersOnce we obtain the n n shortest distance matrix D = [d(i, k)] (for example by the F-W method), it is easy to solve the minsum location problem:let then the best location is the vertex j such that .The vertex j is also called a median (vertex).

  • 3.3 Medians and centersFor example:S1=21S2=19S3=15S4=15 S5=11S6=17

    median vertex

  • 3.3 Medians and centers2. Minmax problemsFind a vertex j such that the distance from j to the farthest vertex is minimized, i.e. to solve the problem:The vertex j is also called a center (vertex).

  • 3.3 Medians and centersThis is also called the norm location problem, because = Max (d (j, 1), d (j, 2), , d (j, n))(if all d(j,k) are non-negative) and we want to find

  • 3.3 Medians and centersThe Minmax location problem can also be solved easily once we obtain the all pair SD matrix D=[d(i, k)]. For each row i, let Then the best location for the minmax problem is vertex j such that

  • 3.3 Medians and centersFor example:e1=6e2=6e3=4e4=5e5=4e6=5center vertexcentervertex

  • 3.3 Medians and centersIt depends on different purposes to choose Minsum or Minmax criterion. For example, a delivery company which transports goods to all vertices may use the Minsum criterion. A fire station may use the Minmax criterion to decide its place.

  • Use NETSOLVE to calculate shortest pathsSpecify directed or undirected graph by typing D or U to answer the question by NETSOLVE, depending on the particular problem.No node data required.Need to enter edge (arc) data. Enter the two node names and the weight of the edge (arc).

  • Use NETSOLVE to calculate shortest pathsNETSOLVE can calculate 4 types of shortest paths.Type 1: from a given source vertex (say 2) to a given destination vertex (say 5).Command: SPATH 2 5Type 2: from a given source vertex (say 1) to all other vertices.Command: SPATH 1 *

  • Use NETSOLVE to calculate shortest pathsType 3: from all vertices to a given destination vertex (say 3).Command: SPATH * 3Type 2: from any vertex to all other vertices.Command: SPATH * *

  • Use NETSOLVE to calculate shortest pathsExample. For the network shown below, calculate all pairs of shortest paths

  • Use NETSOLVE to calculate shortest pathsNeed to enter edge data:1 2 2 4 5 3 | Then type:1 4 2 5 4 1 | SPATH * *1 6 6 5 6 1 | You may see the 2 1 4 6 3 3 | result of SD & SP2 3 4 6 5 2 | from every vertex 3 2 3 | i to any other 3 6 1 | vertex j4 2 1 |