From c2275e4b9625a1a19eb50d0880f70ed583d5c358 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 8 Jul 2024 19:22:16 +0200 Subject: Stats for h48 solver as tool --- tools/run_tool.sh | 14 +++-- tools/stats_tables_h48/stats_tables_h48.c | 85 +++++++++++++++++++++++-------- 2 files changed, 75 insertions(+), 24 deletions(-) (limited to 'tools') diff --git a/tools/run_tool.sh b/tools/run_tool.sh index 21b6ce9..14d0e45 100755 --- a/tools/run_tool.sh +++ b/tools/run_tool.sh @@ -6,21 +6,29 @@ if [ -z "$TOOL" ]; then fi CC="cc -std=c99 -pedantic -Wall -Wextra \ - -Wno-unused-parameter -Wno-unused-function -O3 -D$CUBETYPE \ + -Wno-unused-parameter -Wno-unused-function -D$CUBETYPE \ -D_POSIX_C_SOURCE=199309L" +if [ -n "$DEBUG" ]; then + CC="$CC -fsanitize=address -g3" + CUBEOBJ="debugcube.o" +else + CC="$CC -O3" + CUBEOBJ="cube.o" +fi + [ "$CUBETYPE" = "CUBE_AVX2" ] && CC="$CC -mavx2" BIN="tools/run" -CUBEOBJ="cube.o" d="$(date +'%Y-%m-%d-%H-%M-%S')" for t in tools/*; do if [ ! -d "$t" ] || [ -z "$(echo "$t" | grep "$TOOL")" ]; then continue fi + toolname="$(basename "$t" .c)" $CC -o $BIN $t/*.c $CUBEOBJ || exit 1; - $BIN + $BIN | tee "tools/results/$toolname-$d.txt" break done diff --git a/tools/stats_tables_h48/stats_tables_h48.c b/tools/stats_tables_h48/stats_tables_h48.c index b349f63..33272c1 100644 --- a/tools/stats_tables_h48/stats_tables_h48.c +++ b/tools/stats_tables_h48/stats_tables_h48.c @@ -1,10 +1,13 @@ +#include #include #include "../timerun.h" #include "../../src/cube.h" #define MAXMOVES 20 -#define NCUBES 1000 +#define NCUBES 10000 +#define LOG_EVERY (NCUBES / 20) +const char *filename = "tables/h48h0k4"; char *buf; uint64_t rand64(void) { @@ -16,22 +19,18 @@ uint64_t rand64(void) { return ret; } -void output(int64_t v[13][100]) { -/* TODO: write to file and output only cocsepdata table stats */ +void log_stderr(const char *str, ...) { + va_list args; + + va_start(args, str); + vfprintf(stderr, str, args); + va_end(args); } void run(void) { - uint32_t *h48info; - int i, j; - char sols[13], cube[22]; - int64_t s, ep, eo, cp, co, v[13][100] = {0}; - - s = nissy_gendata("H48stats", "", buf); - - if (s == -1) { - printf("Error generating table\n"); - return; - } + int i, j, k; + char sols[12], cube[22]; + int64_t ep, eo, cp, co, v[12][100] = {0}; for (i = 0; i < NCUBES; i++) { ep = rand64(); @@ -39,13 +38,53 @@ void run(void) { cp = rand64(); co = rand64(); nissy_getcube(ep, eo, cp, co, "fix", cube); - nissy_solve(cube, "H48stats", - "", "", "", 0, MAXMOVES, 1, -1, buf, sols); - for (j = 0; j < 13; j++) + nissy_solve(cube, "h48stats", "", "", + 0, MAXMOVES, 1, -1, buf, sols); + for (j = 0; j < 12; j++) v[j][(int)sols[j]]++; + if ((i+1) % LOG_EVERY == 0) + fprintf(stderr, "%d cubes solved...\n", i+1); } - output(v); + for (j = 0; j < 12; j++) { + printf("Data for h=%d\n", j); + for (k = 0; k <= 16; k++) + printf("%d\t%" PRId64 "\n", k, v[j][k]); + printf("\n"); + } +} + +int getdata(int64_t size) { + int64_t s; + FILE *f; + + buf = malloc(size); + + if ((f = fopen(filename, "rb")) == NULL) { + fprintf(stderr, "Table file not found, generating them." + " This can take a while.\n"); + s = nissy_gendata("h48stats", "", buf); + if (s != size) { + fprintf(stderr, "Error generating table"); + if (s != -1) + fprintf(stderr, " (got %" PRId64 " bytes)", s); + fprintf(stderr, "\n"); + return 1; + } + if ((f = fopen(filename, "wb")) == NULL) { + fprintf(stderr, "Could not write tables to file %s" + ", will be regenerated next time.\n", filename); + } else { + fwrite(buf, size, 1, f); + fclose(f); + } + } else { + fprintf(stderr, "Reading tables from file %s\n", filename); + fread(buf, size, 1, f); + fclose(f); + } + + return 0; } int main() { @@ -53,17 +92,21 @@ int main() { srand(time(NULL)); - size = nissy_datasize("H48", OPTIONS); + nissy_setlogger(log_stderr); + size = nissy_datasize("h48stats", ""); if (size == -1) { printf("h48 stats: error in datasize\n"); return 1; } - buf = malloc(size); + if (getdata(size) != 0) { + printf("Error getting table, stopping\n"); + free(buf); + return 1; + } timerun(run, "h48 table stats"); free(buf); - return 0; } -- cgit v1.3