-
Notifications
You must be signed in to change notification settings - Fork 0
/
extractRunData.py
259 lines (204 loc) · 5.05 KB
/
extractRunData.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
import sqlite3
import sys
import os.path
import math
def getGap(lb, ub):
return 100*(ub-lb)/lb
def getNbMachines(inst):
f = file(inst, "r")
f.readline()
m = int(f.readline().split()[1])
f.close()
return m
def getUbAtRoot(log):
f = file(log , "r")
ub = 0
while True:
l = f.readline()
if l == "":
break
if l.find("SB phase") != -1:
if ub == None:
print "ERROR ub is None"
return None
return ub
if l.find("PB=") != -1:
ub = float(l.split("PB=")[-1].split(">")[0])
if ub == 0:
print "ERROR:UB AT ROOT NOT FOUND FOR INST:", inst
return None
return ub
def getFirstLPVal(log):
f = file(log , "r")
while True:
l = f.readline()
if l == "":
break
if l.find("ColGenEvalAlg final dual bound") != -1:
f.close()
return float(l.split(":")[1].split("(")[0])
f.close()
print "ERROR:FIRST LP VAL NOT FOUND FOR INST:", inst
return None
def getRootLB(inst):
f = file(inst , "r")
while True:
l = f.readline()
if l == "":
break
if (l.find("&") != -1) or (l.find("key") != -1):
continue
if l.find("bcRecRootDb") != -1:
f.close()
return float(l.split(" ")[1])
f.close()
print "ERROR: bcRecRootDb NOT FOUND FOR INST:", inst
return None
def getRootTime(log):
f = file(log , "r")
while True:
l = f.readline()
if l == "":
break
if l.find("bcTimeRootEval") != -1:
f.close()
return float(l.split("&")[0].split()[1])/100.0
f.close()
f = file(log , "r")
while True:
l = f.readline()
if l == "":
break
if l.find("bcTimeRoot") != -1:
f.close()
return float(l.split("&")[0].split()[1])/100.0
f.close()
print "ERROR: bcTimeRoot NOT FOUND FOR INST:", log
f.close()
return None
def getNbLazyCuts(inst, rootOnly):
f = file(inst , "r")
nbCuts = 0
while True:
l = f.readline()
if l == "":
break
if rootOnly and l.find("SB phase") != -1:
break
if l.find("lazy cut added") != -1:
nbCuts += 1
f.close()
return nbCuts
def instanceFinished(inst):
f = file(inst , "r")
finished = False
while True:
l = f.readline()
if l == "":
break
if l.find("Program exited normaly") != -1:
finished = True
break
f.close()
return finished
def getNbNodes(inst):
f = file(inst , "r")
nbNodes = 0
while True:
l = f.readline()
if l == "":
break
if (l.find("&") != -1) or (l.find("key") != -1):
continue
if l.find("bcCountNodeProc") != -1:
nbNodes = int(l.split(" ")[1])
f.close()
return nbNodes
def getLb(inst):
f = file(inst , "r")
lb = 0
while True:
l = f.readline()
if l == "":
break
if (l.find("&") != -1) or (l.find("key") != -1):
continue
if l.find("bcRecBestDb") != -1:
lb = float(l.split(" ")[1])
f.close()
return lb
def getUb(inst):
f = file(inst , "r")
ub = 0
while True:
l = f.readline()
if l == "":
break
if (l.find("&") != -1) or (l.find("key") != -1):
continue
if l.find("bcRecBestInc") != -1:
ub = float(l.split(" ")[1])
f.close()
return ub
def finishedByTimeLimit(inst):
f = file(inst , "r")
flag = False
while True:
l = f.readline()
if l == "":
break
if l.find("TIME LIMIT IS HIT") != -1:
flag = True
break
f.close()
return flag
def getTime(inst):
f = file(inst , "r")
time = 0
while True:
l = f.readline()
if l == "":
break
if (l.find("\\\\") != -1) or (l.find("key") != -1):
continue
if l.find("bcTimeMain") != -1:
time = float(l.split(" ")[1])/100
f.close()
return time
def getHeurUb(inst):
f = file(inst , "r")
ub = 0
while True:
l = f.readline()
if l.find("cutOffValue") != -1:
ub = float(l.split(" = ")[-1]) - 1
break
f.close()
return ub
def main():
if len(sys.argv) != 3:
print "python insertData.py logsDir instDir"
sys.exit()
logsDir = sys.argv[1]
instsDir = sys.argv[2]
if logsDir[-1] != "/":
logsDir += "/"
if instsDir[-1] != "/":
instsDir += "/"
instances = os.listdir(instsDir)
instances.sort()
logs = os.listdir(logsDir)
for inst in instances:
if inst.find("results") != -1:
continue
log = logsDir + inst.replace(".txt", "")
if instanceFinished(log):
try:
rootLB, rootUB, LB, UB = -getUbAtRoot(log), -getRootLB(log), -getUb(log), -getLb(log)
print inst.replace(".txt",""),rootLB,rootUB,getGap(rootLB,rootUB),getRootTime(log),getNbLazyCuts(log,True),LB,UB,getGap(LB,UB),getTime(log),getNbNodes(log),getNbLazyCuts(log,False),-getHeurUb(log)
except Exception as e:
print e
else:
print inst
if __name__ == "__main__":
main()