-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_fmm1_table.pl
133 lines (118 loc) · 4.6 KB
/
make_fmm1_table.pl
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
#!/usr/bin/perl
use strict;
use warnings;
use autodie ':all';
use DBI;
chomp(my $thisHost = `hostname`);
my $verbose = 0; #HACK: Currently no way to turn this on
my $NUMREGEX = '[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?'; #HACK: Probably still wrong somehow, but it gets close to matching any valid FP number.
# Open DB connection and set up its closing
#my $dbh = DBI->connect('dbi:Pg:dbname=wtwhite;host=localhost;port=15433', undef, undef, { RaiseError => 1 }); # Works on my laptop (via SSH tunnel) and on darwin! :)
my $dbPort = ($thisHost eq 'wallace' ? 5432 : 15433); # On wallace we access the DB directly; on all other machines we need an SSH tunnel.
#my $dbh = DBI->connect("dbi:Pg:dbname=wtwhite;host=localhost;port=$dbPort", 'wtwhite', 'asdfasdf', { RaiseError => 1, ShowErrorStatement => 1, TraceLevel => 'SQL' }); #HACK: Disgusting that I include the password...
my $dbh = DBI->connect("dbi:Pg:dbname=wtwhite;host=localhost;port=$dbPort", 'wtwhite', 'asdfasdf', { RaiseError => 1, ShowErrorStatement => 1 }); #HACK: Disgusting that I include the password...
END {
if (defined $dbh) {
$dbh->disconnect;
$dbh = undef;
}
}
my @cols = qw(
.orig_cplex
.reduced4.orig_cplex
.reduced6.orig_cplex
.cut_cplex
.reduced4.cut_cplex
.reduced6.cut_cplex
);
print STDERR "Running query...\n";
my @rows = @{$dbh->selectall_arrayref(<<THE_END, { Slice => {} })};
select
sq1.data_group,
sq1.solver,
sq1.reduction,
comb_red_time + comb_sol_time as comb_time,
sep_red_time + sep_sol_time as sep_time,
ncands
from (
select
data_group,
solver,
reduction,
coalesce(r.elapsed_nonio_secs, 0) as comb_red_time,
s.elapsed_nonio_secs as comb_sol_time
from nice_instances i
left join ok_reductions r using (dataset, reduction)
join ok_solutions s using (dataset, reduction)
where is_combined
) sq1
join (
select
data_group,
solver,
reduction,
sum(coalesce(r.elapsed_nonio_secs, 0)) as sep_red_time,
sum(s.elapsed_nonio_secs) as sep_sol_time,
count(*) as ncands
from nice_instances i
left join ok_reductions r using (dataset, reduction)
join ok_solutions s using (dataset, reduction)
where not is_combined
group by 1, 2, 3
) sq2 on sq1.data_group = sq2.data_group and sq1.solver = sq2.solver and sq1.reduction = sq2.reduction
order by 1, 2, 3
THE_END
print STDERR "Query produced " . scalar(@rows) . " rows.\n";
my %d;
foreach my $r (@rows) {
#$d{$r->{data_group}}{"$r->{reduction}.$r->{solver}.sep"} = $r->{sep_time};
#$d{$r->{data_group}}{"$r->{reduction}.$r->{solver}.comb"} = $r->{comb_time};
$d{$r->{data_group}}{"$r->{reduction}.$r->{solver}.sep"} = sprintf '%.0f', $r->{sep_time};
$d{$r->{data_group}}{"$r->{reduction}.$r->{solver}.comb"} = sprintf '%.0f', $r->{comb_time};
$d{$r->{data_group}}{ncands} = sprintf '%.0f', $r->{ncands};
}
#print "\\begin{tabular}{|c" . ("|d{-1}" x 6) . "|}\\hline\n";
#print "\\begin{tabular}{|c" . ("|r" x 6) . "|}\\hline\n"; # "d{-1}" doesn't work if we try to bold with \textbf{}...
#print "\\begin{tabular}{c" . ("r" x 6) . "}\\hline\n"; # "d{-1}" doesn't work if we try to bold with \textbf{}...
print <<'THE_END'
\begin{tabular}{c r|rrrrrr|rrrrrr}
& & \multicolumn{6}{c|}{solve all candidate instances} &
\multicolumn{6}{c}{solve global instances} \\
%
\emph{ID} & \#cand & \multicolumn{1}{c}{o} & oR2 & oR3 &
\multicolumn{1}{c}{c} & cR2 & cR3
& \multicolumn{1}{c}{o} & oR2 & oR3 &
\multicolumn{1}{c}{c} & cR2 & cR3
\\\hline
THE_END
#print join("\t&\t", 'ID/\#cand', 'o\qquad', 'oR2', 'oR3', 'c\qquad', 'cR2', 'cR3'), "\\\\\\hline\n";
#print join("\t&\t", '\emph{ID}/(\#cand)', '\mbox{o\,\,\,\,}', 'oR2', 'oR3', '\mbox{c\,\,\,\,}', 'cR2', 'cR3'), "\\\\\\hline\n"; #HACK: the \,\,\,\, is disgusting
foreach my $dn (sort keys %d) {
my $short = $dn;
$short =~ s/\.ms$//;
$short =~ s/^mpos/m/; # Need all the horizontal space we can get!
#print "$short";
print "\\emph{$short}";
print "\t&\t$d{$dn}{ncands}"; # Sneak the number of candidates in there! :)
# Find maximum over instance.
#print STDERR join("|", @{$d{$dn}}{map { ("$_.sep", "$_.comb") } @cols}), "\n"; #DEBUG
my $min = (sort { $a <=> $b } @{$d{$dn}}{map { ("$_.sep", "$_.comb") } @cols})[0];
#print STDERR "min=<$min>\n"; #DEBUG
foreach my $c (@cols) {
my $key = "$c.sep";
my $val = $d{$dn}{$key};
$val = "\\textbf{$val}" if $val == $min;
print "\t&\t$val";
}
#print "\\\\\n($d{$dn}{ncands})"; # Sneak the number of candidates in there! :)
foreach my $c (@cols) {
my $key = "$c.comb";
my $val = $d{$dn}{$key};
$val = "\\textbf{$val}" if $val == $min;
print "\t&\t$val";
}
#print "\\\\\\hline\n";
print "\\\\\n";
}
print "\\hline\n";
print "\\end{tabular}\n";