diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-12-07 16:38:40 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-12-07 16:38:40 +0100 |
| commit | 9ac266c76f39620d8343e46ca41cb09d1534384c (patch) | |
| tree | 823bd419d99fe0f00e6b5b713237a73b4ec7ffca /src/core | |
| parent | ea25a7ccad625c4e664dfd114147971b8a2677f3 (diff) | |
| download | nissy-core-9ac266c76f39620d8343e46ca41cb09d1534384c.tar.gz nissy-core-9ac266c76f39620d8343e46ca41cb09d1534384c.zip | |
Merge the "solver-experiments" branch that I have been working on for
a few weeks. This include mainly three things:
1. Various tweaks for a total performance gain of around 30%.
2. Take into account symmetries and avoid repeated work. This
required a re-work of the splitting into tasks before the solve.
3. Add a second fallback table (eoesep). This gives huge performance
gains for particular scrambles (e.g. superflip).
After merging this commit, remove and re-generate all pruning tables.
Squashed commit of the following:
commit 60f0705d2d69050e6a30581a2810f686d6f69b80
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Sat Dec 7 16:06:48 2024 +0100
Fix indentation
commit cc5d489a251812b6188c0ba264ac6cb2236f1afe
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Sat Dec 7 15:56:19 2024 +0100
Updated documentation
commit a3f605dd628546e52564f82b139feb473b0725f3
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Sat Dec 7 14:01:11 2024 +0100
use eoesep table as second fallback
commit c75e43c9116c64f97e92b0fe038be8a032925a72
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Fri Dec 6 16:13:23 2024 +0100
First commit for gendata_eoesep
commit fea7688ab8bdc5ae0c3480622e2510a3bcd39248
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Tue Dec 3 17:31:00 2024 +0100
Add scramble to tool
commit 66866cb71dea4ca8278ecb9e90ff4295771feb42
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Tue Dec 3 17:22:59 2024 +0100
Added tool to check multiple solutions
commit ef65611c772c3996bddca8d181da3538e0af1674
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Tue Dec 3 17:16:20 2024 +0100
Write all solutions for symmetric positions
commit e3ded26db7d7d4ae7c0e2488151ed14f581f7b8e
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Tue Nov 26 09:14:54 2024 +0100
Added symmetry filter (TODO: print excluded solutions)
commit 864c437a9751c58d58562650ca9eba4a9e6ad3eb
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Mon Nov 25 14:51:13 2024 +0100
Improved task split
commit b88926d36d7ab0c64c5fe3bb954fd15d41267fba
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Fri Nov 22 19:06:41 2024 +0100
Reworked tasks for multi-threading in view of symmetry filter
commit 26fa653f97df8cd601aecb80eaf89f0a00e9ba9f
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Thu Oct 31 15:37:43 2024 +0100
Added transform move
commit 19f655ef94d658eaa2fefb5cea3c167a3ec58db6
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Thu Oct 31 09:29:15 2024 +0100
Clarified doc
commit 3b0fe1e5ef8b628854e30f0f0067300e2763c954
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Thu Oct 31 08:36:58 2024 +0100
Handle solved cube correctly
commit 57705cbc4982e3abe97a36ed64871738d4f721c0
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Thu Oct 31 08:24:30 2024 +0100
Close file
commit fc7d462b58bcf3d3a3fbf26c1f3bd04c640a4898
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Tue Oct 29 15:05:48 2024 +0100
Removed stats tool
commit 359bf7cb49ef405ee76ed662207d47cb2abcc5a9
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Tue Oct 29 15:01:51 2024 +0100
Updated theory doc
commit 39c315af562bc4ce896f41004388a4c34d475d37
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Tue Oct 29 14:51:40 2024 +0100
Remove unused constants
commit 57a5d24538aa59a4df9221dad2f99e9f0286bd9d
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Tue Oct 29 10:20:38 2024 +0100
Add tool to solve scrambles from file
commit 07e2918c216636891b1fa6adecc9756086a901e9
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Mon Oct 28 17:00:00 2024 +0100
Add make table to tool
commit f5e5266c654eb027a5a35c57cc618555246f5e5e
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Mon Oct 28 09:35:49 2024 +0100
Remove old solver, other small things
commit a1ec78025b7959dbb845213f7f4e6851ecebc204
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Sun Oct 27 02:00:29 2024 +0200
Improvements
commit 8eea23dbe888d923e662e24ae969130e2c67b999
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Sat Oct 26 12:24:19 2024 +0200
Makefile fix
commit 3fc3927beacc78971cefeb42da8d71fe6c015fc1
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Fri Oct 25 18:25:09 2024 +0200
More performance gains
commit 7b4efa1f9af9722de1ab9ccfc27899825a0d12c4
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Fri Oct 25 15:53:20 2024 +0200
Alternative solver implementation, small performance gain
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/moves.h | 54 | ||||
| -rw-r--r-- | src/core/transform.h | 40 |
2 files changed, 73 insertions, 21 deletions
diff --git a/src/core/moves.h b/src/core/moves.h index e3a9bc1..7d4972e 100644 --- a/src/core/moves.h +++ b/src/core/moves.h | |||
| @@ -2,8 +2,8 @@ | |||
| 2 | #define PREMOVE(M, c) compose(MOVE_CUBE_ ## M, c) | 2 | #define PREMOVE(M, c) compose(MOVE_CUBE_ ## M, c) |
| 3 | 3 | ||
| 4 | STATIC_INLINE bool allowednextmove(uint8_t *, uint8_t); | 4 | STATIC_INLINE bool allowednextmove(uint8_t *, uint8_t); |
| 5 | STATIC_INLINE uint32_t allowednextmove_mask(uint8_t *, uint8_t); | ||
| 5 | 6 | ||
| 6 | STATIC_INLINE uint8_t inverse_trans(uint8_t); | ||
| 7 | STATIC_INLINE uint8_t movebase(uint8_t); | 7 | STATIC_INLINE uint8_t movebase(uint8_t); |
| 8 | STATIC_INLINE uint8_t moveaxis(uint8_t); | 8 | STATIC_INLINE uint8_t moveaxis(uint8_t); |
| 9 | STATIC_INLINE uint32_t disable_moves(uint32_t, uint8_t); | 9 | STATIC_INLINE uint32_t disable_moves(uint32_t, uint8_t); |
| @@ -38,26 +38,38 @@ STATIC cube_t applymoves(cube_t, const char *); | |||
| 38 | STATIC bool | 38 | STATIC bool |
| 39 | allowednextmove(uint8_t *moves, uint8_t n) | 39 | allowednextmove(uint8_t *moves, uint8_t n) |
| 40 | { | 40 | { |
| 41 | uint8_t base[3], axis[3]; | 41 | return n == 0 ? true : |
| 42 | allowednextmove_mask(moves, n-1) & (1 << moves[n-1]); | ||
| 43 | } | ||
| 44 | |||
| 45 | STATIC uint32_t | ||
| 46 | allowednextmove_mask(uint8_t *moves, uint8_t n) | ||
| 47 | { | ||
| 48 | uint32_t result; | ||
| 49 | uint8_t base1, base2, axis1, axis2; | ||
| 50 | |||
| 51 | result = MM_ALLMOVES; | ||
| 42 | 52 | ||
| 43 | if (n < 2) | 53 | if (n == 0) |
| 44 | return true; | 54 | return result; |
| 45 | 55 | ||
| 46 | base[0] = movebase(moves[n-1]); | 56 | base1 = movebase(moves[n-1]); |
| 47 | axis[0] = moveaxis(moves[n-1]); | 57 | axis1 = moveaxis(moves[n-1]); |
| 48 | base[1] = movebase(moves[n-2]); | 58 | result = disable_moves(result, base1 * 3); |
| 49 | axis[1] = moveaxis(moves[n-2]); | ||
| 50 | 59 | ||
| 51 | if (base[0] == base[1] || (axis[0] == axis[1] && base[0] < base[1])) | 60 | if (base1 % 2) |
| 52 | return false; | 61 | result = disable_moves(result, (base1 - 1) * 3); |
| 53 | 62 | ||
| 54 | if (n == 2) | 63 | if (n == 1) |
| 55 | return true; | 64 | return result; |
| 56 | 65 | ||
| 57 | base[2] = movebase(moves[n-3]); | 66 | base2 = movebase(moves[n-2]); |
| 58 | axis[2] = moveaxis(moves[n-3]); | 67 | axis2 = moveaxis(moves[n-2]); |
| 59 | 68 | ||
| 60 | return axis[1] != axis[2] || base[0] != base[2]; | 69 | if(axis1 == axis2) |
| 70 | result = disable_moves(result, base2 * 3); | ||
| 71 | |||
| 72 | return result; | ||
| 61 | } | 73 | } |
| 62 | 74 | ||
| 63 | STATIC_INLINE uint32_t | 75 | STATIC_INLINE uint32_t |
| @@ -67,12 +79,6 @@ disable_moves(uint32_t current_result, uint8_t base_index) | |||
| 67 | } | 79 | } |
| 68 | 80 | ||
| 69 | STATIC_INLINE uint8_t | 81 | STATIC_INLINE uint8_t |
| 70 | inverse_trans(uint8_t t) | ||
| 71 | { | ||
| 72 | return inverse_trans_table[t]; | ||
| 73 | } | ||
| 74 | |||
| 75 | STATIC_INLINE uint8_t | ||
| 76 | movebase(uint8_t move) | 82 | movebase(uint8_t move) |
| 77 | { | 83 | { |
| 78 | return move / 3; | 84 | return move / 3; |
| @@ -84,6 +90,12 @@ moveaxis(uint8_t move) | |||
| 84 | return move / 6; | 90 | return move / 6; |
| 85 | } | 91 | } |
| 86 | 92 | ||
| 93 | STATIC_INLINE uint8_t | ||
| 94 | moveopposite(uint8_t move) | ||
| 95 | { | ||
| 96 | return movebase(move) == 2 * moveaxis(move) ? move + 3 : move - 3; | ||
| 97 | } | ||
| 98 | |||
| 87 | STATIC cube_t | 99 | STATIC cube_t |
| 88 | move(cube_t c, uint8_t m) | 100 | move(cube_t c, uint8_t m) |
| 89 | { | 101 | { |
diff --git a/src/core/transform.h b/src/core/transform.h index 73636fe..f956718 100644 --- a/src/core/transform.h +++ b/src/core/transform.h | |||
| @@ -21,6 +21,9 @@ STATIC cube_t transform_edges(cube_t, uint8_t); | |||
| 21 | STATIC cube_t transform_corners(cube_t, uint8_t); | 21 | STATIC cube_t transform_corners(cube_t, uint8_t); |
| 22 | STATIC cube_t transform(cube_t, uint8_t); | 22 | STATIC cube_t transform(cube_t, uint8_t); |
| 23 | STATIC cube_t applytrans(cube_t, const char *); | 23 | STATIC cube_t applytrans(cube_t, const char *); |
| 24 | STATIC_INLINE uint8_t inverse_trans(uint8_t); | ||
| 25 | STATIC uint8_t transform_move(uint8_t, uint8_t); | ||
| 26 | STATIC uint64_t symmetry_mask(cube_t); | ||
| 24 | 27 | ||
| 25 | STATIC cube_t | 28 | STATIC cube_t |
| 26 | transform_edges(cube_t c, uint8_t t) | 29 | transform_edges(cube_t c, uint8_t t) |
| @@ -354,3 +357,40 @@ applytrans(cube_t cube, const char *buf) | |||
| 354 | 357 | ||
| 355 | return transform(cube, t); | 358 | return transform(cube, t); |
| 356 | } | 359 | } |
| 360 | |||
| 361 | STATIC_INLINE uint8_t | ||
| 362 | inverse_trans(uint8_t t) | ||
| 363 | { | ||
| 364 | return inverse_trans_table[t]; | ||
| 365 | } | ||
| 366 | |||
| 367 | STATIC uint8_t | ||
| 368 | transform_move(uint8_t m, uint8_t t) | ||
| 369 | { | ||
| 370 | uint8_t a, base, modifier; | ||
| 371 | |||
| 372 | a = moveaxis(m); | ||
| 373 | base = trans_move_table[t][a]; | ||
| 374 | if (movebase(m) != 2 * a) | ||
| 375 | base = moveopposite(base); | ||
| 376 | |||
| 377 | modifier = m % 3; | ||
| 378 | if (t >= TRANS_UFm) | ||
| 379 | modifier = 2 - modifier; | ||
| 380 | |||
| 381 | return base + modifier; | ||
| 382 | } | ||
| 383 | |||
| 384 | STATIC uint64_t | ||
| 385 | symmetry_mask(cube_t cube) | ||
| 386 | { | ||
| 387 | uint64_t t, ret; | ||
| 388 | cube_t transformed; | ||
| 389 | |||
| 390 | for (t = 0, ret = 0; t < 48; t++) { | ||
| 391 | transformed = transform(cube, t); | ||
| 392 | ret |= ((uint64_t)equal(cube, transformed)) << t; | ||
| 393 | } | ||
| 394 | |||
| 395 | return ret; | ||
| 396 | } | ||
