diff options
Diffstat (limited to 'tools/003_solve_small/solve_small.c')
| -rw-r--r-- | tools/003_solve_small/solve_small.c | 55 |
1 files changed, 6 insertions, 49 deletions
diff --git a/tools/003_solve_small/solve_small.c b/tools/003_solve_small/solve_small.c index 406e255..dee2b55 100644 --- a/tools/003_solve_small/solve_small.c +++ b/tools/003_solve_small/solve_small.c | |||
| @@ -1,12 +1,12 @@ | |||
| 1 | #include <pthread.h> | 1 | #include <pthread.h> |
| 2 | #include <time.h> | ||
| 3 | #include "../timerun.h" | ||
| 4 | #include "../../src/nissy.h" | ||
| 5 | 2 | ||
| 6 | #define OPTIONS "0;4;20" | 3 | #include "../tool.h" |
| 7 | 4 | ||
| 5 | const char *solver = "h48"; | ||
| 6 | const char *options = "0;4;20"; | ||
| 8 | const char *filename = "tables/h48h0k4"; | 7 | const char *filename = "tables/h48h0k4"; |
| 9 | char *buf; | 8 | char *buf; |
| 9 | |||
| 10 | char *scrambles[] = { | 10 | char *scrambles[] = { |
| 11 | "R D' R2 D R U2 R' D' R U2 R D R'", /* 12 optimal */ | 11 | "R D' R2 D R U2 R' D' R U2 R D R'", /* 12 optimal */ |
| 12 | "RLUD RLUD RLUD", /* 12 optimal */ | 12 | "RLUD RLUD RLUD", /* 12 optimal */ |
| @@ -28,7 +28,7 @@ void run(void) { | |||
| 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 | fprintf(stderr, "No solution found, " |
| 34 | "continuing with next scramble\n"); | 34 | "continuing with next scramble\n"); |
| @@ -36,56 +36,13 @@ void run(void) { | |||
| 36 | printf("\n"); | 36 | printf("\n"); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | int getdata(int64_t size) { | ||
| 40 | int64_t s; | ||
| 41 | FILE *f; | ||
| 42 | |||
| 43 | buf = malloc(size); | ||
| 44 | |||
| 45 | if ((f = fopen(filename, "rb")) == NULL) { | ||
| 46 | fprintf(stderr, "Table file not found, generating them." | ||
| 47 | " This can take a while.\n"); | ||
| 48 | s = nissy_gendata("h48", OPTIONS, buf); | ||
| 49 | if (s != size) { | ||
| 50 | fprintf(stderr, "Error generating table"); | ||
| 51 | if (s != -1) | ||
| 52 | fprintf(stderr, " (got %" PRId64 " bytes)", s); | ||
| 53 | fprintf(stderr, "\n"); | ||
| 54 | return 1; | ||
| 55 | } | ||
| 56 | if ((f = fopen(filename, "wb")) == NULL) { | ||
| 57 | fprintf(stderr, "Could not write tables to file %s" | ||
| 58 | ", will be regenerated next time.\n", filename); | ||
| 59 | } else { | ||
| 60 | fwrite(buf, size, 1, f); | ||
| 61 | fclose(f); | ||
| 62 | } | ||
| 63 | } else { | ||
| 64 | fprintf(stderr, "Reading tables from file %s\n", filename); | ||
| 65 | fread(buf, size, 1, f); | ||
| 66 | fclose(f); | ||
| 67 | } | ||
| 68 | |||
| 69 | return 0; | ||
| 70 | } | ||
| 71 | |||
| 72 | int main(void) { | 39 | int main(void) { |
| 73 | int64_t size; | ||
| 74 | 40 | ||
| 75 | srand(time(NULL)); | 41 | srand(time(NULL)); |
| 76 | |||
| 77 | nissy_setlogger(log_stderr); | 42 | nissy_setlogger(log_stderr); |
| 78 | size = nissy_datasize("h48", OPTIONS); | ||
| 79 | if (size == -1) { | ||
| 80 | printf("h48 stats: error in datasize\n"); | ||
| 81 | return 1; | ||
| 82 | } | ||
| 83 | 43 | ||
| 84 | if (getdata(size) != 0) { | 44 | if (getdata(solver, options, &buf, filename) != 0) |
| 85 | printf("Error getting table, stopping\n"); | ||
| 86 | free(buf); | ||
| 87 | return 1; | 45 | return 1; |
| 88 | } | ||
| 89 | 46 | ||
| 90 | timerun(run, "small solver benchmark"); | 47 | timerun(run, "small solver benchmark"); |
| 91 | 48 | ||
