diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-23 14:42:28 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-23 14:52:58 +0200 |
| commit | 039267a278bb9e0580e8aebd85ef5f3ed774688f (patch) | |
| tree | e569101b585a9aa0426d3a5afbfe3bbddfae0e60 /src/solvers | |
| parent | d969dc0ad57d3e1e346df719cf9f2708ee87d2e7 (diff) | |
| download | nissy-core-039267a278bb9e0580e8aebd85ef5f3ed774688f.tar.gz nissy-core-039267a278bb9e0580e8aebd85ef5f3ed774688f.zip | |
Adjusted solvers, fixed bug
Diffstat (limited to '')
| -rw-r--r-- | src/solvers/coord/solve.h | 17 | ||||
| -rw-r--r-- | src/solvers/h48/solve.h | 15 | ||||
| -rw-r--r-- | src/solvers/solutions.h | 18 | ||||
| -rw-r--r-- | src/solvers/solutions_types_macros.h | 1 |
4 files changed, 35 insertions, 16 deletions
diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h index fb996ac..48cc704 100644 --- a/src/solvers/coord/solve.h +++ b/src/solvers/coord/solve.h | |||
| @@ -12,12 +12,12 @@ typedef struct { | |||
| 12 | const unsigned char *ptable; | 12 | const unsigned char *ptable; |
| 13 | } dfsarg_solve_coord_t; | 13 | } dfsarg_solve_coord_t; |
| 14 | 14 | ||
| 15 | STATIC int64_t solve_coord(cube_t, coord_t [static 1], uint8_t, uint8_t, | 15 | STATIC int64_t solve_coord(oriented_cube_t, coord_t [static 1], uint8_t, |
| 16 | uint8_t, uint8_t, uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, | ||
| 17 | const unsigned char *, size_t n, char [n]); | ||
| 18 | STATIC int64_t solve_coord_dispatch(oriented_cube_t, const char *, uint8_t, | ||
| 16 | uint8_t, uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, | 19 | uint8_t, uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, |
| 17 | const unsigned char *, size_t n, char [n]); | 20 | const unsigned char *, size_t n, char [n]); |
| 18 | STATIC int64_t solve_coord_dispatch(cube_t, const char *, uint8_t, uint8_t, | ||
| 19 | uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, const unsigned char *, | ||
| 20 | size_t n, char [n]); | ||
| 21 | STATIC bool coord_solution_admissible(const dfsarg_solve_coord_t [static 1]); | 21 | STATIC bool coord_solution_admissible(const dfsarg_solve_coord_t [static 1]); |
| 22 | STATIC bool solve_coord_dfs_stop(const dfsarg_solve_coord_t [static 1]); | 22 | STATIC bool solve_coord_dfs_stop(const dfsarg_solve_coord_t [static 1]); |
| 23 | STATIC bool coord_continue_onnormal(const dfsarg_solve_coord_t [static 1]); | 23 | STATIC bool coord_continue_onnormal(const dfsarg_solve_coord_t [static 1]); |
| @@ -200,7 +200,7 @@ solve_coord_dfs(dfsarg_solve_coord_t arg[static 1]) | |||
| 200 | 200 | ||
| 201 | STATIC int64_t | 201 | STATIC int64_t |
| 202 | solve_coord_dispatch( | 202 | solve_coord_dispatch( |
| 203 | cube_t cube, | 203 | oriented_cube_t oc, |
| 204 | const char *coord_and_axis, | 204 | const char *coord_and_axis, |
| 205 | uint8_t nissflag, | 205 | uint8_t nissflag, |
| 206 | uint8_t minmoves, | 206 | uint8_t minmoves, |
| @@ -231,14 +231,14 @@ solve_coord_dispatch( | |||
| 231 | return NISSY_ERROR_INVALID_SOLVER; | 231 | return NISSY_ERROR_INVALID_SOLVER; |
| 232 | } | 232 | } |
| 233 | 233 | ||
| 234 | return solve_coord(cube, coord, axis, nissflag, minmoves, maxmoves, | 234 | return solve_coord(oc, coord, axis, nissflag, minmoves, maxmoves, |
| 235 | maxsolutions, optimal, threads, data_size, data, | 235 | maxsolutions, optimal, threads, data_size, data, |
| 236 | solutions_size, sols); | 236 | solutions_size, sols); |
| 237 | } | 237 | } |
| 238 | 238 | ||
| 239 | STATIC int64_t | 239 | STATIC int64_t |
| 240 | solve_coord( | 240 | solve_coord( |
| 241 | cube_t cube, | 241 | oriented_cube_t oc, |
| 242 | coord_t coord [static 1], | 242 | coord_t coord [static 1], |
| 243 | uint8_t axis, | 243 | uint8_t axis, |
| 244 | uint8_t nissflag, | 244 | uint8_t nissflag, |
| @@ -266,7 +266,7 @@ solve_coord( | |||
| 266 | solution_list_t solution_list; | 266 | solution_list_t solution_list; |
| 267 | 267 | ||
| 268 | t = coord->axistrans[axis]; | 268 | t = coord->axistrans[axis]; |
| 269 | c = transform(cube, t); | 269 | c = transform(oc.cube, t); |
| 270 | 270 | ||
| 271 | if (!coord->is_solvable(c)) | 271 | if (!coord->is_solvable(c)) |
| 272 | goto solve_coord_error_unsolvable; | 272 | goto solve_coord_error_unsolvable; |
| @@ -295,6 +295,7 @@ solve_coord( | |||
| 295 | .maxmoves = maxmoves, | 295 | .maxmoves = maxmoves, |
| 296 | .maxsolutions = maxsolutions, | 296 | .maxsolutions = maxsolutions, |
| 297 | .optimal = optimal, | 297 | .optimal = optimal, |
| 298 | .orientation = oc.orientation, | ||
| 298 | }; | 299 | }; |
| 299 | 300 | ||
| 300 | arg = (dfsarg_solve_coord_t) { | 301 | arg = (dfsarg_solve_coord_t) { |
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index d19309b..86c590a 100644 --- a/src/solvers/h48/solve.h +++ b/src/solvers/h48/solve.h | |||
| @@ -52,8 +52,8 @@ STATIC int64_t solve_h48_maketasks( | |||
| 52 | solve_h48_task_t [static STARTING_CUBES], int [static 1]); | 52 | solve_h48_task_t [static STARTING_CUBES], int [static 1]); |
| 53 | STATIC void *solve_h48_runthread(void *); | 53 | STATIC void *solve_h48_runthread(void *); |
| 54 | STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t [static 1]); | 54 | STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t [static 1]); |
| 55 | STATIC int64_t solve_h48(cube_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, | 55 | STATIC int64_t solve_h48(oriented_cube_t, uint8_t, uint8_t, uint8_t, uint8_t, |
| 56 | uint64_t, const unsigned char *, size_t n, char [n], | 56 | uint8_t, uint64_t, const unsigned char *, size_t n, char [n], |
| 57 | long long [static NISSY_SIZE_SOLVE_STATS]); | 57 | long long [static NISSY_SIZE_SOLVE_STATS]); |
| 58 | 58 | ||
| 59 | STATIC_INLINE bool | 59 | STATIC_INLINE bool |
| @@ -342,7 +342,7 @@ solve_h48_maketasks( | |||
| 342 | 342 | ||
| 343 | STATIC int64_t | 343 | STATIC int64_t |
| 344 | solve_h48( | 344 | solve_h48( |
| 345 | cube_t cube, | 345 | oriented_cube_t oc, |
| 346 | uint8_t minmoves, | 346 | uint8_t minmoves, |
| 347 | uint8_t maxmoves, | 347 | uint8_t maxmoves, |
| 348 | uint8_t maxsolutions, | 348 | uint8_t maxsolutions, |
| @@ -407,17 +407,18 @@ solve_h48( | |||
| 407 | fallback2 = h48data + offset; | 407 | fallback2 = h48data + offset; |
| 408 | 408 | ||
| 409 | settings = (solution_settings_t) { | 409 | settings = (solution_settings_t) { |
| 410 | .tmask = symmetry_mask(cube), | 410 | .tmask = symmetry_mask(oc.cube), |
| 411 | .unniss = true, | 411 | .unniss = true, |
| 412 | .maxmoves = maxmoves, | 412 | .maxmoves = maxmoves, |
| 413 | .maxsolutions = maxsolutions, | 413 | .maxsolutions = maxsolutions, |
| 414 | .optimal = optimal, | 414 | .optimal = optimal, |
| 415 | .orientation = oc.orientation, | ||
| 415 | }; | 416 | }; |
| 416 | 417 | ||
| 417 | for (i = 0; i < threads; i++) { | 418 | for (i = 0; i < threads; i++) { |
| 418 | arg[i] = (dfsarg_solve_h48_t) { | 419 | arg[i] = (dfsarg_solve_h48_t) { |
| 419 | .start_cube = cube, | 420 | .start_cube = oc.cube, |
| 420 | .cube = cube, | 421 | .cube = oc.cube, |
| 421 | .h = info.h48h, | 422 | .h = info.h48h, |
| 422 | .k = info.bits, | 423 | .k = info.bits, |
| 423 | .base = info.base, | 424 | .base = info.base, |
| @@ -441,7 +442,7 @@ solve_h48( | |||
| 441 | pthread_mutex_init(&solutions_mutex, NULL); | 442 | pthread_mutex_init(&solutions_mutex, NULL); |
| 442 | 443 | ||
| 443 | maketasks_arg = (dfsarg_solve_h48_maketasks_t) { | 444 | maketasks_arg = (dfsarg_solve_h48_maketasks_t) { |
| 444 | .cube = cube, | 445 | .cube = oc.cube, |
| 445 | .nmoves = 0, | 446 | .nmoves = 0, |
| 446 | .minmoves = minmoves, | 447 | .minmoves = minmoves, |
| 447 | .maxmoves = maxmoves, | 448 | .maxmoves = maxmoves, |
diff --git a/src/solvers/solutions.h b/src/solvers/solutions.h index 2340a80..75d0804 100644 --- a/src/solvers/solutions.h +++ b/src/solvers/solutions.h | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | STATIC void solution_moves_reset(solution_moves_t [static 1]); | 1 | STATIC void solution_moves_reset(solution_moves_t [static 1]); |
| 2 | STATIC void solution_moves_transform(solution_moves_t [static 1], uint8_t t); | 2 | STATIC void solution_moves_transform(solution_moves_t [static 1], uint8_t); |
| 3 | STATIC void solution_moves_reorient(solution_moves_t [static 1], uint8_t); | ||
| 3 | STATIC bool solution_list_init( | 4 | STATIC bool solution_list_init( |
| 4 | solution_list_t [static 1], size_t n, char [n]); | 5 | solution_list_t [static 1], size_t n, char [n]); |
| 5 | STATIC bool solution_moves_equal( | 6 | STATIC bool solution_moves_equal( |
| @@ -35,6 +36,20 @@ solution_moves_transform(solution_moves_t moves[static 1], uint8_t t) | |||
| 35 | moves->premoves[i] = transform_move(moves->premoves[i], t); | 36 | moves->premoves[i] = transform_move(moves->premoves[i], t); |
| 36 | } | 37 | } |
| 37 | 38 | ||
| 39 | STATIC void | ||
| 40 | solution_moves_reorient(solution_moves_t moves[static 1], uint8_t or) | ||
| 41 | { | ||
| 42 | uint8_t i; | ||
| 43 | |||
| 44 | for (i = 0; i < moves->nmoves; i++) | ||
| 45 | moves->moves[i] = | ||
| 46 | inverse_reorient_move(moves->moves[i], or); | ||
| 47 | |||
| 48 | for (i = 0; i < moves->npremoves; i++) | ||
| 49 | moves->premoves[i] = | ||
| 50 | inverse_reorient_move(moves->premoves[i], or); | ||
| 51 | } | ||
| 52 | |||
| 38 | STATIC bool | 53 | STATIC bool |
| 39 | solution_list_init(solution_list_t sols[static 1], size_t n, char buf[n]) | 54 | solution_list_init(solution_list_t sols[static 1], size_t n, char buf[n]) |
| 40 | { | 55 | { |
| @@ -187,6 +202,7 @@ appendsolution( | |||
| 187 | continue; | 202 | continue; |
| 188 | } | 203 | } |
| 189 | solution_moves_transform(&tsol[r], t); | 204 | solution_moves_transform(&tsol[r], t); |
| 205 | solution_moves_reorient(&tsol[r], settings->orientation); | ||
| 190 | sortparallel_moves(tsol[r].nmoves, tsol[r].moves); | 206 | sortparallel_moves(tsol[r].nmoves, tsol[r].moves); |
| 191 | sortparallel_moves(tsol[r].npremoves, tsol[r].premoves); | 207 | sortparallel_moves(tsol[r].npremoves, tsol[r].premoves); |
| 192 | 208 | ||
diff --git a/src/solvers/solutions_types_macros.h b/src/solvers/solutions_types_macros.h index 9b1431f..f1cb517 100644 --- a/src/solvers/solutions_types_macros.h +++ b/src/solvers/solutions_types_macros.h | |||
| @@ -13,6 +13,7 @@ typedef struct { | |||
| 13 | uint8_t maxmoves; | 13 | uint8_t maxmoves; |
| 14 | uint64_t maxsolutions; | 14 | uint64_t maxsolutions; |
| 15 | uint8_t optimal; | 15 | uint8_t optimal; |
| 16 | uint8_t orientation; | ||
| 16 | } solution_settings_t; | 17 | } solution_settings_t; |
| 17 | 18 | ||
| 18 | typedef struct { | 19 | typedef struct { |
