diff options
| -rw-r--r-- | shell.c | 6 | ||||
| -rw-r--r-- | src/nissy.c | 12 | ||||
| -rw-r--r-- | src/solvers/h48/gendata_cocsep.h | 14 | ||||
| -rw-r--r-- | src/solvers/h48/gendata_h48.h | 134 | ||||
| -rw-r--r-- | src/solvers/h48/h48.h | 2 | ||||
| -rw-r--r-- | test/112_gen_h48short/00_depth_1.in (renamed from test/113_gen_h48short/00_depth_1.in) | 0 | ||||
| -rw-r--r-- | test/112_gen_h48short/00_depth_1.out (renamed from test/113_gen_h48short/00_depth_1.out) | 0 | ||||
| -rw-r--r-- | test/112_gen_h48short/01_depth_3.in (renamed from test/113_gen_h48short/01_depth_3.in) | 0 | ||||
| -rw-r--r-- | test/112_gen_h48short/01_depth_3.out (renamed from test/113_gen_h48short/01_depth_3.out) | 0 | ||||
| -rw-r--r-- | test/112_gen_h48short/gen_h48short.c (renamed from test/113_gen_h48short/gen_h48short.c) | 0 | ||||
| -rw-r--r-- | test/120_gendata_h48h0k4/00_h_0.in (renamed from test/112_gendata_h48/00_h_0.in) | 0 | ||||
| -rw-r--r-- | test/120_gendata_h48h0k4/00_h_0.out (renamed from test/112_gendata_h48/00_h_0.out) | 0 | ||||
| -rw-r--r-- | test/120_gendata_h48h0k4/gendata_h48h0k4_tests.c (renamed from test/112_gendata_h48/gendata_h48_tests.c) | 0 | ||||
| -rw-r--r-- | tools/001_gendata_h48h0k4/gendata_h48h0k4.c (renamed from tools/001_gendata_h48/gendata_h48.c) | 0 | ||||
| -rw-r--r-- | tools/003_solve_small/solve_small.c | 94 |
15 files changed, 219 insertions, 43 deletions
| @@ -183,21 +183,21 @@ struct { | |||
| 183 | ), | 183 | ), |
| 184 | COMMAND( | 184 | COMMAND( |
| 185 | "datasize", | 185 | "datasize", |
| 186 | "datasize" _flag_solver " SOLVER " _flag_options " OPTIONS", | 186 | "datasize " _flag_solver " SOLVER " _flag_options " OPTIONS", |
| 187 | "Return the size in bytes of the data table used by " | 187 | "Return the size in bytes of the data table used by " |
| 188 | "SOLVER when called with the given OPTIONS.", | 188 | "SOLVER when called with the given OPTIONS.", |
| 189 | datasize_exec | 189 | datasize_exec |
| 190 | ), | 190 | ), |
| 191 | COMMAND( | 191 | COMMAND( |
| 192 | "gendata", | 192 | "gendata", |
| 193 | "gendata" _flag_solver " SOLVER " _flag_options " OPTIONS", | 193 | "gendata " _flag_solver " SOLVER " _flag_options " OPTIONS", |
| 194 | "Generate the data table used by " | 194 | "Generate the data table used by " |
| 195 | "SOLVER when called with the given OPTIONS.", | 195 | "SOLVER when called with the given OPTIONS.", |
| 196 | gendata_exec | 196 | gendata_exec |
| 197 | ), | 197 | ), |
| 198 | COMMAND( | 198 | COMMAND( |
| 199 | "solve", | 199 | "solve", |
| 200 | "solve" _flag_solver " SOLVER " _flag_options " OPTIONS " | 200 | "solve " _flag_solver " SOLVER " _flag_options " OPTIONS " |
| 201 | "[" _flag_minmoves " n] [" _flag_maxmoves " N] " | 201 | "[" _flag_minmoves " n] [" _flag_maxmoves " N] " |
| 202 | _flag_cube " CUBE", | 202 | _flag_cube " CUBE", |
| 203 | "Solve the given CUBE using SOLVER with the given OPTIONS, " | 203 | "Solve the given CUBE using SOLVER with the given OPTIONS, " |
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 |
| 27 | parse_h48_options(const char *buf, uint8_t *h, uint8_t *k, uint8_t *maxdepth) | 27 | parse_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 | ||
| 47 | parse_h48_options_error: | 55 | parse_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 |
| 95 | gendata_cocsep_dfs(dfsarg_cocsep_t *arg) | 95 | gendata_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 | |||
| 60 | typedef 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 | |||
| 150 | gendata_h48h0k4(gendata_h48_arg_t *arg) | 167 | gendata_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 |
| 208 | gendata_h48h0k4_bfs(bfsarg_esep_t *arg) | 211 | gendata_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 |
| 219 | gendata_h48h0k4_bfs_fromdone(bfsarg_esep_t *arg) | 222 | gendata_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 |
| 249 | gendata_h48h0k4_bfs_fromnew(bfsarg_esep_t *arg) | 252 | gendata_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 | |||
| 327 | gendata_h48k2_return_size: | 363 | gendata_h48k2_return_size: |
| 328 | return H48_TABLESIZE(arg->h, 2); | 364 | return H48_TABLESIZE(arg->h, 2); |
| 329 | } | 365 | } |
| 330 | 366 | ||
| 367 | _static void | ||
| 368 | gendata_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 |
| 332 | get_esep_pval(const uint32_t *buf32, int64_t i, uint8_t k) | 406 | get_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" |
diff --git a/test/113_gen_h48short/00_depth_1.in b/test/112_gen_h48short/00_depth_1.in index c86f15b..c86f15b 100644 --- a/test/113_gen_h48short/00_depth_1.in +++ b/test/112_gen_h48short/00_depth_1.in | |||
diff --git a/test/113_gen_h48short/00_depth_1.out b/test/112_gen_h48short/00_depth_1.out index b0dba31..b0dba31 100644 --- a/test/113_gen_h48short/00_depth_1.out +++ b/test/112_gen_h48short/00_depth_1.out | |||
diff --git a/test/113_gen_h48short/01_depth_3.in b/test/112_gen_h48short/01_depth_3.in index 920e70a..920e70a 100644 --- a/test/113_gen_h48short/01_depth_3.in +++ b/test/112_gen_h48short/01_depth_3.in | |||
diff --git a/test/113_gen_h48short/01_depth_3.out b/test/112_gen_h48short/01_depth_3.out index dbce376..dbce376 100644 --- a/test/113_gen_h48short/01_depth_3.out +++ b/test/112_gen_h48short/01_depth_3.out | |||
diff --git a/test/113_gen_h48short/gen_h48short.c b/test/112_gen_h48short/gen_h48short.c index 335821a..335821a 100644 --- a/test/113_gen_h48short/gen_h48short.c +++ b/test/112_gen_h48short/gen_h48short.c | |||
diff --git a/test/112_gendata_h48/00_h_0.in b/test/120_gendata_h48h0k4/00_h_0.in index cb6e5ed..cb6e5ed 100644 --- a/test/112_gendata_h48/00_h_0.in +++ b/test/120_gendata_h48h0k4/00_h_0.in | |||
diff --git a/test/112_gendata_h48/00_h_0.out b/test/120_gendata_h48h0k4/00_h_0.out index 04e8bf6..04e8bf6 100644 --- a/test/112_gendata_h48/00_h_0.out +++ b/test/120_gendata_h48h0k4/00_h_0.out | |||
diff --git a/test/112_gendata_h48/gendata_h48_tests.c b/test/120_gendata_h48h0k4/gendata_h48h0k4_tests.c index d6c6cb2..d6c6cb2 100644 --- a/test/112_gendata_h48/gendata_h48_tests.c +++ b/test/120_gendata_h48h0k4/gendata_h48h0k4_tests.c | |||
diff --git a/tools/001_gendata_h48/gendata_h48.c b/tools/001_gendata_h48h0k4/gendata_h48h0k4.c index a73f818..a73f818 100644 --- a/tools/001_gendata_h48/gendata_h48.c +++ b/tools/001_gendata_h48h0k4/gendata_h48h0k4.c | |||
diff --git a/tools/003_solve_small/solve_small.c b/tools/003_solve_small/solve_small.c new file mode 100644 index 0000000..406e255 --- /dev/null +++ b/tools/003_solve_small/solve_small.c | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | #include <pthread.h> | ||
| 2 | #include <time.h> | ||
| 3 | #include "../timerun.h" | ||
| 4 | #include "../../src/nissy.h" | ||
| 5 | |||
| 6 | #define OPTIONS "0;4;20" | ||
| 7 | |||
| 8 | const char *filename = "tables/h48h0k4"; | ||
| 9 | char *buf; | ||
| 10 | char *scrambles[] = { | ||
| 11 | "R D' R2 D R U2 R' D' R U2 R D R'", /* 12 optimal */ | ||
| 12 | "RLUD RLUD RLUD", /* 12 optimal */ | ||
| 13 | NULL | ||
| 14 | }; | ||
| 15 | |||
| 16 | void run(void) { | ||
| 17 | int i; | ||
| 18 | int64_t n; | ||
| 19 | char sol[100], cube[22]; | ||
| 20 | |||
| 21 | printf("Solved the following scrambles:\n\n"); | ||
| 22 | for (i = 0; scrambles[i] != NULL; i++) { | ||
| 23 | printf("%s\n", scrambles[i]); | ||
| 24 | fprintf(stderr, "Solving scramble %s\n", scrambles[i]); | ||
| 25 | if (nissy_frommoves(scrambles[i], cube) == -1) { | ||
| 26 | fprintf(stderr, "Invalid scramble, " | ||
| 27 | "continuing with next scramble\n"); | ||
| 28 | continue; | ||
| 29 | } | ||
| 30 | n = nissy_solve( | ||
| 31 | cube, "h48", OPTIONS, "", 0, 20, 1, -1, buf, sol); | ||
| 32 | if (n == 0) | ||
| 33 | fprintf(stderr, "No solution found, " | ||
| 34 | "continuing with next scramble\n"); | ||
| 35 | } | ||
| 36 | printf("\n"); | ||
| 37 | } | ||
| 38 | |||
| 39 | int getdata(int64_t size) { | ||
| 40 | int64_t s; | ||
| 41 | FILE *f; | ||
| 42 | |||
| 43 | buf = malloc(size); | ||
| 44 | |||
| 45 | if ((f = fopen(filename, "rb")) == NULL) { | ||
| 46 | fprintf(stderr, "Table file not found, generating them." | ||
| 47 | " This can take a while.\n"); | ||
| 48 | s = nissy_gendata("h48", OPTIONS, buf); | ||
| 49 | if (s != size) { | ||
| 50 | fprintf(stderr, "Error generating table"); | ||
| 51 | if (s != -1) | ||
| 52 | fprintf(stderr, " (got %" PRId64 " bytes)", s); | ||
| 53 | fprintf(stderr, "\n"); | ||
| 54 | return 1; | ||
| 55 | } | ||
| 56 | if ((f = fopen(filename, "wb")) == NULL) { | ||
| 57 | fprintf(stderr, "Could not write tables to file %s" | ||
| 58 | ", will be regenerated next time.\n", filename); | ||
| 59 | } else { | ||
| 60 | fwrite(buf, size, 1, f); | ||
| 61 | fclose(f); | ||
| 62 | } | ||
| 63 | } else { | ||
| 64 | fprintf(stderr, "Reading tables from file %s\n", filename); | ||
| 65 | fread(buf, size, 1, f); | ||
| 66 | fclose(f); | ||
| 67 | } | ||
| 68 | |||
| 69 | return 0; | ||
| 70 | } | ||
| 71 | |||
| 72 | int main(void) { | ||
| 73 | int64_t size; | ||
| 74 | |||
| 75 | srand(time(NULL)); | ||
| 76 | |||
| 77 | nissy_setlogger(log_stderr); | ||
| 78 | size = nissy_datasize("h48", OPTIONS); | ||
| 79 | if (size == -1) { | ||
| 80 | printf("h48 stats: error in datasize\n"); | ||
| 81 | return 1; | ||
| 82 | } | ||
| 83 | |||
| 84 | if (getdata(size) != 0) { | ||
| 85 | printf("Error getting table, stopping\n"); | ||
| 86 | free(buf); | ||
| 87 | return 1; | ||
| 88 | } | ||
| 89 | |||
| 90 | timerun(run, "small solver benchmark"); | ||
| 91 | |||
| 92 | free(buf); | ||
| 93 | return 0; | ||
| 94 | } | ||
