-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolve.sh
executable file
·84 lines (71 loc) · 2.42 KB
/
solve.sh
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
#!/bin/sh
set -e
tmp=$(mktemp -d)
trap 'rm -rf -- "$tmp"' EXIT
get_solution_cost() {
local problem=$1 solution=$2 cfg=$3
[ -f "$cfg" ] || cfg=
"$icfpc2022exe" evaluateSolution "$problem" "$solution" "" $cfg
}
info() {
if [ "$2" ]
then
printf " %-20s %s\n" "$1:" "$2"
else
printf " %-20s %s\n" "$1"
fi
}
run_solver() {
local name=$1
shift
local isl=$(mktemp -p "$tmp")
$icfpc2022exe "$@" > "$isl"
local cost=$(get_solution_cost "$problem" "$isl" "$initial_config")
info "$name" "$cost"
if [ "$cost" -lt "$best_cost" ]
then
cp -vf "$isl" "$existing_isl"
best_cost=$cost
fi
}
stack build
icfpc2022exe=$(stack path --local-install-root)/bin/icfpc2022-exe
for problem_no in `seq 1 40`
do
problem="problems/${problem_no}.png"
echo "Solving problem #$problem_no"
existing_isl="solutions/${problem_no}.isl"
initial_config="problems/${problem_no}.initial.json"
existing_cost=$(get_solution_cost "$problem" "$existing_isl" "$initial_config")
info "existing solution" "$existing_cost"
best_cost=$existing_cost
if ! [ -f "$initial_config" ]
then
# run_solver "default solver" "$problem"
# run_solver "spiral sovler" spiral "$problem"
run_solver "average solver" average "$problem"
run_solver "average4 solver" average4 "$problem"
# run_solver "search4 solver" search4 "$problem"
info "quads solver"
for level in $(seq 5); do
run_solver " level $level" quads $level "$problem"
done
info "quads+merge solver"
for level in $(seq 5); do
run_solver " level $level" quadsMerge $level "$problem"
done
info "quads_reset solver"
for level in $(seq 5); do
run_solver " level $level" quads-reset $level "$problem"
done
run_solver "recursive solver" recursive "$problem"
run_solver "billboard solver" billboard "$problem"
else
run_solver "dumb solver" dumbFromInitial "$initial_config" "$problem"
info "merge solver"
for tolerance in 2 5 10 20; do
run_solver " tolerance $tolerance" mergeFromInitial "$initial_config" "$problem" "$tolerance"
done
run_solver "billboard solver" billboardFromInitial "$initial_config" "$problem"
fi
done