aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-07-13 20:32:59 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-07-13 20:32:59 +0200
commita016aa7f78c86c59bab3ae4970f8cc339186bc91 (patch)
treee40d495971428c644fd924868fc983a51ff85a10 /src
parentd3db14d63a03c4a313e818ba1435433dd18acba4 (diff)
downloadnissy-core-a016aa7f78c86c59bab3ae4970f8cc339186bc91.tar.gz
nissy-core-a016aa7f78c86c59bab3ae4970f8cc339186bc91.zip
Added new bfs attempt, but looks wrong
Diffstat (limited to 'src')
-rw-r--r--src/solve_h48.h89
1 files changed, 74 insertions, 15 deletions
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
419gendata_h48h0k4_bfs(bfsarg_esep_t *arg) 422gendata_h48h0k4_bfs(bfsarg_esep_t *arg)
420{ 423{
424/*
425TODO: the new method gives a slightly different answer. If the new
426method is correct, then the old bfs method is wrong. Which one is it?
427Try 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
438gendata_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
483gendata_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;
503neighbor_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
523get_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
529set_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}

Generated with cgit - Back to sebastiano.tronto.net