-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask1.py
26 lines (20 loc) · 863 Bytes
/
task1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from graph import Graph
from component import wcc, scc
def do_task1():
print("Task 1")
g = Graph()
g.read_adj_list(filename="data/graph_list.csv")
results = [sorted(result) for result in scc(g)]
results.sort(key=lambda result: result[0])
print("Number of strongly connected components: ", len(results))
print("Count, Percantage, Component")
for result in results:
print(len(result), "(" + str(len(result)/len(g.vertices()) * 100.0) + "%)", result)
results = [sorted(result) for result in wcc(g)]
results.sort(key=lambda result: result[0])
print("Number of weakly connected components: ", len(results))
print("Count, Percantage, Component")
for result in results:
print(len(result), "(" + str(len(result)/len(g.vertices()) * 100.0) + "%)", result)
if __name__ == "__main__":
do_task1()