-
Notifications
You must be signed in to change notification settings - Fork 1
/
table.jl
executable file
·400 lines (348 loc) · 12.6 KB
/
table.jl
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
#!/usr/bin/env julia
using DataFrames
using CSV
using LatexPrint
using Printf
using Statistics
include("util.jl")
files = ["juniper","bonmin-nlw","knitro-nlw","minotaur-nlw","couenne-nlw","scip-nlw"]
header = ["stdout","instance","nodes","bin_vars","int_vars","constraints",
"sense","objval","best_bound","status","time"]
objval_cols = [:scip_objval,:couenne_objval,:bonmin_objval,:juniper_objval,:knitro_objval,:minotaur_objval]
solver_names = [:scip,:couenne,:bonmin,:minotaur,:knitro,:juniper]
local_solver_names = [:bonmin,:minotaur,:knitro,:juniper]
tex_headers = [:instance,:nodes,:constraints,:disc_vars,:nl_constr,:objval,
:juniper_gap,:bonmin_gap,:minotaur_gap,:knitro_gap,:couenne_gap,:scip_gap,
:juniper_time,:bonmin_time,:minotaur_time,:knitro_time,:couenne_time,:scip_time]
mlibheader = ["instance", "nodes", "constraints", "bin_vars", "int_vars", "nl_constr","sense","dual","primal"]
dir = "/srv/http/BnBVisual/"
function readjoindata()
data = []
c = 1
for f in files
df = CSV.read(dir*"data/"*f*"_data.csv"; header=header, types=[String for h in header])
df[:instance] = [strip(value[1:end-3]) for (i, value) in enumerate(df[:instance])]
for col in [:sense,:status]
df[col] = [strip(value) for (i, value) in enumerate(df[col])]
end
for col in [:nodes,:bin_vars,:int_vars,:constraints]
df[col] = [parse(Int64, value) for (i, value) in enumerate(df[col])]
end
for col in [:objval,:best_bound,:time]
df[col] = [parse(Float64, strip(value)) for (i, value) in enumerate(df[col])]
end
deletecols!(df, :stdout)
deletecols!(df, :sense)
deletecols!(df, :nodes)
deletecols!(df, :bin_vars)
deletecols!(df, :int_vars)
deletecols!(df, :constraints)
deletecols!(df, :best_bound)
for col in [:objval,:status,:time]
if !occursin("juniper", f)
# remove nlw
rename!(df, col => Symbol(f[1:end-4]*"_"*string(col)))
else
rename!(df, col => Symbol("juniper_"*string(col)))
end
end
push!(data,df)
c += 1
end
df = CSV.read(dir*"data/minlib_extra_data.csv"; header=mlibheader, types=[String,Int64,Int64,Int64,Int64,Int64,String,Float64,Float64])
println(df)
push!(data,df)
f = data[1]
for i=2:length(data)
f = join(f, data[i], on = :instance, kind = :outer)
end
println("size: ",size(f,1))
f = sort(f, cols = :bin_vars)
println(f)
return f
end
"""
generateviewdf(f)
Set time to NaN if gap is NaN
Get only every Xth entry (atm x = 13 :D)
"""
function generateviewdf(of)
f = deepcopy(of)
delete_idx = Vector{Int64}()
idx = 1
for r in eachrow(f)
for solver in solver_names
gap_col = Symbol(string(solver)*"_gap")
time_col = Symbol(string(solver)*"_time")
if isnan(r[gap_col])
r[time_col] = NaN
end
end
cnf = 0
for solver in local_solver_names
gap_sym = Symbol(string(solver)*"_gap")
if isnan(r[gap_sym])
cnf += 1
end
end
if cnf == length(local_solver_names)
push!(delete_idx,idx)
end
if r[:instance] == "graphpart_3pm-0444-0444"
push!(delete_idx,idx)
end
idx += 1
end
deleterows!(f, delete_idx)
println("size of view before uniform: ",size(f,1))
return f,f[1:13:end,:]
end
# generate tex
function generate_tex()
written_instances = []
format = Dict{Symbol,Any}()
format[:instance] = format_instance
format[:nodes] = format_string
format[:constraints] = format_string
format[:disc_vars] = format_int
format[:nl_constr] = format_int
gap_cols = [Symbol(string(solver)*"_gap") for solver in solver_names]
for col in gap_cols
format[col] = format_gap
end
time_cols = [Symbol(string(solver)*"_time") for solver in solver_names]
for col in time_cols
format[col] = format_time
end
format[:objval] = format_objval
spaces = Dict{Symbol,Int64}()
for col in tex_headers
spaces[col] = 0
end
# get number of spaces
# extra space for textbf in each column :/
for col in tex_headers
spaces[col] = maximum([length(format[col] != nothing ? format[col](value) : value)+9 for value in vf[col]])
end
noprint_c = 0
tex_file = open(dir*"table_data.tex", "w")
tex_start = ["",
"\\begin{table*}[t]",
"\\footnotesize",
"\\caption{Runtime and optimality gap statistics for 298 MINLPLib2 Instances solved by different local and global solvers.}",
"\\begin{tabular}{|r|r|r|r|r||r||r|r|r|r|r|r||r|r|r|r|r|r|r|}",
"\\hline",
" \\multicolumn{6}{|c||}{} & juniper & bon & minot & knitro & coue & scip & juniper & bon & minot & knitro & coue & scip \\\\ ",
" \\hline",
" \\hline"]
tex_end = ["\\hline","\\end{tabular}\\\\",
"\\label{table:results}",
"\\end{table*}"]
for ln in tex_start
write(tex_file, "$ln \n")
end
# average for each solver over all
ln = "\\multicolumn{6}{|c||}{Feasible instances / Time Limit reached} & "
ln2 = "\\multicolumn{6}{|c||}{Average solver feasible} & "
for head in tex_headers
sthead = string(head)
spsthead = split(sthead,"_")
if Symbol(spsthead[1]) in solver_names
vals = []
tl_reached = 0
for r in eachrow(f)
if !isnan(r[Symbol(spsthead[1]*"_gap")])
push!(vals,r[head])
end
if r[Symbol(spsthead[1]*"_time")] >= 3600
tl_reached += 1
end
end
mean_val = mean(vals)
if sthead[end-2:end] == "gap"
ln *= string(@sprintf "%d" length(vals)) * " & "
else
ln *= string(@sprintf "%d" tl_reached) * " & "
end
if mean_val >= 10000
ln2 *= string(@sprintf "%.0e" mean_val) * " & "
else
ln2 *= string(@sprintf "%.2f" mean_val) * " & "
end
end
end
ln = ln[1:end-2]*" \\\\"
ln2 = ln2[1:end-2]*" \\\\"
write(tex_file, "$ln \n")
write(tex_file, "\\hline \n")
write(tex_file, "\\multicolumn{6}{|c||}{} & \\multicolumn{6}{c||}{Gap (\\%)} & \\multicolumn{6}{c|}{Runtime (seconds)} \\\\ ")
write(tex_file, "\\hline \n")
write(tex_file, "$ln2 \n")
# average where all solves find feasible
ln = ""
l_vals = 0
for head in tex_headers
sthead = string(head)
spsthead = split(sthead,"_")
if Symbol(spsthead[1]) in solver_names
vals = []
for r in eachrow(f)
if allfeasible(r,solver_names)
push!(vals,r[head])
#=if Symbol(spsthead[1]) == :juniper && spsthead[2] == "gap" && r[head] > 100
println(r)
end=#
end
end
mean_val = mean(vals)
l_vals = length(vals)
if mean_val >= 10000
ln *= string(@sprintf "%.0e" mean_val) * " & "
else
ln *= string(@sprintf "%.2f" mean_val) * " & "
end
end
end
ln = ln[1:end-2]*" \\\\"
title_line = "\\multicolumn{6}{|c||}{Average all solvers feasible (n=$l_vals)} & "
write(tex_file, "$title_line $ln \n")
# average where local solves find feasible
ln = ""
l_vals = 0
histo_dict = Dict{Symbol,Vector{Int16}}()
for solver_name in local_solver_names
histo_dict[solver_name] = zeros(Int16,7)
end
for head in tex_headers
sthead = string(head)
spsthead = split(sthead,"_")
if Symbol(spsthead[1]) in solver_names
if Symbol(spsthead[1]) in local_solver_names
vals = []
for r in eachrow(f)
if allfeasible(r,local_solver_names)
if Symbol(spsthead[2]) == :gap
if r[head] < 1
histo_dict[Symbol(spsthead[1])][1] += 1
elseif r[head] < 5
histo_dict[Symbol(spsthead[1])][2] += 1
elseif r[head] < 10
histo_dict[Symbol(spsthead[1])][3] += 1
elseif r[head] < 20
histo_dict[Symbol(spsthead[1])][4] += 1
elseif r[head] < 50
histo_dict[Symbol(spsthead[1])][5] += 1
elseif r[head] < 100
histo_dict[Symbol(spsthead[1])][6] += 1
else
histo_dict[Symbol(spsthead[1])][7] += 1
end
end
push!(vals,r[head])
end
end
mean_val = mean(vals)
l_vals = length(vals)
if mean_val >= 10000
ln *= string(@sprintf "%.0e" mean_val) * " & "
else
ln *= string(@sprintf "%.2f" mean_val) * " & "
end
else
ln *= "- & "
end
end
end
ln = ln[1:end-2]*" \\\\"
title_line = "\\multicolumn{6}{|c||}{Average all local solvers feasible (n=$l_vals)} & "
write(tex_file, "$title_line $ln \n")
write(tex_file, "\\hline \n")
write(tex_file, "Instance & \$|V|\$& \$|C|\$& \$|I|\$& \$|NC|\$ & best obj. & juniper & bon & minot & knitro & coue & scip & juniper & bon & minot & knitro & coue & scip \\\\ \n")
write(tex_file, "\\hline \n")
rc = 0
last_rc = 0
write_counter = 0
println("lvf: ", length(vf))
for r in eachrow(vf)
str_min_gap = format[gap_cols[1]](minimum([isnan(r[col]) ? Inf : r[col] for col in gap_cols]))
str_min_time = format[time_cols[1]](minimum([isnan(r[col]) ? Inf : r[col] for col in time_cols]))
# get
svals = []
for col in tex_headers
push!(svals, format[col](r[col]))
end
ci = 1
for sval in svals
col = tex_headers[ci]
if (col in gap_cols && sval == str_min_gap) || (col in time_cols && sval == str_min_time)
if r[col] >= 1 || col in gap_cols
svals[ci] = "\\textbf{"*sval*"}"
end
end
ci += 1
end
ln = ""
ci = 1
for sval in svals
lval = length(sval)
col = tex_headers[ci]
if ci == length(tex_headers)
ln *= repeat(" ", spaces[col]-lval)*sval*" \\\\"
else
ln *= repeat(" ", spaces[col]-lval)*sval*" &"
end
ci += 1
end
push!(written_instances, r[:instance])
write_counter += 1
write(tex_file, "$ln \n")
rc += 1
if write_counter % 35 == 0 && rc != last_rc && size(vf,1) % 35 != 0
last_rc = rc
for eln in tex_end
write(tex_file, "$eln \n")
end
for sln in tex_start
write(tex_file, "$sln \n")
end
end
end
for eln in tex_end
write(tex_file, "$eln \n")
end
close(tex_file)
println("Resonable lines: ", rc)
println("Written lines: ", write_counter)
println("written_instances: ")
println(written_instances)
end
f = readjoindata()
f = fillmissings(f)
f = computegaps(f)
f = sort(f, cols = :disc_vars)
println("Check for dual bounds")
nviolations = 0
for solver in solver_names
global nviolations
for row in eachrow(f)
objval_col = Symbol(string(solver)*"_objval")
if (row[:sense] == "Min" && row[objval_col]+1e-3 < row[:dual]) ||
(row[:sense] == "Max" && row[objval_col]-1e-3 > row[:dual])
println("Solver: ", solver)
println("Instance: ", row[:instance])
println("Sense: ", row[:sense])
println("Objective: ", row[objval_col])
println("Primal: ", row[:primal])
println("Dual: ", row[:dual])
nviolations += 1
end
end
end
println("#Violations: ", nviolations)
# remove objval columns
for obj_col in objval_cols
deletecols!(f, obj_col)
end
nf, vf = generateviewdf(f)
println(nf[:,[:instance,:scip_gap,:scip_time]])
generate_tex()