Skip to content
Permalink
Browse files

Submit best

  • Loading branch information...
ichyo committed Jun 24, 2019
1 parent 964c848 commit 5926e61b96315203f0d6d05e79cf3029ef9b2d70
Showing with 84 additions and 1 deletion.
  1. +1 −1 make_solution.sh
  2. +62 −0 src/bin/compare.rs
  3. +21 −0 submit_best.sh
@@ -15,7 +15,7 @@ echo "$(date +"%Y-%m-%d %T"): Creating $OUTPUT" | tee -a $LOG_FILE
mkdir -p $OUTPUT

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

echo "$(date +"%Y-%m-%d %T"): Creating zip $OUTPUT/solutions.zip" | tee -a $LOG_FILE
@@ -0,0 +1,62 @@
use clap::{App, Arg};
use icfpc::parse::read_all_inputs;
use icfpc::parse::read_commands;
use std::collections::HashMap;

use std::fs::File;
use std::io::Read;

fn main() {
let matches = App::new("Compare solutions")
.version("0.1.0")
.arg(
Arg::with_name("input")
.long("input")
.takes_value(true)
.help("input root directory"),
)
.arg(
Arg::with_name("file")
.long("file")
.takes_value(true)
.help("solutions path file"),
)
.arg(
Arg::with_name("output")
.long("output")
.takes_value(true)
.help("output root to generate"),
)
.get_matches();

let input_root = matches.value_of("input").expect("no input specified");
let inputs = read_all_inputs(input_root);
let output_root = matches.value_of("output").expect("no output specified");

let path_file = matches.value_of("file").expect("no file specified");
let mut result: HashMap<String, Vec<(usize, String)>> = HashMap::new();
for output_root in std::fs::read_to_string(path_file).unwrap().lines() {
for input in &inputs {
let commands = {
let output_path = format!("{}/{}", output_root, input.output_file_name());
let mut output_file = File::open(&output_path).unwrap();
let mut output_str = String::new();
output_file.read_to_string(&mut output_str).unwrap();
read_commands(&output_str)
};
result
.entry(input.id.to_owned())
.or_default()
.push((commands.len(), output_root.to_owned()));
}
}
for input in &inputs {
let v = result.get_mut(&input.id).unwrap();
v.sort();
let best_root = &v[0].1;
println!("{}: {} ({} {})", input.id, best_root, v[0].0, v[1].0);
let best_path = format!("{}/{}", best_root, input.output_file_name());
let new_path = format!("{}/{}", output_root, input.output_file_name());
std::fs::copy(best_path, new_path).unwrap();
}
}
@@ -0,0 +1,21 @@
#!/bin/bash

set -e

LIST_FILE=./submissions.txt
OUTPUT=./best_solution
LOG_FILE=./best.log

echo "$(date +"%Y-%m-%d %T"): Running make best" | tee -a $LOG_FILE
cat $LIST_FILE | tee -a $LOG_FILE

cargo run --bin compare -- --output $OUTPUT --input ./input --file $LIST_FILE

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

cd -
cargo run --bin score --release -- --input ./input --output $OUTPUT | tee -a $LOG_FILE

./submit.sh $OUTPUT/solutions.zip

0 comments on commit 5926e61

Please sign in to comment.
You can’t perform that action at this time.