1 Network Optimization Chapter 3 Shortest Path Problems.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Graph Theory Arnold Mesa. Basic Concepts n A graph G = (V,E) is defined by a set of vertices and edges v3 v1 v2Vertex (v1) Edge (e1) A Graph with 3 vertices.
Divide and Conquer. Subject Series-Parallel Digraphs Planarity testing.
Introduction to Algorithms
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Chapter 5 Shortest Paths: Label-Correcting Algorithms
Data Structures Using C++
Combinatorial Algorithms
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Applied Discrete Mathematics Week 12: Trees
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
TCOM 501: Networking Theory & Fundamentals
Algorithms All pairs shortest path
Tirgul 13. Unweighted Graphs Wishful Thinking – you decide to go to work on your sun-tan in ‘ Hatzuk ’ beach in Tel-Aviv. Therefore, you take your swimming.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Discrete Math for CS Chapter 8: Directed Graphs. Discrete Math for CS digraph: A digraph is a graph G = (V,E) where V is a finite set of vertices and.
Network Simplex Method Fatme Elmoukaddem Jignesh Patel Martin Porcelli.
The Shortest Path Problem
CS 473 All Pairs Shortest Paths1 CS473 – Algorithms I All Pairs Shortest Paths.
Minimum Spanning Trees. Subgraph A graph G is a subgraph of graph H if –The vertices of G are a subset of the vertices of H, and –The edges of G are a.
1 1 Slide © 2000 South-Western College Publishing/ITP Slides Prepared by JOHN LOUCKS.
NetworkModel-1 Network Optimization Models. NetworkModel-2 Network Terminology A network consists of a set of nodes and arcs. The arcs may have some flow.
TECH Computer Science Graph Optimization Problems and Greedy Algorithms Greedy Algorithms  // Make the best choice now! Optimization Problems  Minimizing.
More Graph Algorithms 15 April Applications of Graphs Graph theory is used in dealing with problems which have a fairly natural graph/network.
Chapter 4 Shortest Path Label-Setting Algorithms Introduction & Assumptions Applications Dijkstra’s Algorithm.
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Operations Research Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD4207 University of Palestine.
Lecture 12-2: Introduction to Computer Algorithms beyond Search & Sort.
Chapter 2 Graph Algorithms.
COSC 2007 Data Structures II Chapter 14 Graphs III.
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
TCP Traffic and Congestion Control in ATM Networks
CSCI 115 Chapter 7 Trees. CSCI 115 §7.1 Trees §7.1 – Trees TREE –Let T be a relation on a set A. T is a tree if there exists a vertex v 0 in A s.t. there.
1 CS104 : Discrete Structures Chapter V Graph Theory.
Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph. Want to compute a shortest path for each possible.
1 The Floyd-Warshall Algorithm Andreas Klappenecker.
1 1 © 2003 Thomson  /South-Western Slide Slides Prepared by JOHN S. LOUCKS St. Edward’s University.
Introduction to Graph Theory
Chapter 4 Minimum Cost Flow Problems (MCF)
Chapter 10 Graph Theory Eulerian Cycle and the property of graph theory 10.3 The important property of graph theory and its representation 10.4.
COSC 2007 Data Structures II Chapter 14 Graphs I.
1 Network Models Transportation Problem (TP) Distributing any commodity from any group of supply centers, called sources, to any group of receiving.
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
Chapter 8 Network Models to accompany Operations Research: Applications and Algorithms 4th edition by Wayne L. Winston Copyright (c) 2004 Brooks/Cole,
Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘length’ c ij (cost, time, distance, …). Determine a path of shortest.
12. Lecture WS 2012/13Bioinformatics III1 V12 Menger’s theorem Borrowing terminology from operations research consider certain primal-dual pairs of optimization.
Iterative Improvement for Domain-Specific Problems Lecturer: Jing Liu Homepage:
Approximation Algorithms by bounding the OPT Instructor Neelima Gupta
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
Tuesday, March 19 The Network Simplex Method for Solving the Minimum Cost Flow Problem Handouts: Lecture Notes Warning: there is a lot to the network.
Proof of correctness of Dijkstra’s algorithm: Basically, we need to prove two claims. (1)Let S be the set of vertices for which the shortest path from.
1 1 Slide © 2005 Thomson/South-Western Chapter 9 Network Models n Shortest-Route Problem n Minimal Spanning Tree Problem n Maximal Flow Problem.
St. Edward’s University
The minimum cost flow problem
Algorithms and Networks
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
EMIS 8374 Dijkstra’s Algorithm Updated 18 February 2008
Autumn 2016 Lecture 11 Minimum Spanning Trees (Part II)
Autumn 2015 Lecture 11 Minimum Spanning Trees (Part II)
Minimum Spanning Tree Algorithms
Chapter 5 Transportation, Assignment, and Transshipment Problems
Algorithms (2IL15) – Lecture 7
Algorithms and Networks
Advanced Algorithms Analysis and Design
Winter 2019 Lecture 11 Minimum Spanning Trees (Part II)
Agenda Review Lecture Content: Shortest Path Algorithm
Autumn 2019 Lecture 11 Minimum Spanning Trees (Part II)
Presentation transcript:

1 Network Optimization Chapter 3 Shortest Path Problems

2 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

