diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-19 12:28:52 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-19 12:28:52 +0200 |
| commit | 3485be851f4fff1c9c6fe621f0619d2b4103bc06 (patch) | |
| tree | 894197f164a7ef66801ae3a701fb10a3c1e3f5e3 | |
| parent | 691da8f06614418ed847bdeefa4e708c372a3ecf (diff) | |
| download | nissy-core-3485be851f4fff1c9c6fe621f0619d2b4103bc06.tar.gz nissy-core-3485be851f4fff1c9c6fe621f0619d2b4103bc06.zip | |
Improved logging, especially for solve
| -rw-r--r-- | src/core/io_moves.h | 2 | ||||
| -rw-r--r-- | src/core/moves.h | 19 | ||||
| -rw-r--r-- | src/core/transform.h | 4 | ||||
| -rw-r--r-- | src/nissy.c | 78 | ||||
| -rw-r--r-- | src/solvers/coord/gendata.h | 9 | ||||
| -rw-r--r-- | src/solvers/coord/solve.h | 30 | ||||
| -rw-r--r-- | src/solvers/coord/utils.h | 2 | ||||
| -rw-r--r-- | src/solvers/h48/gendata_cocsep.h | 2 | ||||
| -rw-r--r-- | src/solvers/h48/gendata_h48.h | 50 | ||||
| -rw-r--r-- | src/solvers/h48/solve.h | 21 | ||||
| -rw-r--r-- | src/solvers/solutions.h | 18 | ||||
| -rw-r--r-- | src/utils/math.h | 4 |
12 files changed, 114 insertions, 125 deletions
diff --git a/src/core/io_moves.h b/src/core/io_moves.h index c94b6b7..97926cc 100644 --- a/src/core/io_moves.h +++ b/src/core/io_moves.h | |||
| @@ -14,7 +14,7 @@ STATIC int64_t writemoves(size_t n, const uint8_t [n], size_t m, char [m]); | |||
| 14 | if (*VAR_B == '\0' || ARG_C == ARG_MAX) \ | 14 | if (*VAR_B == '\0' || ARG_C == ARG_MAX) \ |
| 15 | break; \ | 15 | break; \ |
| 16 | if ((VAR_MOVE_NOMOD = readmove(*VAR_B)) == UINT8_ERROR) { \ | 16 | if ((VAR_MOVE_NOMOD = readmove(*VAR_B)) == UINT8_ERROR) { \ |
| 17 | LOG("Error: unknown move '%c'\n", *VAR_B); \ | 17 | LOG("Unknown move: %c\n", *VAR_B); \ |
| 18 | return RET_ERROR; \ | 18 | return RET_ERROR; \ |
| 19 | } \ | 19 | } \ |
| 20 | if ((VAR_MOD = readmodifier(*(VAR_B+1))) != 0) \ | 20 | if ((VAR_MOD = readmodifier(*(VAR_B+1))) != 0) \ |
diff --git a/src/core/moves.h b/src/core/moves.h index 1238c7d..cc91706 100644 --- a/src/core/moves.h +++ b/src/core/moves.h | |||
| @@ -17,25 +17,6 @@ STATIC bool are_lastmoves_singlecw(size_t n, const uint8_t [n]); | |||
| 17 | 17 | ||
| 18 | STATIC cube_t applymoves(cube_t, const char *); | 18 | STATIC cube_t applymoves(cube_t, const char *); |
| 19 | 19 | ||
| 20 | #define FOREACH_READMOVE(ARG_BUF, ARG_MOVE, ARG_C, ARG_MAX, \ | ||
| 21 | RET_ERROR, ARG_ACTION) \ | ||
| 22 | const char *VAR_B; \ | ||
| 23 | uint8_t VAR_MOVE_NOMOD, VAR_MOD; \ | ||
| 24 | for (VAR_B = ARG_BUF, ARG_C = 0; *VAR_B != '\0'; VAR_B++, ARG_C++) { \ | ||
| 25 | while (*VAR_B == ' ' || *VAR_B == '\t' || *VAR_B == '\n') \ | ||
| 26 | VAR_B++; \ | ||
| 27 | if (*VAR_B == '\0' || ARG_C == ARG_MAX) \ | ||
| 28 | break; \ | ||
| 29 | if ((VAR_MOVE_NOMOD = readmove(*VAR_B)) == UINT8_ERROR) { \ | ||
| 30 | LOG("Error: unknown move '%c'\n", *VAR_B); \ | ||
| 31 | return RET_ERROR; \ | ||
| 32 | } \ | ||
| 33 | if ((VAR_MOD = readmodifier(*(VAR_B+1))) != 0) \ | ||
| 34 | VAR_B++; \ | ||
| 35 | ARG_MOVE = VAR_MOVE_NOMOD + VAR_MOD; \ | ||
| 36 | ARG_ACTION \ | ||
| 37 | } | ||
| 38 | |||
| 39 | STATIC_INLINE bool | 20 | STATIC_INLINE bool |
| 40 | allowednextmove(uint8_t m1, uint8_t m2) | 21 | allowednextmove(uint8_t m1, uint8_t m2) |
| 41 | { | 22 | { |
diff --git a/src/core/transform.h b/src/core/transform.h index a6bb937..b480593 100644 --- a/src/core/transform.h +++ b/src/core/transform.h | |||
| @@ -126,7 +126,7 @@ transform_edges(cube_t c, uint8_t t) | |||
| 126 | case TRANS_BLm: | 126 | case TRANS_BLm: |
| 127 | return TRANS_EDGES_MIRRORED(BLm, c); | 127 | return TRANS_EDGES_MIRRORED(BLm, c); |
| 128 | default: | 128 | default: |
| 129 | LOG("transform error, unknown transformation %" PRIu8 "\n", t); | 129 | LOG("transform error: unknown transformation %" PRIu8 "\n", t); |
| 130 | return ZERO_CUBE; | 130 | return ZERO_CUBE; |
| 131 | } | 131 | } |
| 132 | } | 132 | } |
| @@ -353,7 +353,7 @@ applytrans(cube_t cube, const char *buf) | |||
| 353 | t = readtrans(buf); | 353 | t = readtrans(buf); |
| 354 | 354 | ||
| 355 | if (t == UINT8_ERROR) | 355 | if (t == UINT8_ERROR) |
| 356 | LOG("Unknown transformation '%s'\n", buf); | 356 | LOG("Unknown transformation: %s\n", buf); |
| 357 | 357 | ||
| 358 | return transform(cube, t); | 358 | return transform(cube, t); |
| 359 | } | 359 | } |
diff --git a/src/nissy.c b/src/nissy.c index f22f606..f744fa8 100644 --- a/src/nissy.c +++ b/src/nissy.c | |||
| @@ -60,7 +60,7 @@ parse_h48_solver(const char *buf, uint8_t h[static 1], uint8_t k[static 1]) | |||
| 60 | parse_h48_solver_error: | 60 | parse_h48_solver_error: |
| 61 | *h = 0; | 61 | *h = 0; |
| 62 | *k = 0; | 62 | *k = 0; |
| 63 | LOG("Error parsing solver: must be in \"h48h*k*\" format," | 63 | LOG("Error parsing H48 solver: must be in \"h48h*k*\" format," |
| 64 | " but got %s\n", fullbuf); | 64 | " but got %s\n", fullbuf); |
| 65 | return NISSY_ERROR_INVALID_SOLVER; | 65 | return NISSY_ERROR_INVALID_SOLVER; |
| 66 | } | 66 | } |
| @@ -72,7 +72,7 @@ checkdata(const char *buf, const tableinfo_t info[static 1]) | |||
| 72 | 72 | ||
| 73 | if (my_strnlen(info->solver, INFO_SOLVER_STRLEN) | 73 | if (my_strnlen(info->solver, INFO_SOLVER_STRLEN) |
| 74 | == INFO_SOLVER_STRLEN) { | 74 | == INFO_SOLVER_STRLEN) { |
| 75 | LOG("checkdata: error reading table info\n"); | 75 | LOG("[checkdata] Error reading table info\n"); |
| 76 | return false; | 76 | return false; |
| 77 | } else if (!strncmp(info->solver, "cocsep", 6)) { | 77 | } else if (!strncmp(info->solver, "cocsep", 6)) { |
| 78 | getdistribution_cocsep( | 78 | getdistribution_cocsep( |
| @@ -88,7 +88,7 @@ checkdata(const char *buf, const tableinfo_t info[static 1]) | |||
| 88 | } else if (!strncmp(info->solver, "coord helper table for ", 23)) { | 88 | } else if (!strncmp(info->solver, "coord helper table for ", 23)) { |
| 89 | return true; | 89 | return true; |
| 90 | } else { | 90 | } else { |
| 91 | LOG("checkdata: unknown solver %s\n", info->solver); | 91 | LOG("[checkdata] unknown solver %s\n", info->solver); |
| 92 | return false; | 92 | return false; |
| 93 | } | 93 | } |
| 94 | 94 | ||
| @@ -154,7 +154,7 @@ nissy_compose( | |||
| 154 | c = readcube("B32", cube); | 154 | c = readcube("B32", cube); |
| 155 | 155 | ||
| 156 | if (!isconsistent(c)) { | 156 | if (!isconsistent(c)) { |
| 157 | LOG("Error in nissy_compose: given cube is invalid\n"); | 157 | LOG("[compose] Error: the given cube is invalid\n"); |
| 158 | err = NISSY_ERROR_INVALID_CUBE; | 158 | err = NISSY_ERROR_INVALID_CUBE; |
| 159 | goto nissy_compose_error; | 159 | goto nissy_compose_error; |
| 160 | } | 160 | } |
| @@ -162,7 +162,7 @@ nissy_compose( | |||
| 162 | p = readcube("B32", permutation); | 162 | p = readcube("B32", permutation); |
| 163 | 163 | ||
| 164 | if (!isconsistent(p)) { | 164 | if (!isconsistent(p)) { |
| 165 | LOG("Error in nissy_compose: given permutation is invalid\n"); | 165 | LOG("[compose] Error: given permutation is invalid\n"); |
| 166 | err = NISSY_ERROR_INVALID_CUBE; | 166 | err = NISSY_ERROR_INVALID_CUBE; |
| 167 | goto nissy_compose_error; | 167 | goto nissy_compose_error; |
| 168 | } | 168 | } |
| @@ -170,7 +170,7 @@ nissy_compose( | |||
| 170 | res = compose(c, p); | 170 | res = compose(c, p); |
| 171 | 171 | ||
| 172 | if (!isconsistent(res)) { | 172 | if (!isconsistent(res)) { |
| 173 | LOG("Unknown error: resulting cube is invalid\n"); | 173 | LOG("[compose] Unknown error: resulting cube is invalid\n"); |
| 174 | err = NISSY_ERROR_UNKNOWN; | 174 | err = NISSY_ERROR_UNKNOWN; |
| 175 | goto nissy_compose_error; | 175 | goto nissy_compose_error; |
| 176 | } | 176 | } |
| @@ -194,7 +194,7 @@ nissy_inverse( | |||
| 194 | c = readcube("B32", cube); | 194 | c = readcube("B32", cube); |
| 195 | 195 | ||
| 196 | if (iserror(c)) { | 196 | if (iserror(c)) { |
| 197 | LOG("Error in nissy_inverse: given cube is invalid\n"); | 197 | LOG("[inverse] Error: the given cube is invalid\n"); |
| 198 | err = NISSY_ERROR_INVALID_CUBE; | 198 | err = NISSY_ERROR_INVALID_CUBE; |
| 199 | goto nissy_inverse_error; | 199 | goto nissy_inverse_error; |
| 200 | } | 200 | } |
| @@ -202,7 +202,7 @@ nissy_inverse( | |||
| 202 | res = inverse(c); | 202 | res = inverse(c); |
| 203 | 203 | ||
| 204 | if (!isconsistent(res)) { | 204 | if (!isconsistent(res)) { |
| 205 | LOG("Unknown error: inverted cube is invalid\n"); | 205 | LOG("[inverse] Unknown error: inverted cube is invalid\n"); |
| 206 | err = NISSY_ERROR_UNKNOWN; | 206 | err = NISSY_ERROR_UNKNOWN; |
| 207 | goto nissy_inverse_error; | 207 | goto nissy_inverse_error; |
| 208 | } | 208 | } |
| @@ -225,7 +225,7 @@ nissy_applymoves( | |||
| 225 | long long err; | 225 | long long err; |
| 226 | 226 | ||
| 227 | if (moves == NULL) { | 227 | if (moves == NULL) { |
| 228 | LOG("Error: 'moves' argument is NULL\n"); | 228 | LOG("[applymoves] Error: 'moves' argument is NULL\n"); |
| 229 | err = NISSY_ERROR_NULL_POINTER; | 229 | err = NISSY_ERROR_NULL_POINTER; |
| 230 | goto nissy_applymoves_error; | 230 | goto nissy_applymoves_error; |
| 231 | } | 231 | } |
| @@ -233,7 +233,7 @@ nissy_applymoves( | |||
| 233 | c = readcube("B32", cube); | 233 | c = readcube("B32", cube); |
| 234 | 234 | ||
| 235 | if (!isconsistent(c)) { | 235 | if (!isconsistent(c)) { |
| 236 | LOG("Error in nissy_applymoves: given cube is invalid\n"); | 236 | LOG("[applymoves] Error: given cube is invalid\n"); |
| 237 | err = NISSY_ERROR_INVALID_CUBE; | 237 | err = NISSY_ERROR_INVALID_CUBE; |
| 238 | goto nissy_applymoves_error; | 238 | goto nissy_applymoves_error; |
| 239 | } | 239 | } |
| @@ -266,7 +266,7 @@ nissy_applytrans( | |||
| 266 | c = readcube("B32", cube); | 266 | c = readcube("B32", cube); |
| 267 | 267 | ||
| 268 | if (!isconsistent(c)) { | 268 | if (!isconsistent(c)) { |
| 269 | LOG("Error in nissy_applytrans: given cube is invalid\n"); | 269 | LOG("[applytrans] Error: given cube is invalid\n"); |
| 270 | err = NISSY_ERROR_INVALID_CUBE; | 270 | err = NISSY_ERROR_INVALID_CUBE; |
| 271 | goto nissy_applytrans_error; | 271 | goto nissy_applytrans_error; |
| 272 | } | 272 | } |
| @@ -299,19 +299,19 @@ nissy_convert( | |||
| 299 | long long err; | 299 | long long err; |
| 300 | 300 | ||
| 301 | if (format_in == NULL) { | 301 | if (format_in == NULL) { |
| 302 | LOG("Error: 'format_in' argument is NULL\n"); | 302 | LOG("[convert] Error: 'format_in' argument is NULL\n"); |
| 303 | err = NISSY_ERROR_NULL_POINTER; | 303 | err = NISSY_ERROR_NULL_POINTER; |
| 304 | goto nissy_convert_error; | 304 | goto nissy_convert_error; |
| 305 | } | 305 | } |
| 306 | 306 | ||
| 307 | if (format_out == NULL) { | 307 | if (format_out == NULL) { |
| 308 | LOG("Error: 'format_out' argument is NULL\n"); | 308 | LOG("[convert] Error: 'format_out' argument is NULL\n"); |
| 309 | err = NISSY_ERROR_NULL_POINTER; | 309 | err = NISSY_ERROR_NULL_POINTER; |
| 310 | goto nissy_convert_error; | 310 | goto nissy_convert_error; |
| 311 | } | 311 | } |
| 312 | 312 | ||
| 313 | if (cube_string == NULL) { | 313 | if (cube_string == NULL) { |
| 314 | LOG("Error: 'cube_string' argument is NULL\n"); | 314 | LOG("[convert] Error: 'cube_string' argument is NULL\n"); |
| 315 | err = NISSY_ERROR_NULL_POINTER; | 315 | err = NISSY_ERROR_NULL_POINTER; |
| 316 | goto nissy_convert_error; | 316 | goto nissy_convert_error; |
| 317 | } | 317 | } |
| @@ -344,7 +344,7 @@ nissy_getcube( | |||
| 344 | cube_t c; | 344 | cube_t c; |
| 345 | 345 | ||
| 346 | if (options == NULL) { | 346 | if (options == NULL) { |
| 347 | LOG("Error: 'options' argument is NULL\n"); | 347 | LOG("[getcube] Error: 'options' argument is NULL\n"); |
| 348 | return NISSY_ERROR_NULL_POINTER; | 348 | return NISSY_ERROR_NULL_POINTER; |
| 349 | } | 349 | } |
| 350 | 350 | ||
| @@ -355,8 +355,8 @@ nissy_getcube( | |||
| 355 | c = getcube(ep, eo, cp, co); | 355 | c = getcube(ep, eo, cp, co); |
| 356 | 356 | ||
| 357 | if (!isconsistent(c)) { | 357 | if (!isconsistent(c)) { |
| 358 | LOG("Error: could not get cube with ep=%lld, eo=%lld, " | 358 | LOG("[getcube] Error: could not get cube with ep=%lld, " |
| 359 | "cp=%lld, co=%lld.\n", ep, eo, cp, co); | 359 | "eo=%lld, cp=%lld, co=%lld.\n", ep, eo, cp, co); |
| 360 | return NISSY_ERROR_OPTIONS; | 360 | return NISSY_ERROR_OPTIONS; |
| 361 | } | 361 | } |
| 362 | 362 | ||
| @@ -374,7 +374,7 @@ nissy_datainfo( | |||
| 374 | long long ret; | 374 | long long ret; |
| 375 | 375 | ||
| 376 | if ((size_t)data % 8 != 0) { | 376 | if ((size_t)data % 8 != 0) { |
| 377 | LOG("nissy_datainfo: buffere is not 8-byte aligned\n"); | 377 | LOG("[datainfo] Error: buffer is not 8-byte aligned\n"); |
| 378 | return NISSY_ERROR_DATA; | 378 | return NISSY_ERROR_DATA; |
| 379 | } | 379 | } |
| 380 | 380 | ||
| @@ -429,7 +429,7 @@ nissy_dataid(const char *solver, char dataid[static NISSY_SIZE_DATAID]) | |||
| 429 | } else if (!strncmp(solver, "coord_", 6)) { | 429 | } else if (!strncmp(solver, "coord_", 6)) { |
| 430 | return dataid_coord(solver+6, dataid); | 430 | return dataid_coord(solver+6, dataid); |
| 431 | } else { | 431 | } else { |
| 432 | LOG("gendata: unknown solver %s\n", solver); | 432 | LOG("[gendata] Unknown solver %s\n", solver); |
| 433 | return NISSY_ERROR_INVALID_SOLVER; | 433 | return NISSY_ERROR_INVALID_SOLVER; |
| 434 | } | 434 | } |
| 435 | } | 435 | } |
| @@ -469,12 +469,12 @@ nissy_gendata_unsafe( | |||
| 469 | gendata_h48_arg_t arg; | 469 | gendata_h48_arg_t arg; |
| 470 | 470 | ||
| 471 | if (solver == NULL) { | 471 | if (solver == NULL) { |
| 472 | LOG("Error: 'solver' argument is NULL\n"); | 472 | LOG("[gendata] Error: 'solver' argument is NULL\n"); |
| 473 | return NISSY_ERROR_NULL_POINTER; | 473 | return NISSY_ERROR_NULL_POINTER; |
| 474 | } | 474 | } |
| 475 | 475 | ||
| 476 | if ((size_t)data % 8 != 0) { | 476 | if ((size_t)data % 8 != 0) { |
| 477 | LOG("nissy_gendata: buffere is not 8-byte aligned\n"); | 477 | LOG("[gendata] Error: buffer is not 8-byte aligned\n"); |
| 478 | return NISSY_ERROR_DATA; | 478 | return NISSY_ERROR_DATA; |
| 479 | } | 479 | } |
| 480 | 480 | ||
| @@ -489,7 +489,7 @@ nissy_gendata_unsafe( | |||
| 489 | } else if (!strncmp(solver, "coord_", 6)) { | 489 | } else if (!strncmp(solver, "coord_", 6)) { |
| 490 | return gendata_coord_dispatch(solver+6, data); | 490 | return gendata_coord_dispatch(solver+6, data); |
| 491 | } else { | 491 | } else { |
| 492 | LOG("gendata: unknown solver %s\n", solver); | 492 | LOG("[gendata] Unknown solver %s\n", solver); |
| 493 | return NISSY_ERROR_INVALID_SOLVER; | 493 | return NISSY_ERROR_INVALID_SOLVER; |
| 494 | } | 494 | } |
| 495 | } | 495 | } |
| @@ -505,7 +505,7 @@ nissy_checkdata( | |||
| 505 | int64_t err; | 505 | int64_t err; |
| 506 | 506 | ||
| 507 | if ((size_t)data % 8 != 0) { | 507 | if ((size_t)data % 8 != 0) { |
| 508 | LOG("nissy_checkdata: buffere is not 8-byte aligned\n"); | 508 | LOG("[checkdata] Error: buffer is not 8-byte aligned\n"); |
| 509 | return NISSY_ERROR_DATA; | 509 | return NISSY_ERROR_DATA; |
| 510 | } | 510 | } |
| 511 | 511 | ||
| @@ -514,8 +514,8 @@ nissy_checkdata( | |||
| 514 | buf += info.next, data_size -= info.next) | 514 | buf += info.next, data_size -= info.next) |
| 515 | { | 515 | { |
| 516 | if (!checkdata(buf, &info)) { | 516 | if (!checkdata(buf, &info)) { |
| 517 | LOG("Error: data for solver '%s' is corrupted!\n", | 517 | LOG("[checkdata] Error: data for solver '%s' is " |
| 518 | info.solver); | 518 | "corrupted!\n", info.solver); |
| 519 | return NISSY_ERROR_DATA; | 519 | return NISSY_ERROR_DATA; |
| 520 | } | 520 | } |
| 521 | 521 | ||
| @@ -549,44 +549,38 @@ nissy_solve( | |||
| 549 | int t; | 549 | int t; |
| 550 | 550 | ||
| 551 | if (solver == NULL) { | 551 | if (solver == NULL) { |
| 552 | LOG("Error: 'solver' argument is NULL\n"); | 552 | LOG("[solve] Error: 'solver' argument is NULL\n"); |
| 553 | return NISSY_ERROR_NULL_POINTER; | 553 | return NISSY_ERROR_NULL_POINTER; |
| 554 | } | 554 | } |
| 555 | 555 | ||
| 556 | c = readcube_B32(cube); | 556 | c = readcube_B32(cube); |
| 557 | 557 | ||
| 558 | if (!isconsistent(c)) { | 558 | if (!isconsistent(c)) { |
| 559 | LOG("solve: cube is invalid\n"); | 559 | LOG("[solve] Error: cube is invalid\n"); |
| 560 | return NISSY_ERROR_INVALID_CUBE; | 560 | return NISSY_ERROR_INVALID_CUBE; |
| 561 | } | 561 | } |
| 562 | 562 | ||
| 563 | if (!issolvable(c)) { | 563 | if (!issolvable(c)) { |
| 564 | /* TODO: this is step-dependent */ | 564 | /* TODO: this is step-dependent */ |
| 565 | LOG("solve: cube is not solvable\n"); | 565 | LOG("[solve] Error: cube is not solvable\n"); |
| 566 | return NISSY_ERROR_UNSOLVABLE_CUBE; | 566 | return NISSY_ERROR_UNSOLVABLE_CUBE; |
| 567 | } | 567 | } |
| 568 | 568 | ||
| 569 | /* TODO: checks for minmoves, maxmoves, nissflag */ | 569 | /* TODO: checks for minmoves, maxmoves, nissflag */ |
| 570 | 570 | ||
| 571 | if (maxsols == 0) { | 571 | if (maxsols == 0) { |
| 572 | LOG("solve: 'maxsols' is 0, returning no solution\n"); | 572 | LOG("[solve] 'maxsols' is 0, returning no solution\n"); |
| 573 | return 0; | 573 | return 0; |
| 574 | } | 574 | } |
| 575 | 575 | ||
| 576 | t = threads == 0 ? THREADS : threads; | 576 | if (threads > THREADS) |
| 577 | if (t < 0) { | 577 | LOG("[solve] Selected number of threads (%u) is above the " |
| 578 | LOG("solve: 'threads' is negative. Please provide a " | 578 | "maximum value (%d), using %d threads instead\n", |
| 579 | "number of threads between 1 and %d\n", THREADS); | 579 | threads, THREADS, THREADS); |
| 580 | return NISSY_ERROR_OPTIONS; | 580 | t = threads == 0 ? THREADS : MIN(THREADS, threads); |
| 581 | } | ||
| 582 | if (t > THREADS) { | ||
| 583 | LOG("solve: 'threads' is above the maximum value of %d\n", | ||
| 584 | THREADS); | ||
| 585 | return NISSY_ERROR_OPTIONS; | ||
| 586 | } | ||
| 587 | 581 | ||
| 588 | if ((size_t)data % 8 != 0) { | 582 | if ((size_t)data % 8 != 0) { |
| 589 | LOG("nissy_solve: buffere is not 8-byte aligned\n"); | 583 | LOG("[solve] Error: data buffer is not 8-byte aligned\n"); |
| 590 | return NISSY_ERROR_DATA; | 584 | return NISSY_ERROR_DATA; |
| 591 | } | 585 | } |
| 592 | 586 | ||
| @@ -601,7 +595,7 @@ nissy_solve( | |||
| 601 | minmoves, maxmoves, maxsols, optimal, t, data_size, data, | 595 | minmoves, maxmoves, maxsols, optimal, t, data_size, data, |
| 602 | sols_size, sols); | 596 | sols_size, sols); |
| 603 | } else { | 597 | } else { |
| 604 | LOG("solve: unknown solver '%s'\n", solver); | 598 | LOG("[solve] Error: unknown solver '%s'\n", solver); |
| 605 | return NISSY_ERROR_INVALID_SOLVER; | 599 | return NISSY_ERROR_INVALID_SOLVER; |
| 606 | } | 600 | } |
| 607 | } | 601 | } |
diff --git a/src/solvers/coord/gendata.h b/src/solvers/coord/gendata.h index 6abb5eb..ae7b39e 100644 --- a/src/solvers/coord/gendata.h +++ b/src/solvers/coord/gendata.h | |||
| @@ -22,7 +22,7 @@ gendata_coord_dispatch(const char *coordstr, void *buf) | |||
| 22 | parse_coord_and_axis(strlen(coordstr), coordstr, &coord, NULL); | 22 | parse_coord_and_axis(strlen(coordstr), coordstr, &coord, NULL); |
| 23 | 23 | ||
| 24 | if (coord == NULL) { | 24 | if (coord == NULL) { |
| 25 | LOG("Could not parse coordinate '%s'\n", coordstr); | 25 | LOG("Error: could not parse coordinate '%s'\n", coordstr); |
| 26 | return NISSY_ERROR_INVALID_SOLVER; | 26 | return NISSY_ERROR_INVALID_SOLVER; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| @@ -82,7 +82,7 @@ gendata_coord_return_size: | |||
| 82 | return ninfo * INFOSIZE + coord_dsize + tablesize; | 82 | return ninfo * INFOSIZE + coord_dsize + tablesize; |
| 83 | 83 | ||
| 84 | gendata_coord_error: | 84 | gendata_coord_error: |
| 85 | LOG("An unexpected error occurred when generating the data.\n"); | 85 | LOG("Unexpected error generating coordinate data\n"); |
| 86 | return 0; | 86 | return 0; |
| 87 | } | 87 | } |
| 88 | 88 | ||
| @@ -136,8 +136,9 @@ genptable_coord( | |||
| 136 | } | 136 | } |
| 137 | tot += t; | 137 | tot += t; |
| 138 | info.distribution[d] = t; | 138 | info.distribution[d] = t; |
| 139 | LOG("Depth %" PRIu64 ": found %" PRIu64 " (%" PRIu64 " of %" | 139 | LOG("[%s gendata] Depth %" PRIu64 ": found %" PRIu64 " (%" |
| 140 | PRIu64 ")\n", d, t, tot, coord->max); | 140 | PRIu64 " of %" PRIu64 ")\n", |
| 141 | coord->name, d, t, tot, coord->max); | ||
| 141 | } | 142 | } |
| 142 | info.maxvalue = d-1; | 143 | info.maxvalue = d-1; |
| 143 | 144 | ||
diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h index b289e3f..072aa27 100644 --- a/src/solvers/coord/solve.h +++ b/src/solvers/coord/solve.h | |||
| @@ -121,7 +121,8 @@ solve_coord_dfs(dfsarg_solve_coord_t arg[static 1]) | |||
| 121 | if (!coord_solution_admissible(arg)) | 121 | if (!coord_solution_admissible(arg)) |
| 122 | return 0; | 122 | return 0; |
| 123 | return appendsolution(arg->solution_moves, | 123 | return appendsolution(arg->solution_moves, |
| 124 | arg->solution_settings, arg->solution_list, true); | 124 | arg->solution_settings, arg->solution_list, true, |
| 125 | arg->coord->name); | ||
| 125 | } | 126 | } |
| 126 | 127 | ||
| 127 | if (solve_coord_dfs_stop(arg)) | 128 | if (solve_coord_dfs_stop(arg)) |
| @@ -220,12 +221,13 @@ solve_coord_dispatch( | |||
| 220 | strlen(coord_and_axis), coord_and_axis, &coord, &axis); | 221 | strlen(coord_and_axis), coord_and_axis, &coord, &axis); |
| 221 | 222 | ||
| 222 | if (coord == NULL) { | 223 | if (coord == NULL) { |
| 223 | LOG("Could not parse coordinate from '%s'\n", coord_and_axis); | 224 | LOG("Error: could not parse coordinate from '%s'\n", |
| 225 | coord_and_axis); | ||
| 224 | return NISSY_ERROR_INVALID_SOLVER; | 226 | return NISSY_ERROR_INVALID_SOLVER; |
| 225 | } | 227 | } |
| 226 | 228 | ||
| 227 | if (axis == UINT8_ERROR) { | 229 | if (axis == UINT8_ERROR) { |
| 228 | LOG("Could not parse axis from '%s'\n", coord_and_axis); | 230 | LOG("Error: could not parse axis from '%s'\n", coord_and_axis); |
| 229 | return NISSY_ERROR_INVALID_SOLVER; | 231 | return NISSY_ERROR_INVALID_SOLVER; |
| 230 | } | 232 | } |
| 231 | 233 | ||
| @@ -316,8 +318,8 @@ solve_coord( | |||
| 316 | }; | 318 | }; |
| 317 | 319 | ||
| 318 | if (coord->coord(c, coord_data) == 0) { | 320 | if (coord->coord(c, coord_data) == 0) { |
| 319 | if (minmoves == 0 && !appendsolution( | 321 | if (minmoves == 0 && !appendsolution(&solution_moves, |
| 320 | &solution_moves, &solution_settings, &solution_list, true)) | 322 | &solution_settings, &solution_list, true, coord->name)) |
| 321 | goto solve_coord_error_buffer; | 323 | goto solve_coord_error_buffer; |
| 322 | goto solve_coord_done; | 324 | goto solve_coord_done; |
| 323 | } | 325 | } |
| @@ -327,18 +329,17 @@ solve_coord( | |||
| 327 | !solutions_done(&solution_list, &solution_settings, d); | 329 | !solutions_done(&solution_list, &solution_settings, d); |
| 328 | d++ | 330 | d++ |
| 329 | ) { | 331 | ) { |
| 330 | if (d >= 10) | 332 | if (d >= 12) |
| 331 | LOG("Found %" PRIu64 " solutions, searching at depth %" | 333 | LOG("[%s solve] Found %" PRIu64 " solutions, " |
| 332 | PRId8 "\n", solution_list.nsols, d); | 334 | "searching at depth %" PRId8 "\n", |
| 335 | coord->name, solution_list.nsols, d); | ||
| 333 | 336 | ||
| 334 | arg.target_depth = d; | 337 | arg.target_depth = d; |
| 335 | solution_moves_reset(arg.solution_moves); | 338 | solution_moves_reset(arg.solution_moves); |
| 336 | ndepth = solve_coord_dfs(&arg); | 339 | ndepth = solve_coord_dfs(&arg); |
| 337 | 340 | ||
| 338 | if (ndepth < 0) { | 341 | if (ndepth < 0) |
| 339 | LOG("Error %" PRId64 "\n", ndepth); | ||
| 340 | return ndepth; | 342 | return ndepth; |
| 341 | } | ||
| 342 | 343 | ||
| 343 | solution_list.nsols += (uint64_t)ndepth; | 344 | solution_list.nsols += (uint64_t)ndepth; |
| 344 | } | 345 | } |
| @@ -347,14 +348,15 @@ solve_coord_done: | |||
| 347 | return (int64_t)solution_list.nsols; | 348 | return (int64_t)solution_list.nsols; |
| 348 | 349 | ||
| 349 | solve_coord_error_data: | 350 | solve_coord_error_data: |
| 350 | LOG("solve_coord: error reading table\n"); | 351 | LOG("[%s solve] Error reading table\n", coord->name); |
| 351 | return NISSY_ERROR_DATA; | 352 | return NISSY_ERROR_DATA; |
| 352 | 353 | ||
| 353 | solve_coord_error_buffer: | 354 | solve_coord_error_buffer: |
| 354 | LOG("Could not append solution to buffer: size too small\n"); | 355 | LOG("[%s solve] Error appending solution to buffer: size too small\n", |
| 356 | coord->name); | ||
| 355 | return NISSY_ERROR_BUFFER_SIZE; | 357 | return NISSY_ERROR_BUFFER_SIZE; |
| 356 | 358 | ||
| 357 | solve_coord_error_unsolvable: | 359 | solve_coord_error_unsolvable: |
| 358 | LOG("Cube not ready for solving %s\n", coord->name); | 360 | LOG("[%s solve] Error: cube not ready\n", coord->name); |
| 359 | return NISSY_ERROR_UNSOLVABLE_CUBE; | 361 | return NISSY_ERROR_UNSOLVABLE_CUBE; |
| 360 | } | 362 | } |
diff --git a/src/solvers/coord/utils.h b/src/solvers/coord/utils.h index 5407de3..ef3f817 100644 --- a/src/solvers/coord/utils.h +++ b/src/solvers/coord/utils.h | |||
| @@ -59,7 +59,7 @@ dataid_coord(const char *ca, char dataid[static NISSY_SIZE_DATAID]) | |||
| 59 | parse_coord_and_axis(strlen(ca), ca, &c, NULL); | 59 | parse_coord_and_axis(strlen(ca), ca, &c, NULL); |
| 60 | 60 | ||
| 61 | if (c == NULL) { | 61 | if (c == NULL) { |
| 62 | LOG("dataid_coord: cannot parse coordinate from '%s'\n", ca); | 62 | LOG("Error: cannot parse coordinate from '%s'\n", ca); |
| 63 | return NISSY_ERROR_INVALID_SOLVER; | 63 | return NISSY_ERROR_INVALID_SOLVER; |
| 64 | } | 64 | } |
| 65 | 65 | ||
diff --git a/src/solvers/h48/gendata_cocsep.h b/src/solvers/h48/gendata_cocsep.h index cda1608..f07b71a 100644 --- a/src/solvers/h48/gendata_cocsep.h +++ b/src/solvers/h48/gendata_cocsep.h | |||
| @@ -67,7 +67,7 @@ gendata_cocsep( | |||
| 67 | "cocsep: computed %" PRIu16 " symmetry classes, " | 67 | "cocsep: computed %" PRIu16 " symmetry classes, " |
| 68 | "expected %zu\n", n, COCSEP_CLASSES); | 68 | "expected %zu\n", n, COCSEP_CLASSES); |
| 69 | 69 | ||
| 70 | LOG("cocsep data computed\n"); | 70 | LOG("[H48 gendata] cocsep data computed\n"); |
| 71 | 71 | ||
| 72 | /* The following output is just noise | 72 | /* The following output is just noise |
| 73 | 73 | ||
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index 4478e9e..18157dc 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h | |||
| @@ -87,7 +87,7 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) | |||
| 87 | return size; /* Dry-run */ | 87 | return size; /* Dry-run */ |
| 88 | 88 | ||
| 89 | if (arg->buf_size < size) { | 89 | if (arg->buf_size < size) { |
| 90 | LOG("Error computing H48 data: buffer is too small " | 90 | LOG("[H48 gendata] Error data: buffer is too small " |
| 91 | "(needed %" PRId64 " bytes but received %" PRId64 ")\n", | 91 | "(needed %" PRId64 " bytes but received %" PRId64 ")\n", |
| 92 | size, arg->buf_size); | 92 | size, arg->buf_size); |
| 93 | return NISSY_ERROR_BUFFER_SIZE; | 93 | return NISSY_ERROR_BUFFER_SIZE; |
| @@ -106,22 +106,24 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) | |||
| 106 | } else if (arg->k == 2) { | 106 | } else if (arg->k == 2) { |
| 107 | gendata_h48k2(arg); | 107 | gendata_h48k2(arg); |
| 108 | } else { | 108 | } else { |
| 109 | LOG("Cannot generate data for h = %" PRIu8 " and k = %" PRIu8 | 109 | LOG("[H48 gendata] Error: cannot generate data for h = %" PRIu8 |
| 110 | " (not implemented yet)\n", arg->h, arg->k); | 110 | " and k = %" PRIu8 " (not implemented yet)\n", |
| 111 | arg->h, arg->k); | ||
| 111 | return NISSY_ERROR_INVALID_SOLVER; | 112 | return NISSY_ERROR_INVALID_SOLVER; |
| 112 | } | 113 | } |
| 113 | 114 | ||
| 114 | r = readtableinfo(arg->buf_size, arg->buf, &cocsepinfo); | 115 | r = readtableinfo(arg->buf_size, arg->buf, &cocsepinfo); |
| 115 | if (r != NISSY_OK) { | 116 | if (r != NISSY_OK) { |
| 116 | LOG("gendata_h48: could not read info for cocsep table\n"); | 117 | LOG("[H48 gendata] Error: could not read info " |
| 118 | "for cocsep table\n"); | ||
| 117 | return NISSY_ERROR_UNKNOWN; | 119 | return NISSY_ERROR_UNKNOWN; |
| 118 | } | 120 | } |
| 119 | 121 | ||
| 120 | cocsepinfo.next = cocsepsize; | 122 | cocsepinfo.next = cocsepsize; |
| 121 | r = writetableinfo(&cocsepinfo, arg->buf_size, arg->buf); | 123 | r = writetableinfo(&cocsepinfo, arg->buf_size, arg->buf); |
| 122 | if (r != NISSY_OK) { | 124 | if (r != NISSY_OK) { |
| 123 | LOG("gendata_h48: could not write info for cocsep table" | 125 | LOG("[H48 gendata] Error: could not write info for " |
| 124 | " with updated 'next' value\n"); | 126 | "cocsep table with updated 'next' value\n"); |
| 125 | return NISSY_ERROR_UNKNOWN; | 127 | return NISSY_ERROR_UNKNOWN; |
| 126 | } | 128 | } |
| 127 | 129 | ||
| @@ -149,21 +151,23 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) | |||
| 149 | 151 | ||
| 150 | r = readtableinfo_n(arg->buf_size, arg->buf, 2, &h48info); | 152 | r = readtableinfo_n(arg->buf_size, arg->buf, 2, &h48info); |
| 151 | if (r != NISSY_OK) { | 153 | if (r != NISSY_OK) { |
| 152 | LOG("gendata_h48: could not read info for h48 table\n"); | 154 | LOG("[H48 gendata] Error: could not read info " |
| 155 | "for h48 table\n"); | ||
| 153 | return NISSY_ERROR_UNKNOWN; | 156 | return NISSY_ERROR_UNKNOWN; |
| 154 | } | 157 | } |
| 155 | h48info.next = h48size; | 158 | h48info.next = h48size; |
| 156 | r = writetableinfo(&h48info, | 159 | r = writetableinfo(&h48info, |
| 157 | arg->buf_size - cocsepsize, (char *)arg->buf + cocsepsize); | 160 | arg->buf_size - cocsepsize, (char *)arg->buf + cocsepsize); |
| 158 | if (r != NISSY_OK) { | 161 | if (r != NISSY_OK) { |
| 159 | LOG("gendata_h48: could not write info for h48 table\n"); | 162 | LOG("[H48 gendata] Error: could not write info " |
| 163 | "for h48 table\n"); | ||
| 160 | return NISSY_ERROR_UNKNOWN; | 164 | return NISSY_ERROR_UNKNOWN; |
| 161 | } | 165 | } |
| 162 | 166 | ||
| 163 | if (arg->k == 2) { | 167 | if (arg->k == 2) { |
| 164 | r = readtableinfo_n(arg->buf_size, arg->buf, 3, &fallbackinfo); | 168 | r = readtableinfo_n(arg->buf_size, arg->buf, 3, &fallbackinfo); |
| 165 | if (r != NISSY_OK) { | 169 | if (r != NISSY_OK) { |
| 166 | LOG("gendata_h48: could not read info for h48 " | 170 | LOG("[H48 gendata] Error: could not read info for h48 " |
| 167 | "fallback table\n"); | 171 | "fallback table\n"); |
| 168 | return NISSY_ERROR_UNKNOWN; | 172 | return NISSY_ERROR_UNKNOWN; |
| 169 | } | 173 | } |
| @@ -173,8 +177,8 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) | |||
| 173 | r = writetableinfo(&fallbackinfo, | 177 | r = writetableinfo(&fallbackinfo, |
| 174 | arg->buf_size - of, (char *)arg->buf + of); | 178 | arg->buf_size - of, (char *)arg->buf + of); |
| 175 | if (r != NISSY_OK) { | 179 | if (r != NISSY_OK) { |
| 176 | LOG("gendata_h48: could not write info for h48 " | 180 | LOG("[H48 gendata] Error: could not write info for " |
| 177 | "fallback table\n"); | 181 | "h48 fallback table\n"); |
| 178 | return NISSY_ERROR_UNKNOWN; | 182 | return NISSY_ERROR_UNKNOWN; |
| 179 | } | 183 | } |
| 180 | } | 184 | } |
| @@ -233,7 +237,7 @@ gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) | |||
| 233 | bfsarg[t].table_mutex[tt] = &table_mutex[tt]; | 237 | bfsarg[t].table_mutex[tt] = &table_mutex[tt]; |
| 234 | } | 238 | } |
| 235 | for (done = 1, d = 1; done < h48max && d <= arg->maxdepth; d++) { | 239 | for (done = 1, d = 1; done < h48max && d <= arg->maxdepth; d++) { |
| 236 | LOG("h48: generating depth %" PRId64 "\n", d); | 240 | LOG("[H48 gendata] Generating depth %" PRId64 "\n", d); |
| 237 | 241 | ||
| 238 | for (t = 0; t < THREADS; t++) { | 242 | for (t = 0; t < THREADS; t++) { |
| 239 | bfsarg[t].depth = d; | 243 | bfsarg[t].depth = d; |
| @@ -252,7 +256,7 @@ gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) | |||
| 252 | done += cc; | 256 | done += cc; |
| 253 | arg->info.distribution[d] = cc; | 257 | arg->info.distribution[d] = cc; |
| 254 | 258 | ||
| 255 | LOG("found %" PRId64 "\n", cc); | 259 | LOG("[H48 gendata] Found %" PRId64 "\n", cc); |
| 256 | } | 260 | } |
| 257 | 261 | ||
| 258 | arg->info.maxvalue = d - 1; | 262 | arg->info.maxvalue = d - 1; |
| @@ -382,7 +386,7 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) | |||
| 382 | table = (uint8_t *)arg->h48buf + INFOSIZE; | 386 | table = (uint8_t *)arg->h48buf + INFOSIZE; |
| 383 | memset(table, 0xFF, H48_TABLESIZE(arg->h, arg->k)); | 387 | memset(table, 0xFF, H48_TABLESIZE(arg->h, arg->k)); |
| 384 | 388 | ||
| 385 | LOG("Computing depth <=%" PRIu8 "\n", shortdepth) | 389 | LOG("[H48 gendata] Computing depth <=%" PRIu8 "\n", shortdepth) |
| 386 | h48map_create(&shortcubes, capacity, randomizer); | 390 | h48map_create(&shortcubes, capacity, randomizer); |
| 387 | shortarg = (gendata_h48short_arg_t) { | 391 | shortarg = (gendata_h48short_arg_t) { |
| 388 | .maxdepth = shortdepth, | 392 | .maxdepth = shortdepth, |
| @@ -392,7 +396,7 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) | |||
| 392 | .map = &shortcubes | 396 | .map = &shortcubes |
| 393 | }; | 397 | }; |
| 394 | gendata_h48short(&shortarg); | 398 | gendata_h48short(&shortarg); |
| 395 | LOG("Computed %" PRIu64 " positions\n", shortarg.map->n); | 399 | LOG("[H48 gendata] Computed %" PRIu64 " positions\n", shortarg.map->n); |
| 396 | 400 | ||
| 397 | if (arg->base >= 20) | 401 | if (arg->base >= 20) |
| 398 | arg->base = base[arg->h]; | 402 | arg->base = base[arg->h]; |
| @@ -459,7 +463,8 @@ gendata_h48k2_runthread(void *arg) | |||
| 459 | pthread_mutex_unlock(dfsarg->shortcubes_mutex); | 463 | pthread_mutex_unlock(dfsarg->shortcubes_mutex); |
| 460 | 464 | ||
| 461 | if (count % UINT64_C(1000000) == 0) | 465 | if (count % UINT64_C(1000000) == 0) |
| 462 | LOG("Processing %" PRIu64 "th short cube\n", count); | 466 | LOG("[H48 gendata] Processing %" PRIu64 |
| 467 | "th short cube\n", count); | ||
| 463 | 468 | ||
| 464 | if (kv.val < dfsarg->shortdepth) { | 469 | if (kv.val < dfsarg->shortdepth) { |
| 465 | coord = kv.key >> (int64_t)(11 - dfsarg->h); | 470 | coord = kv.key >> (int64_t)(11 - dfsarg->h); |
| @@ -780,15 +785,16 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) | |||
| 780 | 785 | ||
| 781 | bufsize = COCSEP_FULLSIZE + INFOSIZE; | 786 | bufsize = COCSEP_FULLSIZE + INFOSIZE; |
| 782 | if (readtableinfo(bufsize, buf, &cocsepinfo) != NISSY_OK) { | 787 | if (readtableinfo(bufsize, buf, &cocsepinfo) != NISSY_OK) { |
| 783 | LOG("gendata_h48: could not read info for cocsep table\n"); | 788 | LOG("[H48 derive gendata] Error: could not read info for " |
| 789 | "cocsep table\n"); | ||
| 784 | goto gendata_h48_derive_error; | 790 | goto gendata_h48_derive_error; |
| 785 | } | 791 | } |
| 786 | 792 | ||
| 787 | cocsepinfo.next = cocsepsize; | 793 | cocsepinfo.next = cocsepsize; |
| 788 | bufsize = COCSEP_FULLSIZE + INFOSIZE; | 794 | bufsize = COCSEP_FULLSIZE + INFOSIZE; |
| 789 | if (writetableinfo(&cocsepinfo, bufsize, buf) != NISSY_OK) { | 795 | if (writetableinfo(&cocsepinfo, bufsize, buf) != NISSY_OK) { |
| 790 | LOG("gendata_h48_derive: could not write info for cocsep table" | 796 | LOG("[H48 derive gendata] Error: could not write info for " |
| 791 | " with updated 'next' value\n"); | 797 | "cocsep table with updated 'next' value\n"); |
| 792 | goto gendata_h48_derive_error; | 798 | goto gendata_h48_derive_error; |
| 793 | } | 799 | } |
| 794 | 800 | ||
| @@ -801,7 +807,8 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) | |||
| 801 | h48max = H48_COORDMAX(fulltableinfo.h48h); | 807 | h48max = H48_COORDMAX(fulltableinfo.h48h); |
| 802 | for (i = 0; i < h48max; i++) { | 808 | for (i = 0; i < h48max; i++) { |
| 803 | if (i % INT64_C(1000000000) == 0 && i > 0) | 809 | if (i % INT64_C(1000000000) == 0 && i > 0) |
| 804 | LOG("Processing %" PRId64 "th coordinate\n", i); | 810 | LOG("[H48 derive gendata] Processing %" PRId64 |
| 811 | "th coordinate\n", i); | ||
| 805 | j = i >> (int64_t)(fulltableinfo.h48h - h); | 812 | j = i >> (int64_t)(fulltableinfo.h48h - h); |
| 806 | val_full = get_h48_pval(h48full, i, arg.k); | 813 | val_full = get_h48_pval(h48full, i, arg.k); |
| 807 | val_derive = get_h48_pval(h48derive, j, arg.k); | 814 | val_derive = get_h48_pval(h48derive, j, arg.k); |
| @@ -813,7 +820,8 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) | |||
| 813 | 820 | ||
| 814 | bufsize = arg.buf_size - COCSEP_FULLSIZE - INFOSIZE; | 821 | bufsize = arg.buf_size - COCSEP_FULLSIZE - INFOSIZE; |
| 815 | if (writetableinfo(&arg.info, bufsize, arg.h48buf) != NISSY_OK) { | 822 | if (writetableinfo(&arg.info, bufsize, arg.h48buf) != NISSY_OK) { |
| 816 | LOG("gendata_h48_derive: could not write info for table\n"); | 823 | LOG("H48 derive gendata] Error: could not write info " |
| 824 | "for table\n"); | ||
| 817 | goto gendata_h48_derive_error; | 825 | goto gendata_h48_derive_error; |
| 818 | } | 826 | } |
| 819 | 827 | ||
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index 78b4c97..0fd419d 100644 --- a/src/solvers/h48/solve.h +++ b/src/solvers/h48/solve.h | |||
| @@ -162,7 +162,7 @@ solve_h48_dfs(dfsarg_solve_h48_t arg[static 1]) | |||
| 162 | return 0; | 162 | return 0; |
| 163 | pthread_mutex_lock(arg->solutions_mutex); | 163 | pthread_mutex_lock(arg->solutions_mutex); |
| 164 | ret = appendsolution(arg->solution_moves, | 164 | ret = appendsolution(arg->solution_moves, |
| 165 | arg->solution_settings, arg->solution_list, true); | 165 | arg->solution_settings, arg->solution_list, true, "H48"); |
| 166 | pthread_mutex_unlock(arg->solutions_mutex); | 166 | pthread_mutex_unlock(arg->solutions_mutex); |
| 167 | return ret; | 167 | return ret; |
| 168 | } | 168 | } |
| @@ -295,7 +295,7 @@ solve_h48_maketasks( | |||
| 295 | maketasks_arg->moves, maketasks_arg->nmoves); | 295 | maketasks_arg->moves, maketasks_arg->nmoves); |
| 296 | 296 | ||
| 297 | appret = appendsolution(&moves, solve_arg->solution_settings, | 297 | appret = appendsolution(&moves, solve_arg->solution_settings, |
| 298 | solve_arg->solution_list, true); | 298 | solve_arg->solution_list, true, "H48"); |
| 299 | return appret < 0 ? appret : NISSY_OK; | 299 | return appret < 0 ? appret : NISSY_OK; |
| 300 | } | 300 | } |
| 301 | 301 | ||
| @@ -458,16 +458,17 @@ solve_h48( | |||
| 458 | arg[i].tasks = tasks; | 458 | arg[i].tasks = tasks; |
| 459 | } | 459 | } |
| 460 | 460 | ||
| 461 | LOG("Prepared %d tasks\n", ntasks); | 461 | LOG("[H48 solve] Prepared %d tasks\n", ntasks); |
| 462 | 462 | ||
| 463 | for ( | 463 | for ( |
| 464 | d = MAX(minmoves, STARTING_MOVES + 1); | 464 | d = MAX(minmoves, STARTING_MOVES + 1); |
| 465 | !solutions_done(&sollist, &settings, d); | 465 | !solutions_done(&sollist, &settings, d); |
| 466 | d++ | 466 | d++ |
| 467 | ) { | 467 | ) { |
| 468 | if (d >= 10) | 468 | if (d >= 15) |
| 469 | LOG("Found %" PRId64 " solutions, searching at depth %" | 469 | LOG("[H48 solve] Found %" PRId64 " solutions, " |
| 470 | PRId8 "\n", sollist.nsols, d); | 470 | "searching at depth %" PRId8 "\n", |
| 471 | sollist.nsols, d); | ||
| 471 | for (i = 0; i < threads; i++) { | 472 | for (i = 0; i < threads; i++) { |
| 472 | arg[i].target_depth = d; | 473 | arg[i].target_depth = d; |
| 473 | pthread_create( | 474 | pthread_create( |
| @@ -491,16 +492,16 @@ solve_h48_done: | |||
| 491 | lookups_per_node = table_lookups / (long double)nodes_visited; | 492 | lookups_per_node = table_lookups / (long double)nodes_visited; |
| 492 | fallback_rate = nodes_visited == 0 ? 0.0 : | 493 | fallback_rate = nodes_visited == 0 ? 0.0 : |
| 493 | (table_fallbacks * 100) / (long double)table_lookups; | 494 | (table_fallbacks * 100) / (long double)table_lookups; |
| 494 | LOG("Nodes visited: %" PRId64 "\n", nodes_visited); | 495 | LOG("[H48 solve] Nodes visited: %" PRId64 "\n", nodes_visited); |
| 495 | LOG("Lookups: %" PRId64 " (%.3Lf per node)\n", | 496 | LOG("[H48 solve] Lookups: %" PRId64 " (%.3Lf per node)\n", |
| 496 | table_lookups, lookups_per_node); | 497 | table_lookups, lookups_per_node); |
| 497 | LOG("Table fallbacks: %" PRId64 " (%.3Lf%%)\n", | 498 | LOG("[H48 solve] Table fallbacks: %" PRId64 " (%.3Lf%%)\n", |
| 498 | table_fallbacks, fallback_rate); | 499 | table_fallbacks, fallback_rate); |
| 499 | 500 | ||
| 500 | return sollist.nsols; | 501 | return sollist.nsols; |
| 501 | 502 | ||
| 502 | solve_h48_error_data: | 503 | solve_h48_error_data: |
| 503 | LOG("solve_h48: error reading table\n"); | 504 | LOG("[H48 solve] Error reading data table\n"); |
| 504 | return NISSY_ERROR_DATA; | 505 | return NISSY_ERROR_DATA; |
| 505 | 506 | ||
| 506 | solve_h48_error_solutions_buffer: | 507 | solve_h48_error_solutions_buffer: |
diff --git a/src/solvers/solutions.h b/src/solvers/solutions.h index 95c1d1a..c9a1313 100644 --- a/src/solvers/solutions.h +++ b/src/solvers/solutions.h | |||
| @@ -7,7 +7,8 @@ STATIC bool solution_moves_equal( | |||
| 7 | STATIC bool solution_moves_is_duplicate(size_t n, const solution_moves_t[n+1]); | 7 | STATIC bool solution_moves_is_duplicate(size_t n, const solution_moves_t[n+1]); |
| 8 | STATIC bool appendchar(solution_list_t [static 1], char); | 8 | STATIC bool appendchar(solution_list_t [static 1], char); |
| 9 | STATIC int64_t appendsolution(const solution_moves_t [static 1], | 9 | STATIC int64_t appendsolution(const solution_moves_t [static 1], |
| 10 | const solution_settings_t [static 1], solution_list_t [static 1], bool); | 10 | const solution_settings_t [static 1], solution_list_t [static 1], bool, |
| 11 | const char *); | ||
| 11 | STATIC bool solutions_done(const solution_list_t [static 1], | 12 | STATIC bool solutions_done(const solution_list_t [static 1], |
| 12 | const solution_settings_t [static 1], int8_t depth); | 13 | const solution_settings_t [static 1], int8_t depth); |
| 13 | 14 | ||
| @@ -34,7 +35,7 @@ STATIC bool | |||
| 34 | solution_list_init(solution_list_t sols[static 1], size_t n, char buf[n]) | 35 | solution_list_init(solution_list_t sols[static 1], size_t n, char buf[n]) |
| 35 | { | 36 | { |
| 36 | if (n == 0) { | 37 | if (n == 0) { |
| 37 | LOG("Cannot use solution buffer with size 0\n"); | 38 | LOG("Error: cannot use solution buffer with size 0\n"); |
| 38 | return false; | 39 | return false; |
| 39 | } | 40 | } |
| 40 | 41 | ||
| @@ -98,7 +99,8 @@ appendsolution( | |||
| 98 | const solution_moves_t moves[static 1], | 99 | const solution_moves_t moves[static 1], |
| 99 | const solution_settings_t settings[static 1], | 100 | const solution_settings_t settings[static 1], |
| 100 | solution_list_t list[static 1], | 101 | solution_list_t list[static 1], |
| 101 | bool log | 102 | bool log, |
| 103 | const char *solver_name | ||
| 102 | ) | 104 | ) |
| 103 | { | 105 | { |
| 104 | int64_t r, strl; | 106 | int64_t r, strl; |
| @@ -184,8 +186,8 @@ appendsolution( | |||
| 184 | 186 | ||
| 185 | if (log) { | 187 | if (log) { |
| 186 | list->buf[list->used-1] = '\0'; | 188 | list->buf[list->used-1] = '\0'; |
| 187 | LOG("Found solution #%" PRIu64 ": %s\n", | 189 | LOG("[%s solve] Found solution #%" PRIu64 ": %s\n", |
| 188 | list->nsols, last_start); | 190 | solver_name, list->nsols, last_start); |
| 189 | list->buf[list->used-1] = '\n'; | 191 | list->buf[list->used-1] = '\n'; |
| 190 | } | 192 | } |
| 191 | } | 193 | } |
| @@ -194,14 +196,14 @@ appendsolution( | |||
| 194 | return r; | 196 | return r; |
| 195 | 197 | ||
| 196 | appendsolution_error_buffer: | 198 | appendsolution_error_buffer: |
| 197 | LOG("Could not append solution to buffer: size too small\n"); | 199 | LOG("[%s solve] Error: buffer too small\n", solver_name); |
| 198 | list->buf[0] = '\0'; | 200 | list->buf[0] = '\0'; |
| 199 | return NISSY_ERROR_BUFFER_SIZE; | 201 | return NISSY_ERROR_BUFFER_SIZE; |
| 200 | 202 | ||
| 201 | appendsolution_error_solution_length: | 203 | appendsolution_error_solution_length: |
| 202 | LOG("Error: solution is too long (%" PRIu8 ").\n" | 204 | LOG("[%s solve] Error: solution is too long (%" PRIu8 ").\n" |
| 203 | "This is a bug, please report it.\n", | 205 | "This is a bug, please report it.\n", |
| 204 | moves->nmoves + moves->npremoves); | 206 | solver_name, moves->nmoves + moves->npremoves); |
| 205 | list->buf[0] = '\0'; | 207 | list->buf[0] = '\0'; |
| 206 | return NISSY_ERROR_UNKNOWN; | 208 | return NISSY_ERROR_UNKNOWN; |
| 207 | } | 209 | } |
diff --git a/src/utils/math.h b/src/utils/math.h index 1ae4013..3ecd313 100644 --- a/src/utils/math.h +++ b/src/utils/math.h | |||
| @@ -138,7 +138,7 @@ digitstosumzero(size_t n, const uint8_t a[n], uint8_t b) | |||
| 138 | size_t i, sum; | 138 | size_t i, sum; |
| 139 | 139 | ||
| 140 | if (!((n == 8 && b == 3 ) || (n == 12 && b == 2))) { | 140 | if (!((n == 8 && b == 3 ) || (n == 12 && b == 2))) { |
| 141 | LOG("Won't compute 'sumzero' for n=%zu and b=%" PRIu8 | 141 | LOG("Error: won't compute 'sumzero' for n=%zu and b=%" PRIu8 |
| 142 | " (use n=8 b=3 or n=12 b=2)\n", n, b); | 142 | " (use n=8 b=3 or n=12 b=2)\n", n, b); |
| 143 | return -1; | 143 | return -1; |
| 144 | } | 144 | } |
| @@ -168,7 +168,7 @@ sumzerotodigits(int64_t d, size_t n, uint8_t b, uint8_t a[n]) | |||
| 168 | size_t i; | 168 | size_t i; |
| 169 | 169 | ||
| 170 | if (!((n == 8 && b == 3 ) || (n == 12 && b == 2))) { | 170 | if (!((n == 8 && b == 3 ) || (n == 12 && b == 2))) { |
| 171 | LOG("Won't compute 'digits' for n=%zu and b=%" PRIu8 | 171 | LOG("Error: won't compute 'digits' for n=%zu and b=%" PRIu8 |
| 172 | " (use n=8 b=3 or n=12 b=2)\n", n, b); | 172 | " (use n=8 b=3 or n=12 b=2)\n", n, b); |
| 173 | goto sumzerotodigits_error; | 173 | goto sumzerotodigits_error; |
| 174 | } | 174 | } |
