-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
51 lines (43 loc) · 1.35 KB
/
main.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from Graph import Graph
from LPA import LPA
nodes = {0: [23, 13],
1: [38, 35],
2: [26, 17],
3: [39, 30],
4: [13, 28],
5: [43, 28],
6: [40, 23],
7: [32, 28],
8: [20, 30],
9: [41, 28],
10: [21, 13],
11: [12, 34],
12: [45, 35],
13: [25, 12],
14: [35, 34],
15: [23, 18],
16: [14, 36],
17: [18, 19],
18: [26, 37],
19: [11, 32]}
edges = [[4, 8], [4, 11], [4, 19], [8, 19], [8, 16], [8, 11], [16, 11],
[16, 19], [11, 19], [18, 16], [18, 4], [7, 1], [7, 9], [6, 7],
[1, 5], [9, 12], [12, 5], [6, 12], [10, 17], [18, 11], [5, 3],
[14, 6], [1, 12], [3, 14], [5, 14], [3, 12], [7, 12], [18, 19],
[0, 13], [15, 10], [10, 2], [15, 2], [0, 17], [2, 13], [0, 10],
[0, 2], [17, 15], [10, 13], [13, 17], [2, 13], [0, 15], [6, 5],
[4, 13], [11, 5], [3, 17], [2, 19], [18, 1], [16, 15], [6, 0],
[2, 3], [6, 13], [1, 19]]
if __name__ == '__main__':
# 初始化图
g = Graph(nodes, edges)
# 将图传入LPA算法中
lpa = LPA(g)
# 绘制初始的网络
lpa.draw_raw('Before LPA Algorithm')
# 启动LPA算法
lpa.lpa()
# 输出社区发现结果
lpa.show_communities()
# 绘制结果
lpa.draw('After LPA Algorithm')