aboutsummaryrefslogtreecommitdiff
path: root/src/solvers/h48/gendata_eoesep.h
blob: 52e2b8bc38b6918cfd5e4f47fc8e9eb8e35ddf74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
STATIC int64_t coord_eoesep_sym(cube_t, const uint32_t [static ESEP_MAX]);
STATIC size_t gendata_esep_classes(
    uint32_t [static ESEP_MAX], uint16_t [static ESEP_CLASSES]);
STATIC size_t gendata_eoesep(unsigned char *, uint8_t);
STATIC uint32_t gendata_eoesep_bfs(uint8_t, uint8_t [static EOESEP_BUF],
    uint32_t [static ESEP_MAX], uint16_t [static ESEP_CLASSES]);
STATIC uint32_t gendata_eoesep_fromnew(uint8_t, uint8_t [static EOESEP_BUF],
    uint32_t [static ESEP_MAX], uint16_t [static ESEP_CLASSES]);
STATIC uint32_t gendata_eoesep_fromdone(uint8_t, uint8_t [static EOESEP_BUF],
    uint32_t [static ESEP_MAX], uint16_t [static ESEP_CLASSES]);
STATIC uint32_t gendata_eoesep_marksim(int64_t, uint8_t,
    uint8_t [static EOESEP_BUF], uint32_t [static ESEP_MAX]);
STATIC bool gendata_eoesep_next(cube_t, uint8_t,
    uint8_t [static EOESEP_BUF], uint32_t [static ESEP_MAX]);
STATIC uint8_t get_eoesep_pval(
    const uint8_t [static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)], int64_t);
STATIC uint8_t get_eoesep_pval_cube(const unsigned char *, cube_t);
STATIC void set_eoesep_pval(
    uint8_t [static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)], int64_t, uint8_t);

STATIC int64_t
coord_eoesep_sym(cube_t c, const uint32_t esep_classes[static ESEP_MAX])
{
	uint8_t ttrep;
	uint32_t edata, class;
	int64_t esep, eo;

	esep = coord_esep(c);
	edata = esep_classes[esep];
	class = ECLASS(edata);
	ttrep = TTREP(edata);
	eo = coord_eo(transform(c, ttrep));

	return (class << UINT32_C(11)) + eo;
}

STATIC size_t
gendata_esep_classes(
	uint32_t esep_classes[static ESEP_MAX],
	uint16_t rep[static ESEP_CLASSES]
)
{
	bool visited[ESEP_MAX];
	uint8_t t;
	uint32_t class, cl, ti;
	int64_t i, j;
	cube_t c;

	memset(visited, 0, ESEP_MAX * sizeof(bool));
	class = 0;
	for (i = 0; i < ESEP_MAX; i++) {
		if (visited[i])
			continue;
		c = invcoord_esep(i);
		for (t = 0; t < NTRANS; t++) {
			j = coord_esep(transform(c, t));
			cl = class << UINT32_C(16);
			ti = inverse_trans(t) << UINT32_C(8);
			esep_classes[j] = cl | ti;
			visited[j] = true;
		}
		rep[class] = i;
		class++;
	}

	return class;
}

STATIC size_t
gendata_eoesep(unsigned char *buf, uint8_t maxdepth)
{
	uint8_t d;
	unsigned char *buf8;
	uint16_t rep[ESEP_CLASSES];
	uint32_t *esep_classes, done, level;
	int64_t coord;
	tableinfo_t info;

	if (buf == NULL)
		goto gendata_eoesep_return_size;

	LOG("[H48 gendata] Computing eoesep data\n");
	memset(buf, 0xFF, EOESEP_FULLSIZE);
	esep_classes = (uint32_t *)(buf + INFOSIZE);
	buf8 = buf + INFOSIZE + 4*ESEP_MAX;
	gendata_esep_classes(esep_classes, rep);

	info = (tableinfo_t) {
		.solver = "eoesep data for h48",
		.type = TABLETYPE_SPECIAL,
		.infosize = INFOSIZE,
		.fullsize = EOESEP_FULLSIZE,
		.hash = 0,
		.entries = EOESEP_TABLESIZE,
		.classes = ESEP_CLASSES,
		.bits = 4,
		.base = 0,
		.maxvalue = 11,
		.next = 0
	};

	coord = 0; /* Assumed coordinate of solved cube */
	set_eoesep_pval(buf8, coord, 0);
	done = 1;
	info.distribution[0] = 1;
	for (d = 1; d <= maxdepth && done < EOESEP_TABLESIZE; d++) {
		level = gendata_eoesep_bfs(d, buf8, esep_classes, rep);
		done += level;
		info.distribution[d] = level;
	}

	writetableinfo(&info, EOESEP_FULLSIZE, buf);

	LOG("[H48 gendata] eoesep data computed\n");

gendata_eoesep_return_size:
	return EOESEP_FULLSIZE;
}

