diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-07-13 20:32:59 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-07-13 20:32:59 +0200 |
| commit | a016aa7f78c86c59bab3ae4970f8cc339186bc91 (patch) | |
| tree | e40d495971428c644fd924868fc983a51ff85a10 | |
| parent | d3db14d63a03c4a313e818ba1435433dd18acba4 (diff) | |
| download | nissy-core-a016aa7f78c86c59bab3ae4970f8cc339186bc91.tar.gz nissy-core-a016aa7f78c86c59bab3ae4970f8cc339186bc91.zip | |
Added new bfs attempt, but looks wrong
Diffstat (limited to '')
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | TODO.txt | 5 | ||||
| -rw-r--r-- | src/solve_h48.h | 89 | ||||
| -rw-r--r-- | test/103_gendata_h48_h0/gendata_h48_tests.c | 2 |
4 files changed, 79 insertions, 19 deletions
| @@ -1,6 +1,4 @@ | |||
| 1 | config.mk | 1 | config.mk |
| 2 | benchmark/results | ||
| 3 | benchmark/run | ||
| 4 | gen | 2 | gen |
| 5 | debuggen | 3 | debuggen |
| 6 | perf.data | 4 | perf.data |
| @@ -1,5 +1,8 @@ | |||
| 1 | Check stats for all tables using H48stats solver | 1 | Check stats for all tables using H48stats solver |
| 2 | - what now? | 2 | - try DFS for h0 solver |
| 3 | - compare results, the bfs method could be wrong | ||
| 4 | - if faster: remove bfs | ||
| 5 | - if slower: why do I get different results with the new bfs? | ||
| 3 | 6 | ||
| 4 | Bug in esep table generation | 7 | Bug in esep table generation |
| 5 | - Fails for UFRUFU, try command | 8 | - Fails for UFRUFU, try command |
diff --git a/src/solve_h48.h b/src/solve_h48.h index bfcf585..26cbc73 100644 --- a/src/solve_h48.h +++ b/src/solve_h48.h | |||
| @@ -46,6 +46,7 @@ typedef struct { | |||
| 46 | uint32_t *cocsepdata; | 46 | uint32_t *cocsepdata; |
| 47 | uint32_t *buf32; | 47 | uint32_t *buf32; |
| 48 | uint64_t *selfsim; | 48 | uint64_t *selfsim; |
| 49 | int64_t done; | ||
| 49 | cube_t *crep; | 50 | cube_t *crep; |
| 50 | } bfsarg_esep_t; | 51 | } bfsarg_esep_t; |
| 51 | 52 | ||
| @@ -88,7 +89,9 @@ _static_inline cube_t invcoord_h48(int64_t, const cube_t *, uint8_t); | |||
| 88 | _static size_t gendata_cocsep(void *, uint64_t *, cube_t *); | 89 | _static size_t gendata_cocsep(void *, uint64_t *, cube_t *); |
| 89 | _static uint32_t gendata_cocsep_dfs(dfsarg_cocsep_t *); | 90 | _static uint32_t gendata_cocsep_dfs(dfsarg_cocsep_t *); |
| 90 | _static size_t gendata_h48h0k4(void *, uint8_t); | 91 | _static size_t gendata_h48h0k4(void *, uint8_t); |
| 91 | _static uint64_t gendata_h48h0k4_bfs(bfsarg_esep_t *); | 92 | _static int64_t gendata_h48h0k4_bfs(bfsarg_esep_t *); |
| 93 | _static int64_t gendata_h48h0k4_bfs_fromdone(bfsarg_esep_t *); | ||
| 94 | _static int64_t gendata_h48h0k4_bfs_fromnew(bfsarg_esep_t *); | ||
| 92 | 95 | ||
| 93 | _static_inline bool get_visited(const uint8_t *, int64_t); | 96 | _static_inline bool get_visited(const uint8_t *, int64_t); |
| 94 | _static_inline void set_visited(uint8_t *, int64_t); | 97 | _static_inline void set_visited(uint8_t *, int64_t); |
| @@ -363,7 +366,7 @@ gendata_h48h0k4(void *buf, uint8_t maxdepth) | |||
| 363 | { | 366 | { |
| 364 | uint32_t j, *buf32, *info, *cocsepdata; | 367 | uint32_t j, *buf32, *info, *cocsepdata; |
| 365 | bfsarg_esep_t arg; | 368 | bfsarg_esep_t arg; |
| 366 | int64_t sc, cc, tot, esep_max; | 369 | int64_t sc, cc, esep_max; |
| 367 | uint64_t selfsim[COCSEP_CLASSES]; | 370 | uint64_t selfsim[COCSEP_CLASSES]; |
| 368 | cube_t crep[COCSEP_CLASSES]; | 371 | cube_t crep[COCSEP_CLASSES]; |
| 369 | size_t cocsepsize, infosize; | 372 | size_t cocsepsize, infosize; |
| @@ -388,19 +391,19 @@ gendata_h48h0k4(void *buf, uint8_t maxdepth) | |||
| 388 | arg = (bfsarg_esep_t) { | 391 | arg = (bfsarg_esep_t) { |
| 389 | .cocsepdata = cocsepdata, | 392 | .cocsepdata = cocsepdata, |
| 390 | .buf32 = buf32, | 393 | .buf32 = buf32, |
| 391 | .crep = crep, | 394 | .selfsim = selfsim, |
| 392 | .selfsim = selfsim | 395 | .crep = crep |
| 393 | }; | 396 | }; |
| 394 | for ( | 397 | for ( |
| 395 | tot = 1, arg.depth = 1, cc = 0; | 398 | arg.done = 1, arg.depth = 1, cc = 0; |
| 396 | tot < esep_max && arg.depth <= maxdepth; | 399 | arg.done < esep_max && arg.depth <= maxdepth; |
| 397 | arg.depth++ | 400 | arg.depth++ |
| 398 | ) { | 401 | ) { |
| 399 | LOG("esep: generating depth %" PRIu8 "\n", arg.depth); | 402 | LOG("esep: generating depth %" PRIu8 "\n", arg.depth); |
| 400 | cc = gendata_h48h0k4_bfs(&arg); | 403 | cc = gendata_h48h0k4_bfs(&arg); |
| 401 | tot += cc; | 404 | arg.done += cc; |
| 402 | info[arg.depth+1] = cc; | 405 | info[arg.depth+1] = cc; |
| 403 | LOG("found %" PRIu64 "\n", cc); | 406 | LOG("found %" PRId64 "\n", cc); |
| 404 | } | 407 | } |
| 405 | 408 | ||
| 406 | info[0] = arg.depth-1; | 409 | info[0] = arg.depth-1; |
| @@ -415,17 +418,31 @@ gendata_h48h0k4_return_size: | |||
| 415 | return cocsepsize + ESEP_TABLESIZE(0, 4) + infosize; | 418 | return cocsepsize + ESEP_TABLESIZE(0, 4) + infosize; |
| 416 | } | 419 | } |
| 417 | 420 | ||
| 418 | _static uint64_t | 421 | _static int64_t |
| 419 | gendata_h48h0k4_bfs(bfsarg_esep_t *arg) | 422 | gendata_h48h0k4_bfs(bfsarg_esep_t *arg) |
| 420 | { | 423 | { |
| 424 | /* | ||
| 425 | TODO: the new method gives a slightly different answer. If the new | ||
| 426 | method is correct, then the old bfs method is wrong. Which one is it? | ||
| 427 | Try also DFS and compare results (it could be faster). | ||
| 428 | /* | ||
| 429 | if (2 * arg->done < (int64_t)ESEP_MAX(0)) | ||
| 430 | return gendata_h48h0k4_bfs_fromdone(arg); | ||
| 431 | else | ||
| 432 | return gendata_h48h0k4_bfs_fromnew(arg); | ||
| 433 | */ | ||
| 434 | return gendata_h48h0k4_bfs_fromdone(arg); | ||
| 435 | } | ||
| 436 | |||
| 437 | _static int64_t | ||
| 438 | gendata_h48h0k4_bfs_fromdone(bfsarg_esep_t *arg) | ||
| 439 | { | ||
| 421 | uint8_t c, m, x; | 440 | uint8_t c, m, x; |
| 422 | uint32_t cc; | 441 | uint32_t cc; |
| 423 | int64_t i, j, k, t, cocsep_coord, sim, esep_max; | 442 | int64_t i, j, k, t, cocsep_coord, sim; |
| 424 | cube_t cube, moved, transd; | 443 | cube_t cube, moved, transd; |
| 425 | 444 | ||
| 426 | esep_max = (uint64_t)ESEP_MAX(0); | 445 | for (i = 0, cc = 0; i < (int64_t)ESEP_MAX(0); i++) { |
| 427 | |||
| 428 | for (i = 0, cc = 0; i < esep_max; i++) { | ||
| 429 | c = get_esep_pval(arg->buf32, i); | 446 | c = get_esep_pval(arg->buf32, i); |
| 430 | if (c != arg->depth - 1) | 447 | if (c != arg->depth - 1) |
| 431 | continue; | 448 | continue; |
| @@ -462,12 +479,54 @@ gendata_h48h0k4_bfs(bfsarg_esep_t *arg) | |||
| 462 | return cc; | 479 | return cc; |
| 463 | } | 480 | } |
| 464 | 481 | ||
| 465 | _static_inline bool get_visited(const uint8_t *a, int64_t i) | 482 | _static int64_t |
| 483 | gendata_h48h0k4_bfs_fromnew(bfsarg_esep_t *arg) | ||
| 484 | { | ||
| 485 | uint8_t c, m, x; | ||
| 486 | uint32_t cc; | ||
| 487 | int64_t i, j, t, cocsep_coord, sim; | ||
| 488 | cube_t cube, moved, transd; | ||
| 489 | |||
| 490 | for (i = 0, cc = 0; i < (int64_t)ESEP_MAX(0); i++) { | ||
| 491 | c = get_esep_pval(arg->buf32, i); | ||
| 492 | if (c != 0xF) | ||
| 493 | continue; | ||
| 494 | cube = invcoord_h48(i, arg->crep, 0); | ||
| 495 | for (m = 0; m < 18; m++) { | ||
| 496 | moved = move(cube, m); | ||
| 497 | j = coord_h48(moved, arg->cocsepdata, 0); | ||
| 498 | x = get_esep_pval(arg->buf32, j); | ||
| 499 | if (x < arg->depth) | ||
| 500 | goto neighbor_found; | ||
| 501 | } | ||
| 502 | continue; | ||
| 503 | neighbor_found: | ||
| 504 | set_esep_pval(arg->buf32, i, arg->depth); | ||
| 505 | cc++; | ||
| 506 | cocsep_coord = i / H48_ESIZE(0); | ||
| 507 | sim = arg->selfsim[cocsep_coord] >> 1; | ||
| 508 | for (t = 1; t < 48 && sim; t++, sim >>= 1) { | ||
| 509 | if (!(sim & 1)) | ||
| 510 | continue; | ||
| 511 | transd = transform(cube, t); | ||
| 512 | j = coord_h48(transd, arg->cocsepdata, 0); | ||
| 513 | x = get_esep_pval(arg->buf32, j); | ||
| 514 | set_esep_pval(arg->buf32, j, arg->depth); | ||
| 515 | cc += x == 0xF; | ||
| 516 | } | ||
| 517 | } | ||
| 518 | |||
| 519 | return cc; | ||
| 520 | } | ||
| 521 | |||
| 522 | _static_inline bool | ||
| 523 | get_visited(const uint8_t *a, int64_t i) | ||
| 466 | { | 524 | { |
| 467 | return a[VISITED_IND(i)] & VISITED_MASK(i); | 525 | return a[VISITED_IND(i)] & VISITED_MASK(i); |
| 468 | } | 526 | } |
| 469 | 527 | ||
| 470 | _static_inline void set_visited(uint8_t *a, int64_t i) | 528 | _static_inline void |
| 529 | set_visited(uint8_t *a, int64_t i) | ||
| 471 | { | 530 | { |
| 472 | a[VISITED_IND(i)] |= VISITED_MASK(i); | 531 | a[VISITED_IND(i)] |= VISITED_MASK(i); |
| 473 | } | 532 | } |
diff --git a/test/103_gendata_h48_h0/gendata_h48_tests.c b/test/103_gendata_h48_h0/gendata_h48_tests.c index ed17915..e9de3c0 100644 --- a/test/103_gendata_h48_h0/gendata_h48_tests.c +++ b/test/103_gendata_h48_h0/gendata_h48_tests.c | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | #define COCSEPSIZE 1119792 | 4 | #define COCSEPSIZE 1119792 |
| 5 | #define ETABLESIZE ((3393 * 495 * 70) >> 1) | 5 | #define ETABLESIZE ((3393 * 495 * 70) >> 1) |
| 6 | 6 | ||
| 7 | size_t gendata_h48h0k4(void *, uint8_t); | 7 | int64_t gendata_h48h0k4(void *, uint8_t); |
| 8 | 8 | ||
| 9 | void run(void) { | 9 | void run(void) { |
| 10 | char str[STRLENMAX]; | 10 | char str[STRLENMAX]; |
