diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-07-08 19:22:16 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-07-08 19:22:16 +0200 |
| commit | c2275e4b9625a1a19eb50d0880f70ed583d5c358 (patch) | |
| tree | f1b6798f017dd62ece5b56f05d5c7201ba50ff39 /tools | |
| parent | 66c1c11ec13d362ddfb1b5f6abe8127969c0ad29 (diff) | |
| download | nissy-core-c2275e4b9625a1a19eb50d0880f70ed583d5c358.tar.gz nissy-core-c2275e4b9625a1a19eb50d0880f70ed583d5c358.zip | |
Stats for h48 solver as tool
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/run_tool.sh | 14 | ||||
| -rw-r--r-- | tools/stats_tables_h48/stats_tables_h48.c | 85 |
2 files changed, 75 insertions, 24 deletions
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 | |||
| 6 | fi | 6 | fi |
| 7 | 7 | ||
| 8 | CC="cc -std=c99 -pedantic -Wall -Wextra \ | 8 | CC="cc -std=c99 -pedantic -Wall -Wextra \ |
| 9 | -Wno-unused-parameter -Wno-unused-function -O3 -D$CUBETYPE \ | 9 | -Wno-unused-parameter -Wno-unused-function -D$CUBETYPE \ |
| 10 | -D_POSIX_C_SOURCE=199309L" | 10 | -D_POSIX_C_SOURCE=199309L" |
| 11 | 11 | ||
| 12 | if [ -n "$DEBUG" ]; then | ||
| 13 | CC="$CC -fsanitize=address -g3" | ||
| 14 | CUBEOBJ="debugcube.o" | ||
| 15 | else | ||
| 16 | CC="$CC -O3" | ||
| 17 | CUBEOBJ="cube.o" | ||
| 18 | fi | ||
| 19 | |||
| 12 | [ "$CUBETYPE" = "CUBE_AVX2" ] && CC="$CC -mavx2" | 20 | [ "$CUBETYPE" = "CUBE_AVX2" ] && CC="$CC -mavx2" |
| 13 | 21 | ||
| 14 | BIN="tools/run" | 22 | BIN="tools/run" |
| 15 | CUBEOBJ="cube.o" | ||
| 16 | d="$(date +'%Y-%m-%d-%H-%M-%S')" | 23 | d="$(date +'%Y-%m-%d-%H-%M-%S')" |
| 17 | 24 | ||
| 18 | for t in tools/*; do | 25 | for t in tools/*; do |
| 19 | if [ ! -d "$t" ] || [ -z "$(echo "$t" | grep "$TOOL")" ]; then | 26 | if [ ! -d "$t" ] || [ -z "$(echo "$t" | grep "$TOOL")" ]; then |
| 20 | continue | 27 | continue |
| 21 | fi | 28 | fi |
| 29 | toolname="$(basename "$t" .c)" | ||
| 22 | $CC -o $BIN $t/*.c $CUBEOBJ || exit 1; | 30 | $CC -o $BIN $t/*.c $CUBEOBJ || exit 1; |
| 23 | $BIN | 31 | $BIN | tee "tools/results/$toolname-$d.txt" |
| 24 | break | 32 | break |
| 25 | done | 33 | done |
| 26 | 34 | ||
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 @@ | |||
| 1 | #include <stdarg.h> | ||
| 1 | #include <time.h> | 2 | #include <time.h> |
| 2 | #include "../timerun.h" | 3 | #include "../timerun.h" |
| 3 | #include "../../src/cube.h" | 4 | #include "../../src/cube.h" |
| 4 | 5 | ||
| 5 | #define MAXMOVES 20 | 6 | #define MAXMOVES 20 |
| 6 | #define NCUBES 1000 | 7 | #define NCUBES 10000 |
| 8 | #define LOG_EVERY (NCUBES / 20) | ||
| 7 | 9 | ||
| 10 | const char *filename = "tables/h48h0k4"; | ||
| 8 | char *buf; | 11 | char *buf; |
| 9 | 12 | ||
| 10 | uint64_t rand64(void) { | 13 | uint64_t rand64(void) { |
| @@ -16,22 +19,18 @@ uint64_t rand64(void) { | |||
| 16 | return ret; | 19 | return ret; |
| 17 | } | 20 | } |
| 18 | 21 | ||
| 19 | void output(int64_t v[13][100]) { | 22 | void log_stderr(const char *str, ...) { |
| 20 | /* TODO: write to file and output only cocsepdata table stats */ | 23 | va_list args; |
| 24 | |||
| 25 | va_start(args, str); | ||
| 26 | vfprintf(stderr, str, args); | ||
| 27 | va_end(args); | ||
| 21 | } | 28 | } |
| 22 | 29 | ||
| 23 | void run(void) { | 30 | void run(void) { |
| 24 | uint32_t *h48info; | 31 | int i, j, k; |
| 25 | int i, j; | 32 | char sols[12], cube[22]; |
| 26 | char sols[13], cube[22]; | 33 | int64_t ep, eo, cp, co, v[12][100] = {0}; |
| 27 | int64_t s, ep, eo, cp, co, v[13][100] = {0}; | ||
| 28 | |||
| 29 | s = nissy_gendata("H48stats", "", buf); | ||
| 30 | |||
| 31 | if (s == -1) { | ||
| 32 | printf("Error generating table\n"); | ||
| 33 | return; | ||
| 34 | } | ||
| 35 | 34 | ||
| 36 | for (i = 0; i < NCUBES; i++) { | 35 | for (i = 0; i < NCUBES; i++) { |
| 37 | ep = rand64(); | 36 | ep = rand64(); |
| @@ -39,13 +38,53 @@ void run(void) { | |||
| 39 | cp = rand64(); | 38 | cp = rand64(); |
| 40 | co = rand64(); | 39 | co = rand64(); |
| 41 | nissy_getcube(ep, eo, cp, co, "fix", cube); | 40 | nissy_getcube(ep, eo, cp, co, "fix", cube); |
| 42 | nissy_solve(cube, "H48stats", | 41 | nissy_solve(cube, "h48stats", "", "", |
| 43 | "", "", "", 0, MAXMOVES, 1, -1, buf, sols); | 42 | 0, MAXMOVES, 1, -1, buf, sols); |
| 44 | for (j = 0; j < 13; j++) | 43 | for (j = 0; j < 12; j++) |
| 45 | v[j][(int)sols[j]]++; | 44 | v[j][(int)sols[j]]++; |
| 45 | if ((i+1) % LOG_EVERY == 0) | ||
| 46 | fprintf(stderr, "%d cubes solved...\n", i+1); | ||
| 46 | } | 47 | } |
| 47 | 48 | ||
| 48 | output(v); | 49 | for (j = 0; j < 12; j++) { |
| 50 | printf("Data for h=%d\n", j); | ||
| 51 | for (k = 0; k <= 16; k++) | ||
| 52 | printf("%d\t%" PRId64 "\n", k, v[j][k]); | ||
| 53 | printf("\n"); | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | int getdata(int64_t size) { | ||
| 58 | int64_t s; | ||
| 59 | FILE *f; | ||
| 60 | |||
| 61 | buf = malloc(size); | ||
| 62 | |||
| 63 | if ((f = fopen(filename, "rb")) == NULL) { | ||
| 64 | fprintf(stderr, "Table file not found, generating them." | ||
| 65 | " This can take a while.\n"); | ||
| 66 | s = nissy_gendata("h48stats", "", buf); | ||
| 67 | if (s != size) { | ||
| 68 | fprintf(stderr, "Error generating table"); | ||
| 69 | if (s != -1) | ||
| 70 | fprintf(stderr, " (got %" PRId64 " bytes)", s); | ||
| 71 | fprintf(stderr, "\n"); | ||
| 72 | return 1; | ||
| 73 | } | ||
| 74 | if ((f = fopen(filename, "wb")) == NULL) { | ||
| 75 | fprintf(stderr, "Could not write tables to file %s" | ||
| 76 | ", will be regenerated next time.\n", filename); | ||
| 77 | } else { | ||
| 78 | fwrite(buf, size, 1, f); | ||
| 79 | fclose(f); | ||
| 80 | } | ||
| 81 | } else { | ||
| 82 | fprintf(stderr, "Reading tables from file %s\n", filename); | ||
| 83 | fread(buf, size, 1, f); | ||
| 84 | fclose(f); | ||
| 85 | } | ||
| 86 | |||
| 87 | return 0; | ||
| 49 | } | 88 | } |
| 50 | 89 | ||
| 51 | int main() { | 90 | int main() { |
| @@ -53,17 +92,21 @@ int main() { | |||
| 53 | 92 | ||
| 54 | srand(time(NULL)); | 93 | srand(time(NULL)); |
| 55 | 94 | ||
| 56 | size = nissy_datasize("H48", OPTIONS); | 95 | nissy_setlogger(log_stderr); |
| 96 | size = nissy_datasize("h48stats", ""); | ||
| 57 | if (size == -1) { | 97 | if (size == -1) { |
| 58 | printf("h48 stats: error in datasize\n"); | 98 | printf("h48 stats: error in datasize\n"); |
| 59 | return 1; | 99 | return 1; |
| 60 | } | 100 | } |
| 61 | 101 | ||
| 62 | buf = malloc(size); | 102 | if (getdata(size) != 0) { |
| 103 | printf("Error getting table, stopping\n"); | ||
| 104 | free(buf); | ||
| 105 | return 1; | ||
| 106 | } | ||
| 63 | 107 | ||
| 64 | timerun(run, "h48 table stats"); | 108 | timerun(run, "h48 table stats"); |
| 65 | 109 | ||
| 66 | free(buf); | 110 | free(buf); |
| 67 | |||
| 68 | return 0; | 111 | return 0; |
| 69 | } | 112 | } |
