1 / 17

Lab12

Lab12. closeness and betweenness. Goal . Task 1. Closeness using Djikstra's Single-Source Shortest Path algorithm Djikstra's algorithm is given. Task 2. Betweenness using modified Floyd- Warshall algorithms

Download Presentation

Lab12

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab12 closeness and betweenness

  2. Goal • Task 1. • Closeness using Djikstra's Single-Source Shortest Path algorithm • Djikstra's algorithm is given. • Task 2. • Betweennessusing modified Floyd-Warshallalgorithms • Floyd-Warshallalgorithm is given. Modify the algorithm to determine the betweenness. • You do not have to use modified Floyd-Warshall algorithms. You can come up with your own algorithm.

  3. Closeness • The closeness of a node is defined as the maximum of all the shortest path cost between it and all the other vertices in the graph.

  4. Example of closeness • l1 =Cost(shortestPath(0,1))=2 • l2=Cost (shortestPath(0,2))=7 • l3=Cost (shortestPath(0,3))=8 • C(0)=max(l1,l2,l3)=max(2,7,8)=8 1 2 5 0 2 10 1 3

  5. Example of closeness • l1 =Cost(shortestPath(1,0))=2 • l2=Cost (shortestPath(1,2))=5 • l3=Cost (shortestPath(1,3))=6 • C(1)=max(l1,l2,l3)=max(2,5,6)=6 1 2 5 0 2 10 1 3

  6. Example of closeness • l1 =Cost(shortestPath(2,0))=7 • l2=Cost (shortestPath(2,1))=5 • l3=Cost (shortestPath(2,3))=1 • C(2)=max(l1,l2,l3)=max(7,5,1)=7 1 2 5 0 2 10 1 3

  7. Example of closeness • l1 =Cost(shortestPath(3,0))=8 • l2=Cost (shortestPath(3,1))=6 • l3=Cost (shortestPath(3,2))=1 • C(3)=max(l1,l2,l3)=max(8,6,1)=8 1 2 5 0 2 10 1 3

  8. Algorithm: Let G = (V, E) be an undirected weighted graph Let c(i) = 0 For all vertices j in V Let p = shortestPath(i, j) if length(p)>c(i) Let c(i) = length(p) • Note: Use Djikstra's Single-Source Shortest Path algorithm to determine the shortest path cost.

  9. Betweenness Let G = (V, E) be an undirected weighted graph For all vertices a, b, in V where a != b Let p = shortestPath(a, b) For all vertices u in p where u != a and u != b betweenness[u] = betweenness[u] + 1

  10. Example of betweenness • ShortestPath(0,1)=0,1 • ShortestPath(0,2)=0,1,2 • ShortestPath(0,3)=0,1,2,3 • ShortestPath(1,2)=1,2 • ShortestPath(1,3)=1,2,3 • ShortestPath(2,3)=2,3 • betweenness[1]=2 • betweenness[2]=2 1 2 5 0 2 10 1 3

  11. Floyd-Warshall algorithm • This algorithm calculates the length of the shortest path between all nodes of a graph in O(V3) time. Note that it doesn’t actually find the paths, only their lengths. • G[j,i] is the shortest distance so far from i to j. for all vertices i in V do for all vertices j in V do G(i,j) = weight(i,j) for all vertices i in V do for all vertices j in V do if (G[j,i] > 0) for all vertices k in V do if (G[i,k] > 0) if (G[j,k] == 0) or (G[j,k] > G[j,i]+G[i,k]) G[j,k] = G[j,i]+G[i,k]

  12. Example of Floyd-Warshallalgorithm for all vertices i in V do for all vertices j in V do G(i,j) = weight(i,j) A B C D EA 0 10 0 5 0B 10 0 5 5 10C 0 5 0 0 0D 5 5 0 0 20E 0 10 0 20 0 Matrix G

  13. InterspaceA between any two nodes in hopes of finding a shorter path. A B C D EA 0 10 0 5 0B 10 0 5 5 10C 0 5 0 0 0D 5 5 0 0 20E 0 10 0 20 0 A B C D EA 0 10 0 5 0B 10 0 5 5 10C 0 5 0 0 0D 5 5 0 0 20E 0 10 0 20 0 Old Matrix G New Matrix G

  14. InterspaceB between any two nodes in hopes of finding a shorter path. A B C D EA 0 10 0 5 0B 10 0 5 5 10C 0 5 0 0 0D 5 5 0 0 20E 0 10 0 20 0 A B C D EA 0 10 15 5 20B 10 0 5 5 10C 15 5 0 1015D 5 5 10 0 15E 20 10 1515 0 Old Matrix G New Matrix G

  15. InterspaceC between any two nodes in hopes of finding a shorter path. A B C D EA 0 10 15 5 20B 10 0 5 5 10C 15 5 0 10 15D 5 5 10 0 15E 20 10 15 15 0 A B C D EA 0 10 15 5 20B 10 0 5 5 10C 15 5 0 10 15D 5 5 10 0 15E 20 10 15 15 0 Old Matrix G New Matrix G

  16. InterspaceD between any two nodes in hopes of finding a shorter path. A B C D EA 0 10 15 5 20B 10 0 5 5 10C 15 5 0 10 15D 5 5 10 0 15E 20 10 15 15 0 A B C D EA 0 10 15 5 20B 10 0 5 5 10C 15 5 0 10 15D 5 5 10 0 15E 20 10 15 15 0 Old Matrix G New Matrix G

  17. InterspaceE between any two nodes in hopes of finding a shorter path. A B C D EA 0 10 15 5 20B 10 0 5 5 10C 15 5 0 10 15D 5 5 10 0 15E 20 10 15 15 0 A B C D EA 0 10 15 5 20B 10 0 5 5 10C 15 5 0 10 15D 5 5 10 0 15E 20 10 15 15 0 Old Matrix G New Matrix G

More Related