Download presentation
Presentation is loading. Please wait.
Published byPentti Sipilä Modified over 6 years ago
1
All-Pairs SPs on DG Run Dijkstra;s algorithm for each vertex or
Use DP: Floyd-Warshall O(n3) algorithm. The structure of SP: Intermediate vertices of P={v1,v2,…,vk}: {v2,v3,…,vk-1} {1,2,…,k-1} notation for vertices. For any i,j of V consider all paths with intermediate vertices in {1,2,…,k}. Let P be min-weight path found this way.
2
All-Pairs SP (cont.) Relation between P and SP(i,j) with intermediate vertices in {1,2,…,k-1} K not in P: same K in P: break P: Recursive solution: dij(k) is weight of SP(i,j) with interm. vertices in {1,2,…,k}. dij(k)=wij, if k=0; dij(k)=min{dij(k-1), dik(k-1)+dkj(k-1)} if k >=1. Matrix D(n)=dij(n) gives final solution.
3
SP Bottom-Up Computation
W: wij= 0, if i=j; weight of edge (i,j) if exists; “infinity”, otherwise. D(0)=W; For k=1 to n do for i=1 to n do for j=1 to n do dij(k)=min{dij(k-1),dik(k-1)+dkj(k-1)}. Return D(n).
4
Constructing a SP Compute predecessor matrix P(n) together with D(n).
Pij(k): predecesor of j on SP(i,j) with intermediate vertices in {1,2,…,k}. Pij(0)= nil, if i=j or no edge (i,j). i, if edge (i,j). K >=1: ikj same predecessor as kj with intermediate vertices in {1,2,…,k-1}. Pij(k)=Pij(k-1), if dij(k-1) <= dik(k-1)+dkj(k-1) Pij(k)=Pkj(k-1), if dij(k-1) > dik(k-1)+dkj(k-1)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.