Skip to content

Commit 5926e61

Browse files
committed
Submit best
1 parent 964c848 commit 5926e61

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

make_solution.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ echo "$(date +"%Y-%m-%d %T"): Creating $OUTPUT" | tee -a $LOG_FILE
1515
mkdir -p $OUTPUT
1616

1717
SECONDS=0
18-
./target/release/icfpc2019 --output $OUTPUT --input ./input --duration 300
18+
./target/release/icfpc2019 --output $OUTPUT --input ./input --duration 30000
1919
echo "$(date +"%Y-%m-%d %T"): running time is $SECONDS secs" | tee -a $LOG_FILE
2020

2121
echo "$(date +"%Y-%m-%d %T"): Creating zip $OUTPUT/solutions.zip" | tee -a $LOG_FILE

src/bin/compare.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use clap::{App, Arg};
2+
use icfpc::parse::read_all_inputs;
3+
use icfpc::parse::read_commands;
4+
use std::collections::HashMap;
5+
6+
use std::fs::File;
7+
use std::io::Read;
8+
9+
fn main() {
10+
let matches = App::new("Compare solutions")
11+
.version("0.1.0")
12+
.arg(
13+
Arg::with_name("input")
14+
.long("input")
15+
.takes_value(true)
16+
.help("input root directory"),
17+
)
18+
.arg(
19+
Arg::with_name("file")
20+
.long("file")
21+
.takes_value(true)
22+
.help("solutions path file"),
23+
)
24+
.arg(
25+
Arg::with_name("output")
26+
.long("output")
27+
.takes_value(true)
28+
.help("output root to generate"),
29+
)
30+
.get_matches();
31+
32+
let input_root = matches.value_of("input").expect("no input specified");
33+
let inputs = read_all_inputs(input_root);
34+
let output_root = matches.value_of("output").expect("no output specified");
35+
36+
let path_file = matches.value_of("file").expect("no file specified");
37+
let mut result: HashMap<String, Vec<(usize, String)>> = HashMap::new();
38+
for output_root in std::fs::read_to_string(path_file).unwrap().lines() {
39+
for input in &inputs {
40+
let commands = {
41+
let output_path = format!("{}/{}", output_root, input.output_file_name());
42+
let mut output_file = File::open(&output_path).unwrap();
43+
let mut output_str = String::new();
44+
output_file.read_to_string(&mut output_str).unwrap();
45+
read_commands(&output_str)
46+
};
47+
result
48+
.entry(input.id.to_owned())
49+
.or_default()
50+
.push((commands.len(), output_root.to_owned()));
51+
}
52+
}
53+
for input in &inputs {
54+
let v = result.get_mut(&input.id).unwrap();
55+
v.sort();
56+
let best_root = &v[0].1;
57+
println!("{}: {} ({} {})", input.id, best_root, v[0].0, v[1].0);
58+
let best_path = format!("{}/{}", best_root, input.output_file_name());
59+
let new_path = format!("{}/{}", output_root, input.output_file_name());
60+
std::fs::copy(best_path, new_path).unwrap();
61+
}
62+
}

submit_best.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
LIST_FILE=./submissions.txt
6+
OUTPUT=./best_solution
7+
LOG_FILE=./best.log
8+
9+
echo "$(date +"%Y-%m-%d %T"): Running make best" | tee -a $LOG_FILE
10+
cat $LIST_FILE | tee -a $LOG_FILE
11+
12+
cargo run --bin compare -- --output $OUTPUT --input ./input --file $LIST_FILE
13+
14+
echo "$(date +"%Y-%m-%d %T"): Creating zip $OUTPUT/solutions.zip" | tee -a $LOG_FILE
15+
cd $OUTPUT
16+
zip solutions.zip ./*.sol -q
17+
18+
cd -
19+
cargo run --bin score --release -- --input ./input --output $OUTPUT | tee -a $LOG_FILE
20+
21+
./submit.sh $OUTPUT/solutions.zip

0 commit comments

Comments
 (0)