aboutsummaryrefslogtreecommitdiff
path: root/src/solvers/h48/gendata_eoesep.h
diff options
context:
space:
mode:
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