STATIC uint32_t
gendata_eoesep_bfs(
	uint8_t d,
	uint8_t buf8[EOESEP_BUF],
	uint32_t esep_classes[static ESEP_MAX],
	uint16_t rep[static ESEP_CLASSES]
)
{
	if (d < 9)
		return gendata_eoesep_fromdone(d, buf8, esep_classes, rep);
	else
		return gendata_eoesep_fromnew(d, buf8, esep_classes, rep);
}

STATIC uint32_t
gendata_eoesep_fromdone(
	uint8_t d,
	uint8_t buf8[EOESEP_BUF],
	uint32_t esep_classes[static ESEP_MAX],
	uint16_t rep[static ESEP_CLASSES]
)
{
	uint8_t pval;
	int64_t i, esep, eo, coord, done;

	done = 0;
	for (i = 0; i < (int64_t)ESEP_CLASSES; i++) {
		esep = rep[i];
		for (eo = 0; eo < POW_2_11; eo++) {
			coord = (i << INT64_C(11)) + eo;
			pval = get_eoesep_pval(buf8, coord);
			if (pval != d-1)
				continue;

			coord = (esep << INT64_C(11)) + eo;
			done += gendata_eoesep_marksim(
			    coord, d, buf8, esep_classes);
		}
	}

	return done;
}

STATIC uint32_t
gendata_eoesep_fromnew(
	uint8_t d,
	uint8_t buf8[EOESEP_BUF],
	uint32_t esep_classes[static ESEP_MAX],
	uint16_t rep[static ESEP_CLASSES]
)
{
	uint8_t pval;
	int64_t i, esep, eo, coord, done;
	cube_t c;

	done = 0;
	for (i = 0; i < (int64_t)ESEP_CLASSES; i++) {
		esep = rep[i];
		for (eo = 0; eo < POW_2_11; eo++) {
			coord = (i << INT64_C(11)) + eo;
			pval = get_eoesep_pval(buf8, coord);
			if (pval != 15)
				continue;

			c = invcoord_eoesep((esep << INT64_C(11)) + eo);
			if (gendata_eoesep_next(c, d, buf8, esep_classes)) {
				set_eoesep_pval(buf8, coord, d);
				done++;
			}
		}
	}

	return done;
}

STATIC uint32_t
gendata_eoesep_marksim(
	int64_t i,
	uint8_t d,
	uint8_t buf8[static EOESEP_BUF],
	uint32_t esep_classes[static ESEP_MAX]
)
{
	uint8_t t, m, pval;
	cube_t c, moved, transformed;
	uint32_t done;
	int64_t coord;

	done = 0;
	c = invcoord_eoesep(i);
	for (m = 0; m < 18; m++) {
		moved = move(c, m);
		for (t = 0; t < NTRANS; t++) {
			transformed = transform(moved, t);
			coord = coord_eoesep_sym(transformed, esep_classes);
			pval = get_eoesep_pval(buf8, coord);
			if (pval > d) {
				set_eoesep_pval(buf8, coord, d);
				done++;
			}
		}
	}

	return done;
}

STATIC bool
gendata_eoesep_next(
	cube_t c,
	uint8_t d,
	uint8_t buf8[static EOESEP_BUF],
	uint32_t esep_classes[static ESEP_MAX]
)
{
	uint8_t m, t, pval;
	int64_t coord;
	cube_t moved, transformed;

	for (t = 0; t < NTRANS; t++) {
		transformed = transform(c, t);
		for (m = 0; m < 18; m++) {
			moved = move(transformed, m);
			coord = coord_eoesep_sym(moved, esep_classes);
			pval = get_eoesep_pval(buf8, coord);
			if (pval == d-1)
				return true;
		}
	}

	return false;
}

STATIC uint8_t
get_eoesep_pval(
	const uint8_t table[static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)],
	int64_t i
)
{
	return (table[EOESEP_INDEX(i)] & EOESEP_MASK(i)) >> EOESEP_SHIFT(i);
}

STATIC uint8_t
get_eoesep_pval_cube(const unsigned char *data, cube_t c)
{
	int64_t coord;

	coord = coord_eoesep_sym(c, (const uint32_t *)data);

	return get_eoesep_pval(data + 4*ESEP_MAX, coord);
}

STATIC void
set_eoesep_pval(
	uint8_t table[static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)],
	int64_t i,
	uint8_t val
)
{
	table[EOESEP_INDEX(i)] = (table[EOESEP_INDEX(i)] & (~EOESEP_MASK(i)))
	    | (val << EOESEP_SHIFT(i));
}

Generated with cgit - Back to sebastiano.tronto.net