aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-08-27 21:44:19 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-08-27 21:44:19 +0200
commit1983bacfbb84e2a410ebe663ac1fa7c1b22eb096 (patch)
tree106ddc90aa7aa92558415f89a8b39076ab508364 /src
parent30526a688c8c8e9ffed34a07e959322f75bc639b (diff)
parentb5efa2c7bfa259f1b9f5afa68349e2742427de80 (diff)
downloadnissy-core-1983bacfbb84e2a410ebe663ac1fa7c1b22eb096.tar.gz
nissy-core-1983bacfbb84e2a410ebe663ac1fa7c1b22eb096.zip
Merge branch 'master' of tronto.net:h48
Diffstat (limited to 'src')
-rw-r--r--src/nissy.c12
-rw-r--r--src/solvers/h48/gendata_cocsep.h14
-rw-r--r--src/solvers/h48/gendata_h48.h134
-rw-r--r--src/solvers/h48/h48.h2
4 files changed, 122 insertions, 40 deletions
diff --git a/src/nissy.c b/src/nissy.c
index 5641dd9..f8c1f4d 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -26,23 +26,31 @@ struct {
26_static int 26_static int
27parse_h48_options(const char *buf, uint8_t *h, uint8_t *k, uint8_t *maxdepth) 27parse_h48_options(const char *buf, uint8_t *h, uint8_t *k, uint8_t *maxdepth)
28{ 28{
29 bool h_valid, k_valid, maxdepth_valid;
29 int i; 30 int i;
30 31
31 /* TODO temporarily, options are in the form "h;k;maxdepth" */ 32 /* TODO temporarily, options are in the form "h;k;maxdepth" */
32 if (h != NULL) 33 if (h != NULL)
33 *h = atoi(buf); 34 *h = atoi(buf);
35 h_valid = h == NULL || *h <= 11;
36
34 for (i = 0; buf[i] != ';'; i++) 37 for (i = 0; buf[i] != ';'; i++)
35 if (buf[i] == 0) 38 if (buf[i] == 0)
36 goto parse_h48_options_error; 39 goto parse_h48_options_error;
40
37 if (k != NULL) 41 if (k != NULL)
38 *k = atoi(&buf[i+1]); 42 *k = atoi(&buf[i+1]);
43 k_valid = k == NULL || (*k == 2 || *k == 4);
44
39 for (i = i+1; buf[i] != ';'; i++) 45 for (i = i+1; buf[i] != ';'; i++)
40 if (buf[i] == 0) 46 if (buf[i] == 0)
41 goto parse_h48_options_error; 47 goto parse_h48_options_error;
48
42 if (maxdepth != NULL) 49 if (maxdepth != NULL)
43 *maxdepth = atoi(&buf[i+1]); 50 *maxdepth = atoi(&buf[i+1]);
51 maxdepth_valid = maxdepth == NULL || *maxdepth <= 20;
44 52
45 return (*h <= 11 && (*k == 2 || *k == 4) && *maxdepth <= 20) ? 0 : 1; 53 return h_valid && k_valid && maxdepth_valid ? 0 : 1;
46 54
47parse_h48_options_error: 55parse_h48_options_error:
48 *h = 0; 56 *h = 0;
@@ -202,7 +210,7 @@ nissy_gendata(
202 if (!strcmp(solver, "h48")) { 210 if (!strcmp(solver, "h48")) {
203 p = parse_h48_options(options, &arg.h, &arg.k, &arg.maxdepth); 211 p = parse_h48_options(options, &arg.h, &arg.k, &arg.maxdepth);
204 if (p != 0) { 212 if (p != 0) {
205 LOG("gendata: ould not parse options\n"); 213 LOG("gendata: could not parse options\n");
206 ret = -1; 214 ret = -1;
207 } else { 215 } else {
208 ret = gendata_h48(&arg); 216 ret = gendata_h48(&arg);
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{
diff --git a/src/solvers/h48/h48.h b/src/solvers/h48/h48.h
index d9e8af3..4edc5ac 100644
--- a/src/solvers/h48/h48.h
+++ b/src/solvers/h48/h48.h
@@ -1,5 +1,5 @@
1#include "coordinate.h" 1#include "coordinate.h"
2#include "map.h" 2#include "map.h"
3#include "gendata_cocsep.h" 3#include "gendata_cocsep.h"
4#include "gendata_full.h" 4#include "gendata_h48.h"
5#include "solve.h" 5#include "solve.h"

Generated with cgit - Back to sebastiano.tronto.net