aboutsummaryrefslogtreecommitdiff
path: root/src/solvers/h48/gendata_eoesep.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-12-07 16:38:40 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2024-12-07 16:38:40 +0100
commit9ac266c76f39620d8343e46ca41cb09d1534384c (patch)
tree823bd419d99fe0f00e6b5b713237a73b4ec7ffca /src/solvers/h48/gendata_eoesep.h
parentea25a7ccad625c4e664dfd114147971b8a2677f3 (diff)
downloadnissy-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/solvers/h48/gendata_eoesep.h')
-rw-r--r--src/solvers/h48/gendata_eoesep.h274
1 files changed, 274 insertions, 0 deletions
diff --git a/src/solvers/h48/gendata_eoesep.h b/src/solvers/h48/gendata_eoesep.h
new file mode 100644
index 0000000..d3b73ea
--- /dev/null
+++ b/src/solvers/h48/gendata_eoesep.h
@@ -0,0 +1,274 @@
1STATIC int64_t coord_eoesep_sym(cube_t, const uint32_t [static ESEP_MAX]);
2STATIC size_t gendata_esep_classes(
3 uint32_t [static ESEP_MAX], uint16_t [static ESEP_CLASSES]);
4STATIC size_t gendata_eoesep(char [static EOESEP_FULLSIZE], uint8_t);
5STATIC uint32_t gendata_eoesep_bfs(uint8_t, uint8_t [static EOESEP_BUF],
6 uint32_t [static ESEP_MAX], uint16_t [static ESEP_CLASSES]);
7STATIC uint32_t gendata_eoesep_fromnew(uint8_t, uint8_t [static EOESEP_BUF],
8 uint32_t [static ESEP_MAX], uint16_t [static ESEP_CLASSES]);
9STATIC uint32_t gendata_eoesep_fromdone(uint8_t, uint8_t [static EOESEP_BUF],
10 uint32_t [static ESEP_MAX], uint16_t [static ESEP_CLASSES]);
11STATIC uint32_t gendata_eoesep_marksim(int64_t, uint8_t,
12 uint8_t [static EOESEP_BUF], uint32_t [static ESEP_MAX]);
13STATIC bool gendata_eoesep_next(cube_t, uint8_t,
14 uint8_t [static EOESEP_BUF], uint32_t [static ESEP_MAX]);
15STATIC uint8_t get_eoesep_pval(const uint8_t *, int64_t);
16STATIC uint8_t get_eoesep_pval_cube(const void *, cube_t);
17STATIC void set_eoesep_pval(uint8_t *, int64_t, uint8_t);
18
19STATIC int64_t
20coord_eoesep_sym(cube_t c, const uint32_t esep_classes[static ESEP_MAX])
21{
22 uint8_t ttrep;
23 uint32_t edata, class;
24 int64_t esep, eo;
25
26 esep = coord_esep(c);
27 edata = esep_classes[esep];
28 class = ECLASS(edata);
29 ttrep = TTREP(edata);
30 eo = coord_eo(transform(c, ttrep));
31
32 return (class << UINT32_C(11)) + eo;
33}
34
35STATIC size_t
36gendata_esep_classes(
37 uint32_t esep_classes[static ESEP_MAX],
38 uint16_t rep[static ESEP_CLASSES]
39)
40{
41 bool visited[ESEP_MAX];
42 uint8_t t;
43 uint32_t class, cl, ti;
44 int64_t i, j;
45 cube_t c;
46
47 memset(visited, 0, ESEP_MAX * sizeof(bool));
48 class = 0;
49 for (i = 0; i < ESEP_MAX; i++) {
50 if (visited[i])
51 continue;
52 c = invcoord_esep(i);
53 for (t = 0; t < 48; t++) {
54 j = coord_esep(transform(c, t));
55 cl = class << UINT32_C(16);
56 ti = inverse_trans(t) << UINT32_C(8);
57 esep_classes[j] = cl | ti;
58 visited[j] = true;
59 }
60 rep[class] = i;
61 class++;
62 }
63
64 return class;
65}
66
67STATIC size_t
68gendata_eoesep(char buf[static EOESEP_FULLSIZE], uint8_t maxdepth)
69{
70 uint8_t *buf8, d;
71 uint16_t rep[ESEP_CLASSES];
72 uint32_t *esep_classes, done, level;
73 int64_t coord;
74 tableinfo_t info;
75
76 if (buf == NULL)
77 goto gendata_eoesep_return_size;
78
79 LOG("Computing eoesep data\n");
80 memset(buf, 0xFF, EOESEP_FULLSIZE);
81 esep_classes = (uint32_t *)(buf + INFOSIZE);
82 buf8 = (uint8_t *)(buf + INFOSIZE + 4*ESEP_MAX);
83 gendata_esep_classes(esep_classes, rep);
84
85 info = (tableinfo_t) {
86 .solver = "eoesep data for h48",
87 .type = TABLETYPE_SPECIAL,
88 .infosize = INFOSIZE,
89 .fullsize = EOESEP_FULLSIZE,
90 .hash = 0,
91 .entries = EOESEP_TABLESIZE,
92 .classes = ESEP_CLASSES,
93 .bits = 4,
94 .base = 0,
95 .maxvalue = 11,
96 .next = 0
97 };
98
99 coord = 0; /* Assumed coordinate of solved cube */
100 set_eoesep_pval(buf8, coord, 0);
101 done = 1;
102 info.distribution[0] = 1;
103 for (d = 1; d <= maxdepth && done < EOESEP_TABLESIZE; d++) {
104 level = gendata_eoesep_bfs(d, buf8, esep_classes, rep);
105 done += level;
106 info.distribution[d] = level;
107 }
108
109 writetableinfo(&info, EOESEP_FULLSIZE, buf);
110
111 LOG("eoesep data computed\n");
112
113gendata_eoesep_return_size:
114 return EOESEP_FULLSIZE;
115}
116
117STATIC uint32_t
118gendata_eoesep_bfs(
119 uint8_t d,
120 uint8_t buf8[EOESEP_BUF],
121 uint32_t esep_classes[static ESEP_MAX],
122 uint16_t rep[static ESEP_CLASSES]
123)
124{
125 if (d < 9)
126 return gendata_eoesep_fromdone(d, buf8, esep_classes, rep);
127 else
128 return gendata_eoesep_fromnew(d, buf8, esep_classes, rep);
129}
130
131STATIC uint32_t
132gendata_eoesep_fromdone(
133 uint8_t d,
134 uint8_t buf8[EOESEP_BUF],
135 uint32_t esep_classes[static ESEP_MAX],
136 uint16_t rep[static ESEP_CLASSES]
137)
138{
139 uint8_t pval;
140 int64_t i, esep, eo, coord, done;
141
142 done = 0;
143 for (i = 0; i < (int64_t)ESEP_CLASSES; i++) {
144 esep = rep[i];
145 for (eo = 0; eo < POW_2_11; eo++) {
146 coord = (i << INT64_C(11)) + eo;
147 pval = get_eoesep_pval(buf8, coord);
148 if (pval != d-1)
149 continue;
150
151 coord = (esep << INT64_C(11)) + eo;
152 done += gendata_eoesep_marksim(
153 coord, d, buf8, esep_classes);
154 }
155 }
156
157 return done;
158}
159
160STATIC uint32_t
161gendata_eoesep_fromnew(
162 uint8_t d,
163 uint8_t buf8[EOESEP_BUF],
164 uint32_t esep_classes[static ESEP_MAX],
165 uint16_t rep[static ESEP_CLASSES]
166)
167{
168 uint8_t pval;
169 int64_t i, esep, eo, coord, done;
170 cube_t c;
171
172 done = 0;
173 for (i = 0; i < (int64_t)ESEP_CLASSES; i++) {
174 esep = rep[i];
175 for (eo = 0; eo < POW_2_11; eo++) {
176 coord = (i << INT64_C(11)) + eo;
177 pval = get_eoesep_pval(buf8, coord);
178 if (pval != 15)
179 continue;
180
181 c = invcoord_eoesep((esep << INT64_C(11)) + eo);
182 if (gendata_eoesep_next(c, d, buf8, esep_classes)) {
183 set_eoesep_pval(buf8, coord, d);
184 done++;
185 }
186 }
187 }
188
189 return done;
190}
191
192STATIC uint32_t
193gendata_eoesep_marksim(
194 int64_t i,
195 uint8_t d,
196 uint8_t buf8[static EOESEP_BUF],
197 uint32_t esep_classes[static ESEP_MAX]
198)
199{
200 uint8_t t, m, pval;
201 cube_t c, moved, transformed;
202 uint32_t done;
203 int64_t coord;
204
205 done = 0;
206 c = invcoord_eoesep(i);
207 for (m = 0; m < 18; m++) {
208 moved = move(c, m);
209 for (t = 0; t < 48; t++) {
210 transformed = transform(moved, t);
211 coord = coord_eoesep_sym(transformed, esep_classes);
212 pval = get_eoesep_pval(buf8, coord);
213 if (pval > d) {
214 set_eoesep_pval(buf8, coord, d);
215 done++;
216 }
217 }
218 }
219
220 return done;
221}
222
223STATIC bool
224gendata_eoesep_next(
225 cube_t c,
226 uint8_t d,
227 uint8_t buf8[static EOESEP_BUF],
228 uint32_t esep_classes[static ESEP_MAX]
229)
230{
231 uint8_t m, t, pval;
232 int64_t coord;
233 cube_t moved, transformed;
234
235 for (t = 0; t < 48; t++) {
236 transformed = transform(c, t);
237 for (m = 0; m < 18; m++) {
238 moved = move(transformed, m);
239 coord = coord_eoesep_sym(moved, esep_classes);
240 pval = get_eoesep_pval(buf8, coord);
241 if (pval == d-1)
242 return true;
243 }
244 }
245
246 return false;
247}
248
249STATIC uint8_t
250get_eoesep_pval(const uint8_t *table, int64_t i)
251{
252 return (table[EOESEP_INDEX(i)] & EOESEP_MASK(i)) >> EOESEP_SHIFT(i);
253}
254
255STATIC uint8_t
256get_eoesep_pval_cube(const void *data, cube_t c)
257{
258 int64_t coord;
259 const uint8_t *table;
260 const uint32_t *esep_classes;
261
262 esep_classes = (const uint32_t *)data;
263 table = (const uint8_t *)data + 4*ESEP_MAX;
264 coord = coord_eoesep_sym(c, esep_classes);
265
266 return get_eoesep_pval(table, coord);
267}
268
269STATIC void
270set_eoesep_pval(uint8_t *table, int64_t i, uint8_t val)
271{
272 table[EOESEP_INDEX(i)] = (table[EOESEP_INDEX(i)] & (~EOESEP_MASK(i)))
273 | (val << EOESEP_SHIFT(i));
274}

Generated with cgit - Back to sebastiano.tronto.net