aboutsummaryrefslogtreecommitdiff
path: root/src/solvers/h48/gendata_cocsep.h
blob: 17568ea719c66c02d72dfdcebc3d3f6f266fc2d2 (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
STATIC size_t gendata_cocsep(unsigned char *, uint64_t *, cube_t *);
STATIC uint32_t gendata_cocsep_dfs(cocsep_dfs_arg_t [NON_NULL]);

STATIC_INLINE bool gendata_cocsep_get_visited(
    const uint8_t [SIZE(COCSEP_VISITEDSIZE)], uint64_t);
STATIC_INLINE void gendata_cocsep_set_visited(
    uint8_t [SIZE(COCSEP_VISITEDSIZE)], uint64_t);

STATIC_INLINE int8_t get_h48_cdata(
    cube_t, const uint32_t [SIZE(COCSEP_TABLESIZE)], uint32_t *);

STATIC size_t
gendata_cocsep(
	unsigned char *buf,
	uint64_t *selfsim,
	cube_t *rep
)
{
	uint32_t *buf32, cc;
	uint16_t n;
	uint8_t i, visited[COCSEP_VISITEDSIZE];
	tableinfo_t info;
	cocsep_dfs_arg_t arg;

	if (buf == NULL)
		goto gendata_cocsep_return_size;

	memset(buf, 0xFF, COCSEP_FULLSIZE);
	buf32 = (uint32_t *)(buf + INFOSIZE);
	if (selfsim != NULL)
		memset(selfsim, 0, sizeof(uint64_t) * COCSEP_CLASSES);

	info = (tableinfo_t) {
		.solver = "cocsep data for h48",
		.type = TABLETYPE_SPECIAL,
		.infosize = INFOSIZE,
		.fullsize = COCSEP_FULLSIZE,
		.hash = 0,
		.entries = COCSEP_TABLESIZE,
		.classes = COCSEP_CLASSES,
		.bits = 32,
		.base = 0,
		.maxvalue = 9,
		.next = 0
	};
	arg = (cocsep_dfs_arg_t) {
		.cube = SOLVED_CUBE,
		.n = &n,
		.buf32 = buf32,
		.visited = visited,
		.selfsim = selfsim,
		.rep = rep
	};
	for (i = 0, n = 0, cc = 0; i < 10; i++) {
		memset(visited, 0, COCSEP_VISITEDSIZE);
		arg.depth = 0;
		arg.maxdepth = i;
		cc = gendata_cocsep_dfs(&arg);
		info.distribution[i] = cc;
	}

	writetableinfo(&info, COCSEP_FULLSIZE, buf);

	DBG_ASSERT(n == COCSEP_CLASSES, "cocsep: computed %" PRIu16
	    " symmetry classes, expected %zu\n", n, COCSEP_CLASSES);

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

	/* The following output is just noise

	LOG("Symmetry classes: %" PRIu32 "\n", COCSEP_CLASSES);
	LOG("Pruning value distribution:\n");
	for (j = 0; j < 10; j++)
		LOG("%" PRIu8 ":\t%" PRIu32 "\n", j, info.distribution[j]);
	*/

gendata_cocsep_return_size:
	return COCSEP_FULLSIZE;
}

STATIC uint32_t
gendata_cocsep_dfs(cocsep_dfs_arg_t arg[NON_NULL])
{
	uint8_t m;
	uint32_t cc, class, ttrep, depth, olddepth, tinv;
	uint64_t t;
	uint64_t i, j;
	cube_t d;
	cocsep_dfs_arg_t nextarg;

	i = coord_cocsep(arg->cube);
	olddepth = (uint8_t)(arg->buf32[i] & 0xFF);
	if (olddepth < arg->depth ||
	    gendata_cocsep_get_visited(arg->visited, i))
		return 0;
	gendata_cocsep_set_visited(arg->visited, i);

	if (arg->depth == arg->maxdepth) {
		if ((arg->buf32[i] & 0xFF) != 0xFF)
			return 0;

		if (arg->rep != NULL)
			arg->rep[*arg->n] = arg->cube;
		for (t = 0, cc = 0; t < NTRANS; t++) {
			d = transform_corners(arg->cube, t);
			j = coord_cocsep(d);
			if (i == j && arg->selfsim != NULL)
				arg->selfsim[*arg->n] |= UINT64_C(1) << t;
			if (COCLASS(arg->buf32[j]) != UINT32_C(0xFFFF))
				continue;
			gendata_cocsep_set_visited(arg->visited, j);
			tinv = inverse_trans(t);
			olddepth = arg->buf32[j] & 0xFF;
			cc += olddepth == 0xFF;

			class = (uint32_t)(*arg->n) << UINT32_C(16);
			ttrep = (uint32_t)tinv << UINT32_C(8);
			depth = (uint32_t)arg->depth;
			arg->buf32[j] = class | ttrep | depth;
		}
		(*arg->n)++;

		return cc;
	}

	nextarg = *arg;
	nextarg.depth++;
	for (m = 0, cc = 0; m < 18; m++) {
		nextarg.cube = move(arg->cube, m);
		cc += gendata_cocsep_dfs(&nextarg);
	}

	return cc;
}

STATIC_INLINE bool
gendata_cocsep_get_visited(
	const uint8_t a[SIZE(COCSEP_VISITEDSIZE)],
	uint64_t i
)
{
	return a[VISITED_IND(i)] & VISITED_MASK(i);
}

STATIC_INLINE void
gendata_cocsep_set_visited(
	uint8_t a[SIZE(COCSEP_VISITEDSIZE)],
	uint64_t i
)
{
	a[VISITED_IND(i)] |= VISITED_MASK(i);
}

STATIC_INLINE int8_t
get_h48_cdata(
	cube_t cube,
	const uint32_t cocsepdata[SIZE(COCSEP_TABLESIZE)],
	uint32_t *cdata
)
{
	uint64_t coord;

	coord = coord_cocsep(cube);
	*cdata = cocsepdata[coord];

	return CBOUND(*cdata);
}

Generated with cgit - Back to sebastiano.tronto.net