Add benchmark script and instances
This commit is contained in:
41
infinity/benchmark/scripts/render.sage
Normal file
41
infinity/benchmark/scripts/render.sage
Normal file
@@ -0,0 +1,41 @@
|
||||
import sys
|
||||
import math
|
||||
|
||||
M=3
|
||||
ZERO=1e-10
|
||||
|
||||
def angle_cmp(v):
|
||||
return math.atan2(v[0], v[1])
|
||||
|
||||
for fname in sys.argv[1:]:
|
||||
load(fname)
|
||||
nrays = len(pi)
|
||||
|
||||
frat = f.apply_map(lambda x : x.nearby_rational(max_denominator=1000))
|
||||
vertices = [(f+R[i]/pi[i]).apply_map(lambda x: x.nearby_rational(max_denominator=1000)) for i in range(nrays)]
|
||||
poly = Polyhedron(vertices=vertices)
|
||||
|
||||
print "Writing %s.tex..." % fname
|
||||
texfile = open("%s.tex" % fname, "w")
|
||||
texfile.write("\\draw[fill,fill opacity=0.1] ")
|
||||
for v in sorted(poly.vertices(), key=angle_cmp):
|
||||
texfile.write("(%s, %s) -- " % (v[0], v[1]))
|
||||
texfile.write("cycle;\n")
|
||||
|
||||
#texfile.write("\\draw (%s, %s) circle [radius=1.5pt];\n" % (frat[0], frat[1]))
|
||||
|
||||
for v in vertices:
|
||||
texfile.write("\\draw[dashed] (%s,%s) -- (%s,%s);\n" % (frat[0], frat[1], v[0], v[1]))
|
||||
|
||||
texfile.close()
|
||||
|
||||
print "Writing %s.png..." % fname
|
||||
p0 = sum([arrow(f, f + R[i] / pi[i], color='blue') for i in range(nrays)])
|
||||
pf = list_plot([f], color='red', pointsize=30, zorder=-1)
|
||||
p1 = poly.plot(color='blue', alpha=0.2)
|
||||
p3 = list_plot(
|
||||
[(x,y) for x in range(-M,M+1) for y in range(-M,M+1)],
|
||||
color='black', figsize=20, pointsize=30, zorder=1)
|
||||
|
||||
output = "%s.png" % fname
|
||||
save(p0+pf+p3+p1, output, xmin=-M, ymin=-M, xmax=M, ymax=M)
|
||||
47
infinity/benchmark/scripts/render.sage.py
Normal file
47
infinity/benchmark/scripts/render.sage.py
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
# This file was *autogenerated* from the file scripts/render.sage
|
||||
from sage.all_cmdline import * # import sage library
|
||||
|
||||
_sage_const_3 = Integer(3); _sage_const_1 = Integer(1); _sage_const_0 = Integer(0); _sage_const_0p2 = RealNumber('0.2'); _sage_const_1000 = Integer(1000); _sage_const_1en10 = RealNumber('1e-10'); _sage_const_30 = Integer(30); _sage_const_20 = Integer(20)
|
||||
import sys
|
||||
import math
|
||||
|
||||
M=_sage_const_3
|
||||
ZERO=_sage_const_1en10
|
||||
|
||||
def angle_cmp(v):
|
||||
return math.atan2(v[_sage_const_0 ], v[_sage_const_1 ])
|
||||
|
||||
for fname in sys.argv[_sage_const_1 :]:
|
||||
load(fname)
|
||||
nrays = len(pi)
|
||||
|
||||
frat = f.apply_map(lambda x : x.nearby_rational(max_denominator=_sage_const_1000 ))
|
||||
vertices = [(f+R[i]/pi[i]).apply_map(lambda x: x.nearby_rational(max_denominator=_sage_const_1000 )) for i in range(nrays)]
|
||||
poly = Polyhedron(vertices=vertices)
|
||||
|
||||
print "Writing %s.tex..." % fname
|
||||
texfile = open("%s.tex" % fname, "w")
|
||||
texfile.write("\\draw[fill,fill opacity=0.1] ")
|
||||
for v in sorted(poly.vertices(), key=angle_cmp):
|
||||
texfile.write("(%s, %s) -- " % (v[_sage_const_0 ], v[_sage_const_1 ]))
|
||||
texfile.write("cycle;\n")
|
||||
|
||||
#texfile.write("\\draw (%s, %s) circle [radius=1.5pt];\n" % (frat[0], frat[1]))
|
||||
|
||||
for v in vertices:
|
||||
texfile.write("\\draw[dashed] (%s,%s) -- (%s,%s);\n" % (frat[_sage_const_0 ], frat[_sage_const_1 ], v[_sage_const_0 ], v[_sage_const_1 ]))
|
||||
|
||||
texfile.close()
|
||||
|
||||
print "Writing %s.png..." % fname
|
||||
p0 = sum([arrow(f, f + R[i] / pi[i], color='blue') for i in range(nrays)])
|
||||
pf = list_plot([f], color='red', pointsize=_sage_const_30 , zorder=-_sage_const_1 )
|
||||
p1 = poly.plot(color='blue', alpha=_sage_const_0p2 )
|
||||
p3 = list_plot(
|
||||
[(x,y) for x in range(-M,M+_sage_const_1 ) for y in range(-M,M+_sage_const_1 )],
|
||||
color='black', figsize=_sage_const_20 , pointsize=_sage_const_30 , zorder=_sage_const_1 )
|
||||
|
||||
output = "%s.png" % fname
|
||||
save(p0+pf+p3+p1, output, xmin=-M, ymin=-M, xmax=M, ymax=M)
|
||||
|
||||
110
infinity/benchmark/scripts/table-csv.rb
Executable file
110
infinity/benchmark/scripts/table-csv.rb
Executable file
@@ -0,0 +1,110 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'yaml'
|
||||
|
||||
def gmean(x, shift)
|
||||
sum=0.0
|
||||
x.each {|v| sum += Math.log(v+shift)}
|
||||
sum /= x.size
|
||||
Math.exp(sum)-shift
|
||||
end
|
||||
|
||||
def mean(x)
|
||||
sum=0.0
|
||||
x.each {|v| sum += v}
|
||||
sum /= x.size
|
||||
end
|
||||
|
||||
data = YAML::load(File.open("data/data.yaml"))
|
||||
|
||||
n = 0
|
||||
|
||||
exact_cuts = []
|
||||
exact_gaps = []
|
||||
exact_times = []
|
||||
greedy_cuts = []
|
||||
greedy_gaps = []
|
||||
greedy_times = []
|
||||
mir_cuts = []
|
||||
mir_gaps = []
|
||||
percut_times = []
|
||||
improv = []
|
||||
|
||||
missing = []
|
||||
no_improvement = []
|
||||
mir_differs = []
|
||||
count = 1
|
||||
|
||||
print("instance,")
|
||||
print("gmir,")
|
||||
print("ginfty,")
|
||||
print("gexact,")
|
||||
print("improv,")
|
||||
print("ttotal,")
|
||||
print("tpercut,")
|
||||
print("ncuts")
|
||||
print("\n")
|
||||
|
||||
|
||||
Dir[ARGV[0] + "*yaml"].sort.each do |f|
|
||||
yaml = YAML::load(File.open(f))
|
||||
|
||||
instance = yaml['input-filename'].gsub("instances/", "").gsub(".pre.mps.gz", "")
|
||||
d = data[instance]
|
||||
|
||||
obj_lp = yaml['obj-value'][0]
|
||||
obj_ip = d['ip']
|
||||
gap_pi = d[ARGV[1]]
|
||||
obj_mir = yaml['obj-value'][1]
|
||||
obj_greedy = yaml['obj-value'][2]
|
||||
|
||||
gap_mir = (obj_mir - obj_lp) / (obj_ip - obj_lp) * 100
|
||||
gap_greedy = (obj_greedy - obj_lp) / (obj_ip - obj_lp) * 100
|
||||
|
||||
#gap_pi = [gap_pi, gap_greedy].max
|
||||
|
||||
improv_greedy = (gap_greedy - gap_mir) / (gap_pi - gap_mir) * 100
|
||||
improv_greedy = 0 if improv_greedy.abs < 0.01
|
||||
|
||||
if (gap_mir - d['gmi']).abs > 1
|
||||
mir_differs.push([instance, gap_mir, d['gmi']])
|
||||
end
|
||||
|
||||
begin
|
||||
time_percut = yaml['time-per-cut'][2] * 1000
|
||||
rescue NoMethodError
|
||||
time_percut = 0.0
|
||||
end
|
||||
percut_times.push(time_percut)
|
||||
|
||||
mir_gaps.push(gap_mir)
|
||||
greedy_gaps.push(gap_greedy)
|
||||
exact_gaps.push(gap_pi)
|
||||
improv.push(improv_greedy)
|
||||
|
||||
print("%s," % instance.gsub("_", "\\_"))
|
||||
print("%.1f," % (gap_mir))
|
||||
print("%.1f," % (gap_greedy))
|
||||
print("%.1f," % (gap_pi))
|
||||
|
||||
if (gap_pi - gap_mir).abs > 0.01
|
||||
print("%.1f," % (improv_greedy))
|
||||
else
|
||||
print("%s," % "---")
|
||||
end
|
||||
|
||||
print("%d:%02d," % [yaml['user-cpu-time'][2] / 60, yaml['user-cpu-time'][2] % 60])
|
||||
print("%d ms," % (time_percut))
|
||||
print("%d" % (yaml['added-cuts'][2]))
|
||||
print("\n")
|
||||
|
||||
count += 1
|
||||
end
|
||||
|
||||
mean_exact = mean(exact_gaps)
|
||||
mean_greedy = mean(greedy_gaps)
|
||||
mean_mir = mean(mir_gaps)
|
||||
|
||||
#print("\n%22s" % "")
|
||||
#print("%8.2f%% " % mean_mir)
|
||||
#print("%8.2f%% " % mean_greedy)
|
||||
#print("%8.2f%% " % mean_exact)
|
||||
168
infinity/benchmark/scripts/table.rb
Executable file
168
infinity/benchmark/scripts/table.rb
Executable file
@@ -0,0 +1,168 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'yaml'
|
||||
|
||||
def gmean(x, shift)
|
||||
sum=0.0
|
||||
x.each {|v| sum += Math.log(v+shift)}
|
||||
sum /= x.size
|
||||
Math.exp(sum)-shift
|
||||
end
|
||||
|
||||
def mean(x)
|
||||
sum=0.0
|
||||
x.each {|v| sum += v}
|
||||
sum /= x.size
|
||||
end
|
||||
|
||||
data = YAML::load(File.open("data/data.yaml"))
|
||||
|
||||
n = 0
|
||||
|
||||
exact_cuts = []
|
||||
exact_gaps = []
|
||||
exact_times = []
|
||||
greedy_cuts = []
|
||||
greedy_gaps = []
|
||||
greedy_times = []
|
||||
mir_cuts = []
|
||||
mir_gaps = []
|
||||
percut_times = []
|
||||
improv = []
|
||||
|
||||
missing = []
|
||||
no_improvement = []
|
||||
mir_differs = []
|
||||
count = 1
|
||||
|
||||
print("%4s " % "")
|
||||
print("%16s " % "instance")
|
||||
print("%9s " % "g-mir")
|
||||
print("%9s " % "g-infty")
|
||||
print("%9s " % "g-exact")
|
||||
print("%9s " % "improv")
|
||||
print("%9s " % "t-total")
|
||||
print("%9s " % "t-per-cut")
|
||||
print("%6s " % "n-cuts")
|
||||
print("\n")
|
||||
|
||||
|
||||
Dir[ARGV[0] + "*yaml"].sort.each do |f|
|
||||
yaml = YAML::load(File.open(f))
|
||||
|
||||
instance = yaml['input-filename'].gsub("instances/", "").gsub(".pre.mps.gz", "")
|
||||
d = data[instance]
|
||||
|
||||
obj_lp = yaml['obj-value'][0]
|
||||
obj_ip = d['ip']
|
||||
gap_pi = d[ARGV[1]]
|
||||
obj_mir = yaml['obj-value'][1]
|
||||
obj_greedy = yaml['obj-value'][2]
|
||||
|
||||
gap_mir = (obj_mir - obj_lp) / (obj_ip - obj_lp) * 100
|
||||
gap_greedy = (obj_greedy - obj_lp) / (obj_ip - obj_lp) * 100
|
||||
|
||||
#gap_pi = [gap_pi, gap_greedy].max
|
||||
|
||||
improv_greedy = (gap_greedy - gap_mir) / (gap_pi - gap_mir) * 100
|
||||
improv_greedy = 0 if improv_greedy.abs < 0.01
|
||||
|
||||
if (gap_mir - d['gmi']).abs > 1
|
||||
mir_differs.push([instance, gap_mir, d['gmi']])
|
||||
end
|
||||
|
||||
begin
|
||||
time_percut = yaml['time-per-cut'][2] * 1000
|
||||
rescue NoMethodError
|
||||
time_percut = 0.0
|
||||
end
|
||||
percut_times.push(time_percut)
|
||||
|
||||
mir_gaps.push(gap_mir)
|
||||
greedy_gaps.push(gap_greedy)
|
||||
exact_gaps.push(gap_pi)
|
||||
improv.push(improv_greedy)
|
||||
|
||||
print("%4d " % count)
|
||||
print("%16s " % instance)
|
||||
print("%8.2f%% " % (gap_mir))
|
||||
print("%8.2f%% " % (gap_greedy))
|
||||
print("%8.2f%% " % (gap_pi))
|
||||
|
||||
if (gap_pi - gap_mir).abs > 0.01
|
||||
print("%8.2f%% " % (improv_greedy))
|
||||
else
|
||||
print("%8s " % "---")
|
||||
end
|
||||
|
||||
print("%6d:%02d " % [yaml['user-cpu-time'][2] / 60, yaml['user-cpu-time'][2] % 60])
|
||||
print("%6d ms " % (time_percut))
|
||||
print("%6d " % (yaml['added-cuts'][2]))
|
||||
print("\n")
|
||||
|
||||
count += 1
|
||||
end
|
||||
|
||||
mean_exact = mean(exact_gaps)
|
||||
mean_greedy = mean(greedy_gaps)
|
||||
mean_mir = mean(mir_gaps)
|
||||
|
||||
#ncuts_exact = gmean(exact_cuts, 10)
|
||||
#ncuts_greedy = gmean(greedy_cuts, 10)
|
||||
#ncuts_mir = gmean(mir_cuts, 10)
|
||||
#
|
||||
#time_exact = gmean(exact_times, 5)
|
||||
#time_greedy = gmean(greedy_times, 5)
|
||||
#time_percut = gmean(percut_times, 5)
|
||||
#
|
||||
print("\n%22s" % "")
|
||||
print("%8.2f%% " % mean_mir)
|
||||
print("%8.2f%% " % mean_greedy)
|
||||
print("%8.2f%% " % mean_exact)
|
||||
#print("%8.1f%% " % mean(improv))
|
||||
#print(" %8d " % ncuts_mir)
|
||||
#print("%8d " % ncuts_greedy)
|
||||
#print("%8d " % ncuts_exact)
|
||||
#print("%4d:%02d " % [time_greedy / 60, time_greedy % 60])
|
||||
#print("%4d:%02d " % [time_exact / 60, time_exact % 60])
|
||||
#print(" %4.0f ms" % time_percut)
|
||||
print("\n")
|
||||
|
||||
#print("%30s" % "")
|
||||
#print("%5.1f%% " % ((mean_greedy / mean_mir - 1) * 100))
|
||||
#print("%5.1f%% " % ((mean_exact / mean_mir - 1) * 100))
|
||||
#print("\n")
|
||||
|
||||
print("%34s" % "")
|
||||
print("%6.2f%% " % ((mean_greedy - mean_mir) / (mean_exact - mean_mir) * 100))
|
||||
print("\n")
|
||||
|
||||
if missing.size > 0
|
||||
print("Missing data:\n")
|
||||
missing.each do |m|
|
||||
print(" %s\n" % m)
|
||||
end
|
||||
end
|
||||
|
||||
#if mir_differs.size > 0
|
||||
# print("MIR differs:\n")
|
||||
# mir_differs.each do |m|
|
||||
# print("%4d %16s %6.2f %6.2f\n" % [count, m[0], m[1], m[2]])
|
||||
# count += 1
|
||||
# end
|
||||
# print("\n")
|
||||
#end
|
||||
|
||||
print("Disabled:\n")
|
||||
Dir["instances/off/*"].each do |f|
|
||||
print("%4d %16s\n" % [count, f.gsub("instances/off/", "").gsub(".pre.mps.gz", "")])
|
||||
count += 1
|
||||
end
|
||||
print("\n")
|
||||
|
||||
|
||||
print("Error:\n")
|
||||
Dir[ARGV[0] + "*.err*"].sort.each do |f|
|
||||
instance = f.gsub("greedy/", "").gsub(".pre.err.", " ").split(" ")
|
||||
print("%4d %-30s %4d\n" % [count, instance[0], instance[1]])
|
||||
count += 1
|
||||
end
|
||||
76
infinity/benchmark/scripts/time.rb
Executable file
76
infinity/benchmark/scripts/time.rb
Executable file
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'yaml'
|
||||
|
||||
def gmean(x, shift)
|
||||
sum=0.0
|
||||
x.each {|v| sum += Math.log(v+shift)}
|
||||
sum /= x.size
|
||||
Math.exp(sum)-shift
|
||||
end
|
||||
|
||||
def mean(x)
|
||||
sum=0.0
|
||||
x.each {|v| sum += v}
|
||||
sum /= x.size
|
||||
end
|
||||
|
||||
mip_values = YAML::load(File.open("mip-value.yaml"))
|
||||
|
||||
n = 0
|
||||
|
||||
times = []
|
||||
mir_gaps = []
|
||||
greedy_gaps = []
|
||||
i=1
|
||||
|
||||
ARGV.each do |f|
|
||||
yaml = YAML::load(File.open(f))
|
||||
|
||||
instance = yaml['input-filename'].gsub("instances/", "").gsub(".pre.mps.gz", "")
|
||||
time_greedy = yaml['user-cpu-time'][2]
|
||||
times.push(time_greedy)
|
||||
|
||||
mip_value = mip_values[instance]
|
||||
lp_value = yaml['obj-value'][0]
|
||||
mir_value = yaml['obj-value'][1]
|
||||
greedy_value = yaml['obj-value'][2]
|
||||
|
||||
next if lp_value == mip_value
|
||||
|
||||
mir_gap = (mir_value - lp_value) / (mip_value - lp_value)
|
||||
greedy_gap = (greedy_value - lp_value) / (mip_value - lp_value)
|
||||
|
||||
mir_ncuts = yaml['added-cuts'][1]
|
||||
greedy_ncuts = yaml['added-cuts'][2]
|
||||
|
||||
mir_gaps.push(mir_gap)
|
||||
greedy_gaps.push(greedy_gap)
|
||||
|
||||
print("%20s " % instance)
|
||||
print("%14.2f " % lp_value)
|
||||
print("%14.2f " % mip_value)
|
||||
print("| %14.2f " % mir_value)
|
||||
print("%14.2f " % greedy_value)
|
||||
print("| %5.1f%% " % (mir_gap * 100))
|
||||
print("%5.1f%% " % (greedy_gap * 100))
|
||||
print("| %8d " % mir_ncuts)
|
||||
print("%8d " % greedy_ncuts)
|
||||
print("| %4d:%02d " % [yaml['user-cpu-time'][2] / 60, yaml['user-cpu-time'][2] % 60])
|
||||
print("\n")
|
||||
|
||||
i += 1
|
||||
end
|
||||
|
||||
greedy_gap = mean(greedy_gaps) * 100
|
||||
mir_gap = mean(mir_gaps) * 100
|
||||
|
||||
time_greedy = gmean(times, 10)
|
||||
|
||||
print("\n%85s" % "")
|
||||
print("%5.1f%% " % mir_gap)
|
||||
print("%5.1f%% " % greedy_gap)
|
||||
print("%21s %4d:%02d" % ["", time_greedy / 60, time_greedy % 60])
|
||||
|
||||
print("\n%92s" % "")
|
||||
print("%5.1f%% " % ((greedy_gap / mir_gap - 1) * 100))
|
||||
print("\n")
|
||||
Reference in New Issue
Block a user