lab12
DESCRIPTION
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 - PowerPoint PPT PresentationTRANSCRIPT
Lab12 closeness and betweenness
GoalTask 1.
Closeness using Djikstra's Single-Source Shortest Path algorithm Djikstra's algorithm is given.
Task 2.Betweenness using modified Floyd-Warshall
algorithms Floyd-Warshall algorithm 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.
ClosenessThe 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.
Example of closenessl1 =Cost(shortestPath(0,1))=2l2=Cost (shortestPath(0,2))=7l3=Cost (shortestPath(0,3))=8C(0)=max(l1,l2,l3)=max(2,7,8)=8
0
3
1
2
25
10 1
Example of closenessl1 =Cost(shortestPath(1,0))=2l2=Cost (shortestPath(1,2))=5l3=Cost (shortestPath(1,3))=6C(1)=max(l1,l2,l3)=max(2,5,6)=6
0
3
1
2
25
10 1
Example of closenessl1 =Cost(shortestPath(2,0))=7l2=Cost (shortestPath(2,1))=5l3=Cost (shortestPath(2,3))=1C(2)=max(l1,l2,l3)=max(7,5,1)=7
0
3
1
2
25
10 1
Example of closenessl1 =Cost(shortestPath(3,0))=8l2=Cost (shortestPath(3,1))=6l3=Cost (shortestPath(3,2))=1C(3)=max(l1,l2,l3)=max(8,6,1)=8
0
3
1
2
25
10 1
Algorithm:Let G = (V, E) be an undirected weighted graph Let c(i) = 0For 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.
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
Example of betweennessShortestPath(0,1)=0,1ShortestPath(0,2)=0,1,2ShortestPath(0,3)=0,1,2,3ShortestPath(1,2)=1,2ShortestPath(1,3)=1,2,3ShortestPath(2,3)=2,3betweenness[1]=2betweenness[2]=2
0
3
1
2
2 5
10 1
Floyd-Warshall algorithmThis 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]
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]
Example of Floyd-Warshall algorithmfor 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
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
New Matrix G
Interspace A 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
Old Matrix G
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
New Matrix G
Interspace B 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
Old Matrix G
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
New Matrix G
Interspace C 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
Old Matrix G
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
New Matrix G
Interspace D 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
Old Matrix G
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
New Matrix G
Interspace E 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
Old Matrix G