aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-08-26 21:42:50 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-08-26 21:42:50 +0200
commitc558c7989eaa0921f7b29ee274b325f4f6d97f8c (patch)
tree3f8393c5d8c492ed4600198501f7ecfb28fd6363 /src
parentf2907e471b3caddc5844bc6994e1cbd249019747 (diff)
downloadnissy-core-c558c7989eaa0921f7b29ee274b325f4f6d97f8c.tar.gz
nissy-core-c558c7989eaa0921f7b29ee274b325f4f6d97f8c.zip
Gendata added for h48k2, need to verify with new tool
Diffstat (limited to 'src')
-rw-r--r--src/solvers/h48/gendata_cocsep.h14
-rw-r--r--src/solvers/h48/gendata_h48.h134
2 files changed, 111 insertions, 37 deletions
diff --git a/src/solvers/h48/gendata_cocsep.h b/src/solvers/h48/gendata_cocsep.h
index 13ce68b..0f96da9 100644
--- a/src/solvers/h48/gendata_cocsep.h
+++ b/src/solvers/h48/gendata_cocsep.h
@@ -18,13 +18,13 @@ typedef struct {
18 uint8_t *visited; 18 uint8_t *visited;
19 uint64_t *selfsim; 19 uint64_t *selfsim;
20 cube_t *rep; 20 cube_t *rep;
21} dfsarg_cocsep_t; 21} cocsep_dfs_arg_t;
22 22
23_static_inline bool get_visited(const uint8_t *, int64_t); 23_static_inline bool get_visited(const uint8_t *, int64_t);
24_static_inline void set_visited(uint8_t *, int64_t); 24_static_inline void set_visited(uint8_t *, int64_t);
25 25
26_static size_t gendata_cocsep(void *, uint64_t *, cube_t *); 26_static size_t gendata_cocsep(void *, uint64_t *, cube_t *);
27_static uint32_t gendata_cocsep_dfs(dfsarg_cocsep_t *); 27_static uint32_t gendata_cocsep_dfs(cocsep_dfs_arg_t *);
28 28
29_static_inline int8_t get_h48_cdata(cube_t, uint32_t *, uint32_t *); 29_static_inline int8_t get_h48_cdata(cube_t, uint32_t *, uint32_t *);
30 30
@@ -45,7 +45,7 @@ gendata_cocsep(void *buf, uint64_t *selfsim, cube_t *rep)
45 uint32_t *buf32, *info, cc; 45 uint32_t *buf32, *info, cc;
46 uint16_t n; 46 uint16_t n;
47 uint8_t i, j, visited[COCSEP_VISITEDSIZE]; 47 uint8_t i, j, visited[COCSEP_VISITEDSIZE];
48 dfsarg_cocsep_t arg; 48 cocsep_dfs_arg_t arg;
49 49
50 if (buf == NULL) 50 if (buf == NULL)
51 goto gendata_cocsep_return_size; 51 goto gendata_cocsep_return_size;
@@ -56,7 +56,7 @@ gendata_cocsep(void *buf, uint64_t *selfsim, cube_t *rep)
56 if (selfsim != NULL) 56 if (selfsim != NULL)
57 memset(selfsim, 0, sizeof(uint64_t) * COCSEP_CLASSES); 57 memset(selfsim, 0, sizeof(uint64_t) * COCSEP_CLASSES);
58 58
59 arg = (dfsarg_cocsep_t) { 59 arg = (cocsep_dfs_arg_t) {
60 .cube = solved, 60 .cube = solved,
61 .n = &n, 61 .n = &n,
62 .buf32 = buf32, 62 .buf32 = buf32,
@@ -92,14 +92,14 @@ gendata_cocsep_return_size:
92} 92}
93 93
94_static uint32_t 94_static uint32_t
95gendata_cocsep_dfs(dfsarg_cocsep_t *arg) 95gendata_cocsep_dfs(cocsep_dfs_arg_t *arg)
96{ 96{
97 uint8_t m; 97 uint8_t m;
98 uint32_t cc, class, ttrep, depth, olddepth, tinv; 98 uint32_t cc, class, ttrep, depth, olddepth, tinv;
99 uint64_t t; 99 uint64_t t;
100 int64_t i, j; 100 int64_t i, j;
101 cube_t d; 101 cube_t d;
102 dfsarg_cocsep_t nextarg; 102 cocsep_dfs_arg_t nextarg;
103 103
104 i = coord_cocsep(arg->cube); 104 i = coord_cocsep(arg->cube);
105 olddepth = (uint8_t)(arg->buf32[i] & 0xFF); 105 olddepth = (uint8_t)(arg->buf32[i] & 0xFF);
@@ -135,7 +135,7 @@ gendata_cocsep_dfs(dfsarg_cocsep_t *arg)
135 return cc; 135 return cc;
136 } 136 }
137 137
138 memcpy(&nextarg, arg, sizeof(dfsarg_cocsep_t)); 138 memcpy(&nextarg, arg, sizeof(cocsep_dfs_arg_t));
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 2b1347f..2d222c9 100644
--- a/src/solvers/h48/gendata_h48.h
+++ b/src/solvers/h48/gendata_h48.h
@@ -1,6 +1,6 @@
1#define H48_COORDMAX_NOEO (COCSEP_CLASSES * (size_t)_12c4 * (size_t)_8c4) 1#define H48_COORDMAX_NOEO ((int64_t)(COCSEP_CLASSES * _12c4 * _8c4))
2#define H48_COORDMAX(h) (H48_COORDMAX_NOEO << (size_t)(h)) 2#define H48_COORDMAX(h) ((int64_t)(H48_COORDMAX_NOEO << (int64_t)(h)))
3#define H48_TABLESIZE(h, k) (H48_COORDMAX((h)) / ((size_t)8 / (size_t)(k))) 3#define H48_TABLESIZE(h, k) ((size_t)H48_COORDMAX((h)) / ((size_t)8 / (size_t)(k)))
4 4
5#define H48_COEFF(k) (UINT32_C(32) / (uint32_t)(k)) 5#define H48_COEFF(k) (UINT32_C(32) / (uint32_t)(k))
6#define H48_INDEX(i, k) ((uint32_t)(i) / H48_COEFF(k)) 6#define H48_INDEX(i, k) ((uint32_t)(i) / H48_COEFF(k))
@@ -55,7 +55,23 @@ typedef struct {
55 uint64_t *selfsim; 55 uint64_t *selfsim;
56 int64_t done; 56 int64_t done;
57 cube_t *crep; 57 cube_t *crep;
58} bfsarg_esep_t; 58} h48h0k4_bfs_arg_t;
59
60typedef struct {
61 cube_t cube;
62 uint8_t moves[4];
63 uint8_t h;
64 uint8_t k;
65 uint8_t base;
66 uint8_t depth;
67 uint8_t shortdepth;
68 uint8_t maxdepth;
69 uint32_t *cocsepdata;
70 uint32_t *h48data;
71 uint64_t *selfsim;
72 cube_t *crep;
73 h48map_t *shortcubes;
74} h48k2_dfs_arg_t;
59 75
60_static_inline uint8_t get_esep_pval(const uint32_t *, int64_t, uint8_t); 76_static_inline uint8_t get_esep_pval(const uint32_t *, int64_t, uint8_t);
61_static_inline void set_esep_pval(uint32_t *, int64_t, uint8_t, uint8_t); 77_static_inline void set_esep_pval(uint32_t *, int64_t, uint8_t, uint8_t);
@@ -63,10 +79,11 @@ _static_inline void set_esep_pval(uint32_t *, int64_t, uint8_t, uint8_t);
63_static uint64_t gen_h48short(gendata_h48short_arg_t *); 79_static uint64_t gen_h48short(gendata_h48short_arg_t *);
64_static size_t gendata_h48(gendata_h48_arg_t *); 80_static size_t gendata_h48(gendata_h48_arg_t *);
65_static size_t gendata_h48h0k4(gendata_h48_arg_t *); 81_static size_t gendata_h48h0k4(gendata_h48_arg_t *);
66_static int64_t gendata_h48h0k4_bfs(bfsarg_esep_t *); 82_static int64_t gendata_h48h0k4_bfs(h48h0k4_bfs_arg_t *);
67_static int64_t gendata_h48h0k4_bfs_fromdone(bfsarg_esep_t *); 83_static int64_t gendata_h48h0k4_bfs_fromdone(h48h0k4_bfs_arg_t *);
68_static int64_t gendata_h48h0k4_bfs_fromnew(bfsarg_esep_t *); 84_static int64_t gendata_h48h0k4_bfs_fromnew(h48h0k4_bfs_arg_t *);
69_static size_t gendata_h48k2(gendata_h48_arg_t *); 85_static size_t gendata_h48k2(gendata_h48_arg_t *);
86_static void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg);
70 87
71_static_inline int8_t get_h48_bound(cube_t, uint32_t, uint8_t, uint8_t, uint32_t *); 88_static_inline int8_t get_h48_bound(cube_t, uint32_t, uint8_t, uint8_t, uint32_t *);
72 89
@@ -150,31 +167,17 @@ _static size_t
150gendata_h48h0k4(gendata_h48_arg_t *arg) 167gendata_h48h0k4(gendata_h48_arg_t *arg)
151{ 168{
152 uint32_t j; 169 uint32_t j;
153 bfsarg_esep_t bfsarg; 170 h48h0k4_bfs_arg_t bfsarg;
154 int64_t sc, cc, esep_max; 171 int64_t sc, cc, esep_max;
155/*
156 uint64_t selfsim[COCSEP_CLASSES];
157 cube_t crep[COCSEP_CLASSES];
158 size_t cocsepsize, infosize;
159*/
160 172
161 if (arg->buf == NULL) 173 if (arg->buf == NULL)
162 goto gendata_h48h0k4_return_size; 174 goto gendata_h48h0k4_return_size;
163/*
164 cocsepsize = gendata_cocsep(buf, selfsim, crep);
165 infosize = 88;
166
167 cocsepdata = (uint32_t *)buf;
168 buf32 = cocsepdata + cocsepsize / 4;
169 info = buf32 + (H48_TABLESIZE(0, 4) / sizeof(uint32_t));
170 memset(buf32, 0xFF, H48_TABLESIZE(0, 4));
171*/
172 175
173 esep_max = (int64_t)H48_COORDMAX(0); 176 esep_max = (int64_t)H48_COORDMAX(0);
174 sc = coord_h48(solved, arg->cocsepdata, 0); 177 sc = coord_h48(solved, arg->cocsepdata, 0);
175 set_esep_pval(arg->h48data, sc, 4, 0); 178 set_esep_pval(arg->h48data, sc, 4, 0);
176 arg->info[1] = 1; 179 arg->info[1] = 1;
177 bfsarg = (bfsarg_esep_t) { 180 bfsarg = (h48h0k4_bfs_arg_t) {
178 .cocsepdata = arg->cocsepdata, 181 .cocsepdata = arg->cocsepdata,
179 .buf32 = arg->h48data, 182 .buf32 = arg->h48data,
180 .selfsim = arg->selfsim, 183 .selfsim = arg->selfsim,
@@ -205,7 +208,7 @@ gendata_h48h0k4_return_size:
205} 208}
206 209
207_static int64_t 210_static int64_t
208gendata_h48h0k4_bfs(bfsarg_esep_t *arg) 211gendata_h48h0k4_bfs(h48h0k4_bfs_arg_t *arg)
209{ 212{
210 const uint8_t breakpoint = 10; /* Hand-picked optimal */ 213 const uint8_t breakpoint = 10; /* Hand-picked optimal */
211 214
@@ -216,7 +219,7 @@ gendata_h48h0k4_bfs(bfsarg_esep_t *arg)
216} 219}
217 220
218_static int64_t 221_static int64_t
219gendata_h48h0k4_bfs_fromdone(bfsarg_esep_t *arg) 222gendata_h48h0k4_bfs_fromdone(h48h0k4_bfs_arg_t *arg)
220{ 223{
221 uint8_t c, m, x; 224 uint8_t c, m, x;
222 uint32_t cc; 225 uint32_t cc;
@@ -246,7 +249,7 @@ gendata_h48h0k4_bfs_fromdone(bfsarg_esep_t *arg)
246} 249}
247 250
248_static int64_t 251_static int64_t
249gendata_h48h0k4_bfs_fromnew(bfsarg_esep_t *arg) 252gendata_h48h0k4_bfs_fromnew(h48h0k4_bfs_arg_t *arg)
250{ 253{
251 uint8_t c, m, x; 254 uint8_t c, m, x;
252 uint32_t cc; 255 uint32_t cc;
@@ -298,9 +301,13 @@ gendata_h48k2(gendata_h48_arg_t *arg)
298 [11] = 10 301 [11] = 10
299 }; 302 };
300 303
301 uint64_t nshort; 304 uint8_t t;
305 int64_t j;
306 uint64_t nshort, i;
302 h48map_t shortcubes; 307 h48map_t shortcubes;
308 kvpair_t kv;
303 gendata_h48short_arg_t shortarg; 309 gendata_h48short_arg_t shortarg;
310 h48k2_dfs_arg_t dfsarg;
304 311
305 DBG_ASSERT(base[arg->h] == 8, 0, "Only implemented for h <= 3 (base 8)\n"); 312 DBG_ASSERT(base[arg->h] == 8, 0, "Only implemented for h <= 3 (base 8)\n");
306 313
@@ -317,17 +324,84 @@ gendata_h48k2(gendata_h48_arg_t *arg)
317 .map = &shortcubes 324 .map = &shortcubes
318 }; 325 };
319 nshort = gen_h48short(&shortarg); 326 nshort = gen_h48short(&shortarg);
320 LOG("Found %" PRIu64 "\n", nshort); 327 LOG("Cubes in <= %" PRIu8 " moves: %" PRIu64 "\n", shortdepth, nshort);
328
329 dfsarg = (h48k2_dfs_arg_t){
330 .h = arg->h,
331 .k = arg->k,
332 .base = base[arg->h],
333 .depth = shortdepth,
334 .shortdepth = shortdepth,
335 .maxdepth = arg->maxdepth,
336 .cocsepdata = arg->cocsepdata,
337 .h48data = arg->h48data,
338 .selfsim = arg->selfsim,
339 .crep = arg->crep,
340 .shortcubes = &shortcubes
341 };
321 342
322 /* TODO: loop over map, set all found to 0, do 2 moves each */ 343 i = 0;
323 LOG("The rest is not implemented yet\n"); 344 for (kv = h48map_nextkvpair(&shortcubes, &i);
345 i != shortcubes.capacity;
346 kv = h48map_nextkvpair(&shortcubes, &i)
347 ) {
348 /* TODO maybe over all sim? */
349 dfsarg.cube = invcoord_h48(kv.key, arg->crep, 11);
350 gendata_h48k2_dfs(&dfsarg);
351 }
324 352
325 h48map_destroy(&shortcubes); 353 h48map_destroy(&shortcubes);
326 354
355 /* TODO: move info update to dfs? */
356 memset(arg->info, 0, 5 * sizeof(arg->info[0]));
357 arg->info[0] = base[arg->k];
358 for (j = 0; j < H48_COORDMAX(arg->h); j++) {
359 t = get_esep_pval(arg->h48data, j, 2);
360 arg->info[1 + t]++;
361 }
362
327gendata_h48k2_return_size: 363gendata_h48k2_return_size:
328 return H48_TABLESIZE(arg->h, 2); 364 return H48_TABLESIZE(arg->h, 2);
329} 365}
330 366
367_static void
368gendata_h48k2_dfs(h48k2_dfs_arg_t *arg)
369{
370 uint8_t nmoves;
371 uint64_t val;
372 int64_t coord, fullcoord;
373 h48k2_dfs_arg_t nextarg;
374 uint8_t m;
375
376 fullcoord = coord_h48(arg->cube, arg->cocsepdata, 11);
377 coord = fullcoord >> (int64_t)(11 - arg->h);
378
379 val = h48map_value(arg->shortcubes, fullcoord);
380
381 if (arg->depth >= arg->base && arg->depth <= arg->base + 2)
382 set_esep_pval(
383 arg->h48data, coord, arg->k, arg->depth - arg->base);
384
385 if ((val < arg->shortdepth) ||
386 (arg->depth > arg->shortdepth && val != MAP_UNSET) ||
387 (arg->depth >= arg->maxdepth || arg->depth >= arg->base + 2))
388 return;
389
390 /* TODO: avoid copy, change arg and undo changes after recursion */
391 nextarg = *arg;
392 nextarg.depth = arg->depth + 1;
393 nmoves = nextarg.depth - arg->shortdepth;
394 for (m = 0; m < 18; m++) {
395 nextarg.moves[nmoves - 1] = m;
396 if (!allowednextmove(nextarg.moves, nmoves)) {
397 m += 2;
398 continue;
399 }
400 nextarg.cube = move(arg->cube, m);
401 gendata_h48k2_dfs(&nextarg);
402 }
403}
404
331_static_inline uint8_t 405_static_inline uint8_t
332get_esep_pval(const uint32_t *buf32, int64_t i, uint8_t k) 406get_esep_pval(const uint32_t *buf32, int64_t i, uint8_t k)
333{ 407{

Generated with cgit - Back to sebastiano.tronto.net