summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Harley2020-01-23 13:03:25 +0000
committerTom Harley2020-01-23 13:03:25 +0000
commitf3d375722130e448802c046af2d75f66a06de498 (patch)
tree0c82bd620be0401c6b9ba69c3314dfe0d9522eae /bin
downloadmachinarium-f3d375722130e448802c046af2d75f66a06de498.tar.gz
machinarium-f3d375722130e448802c046af2d75f66a06de498.zip

Initial commit

HEADmaster
Diffstat (limited to 'bin')
-rwxr-xr-xbin/make-data.sh2
-rwxr-xr-xbin/run-all.sh16
-rwxr-xr-xbin/run.sh19
-rwxr-xr-xbin/togrid.pl80
4 files changed, 117 insertions, 0 deletions
diff --git a/bin/make-data.sh b/bin/make-data.sh
new file mode 100755
index 0000000..e7f2607
--- /dev/null
+++ b/bin/make-data.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+sh run-all.sh puzzle4.eprime.m4 | tee csv/$(hostname).csv
diff --git a/bin/run-all.sh b/bin/run-all.sh
new file mode 100755
index 0000000..1c35388
--- /dev/null
+++ b/bin/run-all.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+s="$1"
+
+echo '"file","s-total-time","sr-clause-out","s-solve-time","sr-total-time","s-satisfiable","sr-timeout","s-nodes","s-timeout","s-sols","s-setup","flags"'
+
+for p in P1/*.param ; do
+ for a in "" \
+{," -Dup_down_bounds"}\
+{," -Dopposite_move_check"}\
+{," -Dfill_all"}\
+{," -Dno_block_moves"}\
+{," -Dno_repeat_moves"} ; do
+ echo "$s" "$p" $a
+ done
+done | xargs -L 1 -P $(nproc) sh run.sh
diff --git a/bin/run.sh b/bin/run.sh
new file mode 100755
index 0000000..d4765bb
--- /dev/null
+++ b/bin/run.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+set -e
+
+defs="${@:3}"
+dir=$(mktemp -d)
+trap "rm -rf $dir" EXIT
+
+s=$dir/solver.eprime
+p=$dir/problem.param
+cp $2 $p
+
+< $1 m4 $defs > $s
+
+savilerow -run-solver $s $p &> $p.log
+# infor=$(< $p.infor sed 's/ /,/g')
+# echo "$infor",'"'"$defs"'"'
+info=$(< $p.info awk -F ':' '{printf "%s,", $2}')
+echo '"'"$2"'"',"$info"'"'"$defs"'"'
diff --git a/bin/togrid.pl b/bin/togrid.pl
new file mode 100755
index 0000000..446f32b
--- /dev/null
+++ b/bin/togrid.pl
@@ -0,0 +1,80 @@
+#!/bin/perl
+
+use feature 'unicode_strings';
+use utf8;
+
+use strict;
+use warnings;
+
+use POSIX;
+use List::Util qw(max);
+
+binmode STDOUT, ":utf8";
+
+my @moves;
+my @order;
+while (my $line = <STDIN>) {
+ chomp($line);
+
+ if ($line =~ /moves/) {
+ @moves = split(', ', substr($line, 18, -1));
+ }
+ elsif ($line =~ /order/) {
+ @order = split(', ', substr($line, 18, -1));
+ }
+}
+
+my $width = max(ceil(sqrt(max(@order))), max(@moves));
+
+my @grid;
+
+if ($moves[0] == 1) { $grid[$order[0]-1] = "╺"; }
+elsif ($moves[0] == -1) { $grid[$order[0]-1] = "╸"; }
+elsif ($moves[0] == $width) { $grid[$order[0]-1] = "╻"; }
+elsif ($moves[0] == -$width) { $grid[$order[0]-1] = "╹"; }
+
+$grid[$order[0]-1] = "X";
+
+my $last = $moves[0];
+
+my $i;
+for ($i = 1; $i < scalar(@moves); $i++) {
+ my $o;
+
+ if ($moves[$i] == 1) {
+ if ($last ==1) { $o = "━"; }
+ elsif ($last ==$width) { $o = "┗"; }
+ elsif ($last ==-$width) { $o = "┏"; }
+ }
+ elsif ($moves[$i] == -1) {
+ if ($last ==-1) { $o = "━"; }
+ elsif ($last ==$width) { $o = "┛"; }
+ elsif ($last ==-$width) { $o = "┓"; }
+ }
+ elsif ($moves[$i] == $width) {
+ if ($last ==1) { $o = "┓"; }
+ elsif ($last ==-1) { $o = "┏"; }
+ elsif ($last ==$width) { $o = "┃"; }
+ }
+ elsif ($moves[$i] == -$width) {
+ if ($last ==1) { $o = "┛"; }
+ elsif ($last ==-1) { $o = "┗"; }
+ elsif ($last ==-$width) { $o = "┃"; }
+ }
+
+ $grid[$order[$i]-1] = $o;
+ $last = $moves[$i];
+}
+
+if ($last == -1) { $grid[$order[scalar(@order) - 1]-1] = "╺"; }
+elsif ($last == 1) { $grid[$order[scalar(@order) - 1]-1] = "╸"; }
+elsif ($last == -$width) { $grid[$order[scalar(@order) - 1]-1] = "╻"; }
+elsif ($last == $width) { $grid[$order[scalar(@order) - 1]-1] = "╹"; }
+
+for (my $x = 0; $x < $width; $x++) {
+ for (my $y = 0; $y < $width; $y++) {
+ # print($grid[$x * $width + $y] // "█");
+ print($grid[$x * $width + $y] // "■");
+ }
+ print("\n");
+}