Skip to content

Commit 8881ceb

Browse files
committed
Add solution for exercise 12
1 parent cd1b6f5 commit 8881ceb

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

solutions/12-betweenness.py

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

0 commit comments

Comments
 (0)