diff options
Diffstat (limited to 'src')
| -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/map.h | 5 | ||||
| -rw-r--r-- | src/utils/math.h | 1 |
4 files changed, 32 insertions, 26 deletions
diff --git a/src/solvers/h48/gendata_cocsep.h b/src/solvers/h48/gendata_cocsep.h index 0f96da9..b7d28e1 100644 --- a/src/solvers/h48/gendata_cocsep.h +++ b/src/solvers/h48/gendata_cocsep.h | |||
| @@ -135,7 +135,7 @@ gendata_cocsep_dfs(cocsep_dfs_arg_t *arg) | |||
| 135 | return cc; | 135 | return cc; |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | memcpy(&nextarg, arg, sizeof(cocsep_dfs_arg_t)); | 138 | nextarg = *arg; |
| 139 | nextarg.depth++; | 139 | nextarg.depth++; |
| 140 | for (m = 0, cc = 0; m < 18; m++) { | 140 | for (m = 0, cc = 0; m < 18; m++) { |
| 141 | nextarg.cube = move(arg->cube, m); | 141 | nextarg.cube = move(arg->cube, m); |
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index 2d222c9..6486834 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #define H48_COORDMAX_NOEO ((int64_t)(COCSEP_CLASSES * _12c4 * _8c4)) | 1 | #define H48_COORDMAX_NOEO ((int64_t)(COCSEP_CLASSES * _12c4 * _8c4)) |
| 2 | #define H48_COORDMAX(h) ((int64_t)(H48_COORDMAX_NOEO << (int64_t)(h))) | 2 | #define H48_COORDMAX(h) ((int64_t)(H48_COORDMAX_NOEO << (int64_t)(h))) |
| 3 | #define H48_TABLESIZE(h, k) ((size_t)H48_COORDMAX((h)) / ((size_t)8 / (size_t)(k))) | 3 | #define H48_DIV(k) ((size_t)8 / (size_t)(k)) |
| 4 | #define H48_TABLESIZE(h, k) _div_round_up((size_t)H48_COORDMAX((h)), H48_DIV(k)) | ||
| 4 | 5 | ||
| 5 | #define H48_COEFF(k) (UINT32_C(32) / (uint32_t)(k)) | 6 | #define H48_COEFF(k) (UINT32_C(32) / (uint32_t)(k)) |
| 6 | #define H48_INDEX(i, k) ((uint32_t)(i) / H48_COEFF(k)) | 7 | #define H48_INDEX(i, k) ((uint32_t)(i) / H48_COEFF(k)) |
| @@ -59,7 +60,7 @@ typedef struct { | |||
| 59 | 60 | ||
| 60 | typedef struct { | 61 | typedef struct { |
| 61 | cube_t cube; | 62 | cube_t cube; |
| 62 | uint8_t moves[4]; | 63 | uint8_t moves[MAXLEN]; |
| 63 | uint8_t h; | 64 | uint8_t h; |
| 64 | uint8_t k; | 65 | uint8_t k; |
| 65 | uint8_t base; | 66 | uint8_t base; |
| @@ -140,7 +141,7 @@ gendata_h48(gendata_h48_arg_t *arg) | |||
| 140 | cocsepsize = gendata_cocsep( | 141 | cocsepsize = gendata_cocsep( |
| 141 | (void *)arg->cocsepdata, arg->selfsim, arg->crep); | 142 | (void *)arg->cocsepdata, arg->selfsim, arg->crep); |
| 142 | arg->h48data = arg->cocsepdata + (cocsepsize / sizeof(uint32_t)); | 143 | arg->h48data = arg->cocsepdata + (cocsepsize / sizeof(uint32_t)); |
| 143 | arg->info = arg->h48data + | 144 | arg->info = arg->h48data + 1 + |
| 144 | (H48_TABLESIZE(arg->h, arg->k) / sizeof(uint32_t)); | 145 | (H48_TABLESIZE(arg->h, arg->k) / sizeof(uint32_t)); |
| 145 | 146 | ||
| 146 | if (arg->buf != NULL) | 147 | if (arg->buf != NULL) |
| @@ -303,14 +304,12 @@ gendata_h48k2(gendata_h48_arg_t *arg) | |||
| 303 | 304 | ||
| 304 | uint8_t t; | 305 | uint8_t t; |
| 305 | int64_t j; | 306 | int64_t j; |
| 306 | uint64_t nshort, i; | 307 | uint64_t nshort, i, ii; |
| 307 | h48map_t shortcubes; | 308 | h48map_t shortcubes; |
| 308 | kvpair_t kv; | 309 | kvpair_t kv; |
| 309 | gendata_h48short_arg_t shortarg; | 310 | gendata_h48short_arg_t shortarg; |
| 310 | h48k2_dfs_arg_t dfsarg; | 311 | h48k2_dfs_arg_t dfsarg; |
| 311 | 312 | ||
| 312 | DBG_ASSERT(base[arg->h] == 8, 0, "Only implemented for h <= 3 (base 8)\n"); | ||
| 313 | |||
| 314 | if (arg->buf == NULL) | 313 | if (arg->buf == NULL) |
| 315 | goto gendata_h48k2_return_size; | 314 | goto gendata_h48k2_return_size; |
| 316 | 315 | ||
| @@ -332,7 +331,7 @@ gendata_h48k2(gendata_h48_arg_t *arg) | |||
| 332 | .base = base[arg->h], | 331 | .base = base[arg->h], |
| 333 | .depth = shortdepth, | 332 | .depth = shortdepth, |
| 334 | .shortdepth = shortdepth, | 333 | .shortdepth = shortdepth, |
| 335 | .maxdepth = arg->maxdepth, | 334 | .maxdepth = _min(arg->maxdepth, base[arg->h]+2), |
| 336 | .cocsepdata = arg->cocsepdata, | 335 | .cocsepdata = arg->cocsepdata, |
| 337 | .h48data = arg->h48data, | 336 | .h48data = arg->h48data, |
| 338 | .selfsim = arg->selfsim, | 337 | .selfsim = arg->selfsim, |
| @@ -340,19 +339,19 @@ gendata_h48k2(gendata_h48_arg_t *arg) | |||
| 340 | .shortcubes = &shortcubes | 339 | .shortcubes = &shortcubes |
| 341 | }; | 340 | }; |
| 342 | 341 | ||
| 343 | i = 0; | 342 | i = ii = 0; |
| 344 | for (kv = h48map_nextkvpair(&shortcubes, &i); | 343 | for (kv = h48map_nextkvpair(&shortcubes, &i); |
| 345 | i != shortcubes.capacity; | 344 | i != shortcubes.capacity; |
| 346 | kv = h48map_nextkvpair(&shortcubes, &i) | 345 | kv = h48map_nextkvpair(&shortcubes, &i) |
| 347 | ) { | 346 | ) { |
| 348 | /* TODO maybe over all sim? */ | ||
| 349 | dfsarg.cube = invcoord_h48(kv.key, arg->crep, 11); | 347 | dfsarg.cube = invcoord_h48(kv.key, arg->crep, 11); |
| 350 | gendata_h48k2_dfs(&dfsarg); | 348 | gendata_h48k2_dfs(&dfsarg); |
| 349 | if (++i % UINT64_C(1000000) == 0) | ||
| 350 | LOG("Processed %" PRIu64 " short cubes\n", ii); | ||
| 351 | } | 351 | } |
| 352 | 352 | ||
| 353 | h48map_destroy(&shortcubes); | 353 | h48map_destroy(&shortcubes); |
| 354 | 354 | ||
| 355 | /* TODO: move info update to dfs? */ | ||
| 356 | memset(arg->info, 0, 5 * sizeof(arg->info[0])); | 355 | memset(arg->info, 0, 5 * sizeof(arg->info[0])); |
| 357 | arg->info[0] = base[arg->k]; | 356 | arg->info[0] = base[arg->k]; |
| 358 | for (j = 0; j < H48_COORDMAX(arg->h); j++) { | 357 | for (j = 0; j < H48_COORDMAX(arg->h); j++) { |
| @@ -367,29 +366,34 @@ gendata_h48k2_return_size: | |||
| 367 | _static void | 366 | _static void |
| 368 | gendata_h48k2_dfs(h48k2_dfs_arg_t *arg) | 367 | gendata_h48k2_dfs(h48k2_dfs_arg_t *arg) |
| 369 | { | 368 | { |
| 370 | uint8_t nmoves; | 369 | cube_t ccc; |
| 371 | uint64_t val; | 370 | bool toodeep, backtracked; |
| 371 | uint8_t nmoves, oldval, newval; | ||
| 372 | uint64_t mval; | ||
| 372 | int64_t coord, fullcoord; | 373 | int64_t coord, fullcoord; |
| 373 | h48k2_dfs_arg_t nextarg; | 374 | h48k2_dfs_arg_t nextarg; |
| 374 | uint8_t m; | 375 | uint8_t m; |
| 375 | 376 | ||
| 376 | fullcoord = coord_h48(arg->cube, arg->cocsepdata, 11); | 377 | ccc = arg->cube; |
| 377 | coord = fullcoord >> (int64_t)(11 - arg->h); | 378 | _foreach_h48sim(ccc, arg->cocsepdata, arg->selfsim, 11, |
| 378 | 379 | fullcoord = coord_h48(ccc, arg->cocsepdata, 11); | |
| 379 | val = h48map_value(arg->shortcubes, fullcoord); | 380 | coord = fullcoord >> (int64_t)(11 - arg->h); |
| 380 | 381 | oldval = get_esep_pval(arg->h48data, coord, arg->k); | |
| 381 | if (arg->depth >= arg->base && arg->depth <= arg->base + 2) | 382 | newval = arg->depth >= arg->base ? arg->depth - arg->base : 0; |
| 382 | set_esep_pval( | 383 | set_esep_pval( |
| 383 | arg->h48data, coord, arg->k, arg->depth - arg->base); | 384 | arg->h48data, coord, arg->k, _min(oldval, newval)); |
| 385 | ) | ||
| 384 | 386 | ||
| 385 | if ((val < arg->shortdepth) || | 387 | fullcoord = coord_h48(arg->cube, arg->cocsepdata, 11); /* Necessary? */ |
| 386 | (arg->depth > arg->shortdepth && val != MAP_UNSET) || | 388 | mval = h48map_value(arg->shortcubes, fullcoord); |
| 387 | (arg->depth >= arg->maxdepth || arg->depth >= arg->base + 2)) | 389 | backtracked = mval <= arg->shortdepth && arg->depth != arg->shortdepth; |
| 390 | toodeep = arg->depth >= arg->maxdepth; | ||
| 391 | if (backtracked || toodeep) | ||
| 388 | return; | 392 | return; |
| 389 | 393 | ||
| 390 | /* TODO: avoid copy, change arg and undo changes after recursion */ | 394 | /* TODO: avoid copy, change arg and undo changes after recursion */ |
| 391 | nextarg = *arg; | 395 | nextarg = *arg; |
| 392 | nextarg.depth = arg->depth + 1; | 396 | nextarg.depth++; |
| 393 | nmoves = nextarg.depth - arg->shortdepth; | 397 | nmoves = nextarg.depth - arg->shortdepth; |
| 394 | for (m = 0; m < 18; m++) { | 398 | for (m = 0; m < 18; m++) { |
| 395 | nextarg.moves[nmoves - 1] = m; | 399 | nextarg.moves[nmoves - 1] = m; |
diff --git a/src/solvers/h48/map.h b/src/solvers/h48/map.h index 82e5a2c..0e9f926 100644 --- a/src/solvers/h48/map.h +++ b/src/solvers/h48/map.h | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #define MAP_UNSET UINT64_C(0xFFFFFFFFFFFFFFFF) | 1 | #define MAP_UNSET UINT64_C(0xFFFFFFFFFFFFFFFF) |
| 2 | #define MAP_KEYMASK UINT64_C(0xFFFFFFFFFF) | 2 | #define MAP_KEYMASK UINT64_C(0xFFFFFFFFFF) |
| 3 | #define MAP_KEYSHIFT UINT64_C(40) | 3 | #define MAP_KEYSHIFT UINT64_C(40) |
| 4 | #define MAP_UNSET_VAL (MAP_UNSET >> MAP_KEYSHIFT) | ||
| 4 | 5 | ||
| 5 | typedef struct { | 6 | typedef struct { |
| 6 | uint64_t n; | 7 | uint64_t n; |
| @@ -84,8 +85,8 @@ h48map_nextkvpair(h48map_t *map, uint64_t *p) | |||
| 84 | kvpair_t kv; | 85 | kvpair_t kv; |
| 85 | uint64_t pair; | 86 | uint64_t pair; |
| 86 | 87 | ||
| 87 | kv.key = MAP_UNSET; | 88 | kv.key = MAP_KEYMASK; |
| 88 | kv.val = MAP_UNSET; | 89 | kv.val = MAP_UNSET_VAL; |
| 89 | 90 | ||
| 90 | DBG_ASSERT(*p < map->capacity, kv, | 91 | DBG_ASSERT(*p < map->capacity, kv, |
| 91 | "Error looping over map: given index %" PRIu64 " is out of " | 92 | "Error looping over map: given index %" PRIu64 " is out of " |
diff --git a/src/utils/math.h b/src/utils/math.h index 87402e6..a361808 100644 --- a/src/utils/math.h +++ b/src/utils/math.h | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #define _swap(x, y) do { x ^= y; y ^= x; x ^= y; } while (0) | 1 | #define _swap(x, y) do { x ^= y; y ^= x; x ^= y; } while (0) |
| 2 | #define _min(x, y) ((x) < (y) ? (x) : (y)) | 2 | #define _min(x, y) ((x) < (y) ? (x) : (y)) |
| 3 | #define _max(x, y) ((x) > (y) ? (x) : (y)) | 3 | #define _max(x, y) ((x) > (y) ? (x) : (y)) |
| 4 | #define _div_round_up(n, d) (((n) + (d) - 1) / (d)) | ||
| 4 | 5 | ||
| 5 | _static int64_t factorial(int64_t); | 6 | _static int64_t factorial(int64_t); |
| 6 | _static bool isperm(uint8_t *, int64_t); | 7 | _static bool isperm(uint8_t *, int64_t); |
