aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/constants.h2
-rw-r--r--src/solve_h48.h93
-rw-r--r--test/100_gendata_cocsep/gendata_cocsep_tests.c8
3 files changed, 61 insertions, 42 deletions
diff --git a/src/constants.h b/src/constants.h
index df444b1..00061bd 100644
--- a/src/constants.h
+++ b/src/constants.h
@@ -5,8 +5,6 @@
5#define _12c4 495U 5#define _12c4 495U
6#define _8c4 70U 6#define _8c4 70U
7 7
8#define COCSEP_CLASSES 3393U
9
10_static int64_t binomial[12][12] = { 8_static int64_t binomial[12][12] = {
11 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 9 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
12 {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 10 {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
diff --git a/src/solve_h48.h b/src/solve_h48.h
index 84bea31..d7473bd 100644
--- a/src/solve_h48.h
+++ b/src/solve_h48.h
@@ -4,6 +4,19 @@
4#define _visited_ind(i) (i / 8U) 4#define _visited_ind(i) (i / 8U)
5#define _visited_mask(i) (1U << (i % 8U)) 5#define _visited_mask(i) (1U << (i % 8U))
6 6
7#define COCSEP_CLASSES 3393U
8
9typedef struct {
10 cube_fast_t cube;
11 uint8_t depth;
12 uint8_t maxdepth;
13 uint16_t *n;
14 uint32_t *buf32;
15 uint8_t *visited;
16 uint64_t *selfsim;
17 cube_fast_t *rep;
18} dfsarg_cocsep_t;
19
7typedef struct { 20typedef struct {
8 cube_fast_t cube; 21 cube_fast_t cube;
9 uint8_t *visited; 22 uint8_t *visited;
@@ -13,23 +26,20 @@ typedef struct {
13 uint16_t *nclasses; 26 uint16_t *nclasses;
14 uint32_t *cocsepdata; 27 uint32_t *cocsepdata;
15 uint32_t *buf32; 28 uint32_t *buf32;
16} dfsarg_gendata_t; 29} dfsarg_esep_t;
17 30
18_static_inline int64_t coord_h48(cube_fast_t, uint32_t *, uint8_t); 31_static_inline int64_t coord_h48(cube_fast_t, uint32_t *, uint8_t);
19 32
20_static size_t gendata_cocsep(void *); 33_static size_t gendata_cocsep(void *, uint64_t *, cube_fast_t *);
21_static uint32_t gendata_cocsep_dfs( /* TODO: use dfsarg */ 34_static uint32_t gendata_cocsep_dfs(dfsarg_cocsep_t *);
22 cube_fast_t, uint8_t, uint8_t, uint16_t *, uint32_t *, uint8_t *);
23
24_static size_t gendata_esep(const void *, void *); 35_static size_t gendata_esep(const void *, void *);
25_static uint32_t gendata_esep_dfs(dfsarg_gendata_t *); 36_static uint32_t gendata_esep_dfs(dfsarg_esep_t *);
26 37
27_static_inline bool get_visited(const uint8_t *, int64_t); 38_static_inline bool get_visited(const uint8_t *, int64_t);
28_static_inline void set_visited(uint8_t *, int64_t); 39_static_inline void set_visited(uint8_t *, int64_t);
29_static_inline uint8_t get_esep_pval(const uint32_t *, int64_t); 40_static_inline uint8_t get_esep_pval(const uint32_t *, int64_t);
30_static_inline void set_esep_pval(uint32_t *, int64_t, uint8_t); 41_static_inline void set_esep_pval(uint32_t *, int64_t, uint8_t);
31 42
32/* h is the number of eo bits used */
33_static_inline int64_t 43_static_inline int64_t
34coord_h48(cube_fast_t c, uint32_t *cocsepdata, uint8_t h) 44coord_h48(cube_fast_t c, uint32_t *cocsepdata, uint8_t h)
35{ 45{
@@ -67,27 +77,37 @@ After the data as described above, more auxiliary information is appended:
67 of positions having that pruning value. 77 of positions having that pruning value.
68*/ 78*/
69_static size_t 79_static size_t
70gendata_cocsep(void *buf) 80gendata_cocsep(void *buf, uint64_t *selfsim, cube_fast_t *rep)
71{ 81{
72 size_t tablesize = _3p7 << 7U; 82 size_t tablesize = _3p7 << 7U;
73 size_t visitedsize = (tablesize + 7U) / 8U; 83 size_t visitedsize = (tablesize + 7U) / 8U;
74 size_t infosize = 12; 84 size_t infosize = 12;
75 85
76 cube_fast_t solved;
77 uint32_t *buf32, *info, cc; 86 uint32_t *buf32, *info, cc;
78 uint16_t n; 87 uint16_t n;
79 uint8_t i, j, visited[visitedsize]; 88 uint8_t i, j, visited[visitedsize];
89 dfsarg_cocsep_t arg;
80 90
81 buf32 = (uint32_t *)buf; 91 buf32 = (uint32_t *)buf;
82 info = buf32 + tablesize; 92 info = buf32 + tablesize;
83 memset(buf32, 0xFFU, 4*tablesize); 93 memset(buf32, 0xFFU, sizeof(uint32_t) * tablesize);
84 memset(info, 0, 4*infosize); 94 memset(info, 0, sizeof(uint32_t) * infosize);
95 memset(selfsim, 0, sizeof(uint64_t) * COCSEP_CLASSES);
85 96
86 solved = cubetofast(solvedcube()); 97 arg = (dfsarg_cocsep_t) {
98 .cube = cubetofast(solvedcube()),
99 .n = &n,
100 .buf32 = buf32,
101 .visited = visited,
102 .selfsim = selfsim,
103 .rep = rep
104 };
87 for (i = 0, n = 0, cc = 0; i < 10; i++) { 105 for (i = 0, n = 0, cc = 0; i < 10; i++) {
88 memset(visited, 0, visitedsize);
89 DBG_LOG("cocsep: generating depth %" PRIu8 "\n", i); 106 DBG_LOG("cocsep: generating depth %" PRIu8 "\n", i);
90 cc = gendata_cocsep_dfs(solved, 0, i, &n, buf32, visited); 107 memset(visited, 0, visitedsize);
108 arg.depth = 0;
109 arg.maxdepth = i;
110 cc = gendata_cocsep_dfs(&arg);
91 info[i+2] = cc; 111 info[i+2] = cc;
92 DBG_LOG("found %" PRIu32 "\n", cc); 112 DBG_LOG("found %" PRIu32 "\n", cc);
93 } 113 }
@@ -109,46 +129,43 @@ gendata_cocsep(void *buf)
109} 129}
110 130
111_static uint32_t 131_static uint32_t
112gendata_cocsep_dfs( 132gendata_cocsep_dfs(dfsarg_cocsep_t *arg)
113 cube_fast_t c,
114 uint8_t depth,
115 uint8_t maxdepth,
116 uint16_t *n,
117 uint32_t *buf32,
118 uint8_t *visited
119)
120{ 133{
121 uint8_t m, t, tinv, olddepth; 134 uint8_t m, t, tinv, olddepth;
122 uint32_t cc; 135 uint32_t cc;
123 int64_t i; 136 int64_t i;
124 cube_fast_t d; 137 cube_fast_t d;
138 dfsarg_cocsep_t nextarg;
125 139
126 i = coord_fast_cocsep(c); 140 i = coord_fast_cocsep(arg->cube);
127 olddepth = (uint8_t)(buf32[i] & 0xFFU); 141 olddepth = (uint8_t)(arg->buf32[i] & 0xFFU);
128 if (olddepth < depth || get_visited(visited, i)) 142 if (olddepth < arg->depth || get_visited(arg->visited, i))
129 return 0; 143 return 0;
130 set_visited(visited, i); 144 set_visited(arg->visited, i);
131 145
132 if (depth == maxdepth) { 146 if (arg->depth == arg->maxdepth) {
133 if ((buf32[i] & 0xFFU) != 0xFFU) 147 if ((arg->buf32[i] & 0xFFU) != 0xFFU)
134 return 0; 148 return 0;
135 149
136 for (t = 0, cc = 0; t < 48; t++) { 150 for (t = 0, cc = 0; t < 48; t++) {
137 d = transform(c, t); 151 d = transform(arg->cube, t);
138 i = coord_fast_cocsep(d); 152 i = coord_fast_cocsep(d);
139 set_visited(visited, i); 153 set_visited(arg->visited, i);
140 tinv = inverse_trans(t); 154 tinv = inverse_trans(t);
141 cc += (buf32[i] & 0xFFU) == 0xFFU; 155 cc += (arg->buf32[i] & 0xFFU) == 0xFFU;
142 buf32[i] = (*n << 16U) | (tinv << 8U) | depth; 156 arg->buf32[i] =
157 (*arg->n << 16U) | (tinv << 8U) | arg->depth;
143 } 158 }
144 (*n)++; 159 (*arg->n)++;
145 160
146 return cc; 161 return cc;
147 } 162 }
148 163
164 memcpy(&nextarg, arg, sizeof(dfsarg_cocsep_t));
165 nextarg.depth++;
149 for (m = 0, cc = 0; m < 18; m++) { 166 for (m = 0, cc = 0; m < 18; m++) {
150 d = move(c, m); 167 nextarg.cube = move(arg->cube, m);
151 cc += gendata_cocsep_dfs(d, depth+1, maxdepth, n, buf32, visited); 168 cc += gendata_cocsep_dfs(&nextarg);
152 } 169 }
153 170
154 return cc; 171 return cc;
@@ -167,7 +184,7 @@ gendata_esep(const void *cocsepdata, void *buf)
167 184
168 uint32_t *buf32, *info, cc; 185 uint32_t *buf32, *info, cc;
169 uint8_t moves[20]; 186 uint8_t moves[20];
170 dfsarg_gendata_t arg; 187 dfsarg_esep_t arg;
171 188
172 arg.visited = malloc(visitedsize); 189 arg.visited = malloc(visitedsize);
173 buf32 = (uint32_t *)buf; 190 buf32 = (uint32_t *)buf;
@@ -194,13 +211,13 @@ gendata_esep(const void *cocsepdata, void *buf)
194} 211}
195 212
196_static uint32_t 213_static uint32_t
197gendata_esep_dfs(dfsarg_gendata_t *arg) 214gendata_esep_dfs(dfsarg_esep_t *arg)
198{ 215{
199 uint8_t m, t, olddepth; 216 uint8_t m, t, olddepth;
200 uint32_t cc; 217 uint32_t cc;
201 uint64_t i; 218 uint64_t i;
202 cube_fast_t d; 219 cube_fast_t d;
203 dfsarg_gendata_t nextarg; 220 dfsarg_esep_t nextarg;
204 221
205 if (!allowednextmove(arg->moves, arg->nmoves)) 222 if (!allowednextmove(arg->moves, arg->nmoves))
206 return 0; 223 return 0;
diff --git a/test/100_gendata_cocsep/gendata_cocsep_tests.c b/test/100_gendata_cocsep/gendata_cocsep_tests.c
index 36dd5ce..4e0dce5 100644
--- a/test/100_gendata_cocsep/gendata_cocsep_tests.c
+++ b/test/100_gendata_cocsep/gendata_cocsep_tests.c
@@ -1,12 +1,16 @@
1#include "../test.h" 1#include "../test.h"
2 2
3size_t gendata_cocsep(void *); 3#define COCSEP_CLASSES 3393U
4
5size_t gendata_cocsep(void *, uint64_t *, cube_fast_t *);
4 6
5int main(void) { 7int main(void) {
6 uint32_t buf[300000], i; 8 uint32_t buf[300000], i;
9 uint64_t selfsim[COCSEP_CLASSES];
10 cube_fast_t rep[COCSEP_CLASSES];
7 size_t result; 11 size_t result;
8 12
9 result = gendata_cocsep(buf); 13 result = gendata_cocsep(buf, selfsim, rep);
10 14
11 printf("%zu\n", result); 15 printf("%zu\n", result);
12 printf("Classes: %" PRIu32 "\n", buf[result/4-12]); 16 printf("Classes: %" PRIu32 "\n", buf[result/4-12]);

Generated with cgit - Back to sebastiano.tronto.net