Skip to content

Commit 2e24b11

Browse files
committed
Add solution for exercise 12
1 parent 4a0f103 commit 2e24b11

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

12-betweenness.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
from networkit import *
5+
from operator import itemgetter
6+
from collections import defaultdict
7+
8+
9+
if __name__ == '__main__':
10+
parser = argparse.ArgumentParser(description=("Compute Betweenness for a given graph"))
11+
parser.add_argument('input',
12+
help='path to input graph')
13+
parser.add_argument('dict',
14+
help='path to input dict')
15+
args = parser.parse_args()
16+
17+
graph = None
18+
labels = {}
19+
20+
with open(args.dict, 'r') as dictfile:
21+
for line in dictfile:
22+
vertex, label = line.split(',', 1)
23+
labels[int(vertex)] = label.strip()[1:-1]
24+
25+
graph = readGraph(args.input, Format.METIS)
26+
betweenness = centrality.Betweenness(graph)
27+
ranking = betweenness.run().ranking()
28+
29+
for vertex, rank in ranking[:20]:
30+
print('{}. {}'.format(rank, labels[int(vertex + 1)]))

0 commit comments

Comments
 (0)