3 (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, where P is the set of vertices with permanent labels, and T = V \ P is the set of vertices with tentative labels.

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

Shortest paths from a single source Step 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.

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 j T, 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.

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

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

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.

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.

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.

Shortest paths from a single source Iteration 2 Step 1. 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.

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.

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.

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

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.

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.

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.

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

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.

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

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.

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.

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.

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

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 j T, L ’ (j) is the SD from 1 to j under the restriction that every intermediate vertex is in P.

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 ( △ )

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.

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.

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:

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 (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 source

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. (△) (△)

All shortest path algorithm Let G = (V, A) be a directed network. V = {1, 2, …, n}. Let a uv be the weight of the arc (u, v). (in the method we allow some negative a uv ) 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).

All shortest path algorithm Let A = [a uv ] be the n n weight matrix; P = [P uv ] be the n n matrix with P uv = 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) = [a uv (j)] and P(j)=[P uv (j)] (j = 1, …, n). A(0)=A and P(0)=P.

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

All shortest path algorithm The algorithm is as follows. Step 0Let j = 1, A(0) = A and P(0) = P. Step 1for all (u,v), If a uv (j-1) < a uj (j-1) + a jv (j-1), then a uv (j) = a uv (j-1) and p uv (j) = p uv (j-1), otherwise a uv (j) = a uj (j-1) + a jv (j-1) and p uv (j) = p uj (j-1).

All shortest path algorithm Step 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.

All shortest path algorithm Step 3Each element a uv (n) of the matrix A(n) gives the SD from vertex u to vertex v. To find the SP from u to v, if p uv (n) = j 1, then the first arc of the SP is (u, j 1 ). If j 1 v, we continue by checking p j 1 v (n). If p j 1 v (n)=j 2, then the second arc is (j 1, j 2 ). Repeat the procedure until we reach vertex v. Then the SP is u → j 1 → j 2 → …. → v.

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.

All shortest path algorithm We begin with the following matrices:

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

All shortest path algorithm Matrix 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).

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 a uv (2) = min{a uv (1), a u2 (1) + a 2v (1)}. At the end of this iteration we have the following matrices:

All shortest path algorithm Iteration 2, based on vertex 2 (j=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:

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:

All shortest path algorithm At 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: p 12 (4)=2. So the SP is 1 → 2, i.e., the arc (1, 2). From 1 to 3: p 13 (4) = 3. So the SP from 1 to 3 is the arc (1, 3).

All shortest path algorithm From 1 to 4: p 14 (4) = 3. So take the arc (1, 3) and join it to the SP from 3 to 4. We have p 34 (4) = 4. So the SP from 3 to 4 is the arc (3, 4). Thus the SP is 1 → 3 → 4. 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 2 → 3 → 4. From 3 to 1: the SP is 3 → 4 → 2 → 1. From 3 to 2: the SP is 3 → 4 → 2. From 3 to 4: the SP is the arc (3, 4). From 4 to 1: the SP is 4 → 2 → 1. From 4 to 2: the SP is the arc (4, 2). From 4 to 3: the SP is 4 → 2 → 3.

All shortest path algorithm Locating negative cycles Consider a network for which the weight matrix is as follows:

All shortest path algorithm At the end of the second iteration we have the following matrices:

All shortest path algorithm In A(2), the diagonal element a 44 (2)= -1 <0, indicating the presence of a negative cycle in the network. The negative cycle can be located by using P(2) matrix, which is 4 → 2 → 4. So, the F&W algorithm will stop calculation after obtaining A(2) and P(2).

All shortest path algorithm Theorem 3.2 If the network contains no negative cycle, then in using the Floyd-Warshall algorithm, a uv (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.

All shortest path algorithm We use the induction method to show that for j =1, …, n, a uv (j) is the SD from u to v with each intermediate vertex w j. For j=1, as a uv (1)=, obviously a uv (1) is the SD from u to v if only vertex 1 can be a possible intermediate vertex.

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

All shortest path algorithm (2) Q uv (j) has vertex j as an intermediate vertex. Then the part of Q uv (j) from u to j must be the SP from u to j with every intermediate vertex w j-1, i.e., it is Q uj (j-1), and the part of Q uv (j) from j to v must be Q jv (j-1). So, a uv (j) = a uj (j-1) + a jv (j-1).(b)

All shortest path algorithm Combining (a) and (b), we know that the SD from u to v with each intermediate vertex w j is a uv (j) = min{a uv (j-1), a uj (j-1) + a jv (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.

All shortest path algorithm An 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:

All shortest path algorithm Graph of the exercise

All shortest path algorithm a. 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.

Medians and centers Location Problem In 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.

Medians and centers 1. Minsum Problems Find 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

Medians and centers This problem is also called l 1 norm location problem as for the non- negative vector d j = (d (j,1), d (j,2), …, d (j,n)), the l 1 norm ||d j || 1 =, (if all d(j,k) are non-negative) and the location problem is to find

Medians and centers Once 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).

Medians and centers For example: S 1 =21 S 2 =19 S 3 =15 S 4 =15 S 5 =11 S 6 =17 median vertex

Medians and centers 2. Minmax problems Find 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).

Medians and centers This 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

Medians and centers The 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

Medians and centers For example: e 1 =6 e 2 =6 e 3 =4 e 4 =5 e 5 =4 e 6 =5 center vertex center vertex

Medians and centers It 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.

80 Use NETSOLVE to calculate shortest paths Specify 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).

81 Use NETSOLVE to calculate shortest paths NETSOLVE 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 5 Type 2: from a given source vertex (say 1) to all other vertices. Command: SPATH 1 *

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

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

84 Use NETSOLVE to calculate shortest paths Need to enter edge data: | Then type: | SPATH * * | You may see the | result of SD & SP | from every vertex | i to any other | vertex j |