diff options
Diffstat (limited to 'src/solvers')
| -rw-r--r-- | src/solvers/h48/solve.h | 83 |
1 files changed, 35 insertions, 48 deletions
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index 7430228..751df8f 100644 --- a/src/solvers/h48/solve.h +++ b/src/solvers/h48/solve.h | |||
| @@ -11,10 +11,9 @@ typedef struct { | |||
| 11 | uint32_t *cocsepdata; | 11 | uint32_t *cocsepdata; |
| 12 | uint32_t *h48data; | 12 | uint32_t *h48data; |
| 13 | char **nextsol; | 13 | char **nextsol; |
| 14 | bool niss; | 14 | uint8_t nissbranch; |
| 15 | int8_t npremoves; | 15 | int8_t npremoves; |
| 16 | uint8_t premoves[MAXLEN]; | 16 | uint8_t premoves[MAXLEN]; |
| 17 | int8_t totmoves; | ||
| 18 | } dfsarg_solveh48_t; | 17 | } dfsarg_solveh48_t; |
| 19 | 18 | ||
| 20 | typedef struct { | 19 | typedef struct { |
| @@ -65,37 +64,30 @@ _static_inline bool | |||
| 65 | solve_h48_stop(dfsarg_solveh48_t *arg) | 64 | solve_h48_stop(dfsarg_solveh48_t *arg) |
| 66 | { | 65 | { |
| 67 | uint32_t data, data_inv; | 66 | uint32_t data, data_inv; |
| 68 | int8_t bound, newbound; | 67 | int8_t bound; |
| 69 | bool niss = false; | ||
| 70 | 68 | ||
| 69 | arg->nissbranch = NONISS; | ||
| 71 | bound = get_h48_cdata(arg->cube, arg->cocsepdata, &data); | 70 | bound = get_h48_cdata(arg->cube, arg->cocsepdata, &data); |
| 72 | if (bound + arg->totmoves > arg->depth) | 71 | if (bound + arg->nmoves + arg->npremoves > arg->depth) |
| 73 | return true; | 72 | return true; |
| 74 | 73 | ||
| 75 | newbound = get_h48_cdata(arg->inverse, arg->cocsepdata, &data_inv); | 74 | bound = get_h48_cdata(arg->inverse, arg->cocsepdata, &data_inv); |
| 76 | if (newbound + arg->totmoves > arg->depth) | 75 | if (bound + arg->nmoves + arg->npremoves > arg->depth) |
| 77 | return true; | 76 | return true; |
| 78 | if (newbound < bound) { | ||
| 79 | bound = newbound; | ||
| 80 | niss = true; | ||
| 81 | } | ||
| 82 | 77 | ||
| 83 | newbound = get_h48_bound(arg->cube, data, arg->h, arg->k, arg->h48data); | 78 | bound = get_h48_bound(arg->cube, data, arg->h, arg->k, arg->h48data); |
| 84 | // LOG("Using pval %" PRId8 "\n", bound); | 79 | // LOG("Using pval %" PRId8 "\n", bound); |
| 85 | if (newbound + arg->totmoves > arg->depth) | 80 | if (bound + arg->nmoves + arg->npremoves > arg->depth) |
| 86 | return true; | 81 | return true; |
| 87 | if (newbound < bound) { | 82 | if (bound + arg->nmoves + arg->npremoves == arg->depth) |
| 88 | bound = newbound; | 83 | arg->nissbranch = INVERSEBRANCH; |
| 89 | niss = false; | 84 | |
| 90 | } | 85 | bound = get_h48_bound(arg->inverse, data_inv, arg->h, arg->k, arg->h48data); |
| 91 | newbound = get_h48_bound(arg->inverse, data_inv, arg->h, arg->k, arg->h48data); | 86 | if (bound + arg->nmoves + arg->npremoves > arg->depth) |
| 92 | if (newbound + arg->totmoves > arg->depth) | ||
| 93 | return true; | 87 | return true; |
| 94 | if (newbound < bound) { | 88 | if (bound + arg->nmoves + arg->npremoves == arg->depth) |
| 95 | bound = newbound; | 89 | arg->nissbranch = BRANCH; |
| 96 | niss = true; | 90 | |
| 97 | } | ||
| 98 | arg->niss = niss; | ||
| 99 | return false; | 91 | return false; |
| 100 | } | 92 | } |
| 101 | 93 | ||
| @@ -113,7 +105,7 @@ solve_h48_dfs(dfsarg_solveh48_t *arg) | |||
| 113 | return 0; | 105 | return 0; |
| 114 | 106 | ||
| 115 | if (issolved(arg->cube)) { | 107 | if (issolved(arg->cube)) { |
| 116 | if (arg->totmoves != arg->depth) | 108 | if (arg->nmoves + arg->npremoves != arg->depth) |
| 117 | return 0; | 109 | return 0; |
| 118 | solve_h48_appendsolution(arg); | 110 | solve_h48_appendsolution(arg); |
| 119 | return 1; | 111 | return 1; |
| @@ -122,34 +114,28 @@ solve_h48_dfs(dfsarg_solveh48_t *arg) | |||
| 122 | /* TODO: avoid copy, change arg and undo changes after recursion */ | 114 | /* TODO: avoid copy, change arg and undo changes after recursion */ |
| 123 | nextarg = *arg; | 115 | nextarg = *arg; |
| 124 | ret = 0; | 116 | ret = 0; |
| 125 | nextarg.totmoves = arg->totmoves + 1; | 117 | uint32_t allowed; |
| 126 | if(arg->niss) { | 118 | if(arg->nissbranch & 0x01) { |
| 127 | nextarg.npremoves = arg->npremoves + 1; | 119 | allowed = allowednextmoveH48(arg->premoves, arg->npremoves, arg->nissbranch); |
| 128 | for (m = 0; m < 18; m++) { | 120 | for (m = 0; m < 18; m++) { |
| 129 | nextarg.premoves[arg->npremoves] = m; | 121 | if(allowed & (1 << m)) { |
| 130 | if (!allowednextmove(nextarg.premoves, nextarg.npremoves)) { | 122 | nextarg.npremoves = arg->npremoves + 1; |
| 131 | /* If a move is not allowed, neither are its 180 | 123 | nextarg.premoves[arg->npremoves] = m; |
| 132 | * and 270 degree variations */ | 124 | nextarg.inverse = move(arg->inverse, m); |
| 133 | m += 2; | 125 | nextarg.cube = premove(arg->cube, m); |
| 134 | continue; | 126 | ret += solve_h48_dfs(&nextarg); |
| 135 | } | 127 | } |
| 136 | nextarg.cube = premove(arg->cube, m); | ||
| 137 | nextarg.inverse = move(arg->inverse, m); | ||
| 138 | ret += solve_h48_dfs(&nextarg); | ||
| 139 | } | 128 | } |
| 140 | } else { | 129 | } else { |
| 141 | nextarg.nmoves = arg->nmoves + 1; | 130 | allowed = allowednextmoveH48(arg->moves, arg->nmoves, arg->nissbranch); |
| 142 | for (m = 0; m < 18; m++) { | 131 | for (m = 0; m < 18; m++) { |
| 143 | nextarg.moves[arg->nmoves] = m; | 132 | if (allowed & (1 << m)) { |
| 144 | if (!allowednextmove(nextarg.moves, nextarg.nmoves)) { | 133 | nextarg.nmoves = arg->nmoves + 1; |
| 145 | /* If a move is not allowed, neither are its 180 | 134 | nextarg.moves[arg->nmoves] = m; |
| 146 | * and 270 degree variations */ | 135 | nextarg.cube = move(arg->cube, m); |
| 147 | m += 2; | 136 | nextarg.inverse = premove(arg->inverse, m); |
| 148 | continue; | 137 | ret += solve_h48_dfs(&nextarg); |
| 149 | } | 138 | } |
| 150 | nextarg.cube = move(arg->cube, m); | ||
| 151 | nextarg.inverse = premove(arg->inverse, m); | ||
| 152 | ret += solve_h48_dfs(&nextarg); | ||
| 153 | } | 139 | } |
| 154 | } | 140 | } |
| 155 | 141 | ||
| @@ -192,6 +178,7 @@ solve_h48( | |||
| 192 | LOG("Found %" PRId64 " solutions, searching at depth %" | 178 | LOG("Found %" PRId64 " solutions, searching at depth %" |
| 193 | PRId8 "\n", nsols, arg.depth); | 179 | PRId8 "\n", nsols, arg.depth); |
| 194 | arg.nmoves = 0; | 180 | arg.nmoves = 0; |
| 181 | arg.npremoves = 0; | ||
| 195 | solve_h48_dfs(&arg); | 182 | solve_h48_dfs(&arg); |
| 196 | } | 183 | } |
| 197 | 184 | ||
