diff options
| author | enricotenuti <tenutz_27@outlook.it> | 2024-08-26 17:56:17 +0200 |
|---|---|---|
| committer | enricotenuti <tenutz_27@outlook.it> | 2024-08-26 17:56:17 +0200 |
| commit | 81daed66c3415827de7ab6a15c081a8f696f7a95 (patch) | |
| tree | 9f6a2b7600cbaa6306eb73ef3be6e52fb9084881 /src/solvers/h48 | |
| parent | f2907e471b3caddc5844bc6994e1cbd249019747 (diff) | |
| download | nissy-core-81daed66c3415827de7ab6a15c081a8f696f7a95.tar.gz nissy-core-81daed66c3415827de7ab6a15c081a8f696f7a95.zip | |
premoves and niss
Diffstat (limited to 'src/solvers/h48')
| -rw-r--r-- | src/solvers/h48/solve.h | 98 |
1 files changed, 71 insertions, 27 deletions
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index 0843792..7430228 100644 --- a/src/solvers/h48/solve.h +++ b/src/solvers/h48/solve.h | |||
| @@ -11,6 +11,10 @@ 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; | ||
| 15 | int8_t npremoves; | ||
| 16 | uint8_t premoves[MAXLEN]; | ||
| 17 | int8_t totmoves; | ||
| 14 | } dfsarg_solveh48_t; | 18 | } dfsarg_solveh48_t; |
| 15 | 19 | ||
| 16 | typedef struct { | 20 | typedef struct { |
| @@ -35,41 +39,63 @@ _static int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]); | |||
| 35 | _static void | 39 | _static void |
| 36 | solve_h48_appendsolution(dfsarg_solveh48_t *arg) | 40 | solve_h48_appendsolution(dfsarg_solveh48_t *arg) |
| 37 | { | 41 | { |
| 38 | int strl; | 42 | int strl; |
| 43 | char *solution = *arg->nextsol; | ||
| 39 | 44 | ||
| 40 | strl = writemoves(arg->moves, arg->nmoves, *arg->nextsol); | 45 | strl = writemoves(arg->moves, arg->nmoves, *arg->nextsol); |
| 41 | LOG("Solution found: %s\n", *arg->nextsol); | 46 | *arg->nextsol += strl; |
| 42 | *arg->nextsol += strl; | 47 | |
| 43 | **arg->nextsol = '\n'; | 48 | if (arg->npremoves) { |
| 44 | (*arg->nextsol)++; | 49 | **arg->nextsol = ' '; |
| 45 | (*arg->nsols)++; | 50 | (*arg->nextsol)++; |
| 51 | |||
| 52 | uint8_t* invertedpremoves = invertpremoves(arg->premoves, arg->npremoves); | ||
| 53 | strl = writemoves(invertedpremoves, arg->npremoves, *arg->nextsol); | ||
| 54 | free(invertedpremoves); | ||
| 55 | *arg->nextsol += strl; | ||
| 56 | } | ||
| 57 | LOG("Solution found: %s\n", solution); | ||
| 58 | |||
| 59 | **arg->nextsol = '\n'; | ||
| 60 | (*arg->nextsol)++; | ||
| 61 | (*arg->nsols)++; | ||
| 46 | } | 62 | } |
| 47 | 63 | ||
| 48 | _static_inline bool | 64 | _static_inline bool |
| 49 | solve_h48_stop(dfsarg_solveh48_t *arg) | 65 | solve_h48_stop(dfsarg_solveh48_t *arg) |
| 50 | { | 66 | { |
| 51 | uint32_t data, data_inv; | 67 | uint32_t data, data_inv; |
| 52 | int8_t bound; | 68 | int8_t bound, newbound; |
| 69 | bool niss = false; | ||
| 53 | 70 | ||
| 54 | bound = get_h48_cdata(arg->cube, arg->cocsepdata, &data); | 71 | bound = get_h48_cdata(arg->cube, arg->cocsepdata, &data); |
| 55 | if (bound + arg->nmoves > arg->depth) | 72 | if (bound + arg->totmoves > arg->depth) |
| 56 | return true; | 73 | return true; |
| 57 | 74 | ||
| 58 | bound = get_h48_cdata(arg->inverse, arg->cocsepdata, &data_inv); | 75 | newbound = get_h48_cdata(arg->inverse, arg->cocsepdata, &data_inv); |
| 59 | if (bound + arg->nmoves > arg->depth) | 76 | if (newbound + arg->totmoves > arg->depth) |
| 60 | return true; | 77 | return true; |
| 78 | if (newbound < bound) { | ||
| 79 | bound = newbound; | ||
| 80 | niss = true; | ||
| 81 | } | ||
| 61 | 82 | ||
| 62 | /* | 83 | newbound = get_h48_bound(arg->cube, data, arg->h, arg->k, arg->h48data); |
| 63 | bound = get_h48_bound(arg->cube, data, arg->h, arg->k, arg->h48data); | 84 | // LOG("Using pval %" PRId8 "\n", bound); |
| 64 | LOG("Using pval %" PRId8 "\n", bound); | 85 | if (newbound + arg->totmoves > arg->depth) |
| 65 | if (bound + arg->nmoves > arg->depth) | ||
| 66 | return true; | 86 | return true; |
| 67 | 87 | if (newbound < bound) { | |
| 68 | bound = get_h48_bound(arg->inverse, data_inv, arg->h, arg->k, arg->h48data); | 88 | bound = newbound; |
| 69 | if (bound + arg->nmoves > arg->depth) | 89 | niss = false; |
| 90 | } | ||
| 91 | newbound = get_h48_bound(arg->inverse, data_inv, arg->h, arg->k, arg->h48data); | ||
| 92 | if (newbound + arg->totmoves > arg->depth) | ||
| 70 | return true; | 93 | return true; |
| 71 | */ | 94 | if (newbound < bound) { |
| 72 | 95 | bound = newbound; | |
| 96 | niss = true; | ||
| 97 | } | ||
| 98 | arg->niss = niss; | ||
| 73 | return false; | 99 | return false; |
| 74 | } | 100 | } |
| 75 | 101 | ||
| @@ -87,7 +113,7 @@ solve_h48_dfs(dfsarg_solveh48_t *arg) | |||
| 87 | return 0; | 113 | return 0; |
| 88 | 114 | ||
| 89 | if (issolved(arg->cube)) { | 115 | if (issolved(arg->cube)) { |
| 90 | if (arg->nmoves != arg->depth) | 116 | if (arg->totmoves != arg->depth) |
| 91 | return 0; | 117 | return 0; |
| 92 | solve_h48_appendsolution(arg); | 118 | solve_h48_appendsolution(arg); |
| 93 | return 1; | 119 | return 1; |
| @@ -95,21 +121,39 @@ solve_h48_dfs(dfsarg_solveh48_t *arg) | |||
| 95 | 121 | ||
| 96 | /* TODO: avoid copy, change arg and undo changes after recursion */ | 122 | /* TODO: avoid copy, change arg and undo changes after recursion */ |
| 97 | nextarg = *arg; | 123 | nextarg = *arg; |
| 98 | nextarg.nmoves = arg->nmoves + 1; | ||
| 99 | ret = 0; | 124 | ret = 0; |
| 100 | for (m = 0; m < 18; m++) { | 125 | nextarg.totmoves = arg->totmoves + 1; |
| 101 | nextarg.moves[arg->nmoves] = m; | 126 | if(arg->niss) { |
| 102 | if (!allowednextmove(nextarg.moves, nextarg.nmoves)) { | 127 | nextarg.npremoves = arg->npremoves + 1; |
| 128 | for (m = 0; m < 18; m++) { | ||
| 129 | nextarg.premoves[arg->npremoves] = m; | ||
| 130 | if (!allowednextmove(nextarg.premoves, nextarg.npremoves)) { | ||
| 103 | /* If a move is not allowed, neither are its 180 | 131 | /* If a move is not allowed, neither are its 180 |
| 104 | * and 270 degree variations */ | 132 | * and 270 degree variations */ |
| 105 | m += 2; | 133 | m += 2; |
| 106 | continue; | 134 | continue; |
| 107 | } | 135 | } |
| 108 | nextarg.cube = move(arg->cube, m); | 136 | nextarg.cube = premove(arg->cube, m); |
| 109 | nextarg.inverse = inverse(nextarg.cube); /* TODO: use premove */ | 137 | nextarg.inverse = move(arg->inverse, m); |
| 110 | ret += solve_h48_dfs(&nextarg); | 138 | ret += solve_h48_dfs(&nextarg); |
| 139 | } | ||
| 140 | } else { | ||
| 141 | nextarg.nmoves = arg->nmoves + 1; | ||
| 142 | for (m = 0; m < 18; m++) { | ||
| 143 | nextarg.moves[arg->nmoves] = m; | ||
| 144 | if (!allowednextmove(nextarg.moves, nextarg.nmoves)) { | ||
| 145 | /* If a move is not allowed, neither are its 180 | ||
| 146 | * and 270 degree variations */ | ||
| 147 | m += 2; | ||
| 148 | continue; | ||
| 149 | } | ||
| 150 | nextarg.cube = move(arg->cube, m); | ||
| 151 | nextarg.inverse = premove(arg->inverse, m); | ||
| 152 | ret += solve_h48_dfs(&nextarg); | ||
| 153 | } | ||
| 111 | } | 154 | } |
| 112 | 155 | ||
| 156 | |||
| 113 | return ret; | 157 | return ret; |
| 114 | } | 158 | } |
| 115 | 159 | ||
