Shortest Path Problems: - PowerPoint PPT Presentation

Loading...

PPT – Shortest Path Problems: PowerPoint presentation | free to download - id: 413c01-ODFlY



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Shortest Path Problems:

Description:

Shortest Path Problems: Floyd-Warshall Algorithm for the All-Pairs Shortest Path Problem with Arbitrary Arc Costs Updated 18 February 2008 Floyd-Warshall Algorithm ... – PowerPoint PPT presentation

Number of Views:56
Avg rating:3.0/5.0
Slides: 18
Provided by: SeaS59
Learn more at: http://lyle.smu.edu
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Shortest Path Problems:


1
Shortest Path Problems
  • Floyd-Warshall Algorithm for the All-Pairs
    Shortest Path Problem with Arbitrary Arc Costs
  • Updated 18 February 2008

2
Floyd-Warshall Algorithm (AMO pg 148)
begin for all node pairs i,j ? N x N do
di,j ?, predi,j 0 for all nodes i ?
N do di,i 0 for all arcs (i, j) ? A do
di, j cij and predi, j i for k
1 to n do for all node pairs i, j ? N x
N do if di, j gt di, k dk, j
then di, j di, k dk, j and
predi, j predk, j end
3
Interpretation of d and pred Matrices
  • At the end of iteration k, di, j is the length
    of a shortest path from i to j that uses only
    nodes in the set 1, 2, , k as internal nodes.
  • predi, j is the node prior to node j on the
    (current) shortest path from i to j.

4
The Triangle Operation Iteration k
k
i
j
Check if di, j gt di, k dk, j
5
The Triangle Operation Update predi,j
k
i
predk, j
old predi, j
j
new predi, j predk, j
6
Floyd-Warshall (FW) Example 1
12
2
1
1
2
1
4
3
4
3
7
FW Example 1 End of Iteration 1
12
2
1
1
2
1
4
3
4
3
8
FW Example 1 End of Iteration 2
12
2
1
1
2
1
4
3
4
3
9
FW Example 1 End of Iteration 3
12
2
1
1
2
1
4
3
4
3
10
FW Example 1 Solution
12
2
1
1
2
1
4
3
4
3
11
FW Example 1 Shortest Path from 1 to 2
12
2
1
1
2
1
4
3
4
3
pred1,2 3
pred1,3 4
pred1,4 1
12
Complexity of Floyd-Warshall
  • Each triangle operation is O(1)
  • Each iteration does n2 triangle operations
  • There are n iterations
  • Complexity is O(n3)

13
Testing for Negative-Cost Cycles
for k 1 to n do for all node pairs i,
j ? N x N do if di, j gt di, k
dk, j then begin di, j
di, k dk, j and predi, j predk,
j if i j and di, i lt 0 then
exit (G has a negative-cost cycle)
end
14
FW Example 2 (From Papadimitriou and Steiglitz)
2
15
FW Example 2 (after k 1)
2
16
FW Example 2 (after k 2)
2
17
FW Example 2 d4, 4 1
2
2
1
-4
1
1
3
4
3
pred4,4 1
pred4,1 2
pred4,2 4
About PowerShow.com