-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect.pl
More file actions
executable file
·108 lines (83 loc) · 2.03 KB
/
select.pl
File metadata and controls
executable file
·108 lines (83 loc) · 2.03 KB
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
#!/usr/bin/env perl
use warnings;
use strict;
use feature qw(say switch);
use 5.012;
use Cwd qw(abs_path getcwd);
if ($#ARGV < 2) {
say "Usage: $0 output.zip input1.zip input2.zip [input.zip...]";
say "";
say "Compares solutions from input files, and puts the best one into output.zip";
exit 1;
}
my $KEYFILE=abs_path('privatekey');
my $KEY;
if (-f "$KEYFILE") {
$KEY = `cat $KEYFILE`;
chomp($KEY);
} else {
say "Keyfile missing, won't be able to decrypt input zips! Aborting.";
say "";
say "Please put team's private ID into \`privatekey' file in the root";
say "of the repository.";
exit 1;
};
my $MODELS = abs_path('problemsF');
if (! -d $MODELS) {
say "Models missing! Aborting.";
say "";
say "Please unpack problemsF.zip into problemsF directory in the root ";
say "of the repository.";
exit 1;
};
system "stack build";
my $OUTPUT=shift;
$OUTPUT = abs_path($OUTPUT);
my $repo = getcwd;
my @INPUT_DIRS = ();
for my $input (@ARGV) {
my $tmp = `mktemp -d`;
chomp($tmp);
push @INPUT_DIRS, $tmp;
$input = abs_path($input);
say $input;
chdir $tmp;
system "unzip -P $KEY $input";
chdir $repo;
}
my $OUTPUT_DIR = `mktemp -d`;
chomp($OUTPUT_DIR);
opendir(my $dh, $INPUT_DIRS[0]);
while (readdir $dh) {
my $filename = $_;
next if $filename !~ /\.nbt$/;
my $arguments = "";
for my $tmp (@INPUT_DIRS) {
$arguments = "$arguments $tmp/$filename";
}
my $problem_type = substr($filename, 0, 2);
my $model = "";
given ($problem_type) {
when ("FA") {
$model = $filename =~ s/\.nbt/_tgt.mdl/r;
}
when ("FD") {
$model = $filename =~ s/\.nbt/_src.mdl/r;
}
when ("FR") {
$model = $filename =~ s/\.nbt/_src.mdl/r;
}
default {
say "Unknown problem type \"$problem_type\"! Aborting.";
exit 1;
}
};
$model = "problemsF/$model";
my $best = `stack exec icfpc2018-exe -- select $model $arguments`;
chomp($best);
system "cp -v $best $OUTPUT_DIR"
}
closedir $dh;
chdir $OUTPUT_DIR;
system "zip --encrypt -P $KEY $OUTPUT *";
chdir $repo;