-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprofile_undirected_hp_rw.py
114 lines (88 loc) · 3.75 KB
/
profile_undirected_hp_rw.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import igraph as ig
import easygraph as eg
from benchmark import benchmark
import random
import numpy as np
import os
n = 5
# Random nodes generation
def random_nodes(nodes_num, start_idx, end_idx, seed=3407):
random.seed(seed)
node_list = []
for i in range(nodes_num):
node_list.append(random.randint(start_idx, end_idx))
return node_list
def pre_data(path, file):
# print(file)
data = np.loadtxt(path+file,usecols=(0,1))
np.savetxt(path+file, data, fmt='%i')
return path+file
if __name__ == "__main__":
print('for undirected networks..............')
filepath = 'datasets/undirected_datasets/'
filelist = os.listdir(filepath)
print(filelist)
for file in filelist:
if file == '.DS_Store':
continue
# =======================EasyGraph=======================
filename = filepath + file
print(f"Profiling dataset {file}")
print("Profiling loading")
print("=================")
print()
benchmark('eg.GraphC().add_edges_from_file(filename, weighted=False,is_transform=True)', globals=globals(), n=n)
g = eg.GraphC()
g.add_edges_from_file(filename, weighted=False,is_transform=True)
# node_num: sample node for dijkstra
node_num = 1000
start_idx, end_idx = 0, len(g.nodes)-1
random_node_index_list = random_nodes(node_num, start_idx, end_idx)
nodes = list(g.nodes)
eg_node_list = []
for index in random_node_index_list:
eg_node_list.append(nodes[index])
if "_lcc" not in file:
print("Profiling shortest path")
print("=======================")
print()
benchmark('eg.multi_source_dijkstra(g, sources = eg_node_list)', globals=globals(), n=n)
print("========k-core=======")
print("=================")
print()
benchmark('eg.k_core(g)', globals=globals(), n=n)
print("========betweenness_centrality=======")
print("=================")
print()
benchmark('eg.betweenness_centrality(g)', globals=globals(), n=n)
# since igraph only supports the metric of closeness centrality for lcc of each dataset, we choose the same for fair comparison
print("========closeness_centrality=======")
print("=================")
print()
benchmark('eg.closeness_centrality(g)', globals=globals(), n=n)
# =======================igraph=======================
print(f"Profiling dataset {file}")
print("Profiling loading")
print("=================")
print()
benchmark("ig.Graph.Read_Edgelist(filename,False)", globals=globals(), n=n)
g= ig.Graph.Read_Edgelist(filename,False)
ig_node_list = [int(i) for i in eg_node_list]
if "_lcc" not in file:
print("Profiling shortest path")
print("=======================")
print()
benchmark("g.distances(source = ig_node_list,weights=[1]*len(g.es))", globals=globals(), n=n)
print("========k-core=======")
print("=================")
print()
benchmark('g.coreness()', globals=globals(), n=n)
print("========betweenness_centrality=======")
print("=================")
print()
benchmark('g.betweenness(directed=False,weights=[1]*len(g.es))', globals=globals(), n=n)
# We only measure closeness for lcc of each dataset
print("========closeness_centrality=======")
print("=================")
print()
benchmark('g.closeness(weights=[1]*len(g.es))', globals=globals(), n=n)