Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4 Network Algorithms Section 4.1 Shortest Paths Colleen Raimondi.

Similar presentations


Presentation on theme: "Chapter 4 Network Algorithms Section 4.1 Shortest Paths Colleen Raimondi."— Presentation transcript:

1 Chapter 4 Network Algorithms Section 4.1 Shortest Paths Colleen Raimondi

2 Section 4.1 Shortest Paths In this chapter we present algorithms for the solution of two important network optimization problems. Network: a graph with a positive integer k(e) assigned to each edge e, it will typically represent the “length” of an edge, in units such as miles, or represent “capacity” of an edge, in units such as megawatts or gallons per minute. a b d c e 2 3 4 1 5 2 4 6 Note: Edge (a,b) has a “capacity” of 5, so k(a,b)=5.

3 Section 4.1 Shortest Paths We begin with an algorithm for a relatively simple problem, finding a shortest path in a network from point a to point z. We say a shortest path because, in general, there may be more than one shortest path from a to z. So when we find a shortest path, we must be able to prove it is shortest without explicitly comparing it with all over a-z paths. Although the problem is now starting to sound difficult, there is still a straightforward algorithmic solution.

4 Section 4.1 Shortest Path Let variable m be a “distance counter.” For increasing values of m, label vertices whose minimal distance from a vertex a is m. The first label of a vertex will be the previous vertex on the shortest path from a to x. The second label of x will be the length of the shortest path from a to x. Dijkstra’s algorithm

5 Section 4.1 Shortest Path Shortest Path Algorithm 1.Set m=1 and label vertex a with (-,0) (the “-” represents a blank). 2.Check each edge e=(p,q) from some labeled vertex p to some unlabeled vertex q. Suppose p’s labels are [r,d(p)]. If d(p)+k(e)=m, label q with (p,m). 3.If all vertices are not yet labeled, increment m by one and go to Step 2. Otherwise go to Step 4. If we are only interested in a shortest path to z, then we go to Step 4 when z is labeled. 4.For any vertex y, a shortest path from a to y has length d(y), the second label of y. Such a path may be found by backtracking from y (using the first labels).

6 Section 4.1 Shortest Path a b d c e 2 3 4 1 5 2 4 6 We want to find the shortest path from a to c. a(-,0) d(a,1) e(d,3) c(d,5) m=1; m=3; m=5; The shortest path would be a-d-c.

7 Section 4.1 Shortest Paths Note: The algorithm given previously has one significant inefficiency: if all sums d(p)+k(e) in Step 2 have values of at least m’>m, then the distance counter m should be increased immediately to m’.

8 Section 4.1 Example Example 1 Pg. 134 We want to find a shortest path from point a to point h. f i a r k j e d g h 3 9 5 4 1 6 2 3 2 74 1 2 6 2 a(-,0) i(a,1) f(i,3) j(a,4) e(f,4) g(e,5) r(a,6) k(j,6) h(g,7) The shortest path is a-i-e-g-h. m=1; m=3; m=4; m=5; m=6; m=7

9 Section 4.1 Class Work As seen on page 135 #1 Use the shortest path algorithm to find the shortest path between vertex c and vertex m. i n b m r k j e d g h c 10 f 5 5 5 6 6 6 6 2 2 2 2 4 4 4 4 3 3 3 12 20 8 f m(-,0) j(m,2) f(i,10) e(g,10) d(h,12) c(d,14) h(k,10) i(m,6) k(j,5) r(m,5)g(j,7) m=2; m=5; m=6; m=7; m=10; m=12; m=14 The shortest path is m-j-k-h-d-c.


Download ppt "Chapter 4 Network Algorithms Section 4.1 Shortest Paths Colleen Raimondi."

Similar presentations


Ads by Google