diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-11 17:01:49 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-11 17:01:49 +0200 |
| commit | e6ff0ce6926fa921a13055c9c35d8e60b691e776 (patch) | |
| tree | 4af98713a2b43cbd229ca081d2dac877c8c36880 | |
| parent | dd6078288b5d7af4a4c0cdd1377a2976af569c9a (diff) | |
| download | nissy-core-e6ff0ce6926fa921a13055c9c35d8e60b691e776.tar.gz nissy-core-e6ff0ce6926fa921a13055c9c35d8e60b691e776.zip | |
Finished table refactor
| -rw-r--r-- | src/nissy.c | 47 | ||||
| -rw-r--r-- | src/nissy.h | 6 | ||||
| -rw-r--r-- | src/solvers/tables.h | 6 | ||||
| -rw-r--r-- | tools/001_gendata_h48h0k4/gendata_h48h0k4.c | 22 | ||||
| -rw-r--r-- | tools/002_gendata_h48h0k2/gendata_h48h0k2.c | 21 | ||||
| -rw-r--r-- | tools/020_solve_small/solve_small.c | 16 | ||||
| -rwxr-xr-x | tools/run_tool.sh | 2 | ||||
| -rw-r--r-- | tools/tool.h | 10 |
8 files changed, 88 insertions, 42 deletions
diff --git a/src/nissy.c b/src/nissy.c index de95e94..2d6af4b 100644 --- a/src/nissy.c +++ b/src/nissy.c | |||
| @@ -196,6 +196,53 @@ nissy_datasize( | |||
| 196 | } | 196 | } |
| 197 | 197 | ||
| 198 | int64_t | 198 | int64_t |
| 199 | nissy_datainfo( | ||
| 200 | const void *table, | ||
| 201 | void (*write)(const char *, ...) | ||
| 202 | ) | ||
| 203 | { | ||
| 204 | uint8_t i; | ||
| 205 | tableinfo_t info; | ||
| 206 | |||
| 207 | readtableinfo(table, &info); | ||
| 208 | |||
| 209 | write("\n---------\n\n"); | ||
| 210 | write("Table information for '%s'\n", info.solver); | ||
| 211 | write("\n"); | ||
| 212 | write("Size: %" PRIu64 " bytes\n", info.fullsize); | ||
| 213 | write("Entries: %" PRIu64 " (%" PRIu8 " bits per entry)", | ||
| 214 | info.entries, info.bits); | ||
| 215 | write("\n"); | ||
| 216 | |||
| 217 | switch (info.type) { | ||
| 218 | case TABLETYPE_PRUNING: | ||
| 219 | write("\n"); | ||
| 220 | if (info.base != 0) | ||
| 221 | write(" (base value = %" PRIu8 ")", info.base); | ||
| 222 | write(":\nValue\tPositions\n"); | ||
| 223 | for (i = 0; i <= info.maxvalue; i++) { | ||
| 224 | write("%" PRIu8 "\t%" PRIu64 "\n", | ||
| 225 | i, info.distribution[i]); | ||
| 226 | } | ||
| 227 | break; | ||
| 228 | case TABLETYPE_SPECIAL: | ||
| 229 | write("This is an ad-hoc table\n"); | ||
| 230 | break; | ||
| 231 | default: | ||
| 232 | LOG("datainfo: unknown table type\n"); | ||
| 233 | return 1; | ||
| 234 | } | ||
| 235 | |||
| 236 | if (info.next != 0) { | ||
| 237 | return nissy_datainfo((char *)table + info.next, write); | ||
| 238 | } | ||
| 239 | |||
| 240 | write("\n---------\n"); | ||
| 241 | |||
| 242 | return 0; | ||
| 243 | } | ||
| 244 | |||
| 245 | int64_t | ||
| 199 | nissy_gendata( | 246 | nissy_gendata( |
| 200 | const char *solver, | 247 | const char *solver, |
| 201 | const char *options, | 248 | const char *options, |
diff --git a/src/nissy.h b/src/nissy.h index 346b99a..336130c 100644 --- a/src/nissy.h +++ b/src/nissy.h | |||
| @@ -86,6 +86,12 @@ int64_t nissy_gendata( | |||
| 86 | void *generated_data | 86 | void *generated_data |
| 87 | ); | 87 | ); |
| 88 | 88 | ||
| 89 | /* Print information on a data table via the provided callback writer */ | ||
| 90 | int64_t nissy_datainfo( | ||
| 91 | const void *table, | ||
| 92 | void (*write)(const char *, ...) | ||
| 93 | ); | ||
| 94 | |||
| 89 | /* Returns the number of solutions found, or -1 in case of error */ | 95 | /* Returns the number of solutions found, or -1 in case of error */ |
| 90 | int64_t nissy_solve( | 96 | int64_t nissy_solve( |
| 91 | const char cube[static 22], | 97 | const char cube[static 22], |
diff --git a/src/solvers/tables.h b/src/solvers/tables.h index 44363fe..988de52 100644 --- a/src/solvers/tables.h +++ b/src/solvers/tables.h | |||
| @@ -4,6 +4,9 @@ | |||
| 4 | #define INFO_SOLVER_STRLEN 100 | 4 | #define INFO_SOLVER_STRLEN 100 |
| 5 | #define INFO_DISTRIBUTION_LEN 21 | 5 | #define INFO_DISTRIBUTION_LEN 21 |
| 6 | 6 | ||
| 7 | #define TABLETYPE_PRUNING 0 | ||
| 8 | #define TABLETYPE_SPECIAL 1 | ||
| 9 | |||
| 7 | #define INFO_OFFSET_SOLVER 0 | 10 | #define INFO_OFFSET_SOLVER 0 |
| 8 | #define INFO_OFFSET_TYPE INFO_SOLVER_STRLEN | 11 | #define INFO_OFFSET_TYPE INFO_SOLVER_STRLEN |
| 9 | #define INFO_OFFSET_INFOSIZE (INFO_OFFSET_TYPE + sizeof(uint64_t)) | 12 | #define INFO_OFFSET_INFOSIZE (INFO_OFFSET_TYPE + sizeof(uint64_t)) |
| @@ -17,9 +20,6 @@ | |||
| 17 | #define INFO_OFFSET_NEXT (INFO_OFFSET_MAXVALUE + sizeof(uint8_t)) | 20 | #define INFO_OFFSET_NEXT (INFO_OFFSET_MAXVALUE + sizeof(uint8_t)) |
| 18 | #define INFO_OFFSET_DISTRIBUTION (INFO_OFFSET_NEXT + sizeof(uint64_t)) | 21 | #define INFO_OFFSET_DISTRIBUTION (INFO_OFFSET_NEXT + sizeof(uint64_t)) |
| 19 | 22 | ||
| 20 | const uint64_t TABLETYPE_PRUNING = 0; | ||
| 21 | const uint64_t TABLETYPE_SPECIAL = 1; | ||
| 22 | |||
| 23 | typedef struct { | 23 | typedef struct { |
| 24 | char solver[INFO_SOLVER_STRLEN]; | 24 | char solver[INFO_SOLVER_STRLEN]; |
| 25 | uint64_t type; | 25 | uint64_t type; |
diff --git a/tools/001_gendata_h48h0k4/gendata_h48h0k4.c b/tools/001_gendata_h48h0k4/gendata_h48h0k4.c index 0e3deb1..a9993b8 100644 --- a/tools/001_gendata_h48h0k4/gendata_h48h0k4.c +++ b/tools/001_gendata_h48h0k4/gendata_h48h0k4.c | |||
| @@ -27,8 +27,6 @@ uint32_t expected[21] = { | |||
| 27 | char *buf; | 27 | char *buf; |
| 28 | 28 | ||
| 29 | void run(void) { | 29 | void run(void) { |
| 30 | uint32_t *h48info, x; | ||
| 31 | int i; | ||
| 32 | int64_t s; | 30 | int64_t s; |
| 33 | 31 | ||
| 34 | s = nissy_gendata("h48", OPTIONS, buf); | 32 | s = nissy_gendata("h48", OPTIONS, buf); |
| @@ -36,20 +34,12 @@ void run(void) { | |||
| 36 | if (s == -1) { | 34 | if (s == -1) { |
| 37 | printf("Error generating table\n"); | 35 | printf("Error generating table\n"); |
| 38 | } else { | 36 | } else { |
| 39 | printf("Table is probably ok\n"); | 37 | nissy_datainfo(buf, write_stdout); |
| 40 | /* | 38 | printf("\n"); |
| 41 | TODO: adapt to new tables | 39 | printf("Succesfully generated %" PRId64 " bytes. " |
| 42 | printf("Succesfully generated %" PRId64 " bytes. Table:\n", s); | 40 | "See above for details on the tables.\n", s); |
| 43 | h48info = (uint32_t *)buf + 1 + (ETABLESIZE(HVALUE) + COCSEPSIZE) / 4; | 41 | |
| 44 | for (i = 0; i < MAXDEPTH+1 && h48info[i+1]; i++) { | 42 | /* TODO: check that the table is correct */ |
| 45 | x = h48info[i+1]; | ||
| 46 | printf("%d:\t%" PRIu32, i, x); | ||
| 47 | if (x != expected[i]) | ||
| 48 | printf(" <--- Error! Expected: %" PRIu32, | ||
| 49 | expected[i]); | ||
| 50 | printf("\n"); | ||
| 51 | } | ||
| 52 | */ | ||
| 53 | } | 43 | } |
| 54 | } | 44 | } |
| 55 | 45 | ||
diff --git a/tools/002_gendata_h48h0k2/gendata_h48h0k2.c b/tools/002_gendata_h48h0k2/gendata_h48h0k2.c index 2754f80..271d339 100644 --- a/tools/002_gendata_h48h0k2/gendata_h48h0k2.c +++ b/tools/002_gendata_h48h0k2/gendata_h48h0k2.c | |||
| @@ -5,9 +5,6 @@ | |||
| 5 | #define OPTIONS "0;2;20" | 5 | #define OPTIONS "0;2;20" |
| 6 | #define LONGOPTIONS "h = 0, k = 2, max depth = 20" | 6 | #define LONGOPTIONS "h = 0, k = 2, max depth = 20" |
| 7 | 7 | ||
| 8 | #define COCSEPSIZE 1119792 | ||
| 9 | #define ETABLESIZE(h) (((3393 * 495 * 70) >> 2) << (size_t)(h)) | ||
| 10 | |||
| 11 | uint32_t expected[21] = { | 8 | uint32_t expected[21] = { |
| 12 | /* Base value is 8 */ | 9 | /* Base value is 8 */ |
| 13 | [0] = 5473562, | 10 | [0] = 5473562, |
| @@ -19,8 +16,6 @@ uint32_t expected[21] = { | |||
| 19 | char *buf; | 16 | char *buf; |
| 20 | 17 | ||
| 21 | void run(void) { | 18 | void run(void) { |
| 22 | uint32_t *h48info, x; | ||
| 23 | int i; | ||
| 24 | int64_t s; | 19 | int64_t s; |
| 25 | 20 | ||
| 26 | s = nissy_gendata("h48", OPTIONS, buf); | 21 | s = nissy_gendata("h48", OPTIONS, buf); |
| @@ -28,16 +23,12 @@ void run(void) { | |||
| 28 | if (s == -1) { | 23 | if (s == -1) { |
| 29 | printf("Error generating table\n"); | 24 | printf("Error generating table\n"); |
| 30 | } else { | 25 | } else { |
| 31 | printf("Succesfully generated %" PRId64 " bytes. Table:\n", s); | 26 | nissy_datainfo(buf, write_stdout); |
| 32 | h48info = (uint32_t *)buf + 1 + (ETABLESIZE(HVALUE) + COCSEPSIZE) / 4; | 27 | printf("\n"); |
| 33 | for (i = 0; i < 4; i++) { | 28 | printf("Succesfully generated %" PRId64 " bytes. " |
| 34 | x = h48info[i+1]; | 29 | "See above for details on the tables.\n", s); |
| 35 | printf("%d:\t%" PRIu32, i, x); | 30 | |
| 36 | if (x != expected[i]) | 31 | /* TODO: check that the table is correct */ |
| 37 | printf(" <--- Error! Expected: %" PRIu32, | ||
| 38 | expected[i]); | ||
| 39 | printf("\n"); | ||
| 40 | } | ||
| 41 | } | 32 | } |
| 42 | } | 33 | } |
| 43 | 34 | ||
diff --git a/tools/020_solve_small/solve_small.c b/tools/020_solve_small/solve_small.c index dee2b55..4d07728 100644 --- a/tools/020_solve_small/solve_small.c +++ b/tools/020_solve_small/solve_small.c | |||
| @@ -20,20 +20,22 @@ void run(void) { | |||
| 20 | 20 | ||
| 21 | printf("Solved the following scrambles:\n\n"); | 21 | printf("Solved the following scrambles:\n\n"); |
| 22 | for (i = 0; scrambles[i] != NULL; i++) { | 22 | for (i = 0; scrambles[i] != NULL; i++) { |
| 23 | printf("%s\n", scrambles[i]); | 23 | printf("%d. %s\n", i+1, scrambles[i]); |
| 24 | fprintf(stderr, "Solving scramble %s\n", scrambles[i]); | 24 | fprintf(stderr, "Solving scramble %s\n", scrambles[i]); |
| 25 | if (nissy_frommoves(scrambles[i], cube) == -1) { | 25 | if (nissy_frommoves(scrambles[i], cube) == -1) { |
| 26 | fprintf(stderr, "Invalid scramble, " | 26 | fprintf(stderr, "Invalid scramble\n"); |
| 27 | "continuing with next scramble\n"); | 27 | printf("Invalid\n"); |
| 28 | continue; | 28 | continue; |
| 29 | } | 29 | } |
| 30 | n = nissy_solve( | 30 | n = nissy_solve( |
| 31 | cube, "h48", options, "", 0, 20, 1, -1, buf, sol); | 31 | cube, "h48", options, "", 0, 20, 1, -1, buf, sol); |
| 32 | if (n == 0) | 32 | if (n == 0) { |
| 33 | fprintf(stderr, "No solution found, " | 33 | printf("No solution\n"); |
| 34 | "continuing with next scramble\n"); | 34 | fprintf(stderr, "No solution found\n"); |
| 35 | } else { | ||
| 36 | printf("Solutions:\n%s\n", sol); | ||
| 37 | } | ||
| 35 | } | 38 | } |
| 36 | printf("\n"); | ||
| 37 | } | 39 | } |
| 38 | 40 | ||
| 39 | int main(void) { | 41 | int main(void) { |
diff --git a/tools/run_tool.sh b/tools/run_tool.sh index 2462b2d..cec7630 100755 --- a/tools/run_tool.sh +++ b/tools/run_tool.sh | |||
| @@ -16,7 +16,7 @@ for t in tools/*; do | |||
| 16 | fi | 16 | fi |
| 17 | toolname="$(basename "$t" .c)" | 17 | toolname="$(basename "$t" .c)" |
| 18 | $CC -o $BIN $t/*.c $CUBEOBJ || exit 1; | 18 | $CC -o $BIN $t/*.c $CUBEOBJ || exit 1; |
| 19 | $BIN | tee "tools/results/$toolname-$d.txt" | 19 | $BIN | tee "tools/results/$toolname-$d.txt" "tools/results/last.out" |
| 20 | break | 20 | break |
| 21 | done | 21 | done |
| 22 | 22 | ||
diff --git a/tools/tool.h b/tools/tool.h index d75342d..7995621 100644 --- a/tools/tool.h +++ b/tools/tool.h | |||
| @@ -18,6 +18,16 @@ log_stderr(const char *str, ...) | |||
| 18 | va_end(args); | 18 | va_end(args); |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | static void | ||
| 22 | write_stdout(const char *str, ...) | ||
| 23 | { | ||
| 24 | va_list args; | ||
| 25 | |||
| 26 | va_start(args, str); | ||
| 27 | vfprintf(stdout, str, args); | ||
| 28 | va_end(args); | ||
| 29 | } | ||
| 30 | |||
| 21 | static double | 31 | static double |
| 22 | timerun(void (*run)(void), char *name) | 32 | timerun(void (*run)(void), char *name) |
| 23 | { | 33 | { |
