diff options
Diffstat (limited to 'src/solvers/h48/solve.h')
| -rw-r--r-- | src/solvers/h48/solve.h | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index 2a5e341..8f55501 100644 --- a/src/solvers/h48/solve.h +++ b/src/solvers/h48/solve.h | |||
| @@ -11,6 +11,7 @@ typedef struct { | |||
| 11 | uint8_t base; | 11 | uint8_t base; |
| 12 | const uint32_t *cocsepdata; | 12 | const uint32_t *cocsepdata; |
| 13 | const uint8_t *h48data; | 13 | const uint8_t *h48data; |
| 14 | const uint8_t *h48data_fallback; | ||
| 14 | uint64_t solutions_size; | 15 | uint64_t solutions_size; |
| 15 | char **nextsol; | 16 | char **nextsol; |
| 16 | uint8_t nissbranch; | 17 | uint8_t nissbranch; |
| @@ -112,16 +113,31 @@ solve_h48_stop(dfsarg_solveh48_t *arg) | |||
| 112 | 113 | ||
| 113 | h48bound = get_h48_bound(arg->cube, data, arg->h, arg->k, arg->h48data); | 114 | h48bound = get_h48_bound(arg->cube, data, arg->h, arg->k, arg->h48data); |
| 114 | 115 | ||
| 115 | /* If the h48 bound is > 0, we add the base value. */ | 116 | /* If the h48 bound is > 0, we add the base value. */ |
| 116 | /* Otherwise, we use the cbound value instead (fallback). */ | 117 | /* Otherwise, we use the fallback h0k4 value instead. */ |
| 117 | h48bound += h48bound == 0 ? cbound : arg->base; | 118 | |
| 119 | if (arg->k == 2) { | ||
| 120 | if (h48bound == 0) { | ||
| 121 | h48bound = get_h48_bound( | ||
| 122 | arg->cube, data, 0, 4, arg->h48data_fallback); | ||
| 123 | } else { | ||
| 124 | h48bound += arg->base; | ||
| 125 | } | ||
| 126 | } | ||
| 118 | if (h48bound + arg->nmoves + arg->npremoves > arg->depth) | 127 | if (h48bound + arg->nmoves + arg->npremoves > arg->depth) |
| 119 | return true; | 128 | return true; |
| 120 | if (h48bound + arg->nmoves + arg->npremoves == arg->depth) | 129 | if (h48bound + arg->nmoves + arg->npremoves == arg->depth) |
| 121 | arg->nissbranch = MM_INVERSEBRANCH; | 130 | arg->nissbranch = MM_INVERSEBRANCH; |
| 122 | 131 | ||
| 123 | h48bound_inv = get_h48_bound(arg->inverse, data_inv, arg->h, arg->k, arg->h48data); | 132 | h48bound_inv = get_h48_bound(arg->inverse, data_inv, arg->h, arg->k, arg->h48data); |
| 124 | h48bound_inv += h48bound_inv == 0 ? cbound_inv : arg->base; | 133 | if (arg->k == 2) { |
| 134 | if (h48bound_inv == 0) { | ||
| 135 | h48bound_inv = get_h48_bound( | ||
| 136 | arg->inverse, data_inv, 0, 4, arg->h48data_fallback); | ||
| 137 | } else { | ||
| 138 | h48bound_inv += arg->base; | ||
| 139 | } | ||
| 140 | } | ||
| 125 | if (h48bound_inv + arg->nmoves + arg->npremoves > arg->depth) | 141 | if (h48bound_inv + arg->nmoves + arg->npremoves > arg->depth) |
| 126 | return true; | 142 | return true; |
| 127 | if (h48bound_inv + arg->nmoves + arg->npremoves == arg->depth) | 143 | if (h48bound_inv + arg->nmoves + arg->npremoves == arg->depth) |
| @@ -194,12 +210,10 @@ solve_h48( | |||
| 194 | { | 210 | { |
| 195 | _Atomic int64_t nsols; | 211 | _Atomic int64_t nsols; |
| 196 | dfsarg_solveh48_t arg; | 212 | dfsarg_solveh48_t arg; |
| 197 | tableinfo_t info; | 213 | tableinfo_t info, fbinfo; |
| 198 | 214 | ||
| 199 | if(readtableinfo_n(data_size, data, 2, &info) != NISSY_OK) { | 215 | if(readtableinfo_n(data_size, data, 2, &info) != NISSY_OK) |
| 200 | LOG("solve_h48: error reading table\n"); | 216 | goto solve_h48_error_data; |
| 201 | return NISSY_ERROR_DATA; | ||
| 202 | } | ||
| 203 | 217 | ||
| 204 | arg = (dfsarg_solveh48_t) { | 218 | arg = (dfsarg_solveh48_t) { |
| 205 | .cube = cube, | 219 | .cube = cube, |
| @@ -209,12 +223,23 @@ solve_h48( | |||
| 209 | .h = info.h48h, | 223 | .h = info.h48h, |
| 210 | .k = info.bits, | 224 | .k = info.bits, |
| 211 | .base = info.base, | 225 | .base = info.base, |
| 212 | .cocsepdata = get_cocsepdata_constptr(data), | 226 | .cocsepdata = (uint32_t *)((char *)data + INFOSIZE), |
| 213 | .h48data = get_h48data_constptr(data), | 227 | .h48data = (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE, |
| 214 | .solutions_size = solutions_size, | 228 | .solutions_size = solutions_size, |
| 215 | .nextsol = &solutions | 229 | .nextsol = &solutions |
| 216 | }; | 230 | }; |
| 217 | 231 | ||
| 232 | if (info.bits == 2) { | ||
| 233 | if (readtableinfo_n(data_size, data, 3, &fbinfo) != NISSY_OK) | ||
| 234 | goto solve_h48_error_data; | ||
| 235 | /* We only support h0k4 as fallback table */ | ||
| 236 | if (fbinfo.h48h != 0 || fbinfo.bits != 4) | ||
| 237 | goto solve_h48_error_data; | ||
| 238 | arg.h48data_fallback = arg.h48data + info.next; | ||
| 239 | } else { | ||
| 240 | arg.h48data_fallback = NULL; | ||
| 241 | } | ||
| 242 | |||
| 218 | nsols = 0; | 243 | nsols = 0; |
| 219 | for (arg.depth = minmoves; | 244 | for (arg.depth = minmoves; |
| 220 | arg.depth <= maxmoves && nsols < maxsolutions; | 245 | arg.depth <= maxmoves && nsols < maxsolutions; |
| @@ -229,4 +254,8 @@ solve_h48( | |||
| 229 | **arg.nextsol = '\0'; | 254 | **arg.nextsol = '\0'; |
| 230 | (*arg.nextsol)++; | 255 | (*arg.nextsol)++; |
| 231 | return nsols; | 256 | return nsols; |
| 257 | |||
| 258 | solve_h48_error_data: | ||
| 259 | LOG("solve_h48: error reading table\n"); | ||
| 260 | return NISSY_ERROR_DATA; | ||
| 232 | } | 261 | } |
