-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerateSubGraphs.py
130 lines (122 loc) · 4.6 KB
/
generateSubGraphs.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import sys
import numpy as np
import pandas as pd
def selectNodes():
try:
nextQ = list(edges.loc[int(line.split()[0])][1])
for j in nextQ:
d[i][j] = kl[i]
kl[i] += 1
nodesSelected[i] += 1
try:
nnextQ = list(edges.loc[j][1])
for jko in nnextQ:
d[i][jko] = kl[i]
kl[i] += 1
nodesSelected[i] += 1
except:
try:
jko = edges.loc[j][1]
d[i][jko] = kl[i]
kl[i] += 1
nodesSelected[i] += 1
except:
pass
except:
try:
j = edges.loc[int(line.split()[0])][1]
d[i][j] = kl[i]
kl[i] += 1
nodesSelected[i] += 1
except:
pass
cons = ["2500", "5000", "7500"]
ktk = sys.argv[1:]
if ktk[-1] == "twitter":
ktk = ktk[:-1]
edges = pd.read_csv("../twitter/edges.txt", delimiter = ' ',index_col = 0, header = None)
cons = ["100", "133", "150", "166", "175","200"]
for inp in ["twitter"]:
n = 0
print(inp)
infile1 = open("../"+inp+"/labels.txt", 'r')
d1 = {}
d2 = {}
d3 = {}
d4 = {}
d5 = {}
d_0 = {}
outfile1 = open("../"+inp+"/subgraphs/labels100.txt", 'w')
outfile2 = open("../"+inp+"/subgraphs/labels133.txt", 'w')
outfile3 = open("../"+inp+"/subgraphs/labels150.txt", 'w')
outfile4 = open("../"+inp+"/subgraphs/labels166.txt", 'w')
outfile5 = open("../"+inp+"/subgraphs/labels175.txt", 'w')
outfile_0 = open("../"+inp+"/subgraphs/labels200.txt", 'w')
d = [d1,d2,d3,d4,d5,d_0]
outfile = [outfile1, outfile2, outfile3, outfile4, outfile5, outfile_0]
line = infile1.readline()
kl = [1,1,1,1,1,1]
nodesSelected = [0,0,0,0,0,0]
while line:
n+=1
try:
if d[0][int(line.split()[0])] >= 1:
outfile1.write(str(d[0][int(line.split()[0])])+' '+line.split()[1]+'\n')
if d[1][int(line.split()[0])] >= 1:
outfile2.write(str(d[1][int(line.split()[0])])+' '+line.split()[1]+'\n')
if d[2][int(line.split()[0])] >= 1:
outfile3.write(str(d[2][int(line.split()[0])])+' '+line.split()[1]+'\n')
if d[3][int(line.split()[0])] >= 1:
outfile4.write(str(d[3][int(line.split()[0])])+' '+line.split()[1]+'\n')
if d[4][int(line.split()[0])] >= 1:
outfile5.write(str(d[4][int(line.split()[0])])+' '+line.split()[1]+'\n')
if d[5][int(line.split()[0])] >= 1:
outfile_0.write(str(d[5][int(line.split()[0])])+' '+line.split()[1]+'\n')
except:
x = np.random.randint(10000)
i = -1
for inp2 in cons:
i+=1
if nodesSelected[i] > int(inp2)*400:
x = 10000
if x < int(inp2):
d[i][int(line.split()[0])] = kl[i]
kl[i]+=1
outfile[i].write(str(d[i][int(line.split()[0])])+' '+line.split()[1]+'\n')
nodesSelected[i] += 1
normalSelected[i] += 1
selectNodes()
else:
d[i][int(line.split()[0])] = 0
line = infile1.readline()
for inp in ktk:
for inp2 in cons:
infile1 = open("../"+inp+"/labels.txt", 'r')
print(inp2)
d = {}
i = 1
outfile = open("../"+inp+"/subgraphs/labels"+inp2+".txt", 'w')
line = infile1.readline()
while line:
try:
if d[int(line.split()[0])] >= 1:
outfile.write(line)
except:
x = np.random.randint(10000)
if x < int(inp2):
d[int(line.split()[0])] = 1
i+=1
outfile.write(line)
else:
d[int(line.split()[0])] = 0
line = infile1.readline()
infile2 = open("../"+inp+"/edges.txt", 'r')
outfile2 = open("../"+inp+"/subgraphs/edges"+inp2+".txt", 'w')
line = infile2.readline()
while line:
try:
if d[int(line.split()[0])] >= 1 and d[int(line.split()[1])] >= 1:
outfile2.write(line)
except:
pass
line = infile2.readline()