diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-10-10 14:30:39 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-10-10 14:30:39 +0200 |
| commit | f8d247c53c3c3bd94fed645b5b47a9096cadc123 (patch) | |
| tree | 7a62cc7322ea8175a7df9b655d4a9d5e026a004a | |
| parent | 2e93de4ad102973961cb24d5b91f0c299763299f (diff) | |
| download | nissy-core-f8d247c53c3c3bd94fed645b5b47a9096cadc123.tar.gz nissy-core-f8d247c53c3c3bd94fed645b5b47a9096cadc123.zip | |
Removed "options" from solver selection
Now the solver name fully determines the solver (and options)
to be used. For example, now one must specify "h48h0k4" as the
name of the solver.
This PR also fixes a couple of things in tools.
| -rw-r--r-- | README.md | 4 | ||||
| -rwxr-xr-x | configure.sh | 1 | ||||
| -rw-r--r-- | shell.c | 32 | ||||
| -rw-r--r-- | src/nissy.c | 112 | ||||
| -rw-r--r-- | src/nissy.h | 7 | ||||
| -rw-r--r-- | tools/000_gendata/gendata.c | 23 | ||||
| -rw-r--r-- | tools/001_derive_h48/derive_h48.c | 12 | ||||
| -rw-r--r-- | tools/100_checkdata/checkdata.c | 17 | ||||
| -rw-r--r-- | tools/200_stats_tables_h48/stats_tables_h48.c | 30 | ||||
| -rw-r--r-- | tools/300_solve_small/solve_small.c | 11 | ||||
| -rw-r--r-- | tools/expected_distributions.h | 2 | ||||
| -rw-r--r-- | tools/nissy_extra.h | 2 | ||||
| -rw-r--r-- | tools/tool.h | 88 | ||||
| -rwxr-xr-x | tools/tool.sh | 3 |
14 files changed, 161 insertions, 183 deletions
| @@ -130,10 +130,10 @@ $ ./run convert -fin B32 -fout H48 -cubestr "WDSQREVX=VBKYDUCJXWAb" | |||
| 130 | UL1 UB0 BL0 FR1 DF0 UR1 DB0 FL0 DR1 DL1 UF0 BR1 DFR2 DBR0 DFL2 UFR2 UBL2 UFL0 UBR2 DBL2 | 130 | UL1 UB0 BL0 FR1 DF0 UR1 DB0 FL0 DR1 DL1 UF0 BR1 DFR2 DBR0 DFL2 UFR2 UBL2 UFL0 UBR2 DBL2 |
| 131 | ``` | 131 | ``` |
| 132 | 132 | ||
| 133 | To solve a cube (experimental) you can use: | 133 | To solve a cube you can use: |
| 134 | 134 | ||
| 135 | ``` | 135 | ``` |
| 136 | $ ./run solve -solver "h48" -options "0;20" -n 1 -M 4 -cube "JLQWSVUH=ZLCUABGIVTKH" | 136 | $ ./run solve -solver "h48h0k4" -n 1 -M 4 -cube "JLQWSVUH=ZLCUABGIVTKH" |
| 137 | Found 0 solutions, searching at depth 0 | 137 | Found 0 solutions, searching at depth 0 |
| 138 | Found 0 solutions, searching at depth 1 | 138 | Found 0 solutions, searching at depth 1 |
| 139 | Found 0 solutions, searching at depth 2 | 139 | Found 0 solutions, searching at depth 2 |
diff --git a/configure.sh b/configure.sh index 09d1310..51e1089 100755 --- a/configure.sh +++ b/configure.sh | |||
| @@ -71,6 +71,7 @@ validatearch() { | |||
| 71 | ;; | 71 | ;; |
| 72 | *) | 72 | *) |
| 73 | echo "Error: architecture '$ARCH' not supported" | 73 | echo "Error: architecture '$ARCH' not supported" |
| 74 | echo "Supported architectures: AVX2, NEON, PORTABLE" | ||
| 74 | exit 1 | 75 | exit 1 |
| 75 | ;; | 76 | ;; |
| 76 | esac | 77 | esac |
| @@ -23,7 +23,6 @@ | |||
| 23 | #define FLAG_MOVES "-moves" | 23 | #define FLAG_MOVES "-moves" |
| 24 | #define FLAG_TRANS "-trans" | 24 | #define FLAG_TRANS "-trans" |
| 25 | #define FLAG_SOLVER "-solver" | 25 | #define FLAG_SOLVER "-solver" |
| 26 | #define FLAG_OPTIONS "-options" | ||
| 27 | #define FLAG_NISSTYPE "-nisstype" | 26 | #define FLAG_NISSTYPE "-nisstype" |
| 28 | #define FLAG_MINMOVES "-m" | 27 | #define FLAG_MINMOVES "-m" |
| 29 | #define FLAG_MAXMOVES "-M" | 28 | #define FLAG_MAXMOVES "-M" |
| @@ -50,7 +49,6 @@ typedef struct { | |||
| 50 | char *str_moves; | 49 | char *str_moves; |
| 51 | char *str_trans; | 50 | char *str_trans; |
| 52 | char *str_solver; | 51 | char *str_solver; |
| 53 | char *str_options; /* TODO: remove, use only solver */ | ||
| 54 | char *str_nisstype; /* TODO: remove, use flags */ | 52 | char *str_nisstype; /* TODO: remove, use flags */ |
| 55 | int8_t minmoves; | 53 | int8_t minmoves; |
| 56 | int8_t maxmoves; | 54 | int8_t maxmoves; |
| @@ -87,7 +85,6 @@ static bool set_str_format_out(int, char **, args_t *); | |||
| 87 | static bool set_str_moves(int, char **, args_t *); | 85 | static bool set_str_moves(int, char **, args_t *); |
| 88 | static bool set_str_trans(int, char **, args_t *); | 86 | static bool set_str_trans(int, char **, args_t *); |
| 89 | static bool set_str_solver(int, char **, args_t *); | 87 | static bool set_str_solver(int, char **, args_t *); |
| 90 | static bool set_str_options(int, char **, args_t *); | ||
| 91 | static bool set_str_nisstype(int, char **, args_t *); | 88 | static bool set_str_nisstype(int, char **, args_t *); |
| 92 | static bool set_minmoves(int, char **, args_t *); | 89 | static bool set_minmoves(int, char **, args_t *); |
| 93 | static bool set_maxmoves(int, char **, args_t *); | 90 | static bool set_maxmoves(int, char **, args_t *); |
| @@ -113,7 +110,6 @@ struct { | |||
| 113 | OPTION(FLAG_MOVES, 1, set_str_moves), | 110 | OPTION(FLAG_MOVES, 1, set_str_moves), |
| 114 | OPTION(FLAG_TRANS, 1, set_str_trans), | 111 | OPTION(FLAG_TRANS, 1, set_str_trans), |
| 115 | OPTION(FLAG_SOLVER, 1, set_str_solver), | 112 | OPTION(FLAG_SOLVER, 1, set_str_solver), |
| 116 | OPTION(FLAG_OPTIONS, 1, set_str_options), /* TODO: remove, use only solver */ | ||
| 117 | OPTION(FLAG_NISSTYPE, 1, set_str_nisstype), /* TODO: remove, use flags */ | 113 | OPTION(FLAG_NISSTYPE, 1, set_str_nisstype), /* TODO: remove, use flags */ |
| 118 | OPTION(FLAG_MINMOVES, 1, set_minmoves), | 114 | OPTION(FLAG_MINMOVES, 1, set_minmoves), |
| 119 | OPTION(FLAG_MAXMOVES, 1, set_maxmoves), | 115 | OPTION(FLAG_MAXMOVES, 1, set_maxmoves), |
| @@ -183,21 +179,21 @@ struct { | |||
| 183 | ), | 179 | ), |
| 184 | COMMAND( | 180 | COMMAND( |
| 185 | "datasize", | 181 | "datasize", |
| 186 | "datasize " FLAG_SOLVER " SOLVER " FLAG_OPTIONS " OPTIONS", | 182 | "datasize " FLAG_SOLVER " SOLVER", |
| 187 | "Return the size in bytes of the data table used by " | 183 | "Return the size in bytes of the data table used by " |
| 188 | "SOLVER when called with the given OPTIONS.", | 184 | "SOLVER when called with the given OPTIONS.", |
| 189 | datasize_exec | 185 | datasize_exec |
| 190 | ), | 186 | ), |
| 191 | COMMAND( | 187 | COMMAND( |
| 192 | "gendata", | 188 | "gendata", |
| 193 | "gendata " FLAG_SOLVER " SOLVER " FLAG_OPTIONS " OPTIONS", | 189 | "gendata " FLAG_SOLVER " SOLVER", |
| 194 | "Generate the data table used by " | 190 | "Generate the data table used by " |
| 195 | "SOLVER when called with the given OPTIONS.", | 191 | "SOLVER when called with the given OPTIONS.", |
| 196 | gendata_exec | 192 | gendata_exec |
| 197 | ), | 193 | ), |
| 198 | COMMAND( | 194 | COMMAND( |
| 199 | "solve", | 195 | "solve", |
| 200 | "solve " FLAG_SOLVER " SOLVER " FLAG_OPTIONS " OPTIONS " | 196 | "solve " FLAG_SOLVER " SOLVER" |
| 201 | "[" FLAG_MINMOVES " n] [" FLAG_MAXMOVES " N] " | 197 | "[" FLAG_MINMOVES " n] [" FLAG_MAXMOVES " N] " |
| 202 | FLAG_CUBE " CUBE", | 198 | FLAG_CUBE " CUBE", |
| 203 | "Solve the given CUBE using SOLVER with the given OPTIONS, " | 199 | "Solve the given CUBE using SOLVER with the given OPTIONS, " |
| @@ -357,7 +353,7 @@ datasize_exec(args_t *args) | |||
| 357 | { | 353 | { |
| 358 | int64_t ret; | 354 | int64_t ret; |
| 359 | 355 | ||
| 360 | ret = nissy_datasize(args->str_solver, args->str_options); | 356 | ret = nissy_datasize(args->str_solver); |
| 361 | if (ret < 0) | 357 | if (ret < 0) |
| 362 | fprintf(stderr, "Unknown error (make sure solver is valid)\n"); | 358 | fprintf(stderr, "Unknown error (make sure solver is valid)\n"); |
| 363 | printf("%" PRId64 "\n", ret); | 359 | printf("%" PRId64 "\n", ret); |
| @@ -389,7 +385,7 @@ gendata_exec(args_t *args) | |||
| 389 | return -2; | 385 | return -2; |
| 390 | } | 386 | } |
| 391 | 387 | ||
| 392 | size = nissy_datasize(args->str_solver, args->str_options); | 388 | size = nissy_datasize(args->str_solver); |
| 393 | 389 | ||
| 394 | if (size < 0) { | 390 | if (size < 0) { |
| 395 | fprintf(stderr, | 391 | fprintf(stderr, |
| @@ -401,7 +397,7 @@ gendata_exec(args_t *args) | |||
| 401 | 397 | ||
| 402 | buf = malloc(size); | 398 | buf = malloc(size); |
| 403 | 399 | ||
| 404 | ret = nissy_gendata(args->str_solver, args->str_options, buf); | 400 | ret = nissy_gendata(args->str_solver, buf); |
| 405 | if (ret < 0) { | 401 | if (ret < 0) { |
| 406 | fprintf(stderr, "Unknown error in generating data\n"); | 402 | fprintf(stderr, "Unknown error in generating data\n"); |
| 407 | fclose(file); | 403 | fclose(file); |
| @@ -476,7 +472,7 @@ solve_exec(args_t *args) | |||
| 476 | return -1; | 472 | return -1; |
| 477 | } | 473 | } |
| 478 | 474 | ||
| 479 | size = nissy_datasize(args->str_solver, args->str_options); | 475 | size = nissy_datasize(args->str_solver); |
| 480 | buf = malloc(size); | 476 | buf = malloc(size); |
| 481 | read = fread(buf, size, 1, file); | 477 | read = fread(buf, size, 1, file); |
| 482 | fclose(file); | 478 | fclose(file); |
| @@ -488,9 +484,8 @@ solve_exec(args_t *args) | |||
| 488 | } | 484 | } |
| 489 | 485 | ||
| 490 | ret = nissy_solve( | 486 | ret = nissy_solve( |
| 491 | args->cube, args->str_solver, args->str_options, args->str_nisstype, | 487 | args->cube, args->str_solver, args->str_nisstype, args->minmoves, |
| 492 | args->minmoves, args->maxmoves, args->maxsolutions, args->optimal, | 488 | args->maxmoves, args->maxsolutions, args->optimal, buf, solutions); |
| 493 | buf, solutions); | ||
| 494 | 489 | ||
| 495 | free(buf); | 490 | free(buf); |
| 496 | 491 | ||
| @@ -545,7 +540,6 @@ parse_args(int argc, char **argv, args_t *args) | |||
| 545 | .str_moves = "", | 540 | .str_moves = "", |
| 546 | .str_trans = "", | 541 | .str_trans = "", |
| 547 | .str_solver = "", | 542 | .str_solver = "", |
| 548 | .str_options = "", | ||
| 549 | .str_nisstype = "", | 543 | .str_nisstype = "", |
| 550 | .minmoves = 0, | 544 | .minmoves = 0, |
| 551 | .maxmoves = 20, | 545 | .maxmoves = 20, |
| @@ -703,14 +697,6 @@ set_str_solver(int argc, char **argv, args_t *args) | |||
| 703 | } | 697 | } |
| 704 | 698 | ||
| 705 | static bool | 699 | static bool |
| 706 | set_str_options(int argc, char **argv, args_t *args) | ||
| 707 | { | ||
| 708 | args->str_options = argv[0]; | ||
| 709 | |||
| 710 | return true; | ||
| 711 | } | ||
| 712 | |||
| 713 | static bool | ||
| 714 | set_str_nisstype(int argc, char **argv, args_t *args) | 700 | set_str_nisstype(int argc, char **argv, args_t *args) |
| 715 | { | 701 | { |
| 716 | args->str_nisstype = argv[0]; | 702 | args->str_nisstype = argv[0]; |
diff --git a/src/nissy.c b/src/nissy.c index 44efb83..4a4c0fd 100644 --- a/src/nissy.c +++ b/src/nissy.c | |||
| @@ -12,13 +12,12 @@ | |||
| 12 | 12 | ||
| 13 | #include "nissy.h" | 13 | #include "nissy.h" |
| 14 | 14 | ||
| 15 | int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); | 15 | int parse_h48_solver(const char *, uint8_t [static 1], uint8_t [static 1]); |
| 16 | STATIC int64_t write_result(cube_t, char [static 22]); | 16 | STATIC int64_t write_result(cube_t, char [static 22]); |
| 17 | STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], | 17 | STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], |
| 18 | const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); | 18 | const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); |
| 19 | STATIC bool checkdata(const void *, const tableinfo_t *); | 19 | STATIC bool checkdata(const void *, const tableinfo_t *); |
| 20 | 20 | ||
| 21 | /* TODO: add option to get DR, maybe C-only, E-only, eo... */ | ||
| 22 | #define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F } | 21 | #define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F } |
| 23 | struct { | 22 | struct { |
| 24 | char *option; | 23 | char *option; |
| @@ -29,40 +28,41 @@ struct { | |||
| 29 | }; | 28 | }; |
| 30 | 29 | ||
| 31 | int | 30 | int |
| 32 | parse_h48_options(const char *buf, uint8_t *h, uint8_t *k, uint8_t *maxdepth) | 31 | parse_h48_solver(const char *buf, uint8_t h[static 1], uint8_t k[static 1]) |
| 33 | { | 32 | { |
| 34 | bool h_valid, k_valid, maxdepth_valid; | 33 | const char *fullbuf = buf; |
| 35 | int i; | 34 | |
| 35 | buf += 3; | ||
| 36 | |||
| 37 | if (!strcmp(buf, "stats")) { | ||
| 38 | *h = 0; | ||
| 39 | *k = 4; | ||
| 40 | return 0; | ||
| 41 | } | ||
| 36 | 42 | ||
| 37 | /* TODO temporarily, options are in the form "h;k;maxdepth" */ | 43 | if (*buf != 'h') |
| 38 | if (h != NULL) | 44 | goto parse_h48_solver_error; |
| 39 | *h = atoi(buf); | 45 | buf++; |
| 40 | h_valid = h == NULL || *h <= 11; | ||
| 41 | 46 | ||
| 42 | for (i = 0; buf[i] != ';'; i++) | 47 | *h = atoi(buf); |
| 43 | if (buf[i] == 0) | ||
| 44 | goto parse_h48_options_error; | ||
| 45 | 48 | ||
| 46 | if (k != NULL) | 49 | for ( ; *buf >= 0 + '0' && *buf <= 9 + '0'; buf++) |
| 47 | *k = atoi(&buf[i+1]); | 50 | if (*buf == 0) |
| 48 | k_valid = k == NULL || (*k == 2 || *k == 4); | 51 | goto parse_h48_solver_error; |
| 49 | 52 | ||
| 50 | for (i = i+1; buf[i] != ';'; i++) | 53 | if (*buf != 'k') |
| 51 | if (buf[i] == 0) | 54 | goto parse_h48_solver_error; |
| 52 | goto parse_h48_options_error; | 55 | buf++; |
| 53 | 56 | ||
| 54 | if (maxdepth != NULL) | 57 | *k = atoi(buf); |
| 55 | *maxdepth = atoi(&buf[i+1]); | ||
| 56 | maxdepth_valid = maxdepth == NULL || *maxdepth <= 20; | ||
| 57 | 58 | ||
| 58 | return h_valid && k_valid && maxdepth_valid ? 0 : 1; | 59 | return *h < 12 && (*k == 2 || (*k == 4 && *h == 0)) ? 0 : 1; |
| 59 | 60 | ||
| 60 | parse_h48_options_error: | 61 | parse_h48_solver_error: |
| 61 | *h = 0; | 62 | *h = 0; |
| 62 | *k = 0; | 63 | *k = 0; |
| 63 | *maxdepth = 0; | 64 | LOG("Error parsing solver: must be in \"h48h*k*\" format" |
| 64 | LOG("Error parsing options: must be in \"h;k;maxdepth\" format " | 65 | " or \"h48stats\", but got %s\n", fullbuf); |
| 65 | " (instead it was \"%s\")\n", buf); | ||
| 66 | return -1; | 66 | return -1; |
| 67 | } | 67 | } |
| 68 | 68 | ||
| @@ -103,13 +103,7 @@ distribution_equal( | |||
| 103 | } | 103 | } |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | if (wrong > 0) { | 106 | return wrong == 0; |
| 107 | LOG("checkdata: %d wrong values\n", wrong); | ||
| 108 | } else { | ||
| 109 | LOG("checkdata: table is consistent with info\n"); | ||
| 110 | } | ||
| 111 | |||
| 112 | return wrong > 0; | ||
| 113 | } | 107 | } |
| 114 | 108 | ||
| 115 | STATIC int64_t | 109 | STATIC int64_t |
| @@ -238,12 +232,11 @@ nissy_getcube( | |||
| 238 | 232 | ||
| 239 | int64_t | 233 | int64_t |
| 240 | nissy_datasize( | 234 | nissy_datasize( |
| 241 | const char *solver, | 235 | const char *solver |
| 242 | const char *options | ||
| 243 | ) | 236 | ) |
| 244 | { | 237 | { |
| 245 | /* gendata() handles a NULL *data as a "dryrun" request */ | 238 | /* gendata() handles a NULL *data as a "dryrun" request */ |
| 246 | return nissy_gendata(solver, options, NULL); | 239 | return nissy_gendata(solver, NULL); |
| 247 | } | 240 | } |
| 248 | 241 | ||
| 249 | int64_t | 242 | int64_t |
| @@ -294,7 +287,6 @@ nissy_datainfo( | |||
| 294 | int64_t | 287 | int64_t |
| 295 | nissy_gendata( | 288 | nissy_gendata( |
| 296 | const char *solver, | 289 | const char *solver, |
| 297 | const char *options, | ||
| 298 | void *data | 290 | void *data |
| 299 | ) | 291 | ) |
| 300 | { | 292 | { |
| @@ -303,21 +295,12 @@ nissy_gendata( | |||
| 303 | gendata_h48_arg_t arg; | 295 | gendata_h48_arg_t arg; |
| 304 | 296 | ||
| 305 | arg.buf = data; | 297 | arg.buf = data; |
| 306 | if (!strcmp(solver, "h48")) { | 298 | if (!strncmp(solver, "h48", 3)) { |
| 307 | p = parse_h48_options(options, &arg.h, &arg.k, &arg.maxdepth); | 299 | p = parse_h48_solver(solver, &arg.h, &arg.k); |
| 308 | if (p != 0) { | ||
| 309 | LOG("gendata: could not parse options\n"); | ||
| 310 | ret = -1; | ||
| 311 | } else { | ||
| 312 | ret = gendata_h48(&arg); | ||
| 313 | } | ||
| 314 | } else if (!strcmp(solver, "h48stats")) { | ||
| 315 | arg.h = 0; | ||
| 316 | arg.k = 4; | ||
| 317 | arg.maxdepth = 20; | 300 | arg.maxdepth = 20; |
| 318 | ret = gendata_h48(&arg); | 301 | ret = p == 0 ? (int64_t)gendata_h48(&arg) : -1; |
| 319 | } else { | 302 | } else { |
| 320 | LOG("gendata: implemented only for h48 solver\n"); | 303 | LOG("gendata: unknown solver %s\n", solver); |
| 321 | ret = -1; | 304 | ret = -1; |
| 322 | } | 305 | } |
| 323 | 306 | ||
| @@ -327,7 +310,6 @@ nissy_gendata( | |||
| 327 | int64_t | 310 | int64_t |
| 328 | nissy_checkdata( | 311 | nissy_checkdata( |
| 329 | const char *solver, | 312 | const char *solver, |
| 330 | const char *options, | ||
| 331 | const void *data | 313 | const void *data |
| 332 | ) | 314 | ) |
| 333 | { | 315 | { |
| @@ -335,8 +317,11 @@ nissy_checkdata( | |||
| 335 | tableinfo_t info; | 317 | tableinfo_t info; |
| 336 | 318 | ||
| 337 | for (buf = (char *)data; readtableinfo(buf, &info); buf += info.next) { | 319 | for (buf = (char *)data; readtableinfo(buf, &info); buf += info.next) { |
| 338 | if (!checkdata(buf, &info)) | 320 | if (!checkdata(buf, &info)) { |
| 321 | LOG("Error: data for %s is inconsistent with info!\n", | ||
| 322 | info.solver); | ||
| 339 | return 1; | 323 | return 1; |
| 324 | } | ||
| 340 | if (info.next == 0) | 325 | if (info.next == 0) |
| 341 | break; | 326 | break; |
| 342 | } | 327 | } |
| @@ -348,7 +333,6 @@ int64_t | |||
| 348 | nissy_solve( | 333 | nissy_solve( |
| 349 | const char cube[static 22], | 334 | const char cube[static 22], |
| 350 | const char *solver, | 335 | const char *solver, |
| 351 | const char *options, | ||
| 352 | const char *nisstype, | 336 | const char *nisstype, |
| 353 | int8_t minmoves, | 337 | int8_t minmoves, |
| 354 | int8_t maxmoves, | 338 | int8_t maxmoves, |
| @@ -360,7 +344,6 @@ nissy_solve( | |||
| 360 | { | 344 | { |
| 361 | cube_t c; | 345 | cube_t c; |
| 362 | int p; | 346 | int p; |
| 363 | int64_t ret; | ||
| 364 | uint8_t h, k; | 347 | uint8_t h, k; |
| 365 | 348 | ||
| 366 | c = readcube_B32(cube); | 349 | c = readcube_B32(cube); |
| @@ -395,28 +378,25 @@ nissy_solve( | |||
| 395 | return -1; | 378 | return -1; |
| 396 | } | 379 | } |
| 397 | 380 | ||
| 398 | /* TODO define and use solve_options_t */ | 381 | if (!strncmp(solver, "h48", 3)) { |
| 399 | if (!strcmp(solver, "h48")) { | 382 | if (!strcmp(solver, "h48stats")) |
| 400 | p = parse_h48_options(options, &h, &k, NULL); | 383 | return solve_h48stats(c, maxmoves, data, solutions); |
| 384 | |||
| 385 | p = parse_h48_solver(solver, &h, &k); | ||
| 401 | if (p != 0) { | 386 | if (p != 0) { |
| 402 | LOG("gendata: could not parse options\n"); | 387 | return -1; |
| 403 | ret = -1; | ||
| 404 | } else { | 388 | } else { |
| 405 | ret = THREADS > 1 ? | 389 | return THREADS > 1 ? |
| 406 | solve_h48_multithread(c, minmoves, maxmoves, maxsolutions, data, solutions) : | 390 | solve_h48_multithread(c, minmoves, maxmoves, maxsolutions, data, solutions) : |
| 407 | solve_h48(c, minmoves, maxmoves, maxsolutions, data, solutions); | 391 | solve_h48(c, minmoves, maxmoves, maxsolutions, data, solutions); |
| 408 | } | 392 | } |
| 409 | } else if (!strcmp(solver, "h48stats")) { | ||
| 410 | ret = solve_h48stats(c, maxmoves, data, solutions); | ||
| 411 | } else if (!strcmp(solver, "simple")) { | 393 | } else if (!strcmp(solver, "simple")) { |
| 412 | ret = solve_simple( | 394 | return solve_simple( |
| 413 | c, minmoves, maxmoves, maxsolutions, optimal, solutions); | 395 | c, minmoves, maxmoves, maxsolutions, optimal, solutions); |
| 414 | } else { | 396 | } else { |
| 415 | LOG("solve: unknown solver '%s'\n", solver); | 397 | LOG("solve: unknown solver '%s'\n", solver); |
| 416 | ret = -1; | 398 | return -1; |
| 417 | } | 399 | } |
| 418 | |||
| 419 | return ret; | ||
| 420 | } | 400 | } |
| 421 | 401 | ||
| 422 | void | 402 | void |
diff --git a/src/nissy.h b/src/nissy.h index 0545556..1fc1776 100644 --- a/src/nissy.h +++ b/src/nissy.h | |||
| @@ -75,14 +75,12 @@ the same parameters, or -1 in case of error. The returned value can be | |||
| 75 | slightly larger than the actual table size. | 75 | slightly larger than the actual table size. |
| 76 | */ | 76 | */ |
| 77 | int64_t nissy_datasize( | 77 | int64_t nissy_datasize( |
| 78 | const char *solver, | 78 | const char *solver |
| 79 | const char *options /* TODO: remove options, use only solver name */ | ||
| 80 | ); | 79 | ); |
| 81 | 80 | ||
| 82 | /* Returns the number of bytes written, or -1 in case of error */ | 81 | /* Returns the number of bytes written, or -1 in case of error */ |
| 83 | int64_t nissy_gendata( | 82 | int64_t nissy_gendata( |
| 84 | const char *solver, | 83 | const char *solver, |
| 85 | const char *options, /* TODO: remove options, use only solver name */ | ||
| 86 | void *generated_data | 84 | void *generated_data |
| 87 | ); | 85 | ); |
| 88 | 86 | ||
| @@ -93,9 +91,9 @@ int64_t nissy_derivedata( | |||
| 93 | void *generated_data | 91 | void *generated_data |
| 94 | ); | 92 | ); |
| 95 | 93 | ||
| 94 | /* Returns 0 on positive check, 1 on error */ | ||
| 96 | int64_t nissy_checkdata( | 95 | int64_t nissy_checkdata( |
| 97 | const char *solver, | 96 | const char *solver, |
| 98 | const char *options, | ||
| 99 | const void *data | 97 | const void *data |
| 100 | ); | 98 | ); |
| 101 | 99 | ||
| @@ -109,7 +107,6 @@ int64_t nissy_datainfo( | |||
| 109 | int64_t nissy_solve( | 107 | int64_t nissy_solve( |
| 110 | const char cube[static 22], | 108 | const char cube[static 22], |
| 111 | const char *solver, | 109 | const char *solver, |
| 112 | const char *options, /* TODO: remove options, use only solver name */ | ||
| 113 | const char *nisstype, /* TODO: remove, use flags */ | 110 | const char *nisstype, /* TODO: remove, use flags */ |
| 114 | int8_t minmoves, | 111 | int8_t minmoves, |
| 115 | int8_t maxmoves, | 112 | int8_t maxmoves, |
diff --git a/tools/000_gendata/gendata.c b/tools/000_gendata/gendata.c index 2798862..eec9f76 100644 --- a/tools/000_gendata/gendata.c +++ b/tools/000_gendata/gendata.c | |||
| @@ -1,16 +1,16 @@ | |||
| 1 | #include "../tool.h" | 1 | #include "../tool.h" |
| 2 | #include "../expected_distributions.h" | 2 | #include "../expected_distributions.h" |
| 3 | 3 | ||
| 4 | char *solver, *options; | 4 | char *solver; |
| 5 | uint64_t *expected; | 5 | uint64_t *expected; |
| 6 | 6 | ||
| 7 | static void | 7 | static void |
| 8 | run(void) { | 8 | run(void) { |
| 9 | int64_t size; | 9 | int64_t size; |
| 10 | bool consistent, expected; | ||
| 10 | char *buf, filename[1024]; | 11 | char *buf, filename[1024]; |
| 11 | 12 | ||
| 12 | getfilename(solver, options, filename); | 13 | size = generatetable(solver, &buf); |
| 13 | size = generatetable(solver, options, &buf); | ||
| 14 | switch (size) { | 14 | switch (size) { |
| 15 | case -1: | 15 | case -1: |
| 16 | return; | 16 | return; |
| @@ -18,11 +18,19 @@ run(void) { | |||
| 18 | goto gendata_run_finish; | 18 | goto gendata_run_finish; |
| 19 | default: | 19 | default: |
| 20 | nissy_datainfo(buf, write_stdout); | 20 | nissy_datainfo(buf, write_stdout); |
| 21 | if (check_distribution(solver, buf)) { | 21 | consistent = nissy_checkdata(solver, buf) == 0; |
| 22 | expected = check_distribution(solver, buf); | ||
| 23 | if (consistent && expected) { | ||
| 22 | printf("\n"); | 24 | printf("\n"); |
| 23 | printf("Generated %" PRId64 " bytes.\n", size); | 25 | printf("Generated %" PRId64 " bytes.\n", size); |
| 26 | sprintf(filename, "tables/%s", solver); | ||
| 24 | writetable(buf, size, filename); | 27 | writetable(buf, size, filename); |
| 25 | } | 28 | } |
| 29 | if (!consistent) | ||
| 30 | printf("Error: table is not consistent with info" | ||
| 31 | " (nissy_checkdata() failed)\n"); | ||
| 32 | if (!expected) | ||
| 33 | printf("Error: distribution is not as expected\n"); | ||
| 26 | break; | 34 | break; |
| 27 | } | 35 | } |
| 28 | 36 | ||
| @@ -33,15 +41,14 @@ gendata_run_finish: | |||
| 33 | int main(int argc, char **argv) { | 41 | int main(int argc, char **argv) { |
| 34 | uint8_t h, k; | 42 | uint8_t h, k; |
| 35 | 43 | ||
| 36 | if (argc < 3) { | 44 | if (argc < 2) { |
| 37 | fprintf(stderr, "Error: not enough arguments. " | 45 | fprintf(stderr, "Error: not enough arguments. " |
| 38 | "A solver and its options must be given.\n"); | 46 | "A solver must be given.\n"); |
| 39 | return 1; | 47 | return 1; |
| 40 | } | 48 | } |
| 41 | 49 | ||
| 42 | solver = argv[1]; | 50 | solver = argv[1]; |
| 43 | options = argv[2]; | 51 | parse_h48_solver(solver, &h, &k); |
| 44 | parse_h48_options(options, &h, &k, NULL); | ||
| 45 | expected = expected_h48[h][k]; | 52 | expected = expected_h48[h][k]; |
| 46 | 53 | ||
| 47 | nissy_setlogger(log_stderr); | 54 | nissy_setlogger(log_stderr); |
diff --git a/tools/001_derive_h48/derive_h48.c b/tools/001_derive_h48/derive_h48.c index ba282ff..c5f28c8 100644 --- a/tools/001_derive_h48/derive_h48.c +++ b/tools/001_derive_h48/derive_h48.c | |||
| @@ -11,25 +11,25 @@ edit the base value in the source code and recompile. | |||
| 11 | 11 | ||
| 12 | #include "../tool.h" | 12 | #include "../tool.h" |
| 13 | 13 | ||
| 14 | char *opts_large, *opts_small, *filename_large, *filename_small; | 14 | char *solver_large, *solver_small, *filename_large, *filename_small; |
| 15 | 15 | ||
| 16 | void run(void) { | 16 | void run(void) { |
| 17 | derivedata_run(opts_large, opts_small, filename_large, filename_small); | 17 | derivedata_run(solver_large, solver_small, filename_large, filename_small); |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | int main(int argc, char **argv) { | 20 | int main(int argc, char **argv) { |
| 21 | if (argc < 5) { | 21 | if (argc < 5) { |
| 22 | fprintf(stderr, | 22 | fprintf(stderr, |
| 23 | "Error: not enough arguments. Required:\n" | 23 | "Error: not enough arguments. Required:\n" |
| 24 | "1. Options for large table\n" | 24 | "1. Solver name for large table\n" |
| 25 | "2. Options for derived table\n" | 25 | "2. Solver name for derived table\n" |
| 26 | "3. Filename containing large table\n" | 26 | "3. Filename containing large table\n" |
| 27 | "4. Filename for saving derived table\n"); | 27 | "4. Filename for saving derived table\n"); |
| 28 | return 1; | 28 | return 1; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | opts_large = argv[1]; | 31 | solver_large = argv[1]; |
| 32 | opts_small = argv[2]; | 32 | solver_small = argv[2]; |
| 33 | filename_large = argv[3]; | 33 | filename_large = argv[3]; |
| 34 | filename_small = argv[4]; | 34 | filename_small = argv[4]; |
| 35 | 35 | ||
diff --git a/tools/100_checkdata/checkdata.c b/tools/100_checkdata/checkdata.c index 502925f..695a4dd 100644 --- a/tools/100_checkdata/checkdata.c +++ b/tools/100_checkdata/checkdata.c | |||
| @@ -1,15 +1,15 @@ | |||
| 1 | #include "../tool.h" | 1 | #include "../tool.h" |
| 2 | #include "../expected_distributions.h" | 2 | #include "../expected_distributions.h" |
| 3 | 3 | ||
| 4 | char *solver, *options, *filename; | 4 | char *solver, *filename; |
| 5 | 5 | ||
| 6 | static void | 6 | static void |
| 7 | run(void) { | 7 | run(void) { |
| 8 | int64_t size; | 8 | int64_t size, result; |
| 9 | char *buf; | 9 | char *buf; |
| 10 | FILE *f; | 10 | FILE *f; |
| 11 | 11 | ||
| 12 | size = nissy_datasize(solver, options); | 12 | size = nissy_datasize(solver); |
| 13 | 13 | ||
| 14 | if (size <= 0) { | 14 | if (size <= 0) { |
| 15 | fprintf(stderr, "Error in datasize\n"); | 15 | fprintf(stderr, "Error in datasize\n"); |
| @@ -24,22 +24,23 @@ run(void) { | |||
| 24 | buf = malloc(size); | 24 | buf = malloc(size); |
| 25 | fread(buf, size, 1, f); | 25 | fread(buf, size, 1, f); |
| 26 | fclose(f); | 26 | fclose(f); |
| 27 | nissy_checkdata(solver, options, buf); | 27 | result = nissy_checkdata(solver, buf); |
| 28 | free(buf); | 28 | free(buf); |
| 29 | 29 | ||
| 30 | printf("checkdata %s\n", result == 0 ? "succeeded" : "failed"); | ||
| 31 | |||
| 30 | /* TODO: cross-check with expected distributions? */ | 32 | /* TODO: cross-check with expected distributions? */ |
| 31 | } | 33 | } |
| 32 | 34 | ||
| 33 | int main(int argc, char **argv) { | 35 | int main(int argc, char **argv) { |
| 34 | if (argc < 4) { | 36 | if (argc < 3) { |
| 35 | fprintf(stderr, "Error: not enough arguments. " | 37 | fprintf(stderr, "Error: not enough arguments. " |
| 36 | "A solver, its options and a file name must be given.\n"); | 38 | "A solver and a file name must be given.\n"); |
| 37 | return 1; | 39 | return 1; |
| 38 | } | 40 | } |
| 39 | 41 | ||
| 40 | solver = argv[1]; | 42 | solver = argv[1]; |
| 41 | options = argv[2]; | 43 | filename = argv[2]; |
| 42 | filename = argv[3]; | ||
| 43 | nissy_setlogger(log_stderr); | 44 | nissy_setlogger(log_stderr); |
| 44 | 45 | ||
| 45 | timerun(run); | 46 | timerun(run); |
diff --git a/tools/200_stats_tables_h48/stats_tables_h48.c b/tools/200_stats_tables_h48/stats_tables_h48.c index ea5fa5a..a9a2a1e 100644 --- a/tools/200_stats_tables_h48/stats_tables_h48.c +++ b/tools/200_stats_tables_h48/stats_tables_h48.c | |||
| @@ -3,11 +3,10 @@ | |||
| 3 | #include "../tool.h" | 3 | #include "../tool.h" |
| 4 | 4 | ||
| 5 | #define MAXMOVES 20 | 5 | #define MAXMOVES 20 |
| 6 | #define NCUBES_PER_THREAD 10000 | ||
| 7 | #define LOG_EVERY (NCUBES_PER_THREAD / 10) | 6 | #define LOG_EVERY (NCUBES_PER_THREAD / 10) |
| 8 | 7 | ||
| 8 | int NCUBES_PER_THREAD; | ||
| 9 | const char *solver = "h48stats"; | 9 | const char *solver = "h48stats"; |
| 10 | const char *options = ""; | ||
| 11 | const char *filename = "tables/h48h0k4"; | 10 | const char *filename = "tables/h48h0k4"; |
| 12 | char *buf; | 11 | char *buf; |
| 13 | 12 | ||
| @@ -29,7 +28,7 @@ uint64_t rand64(void) { | |||
| 29 | static void * | 28 | static void * |
| 30 | run_thread(void *arg) | 29 | run_thread(void *arg) |
| 31 | { | 30 | { |
| 32 | char sols[12], cube[22]; | 31 | char s[12], cube[22]; |
| 33 | int64_t ep, eo, cp, co; | 32 | int64_t ep, eo, cp, co; |
| 34 | int i, j; | 33 | int i, j; |
| 35 | 34 | ||
| @@ -41,10 +40,9 @@ run_thread(void *arg) | |||
| 41 | cp = rand64(); | 40 | cp = rand64(); |
| 42 | co = rand64(); | 41 | co = rand64(); |
| 43 | nissy_getcube(ep, eo, cp, co, "fix", cube); | 42 | nissy_getcube(ep, eo, cp, co, "fix", cube); |
| 44 | nissy_solve(cube, "h48stats", "", "", | 43 | nissy_solve(cube, "h48stats", "", 0, MAXMOVES, 1, -1, buf, s); |
| 45 | 0, MAXMOVES, 1, -1, buf, sols); | ||
| 46 | for (j = 0; j < 12; j++) | 44 | for (j = 0; j < 12; j++) |
| 47 | a->v[j][(int)sols[j]]++; | 45 | a->v[j][(int)s[j]]++; |
| 48 | if ((i+1) % LOG_EVERY == 0) | 46 | if ((i+1) % LOG_EVERY == 0) |
| 49 | fprintf(stderr, "[thread %d] %d cubes solved...\n", | 47 | fprintf(stderr, "[thread %d] %d cubes solved...\n", |
| 50 | a->thread_id, i+1); | 48 | a->thread_id, i+1); |
| @@ -85,11 +83,27 @@ void run(void) { | |||
| 85 | } | 83 | } |
| 86 | } | 84 | } |
| 87 | 85 | ||
| 88 | int main(void) { | 86 | int main(int argc, char **argv) { |
| 89 | srand(time(NULL)); | 87 | srand(time(NULL)); |
| 90 | nissy_setlogger(log_stderr); | 88 | nissy_setlogger(log_stderr); |
| 91 | 89 | ||
| 92 | if (getdata(solver, options, &buf, filename) != 0) | 90 | if (argc < 2) { |
| 91 | fprintf(stderr, "Error: not enough arguments. " | ||
| 92 | "Number of cubes per thread must be provided.\n"); | ||
| 93 | return 1; | ||
| 94 | } | ||
| 95 | |||
| 96 | NCUBES_PER_THREAD = atoi(argv[1]); | ||
| 97 | |||
| 98 | if (NCUBES_PER_THREAD < 1 || NCUBES_PER_THREAD > 1000000) { | ||
| 99 | fprintf(stderr, "Invalid number of cubes: must be > 0 and " | ||
| 100 | "< 1000000, but %d was given.\n", NCUBES_PER_THREAD); | ||
| 101 | return 1; | ||
| 102 | } | ||
| 103 | |||
| 104 | printf("Using %d cubes per thread (%d total)\n", | ||
| 105 | NCUBES_PER_THREAD, NCUBES_PER_THREAD * THREADS); | ||
| 106 | if (getdata(solver, &buf, filename) != 0) | ||
| 93 | return 1; | 107 | return 1; |
| 94 | 108 | ||
| 95 | timerun(run); | 109 | timerun(run); |
diff --git a/tools/300_solve_small/solve_small.c b/tools/300_solve_small/solve_small.c index b572cf5..ade949a 100644 --- a/tools/300_solve_small/solve_small.c +++ b/tools/300_solve_small/solve_small.c | |||
| @@ -1,8 +1,6 @@ | |||
| 1 | #include "../tool.h" | 1 | #include "../tool.h" |
| 2 | 2 | ||
| 3 | const char *solver = "h48"; | 3 | const char *solver = "h48h0k4"; |
| 4 | const char *options = "0;4;20"; | ||
| 5 | const char *filename = "tables/h48h0k4"; | ||
| 6 | char *buf; | 4 | char *buf; |
| 7 | 5 | ||
| 8 | char *scrambles[] = { | 6 | char *scrambles[] = { |
| @@ -28,7 +26,7 @@ void run(void) { | |||
| 28 | continue; | 26 | continue; |
| 29 | } | 27 | } |
| 30 | n = nissy_solve( | 28 | n = nissy_solve( |
| 31 | cube, "h48", options, "", 0, 20, 1, -1, buf, sol); | 29 | cube, solver, "", 0, 20, 1, -1, buf, sol); |
| 32 | if (n == 0) { | 30 | if (n == 0) { |
| 33 | printf("No solution\n"); | 31 | printf("No solution\n"); |
| 34 | fprintf(stderr, "No solution found\n"); | 32 | fprintf(stderr, "No solution found\n"); |
| @@ -39,10 +37,13 @@ void run(void) { | |||
| 39 | } | 37 | } |
| 40 | 38 | ||
| 41 | int main(void) { | 39 | int main(void) { |
| 40 | char filename[255]; | ||
| 41 | |||
| 42 | srand(time(NULL)); | 42 | srand(time(NULL)); |
| 43 | nissy_setlogger(log_stderr); | 43 | nissy_setlogger(log_stderr); |
| 44 | 44 | ||
| 45 | if (getdata(solver, options, &buf, filename) != 0) | 45 | sprintf(filename, "tables/%s", solver); |
| 46 | if (getdata(solver, &buf, filename) != 0) | ||
| 46 | return 1; | 47 | return 1; |
| 47 | 48 | ||
| 48 | timerun(run); | 49 | timerun(run); |
diff --git a/tools/expected_distributions.h b/tools/expected_distributions.h index 202edf9..1b97166 100644 --- a/tools/expected_distributions.h +++ b/tools/expected_distributions.h | |||
| @@ -155,7 +155,7 @@ check_distribution(const char *solver, const void *data) | |||
| 155 | { | 155 | { |
| 156 | tableinfo_t info = {0}; | 156 | tableinfo_t info = {0}; |
| 157 | 157 | ||
| 158 | if (!strcmp(solver, "h48")) { | 158 | if (!strncmp(solver, "h48", 3)) { |
| 159 | readtableinfo(data, &info); | 159 | readtableinfo(data, &info); |
| 160 | if (!distribution_equal( | 160 | if (!distribution_equal( |
| 161 | expected_cocsep, info.distribution, info.maxvalue)) { | 161 | expected_cocsep, info.distribution, info.maxvalue)) { |
diff --git a/tools/nissy_extra.h b/tools/nissy_extra.h index f9baf00..53c3df7 100644 --- a/tools/nissy_extra.h +++ b/tools/nissy_extra.h | |||
| @@ -9,4 +9,4 @@ for testing purposes only. | |||
| 9 | #include "../src/solvers/tables.h" | 9 | #include "../src/solvers/tables.h" |
| 10 | 10 | ||
| 11 | size_t gendata_h48_derive(uint8_t, const void *, void *); | 11 | size_t gendata_h48_derive(uint8_t, const void *, void *); |
| 12 | int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); | 12 | int parse_h48_solver(const char *, uint8_t [static 1], uint8_t [static 1]); |
diff --git a/tools/tool.h b/tools/tool.h index 2aaabae..02ff0f2 100644 --- a/tools/tool.h +++ b/tools/tool.h | |||
| @@ -12,12 +12,11 @@ | |||
| 12 | static void log_stderr(const char *, ...); | 12 | static void log_stderr(const char *, ...); |
| 13 | static void log_stdout(const char *, ...); | 13 | static void log_stdout(const char *, ...); |
| 14 | static double timerun(void (*)(void)); | 14 | static double timerun(void (*)(void)); |
| 15 | static void getfilename(const char *, const char *, char *); | ||
| 16 | static void writetable(const char *, int64_t, const char *); | 15 | static void writetable(const char *, int64_t, const char *); |
| 17 | static int64_t generatetable(const char *, const char *, char **); | 16 | static int64_t generatetable(const char *, char **); |
| 18 | static int64_t derivetable(const char *, const char *, const char *, char **); | 17 | static int64_t derivetable(const char *, const char *, const char *, char **); |
| 19 | static int getdata(const char *, const char *, char **, const char *); | 18 | static int getdata(const char *, char **, const char *); |
| 20 | static void gendata_run(const char *, const char *, uint64_t[static 21]); | 19 | static void gendata_run(const char *, uint64_t[static 21]); |
| 21 | static void derivedata_run( | 20 | static void derivedata_run( |
| 22 | const char *, const char *, const char *, const char *); | 21 | const char *, const char *, const char *, const char *); |
| 23 | 22 | ||
| @@ -71,50 +70,39 @@ timerun(void (*run)(void)) | |||
| 71 | } | 70 | } |
| 72 | 71 | ||
| 73 | static void | 72 | static void |
| 74 | getfilename(const char *solver, const char *options, char *filename) | ||
| 75 | { | ||
| 76 | uint8_t h, k; | ||
| 77 | |||
| 78 | /* Only h48 supported for now */ | ||
| 79 | parse_h48_options(options, &h, &k, NULL); | ||
| 80 | |||
| 81 | sprintf(filename, "tables/%sh%dk%d", solver, h, k); | ||
| 82 | } | ||
| 83 | |||
| 84 | static void | ||
| 85 | writetable(const char *buf, int64_t size, const char *filename) | 73 | writetable(const char *buf, int64_t size, const char *filename) |
| 86 | { | 74 | { |
| 87 | FILE *f; | 75 | FILE *f; |
| 88 | 76 | ||
| 89 | if ((f = fopen(filename, "wb")) == NULL) { | 77 | if ((f = fopen(filename, "wb")) == NULL) { |
| 90 | fprintf(stderr, "Could not write tables to file %s" | 78 | printf("Could not write tables to file %s" |
| 91 | ", will be regenerated next time.\n", filename); | 79 | ", will be regenerated next time.\n", filename); |
| 92 | } else { | 80 | } else { |
| 93 | fwrite(buf, size, 1, f); | 81 | fwrite(buf, size, 1, f); |
| 94 | fclose(f); | 82 | fclose(f); |
| 95 | fprintf(stderr, "Table written to %s.\n", filename); | 83 | printf("Table written to %s.\n", filename); |
| 96 | } | 84 | } |
| 97 | } | 85 | } |
| 98 | 86 | ||
| 99 | static int64_t | 87 | static int64_t |
| 100 | generatetable(const char *solver, const char *options, char **buf) | 88 | generatetable(const char *solver, char **buf) |
| 101 | { | 89 | { |
| 102 | int64_t size, gensize; | 90 | int64_t size, gensize; |
| 103 | 91 | ||
| 104 | size = nissy_datasize(solver, options); | 92 | size = nissy_datasize(solver); |
| 105 | if (size == -1) { | 93 | if (size == -1) { |
| 106 | printf("Error getting table size.\n"); | 94 | printf("Error getting table size.\n"); |
| 107 | return -1; | 95 | return -1; |
| 108 | } | 96 | } |
| 109 | 97 | ||
| 110 | *buf = malloc(size); | 98 | *buf = malloc(size); |
| 111 | gensize = nissy_gendata(solver, options, *buf); | 99 | gensize = nissy_gendata(solver, *buf); |
| 112 | 100 | ||
| 113 | if (gensize != size) { | 101 | if (gensize != size) { |
| 114 | fprintf(stderr, "Error generating table"); | 102 | printf("Error generating table"); |
| 115 | if (gensize != -1) | 103 | if (gensize != -1) |
| 116 | fprintf(stderr, " (got %" PRId64 " bytes)", gensize); | 104 | printf(" (got %" PRId64 " bytes)", gensize); |
| 117 | fprintf(stderr, "\n"); | 105 | printf("\n"); |
| 118 | return -2; | 106 | return -2; |
| 119 | } | 107 | } |
| 120 | 108 | ||
| @@ -123,46 +111,53 @@ generatetable(const char *solver, const char *options, char **buf) | |||
| 123 | 111 | ||
| 124 | static int64_t | 112 | static int64_t |
| 125 | derivetable( | 113 | derivetable( |
| 126 | const char *opts_large, | 114 | const char *solver_large, |
| 127 | const char *opts_small, | 115 | const char *solver_small, |
| 128 | const char *filename_large, | 116 | const char *filename_large, |
| 129 | char **buf | 117 | char **buf |
| 130 | ) | 118 | ) |
| 131 | { | 119 | { |
| 132 | uint8_t h; | 120 | uint8_t h, k; |
| 133 | int64_t size, gensize; | 121 | int64_t size, gensize; |
| 134 | char *fulltable; | 122 | char *fulltable; |
| 135 | 123 | ||
| 136 | if (getdata("h48", opts_large, &fulltable, filename_large) != 0) { | 124 | if (getdata(solver_large, &fulltable, filename_large) != 0) { |
| 137 | printf("Error reading full table.\n"); | 125 | printf("Error reading full table.\n"); |
| 138 | return -1; | 126 | gensize = -1; |
| 127 | goto derivetable_error_nofree; | ||
| 139 | } | 128 | } |
| 140 | 129 | ||
| 141 | size = nissy_datasize("h48", opts_small); | 130 | size = nissy_datasize(solver_small); |
| 142 | if (size == -1) { | 131 | if (size == -1) { |
| 143 | printf("Error getting table size.\n"); | 132 | printf("Error getting table size.\n"); |
| 144 | free(fulltable); | 133 | gensize = -2; |
| 145 | return -1; | 134 | goto derivetable_error; |
| 135 | } | ||
| 136 | |||
| 137 | if (parse_h48_solver(solver_small, &h, &k) != 0) { | ||
| 138 | gensize = -3; | ||
| 139 | goto derivetable_error; | ||
| 146 | } | 140 | } |
| 147 | 141 | ||
| 148 | h = atoi(opts_small); /* TODO: use option parser */ | ||
| 149 | *buf = malloc(size); | 142 | *buf = malloc(size); |
| 150 | gensize = gendata_h48_derive(h, fulltable, *buf); | 143 | gensize = gendata_h48_derive(h, fulltable, *buf); |
| 151 | 144 | ||
| 152 | if (gensize != size) { | 145 | if (gensize != size) { |
| 153 | fprintf(stderr, "Error deriving table\n"); | 146 | printf("Error deriving table\n"); |
| 154 | free(fulltable); | 147 | gensize = -4; |
| 155 | return -2; | 148 | goto derivetable_error; |
| 156 | } | 149 | } |
| 157 | 150 | ||
| 151 | derivetable_error: | ||
| 158 | free(fulltable); | 152 | free(fulltable); |
| 153 | |||
| 154 | derivetable_error_nofree: | ||
| 159 | return gensize; | 155 | return gensize; |
| 160 | } | 156 | } |
| 161 | 157 | ||
| 162 | static int | 158 | static int |
| 163 | getdata( | 159 | getdata( |
| 164 | const char *solver, | 160 | const char *solver, |
| 165 | const char *options, | ||
| 166 | char **buf, | 161 | char **buf, |
| 167 | const char *filename | 162 | const char *filename |
| 168 | ) { | 163 | ) { |
| @@ -170,8 +165,8 @@ getdata( | |||
| 170 | FILE *f; | 165 | FILE *f; |
| 171 | 166 | ||
| 172 | if ((f = fopen(filename, "rb")) == NULL) { | 167 | if ((f = fopen(filename, "rb")) == NULL) { |
| 173 | fprintf(stderr, "Table file not found, generating it.\n"); | 168 | printf("Table file not found, generating it.\n"); |
| 174 | size = generatetable(solver, options, buf); | 169 | size = generatetable(solver, buf); |
| 175 | switch (size) { | 170 | switch (size) { |
| 176 | case -1: | 171 | case -1: |
| 177 | goto getdata_error_nofree; | 172 | goto getdata_error_nofree; |
| @@ -182,13 +177,13 @@ getdata( | |||
| 182 | break; | 177 | break; |
| 183 | } | 178 | } |
| 184 | } else { | 179 | } else { |
| 185 | fprintf(stderr, "Reading tables from file %s\n", filename); | 180 | printf("Reading tables from file %s\n", filename); |
| 186 | size = nissy_datasize(solver, options); | 181 | size = nissy_datasize(solver); |
| 187 | *buf = malloc(size); | 182 | *buf = malloc(size); |
| 188 | sizeread = fread(*buf, size, 1, f); | 183 | sizeread = fread(*buf, size, 1, f); |
| 189 | fclose(f); | 184 | fclose(f); |
| 190 | if (sizeread != 1) { | 185 | if (sizeread != 1) { |
| 191 | fprintf(stderr, "Error reading table, stopping\n"); | 186 | printf("Error reading table, stopping\n"); |
| 192 | goto getdata_error; | 187 | goto getdata_error; |
| 193 | } | 188 | } |
| 194 | } | 189 | } |
| @@ -204,14 +199,13 @@ getdata_error_nofree: | |||
| 204 | static void | 199 | static void |
| 205 | gendata_run( | 200 | gendata_run( |
| 206 | const char *solver, | 201 | const char *solver, |
| 207 | const char *options, | ||
| 208 | uint64_t expected[static 21] | 202 | uint64_t expected[static 21] |
| 209 | ) { | 203 | ) { |
| 210 | int64_t size; | 204 | int64_t size; |
| 211 | char *buf, filename[1024]; | 205 | char *buf, filename[1024]; |
| 212 | 206 | ||
| 213 | getfilename(solver, options, filename); | 207 | sprintf(filename, "tables/%s", solver); |
| 214 | size = generatetable(solver, options, &buf); | 208 | size = generatetable(solver, &buf); |
| 215 | switch (size) { | 209 | switch (size) { |
| 216 | case -1: | 210 | case -1: |
| 217 | return; | 211 | return; |
| @@ -234,8 +228,8 @@ gendata_run_finish: | |||
| 234 | 228 | ||
| 235 | static void | 229 | static void |
| 236 | derivedata_run( | 230 | derivedata_run( |
| 237 | const char *opts_large, | 231 | const char *solver_large, |
| 238 | const char *opts_small, | 232 | const char *solver_small, |
| 239 | const char *filename_large, | 233 | const char *filename_large, |
| 240 | const char *filename_small | 234 | const char *filename_small |
| 241 | ) | 235 | ) |
| @@ -243,7 +237,7 @@ derivedata_run( | |||
| 243 | int64_t size; | 237 | int64_t size; |
| 244 | char *buf; | 238 | char *buf; |
| 245 | 239 | ||
| 246 | size = derivetable(opts_large, opts_small, filename_large, &buf); | 240 | size = derivetable(solver_large, solver_small, filename_large, &buf); |
| 247 | switch (size) { | 241 | switch (size) { |
| 248 | case -1: | 242 | case -1: |
| 249 | return; | 243 | return; |
diff --git a/tools/tool.sh b/tools/tool.sh index 23d781d..aea203f 100755 --- a/tools/tool.sh +++ b/tools/tool.sh | |||
| @@ -29,15 +29,12 @@ date +'%Y-%m-%d %H:%M' | |||
| 29 | echo "" | 29 | echo "" |
| 30 | echo "======== config.mk ========" | 30 | echo "======== config.mk ========" |
| 31 | cat config.mk | 31 | cat config.mk |
| 32 | echo "===========================" | ||
| 33 | echo "" | 32 | echo "" |
| 34 | echo "=== tool configuration ====" | 33 | echo "=== tool configuration ====" |
| 35 | echo "TOOL=$toolname" | 34 | echo "TOOL=$toolname" |
| 36 | echo "TOOLARGS=$TOOLARGS" | 35 | echo "TOOLARGS=$TOOLARGS" |
| 37 | echo "CC=$CC" | 36 | echo "CC=$CC" |
| 38 | echo "===========================" | ||
| 39 | echo "" | 37 | echo "" |
| 40 | echo "======= tool output =======" | 38 | echo "======= tool output =======" |
| 41 | $BIN $TOOLARGS | 39 | $BIN $TOOLARGS |
| 42 | echo "===========================" | ||
| 43 | ) | tee "$file" "$LAST" | 40 | ) | tee "$file" "$LAST" |
