aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-10-14 19:10:39 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-10-14 20:21:07 +0200
commit3c12def93ed667548bcd9c534c31ec31bfefb8e0 (patch)
treee47695e828792aec00d73d9e9e34cb6cd3a666f4
parent87de946c47b3b5ef0fb0c5f2289bb033bc8d9038 (diff)
downloadnissy-core-3c12def93ed667548bcd9c534c31ec31bfefb8e0.tar.gz
nissy-core-3c12def93ed667548bcd9c534c31ec31bfefb8e0.zip
Fallback tables
Diffstat (limited to '')
-rw-r--r--.gitignore1
-rw-r--r--src/solvers/h48/gendata_h48.h44
-rw-r--r--src/solvers/h48/solve.h51
-rw-r--r--src/solvers/h48/solve_multithread.h30
-rw-r--r--src/solvers/h48/stats.h4
-rw-r--r--tools/300_solve_small/solve_small.c4
6 files changed, 103 insertions, 31 deletions
diff --git a/.gitignore b/.gitignore
index 0a26988..451da56 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,6 +11,7 @@ run
11shell/lasttest.out 11shell/lasttest.out
12shell/lasttest.err 12shell/lasttest.err
13tables/* 13tables/*
14tables-old/*
14test/*/runtest 15test/*/runtest
15test/.DS_Store 16test/.DS_Store
16test/run 17test/run
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h
index 2a4469f..4400011 100644
--- a/src/solvers/h48/gendata_h48.h
+++ b/src/solvers/h48/gendata_h48.h
@@ -67,17 +67,20 @@ gendata_h48short(gendata_h48short_arg_t *arg)
67STATIC int64_t 67STATIC int64_t
68gendata_h48(gendata_h48_arg_t *arg) 68gendata_h48(gendata_h48_arg_t *arg)
69{ 69{
70 uint64_t size; 70 uint64_t size, cocsepsize, h48size, fallbacksize;
71 void *cocsepdata_offset; 71 void *cocsepdata_offset;
72 size_t cocsepsize; 72 tableinfo_t cocsepinfo, h48info;
73 tableinfo_t cocsepinfo; 73 gendata_h48_arg_t arg_h0k4;
74 74
75 if (arg == NULL) { 75 if (arg == NULL) {
76 LOG("Error computing H48 data: arg is NULL.\n"); 76 LOG("Error computing H48 data: arg is NULL.\n");
77 return NISSY_ERROR_UNKNOWN; 77 return NISSY_ERROR_UNKNOWN;
78 } 78 }
79 79
80 size = 2*INFOSIZE + COCSEP_FULLSIZE + H48_TABLESIZE(arg->h, arg->k); 80 cocsepsize = COCSEP_FULLSIZE;
81 h48size = INFOSIZE + H48_TABLESIZE(arg->h, arg->k);
82 fallbacksize = arg->k == 2 ? INFOSIZE + H48_TABLESIZE(0, 4) : 0;
83 size = cocsepsize + h48size + fallbacksize;
81 84
82 if (arg->buf == NULL) 85 if (arg->buf == NULL)
83 return size; /* Dry-run */ 86 return size; /* Dry-run */
@@ -89,7 +92,7 @@ gendata_h48(gendata_h48_arg_t *arg)
89 return NISSY_ERROR_BUFFER_SIZE; 92 return NISSY_ERROR_BUFFER_SIZE;
90 } 93 }
91 94
92 cocsepsize = gendata_cocsep(arg->buf, arg->selfsim, arg->crep); 95 gendata_cocsep(arg->buf, arg->selfsim, arg->crep);
93 96
94 cocsepdata_offset = (char *)arg->buf + INFOSIZE; 97 cocsepdata_offset = (char *)arg->buf + INFOSIZE;
95 arg->cocsepdata = (uint32_t *)cocsepdata_offset; 98 arg->cocsepdata = (uint32_t *)cocsepdata_offset;
@@ -121,6 +124,32 @@ gendata_h48(gendata_h48_arg_t *arg)
121 return NISSY_ERROR_UNKNOWN; 124 return NISSY_ERROR_UNKNOWN;
122 } 125 }
123 126
127 if (arg->k == 2) {
128 arg_h0k4 = *arg;
129 arg_h0k4.h = 0;
130 arg_h0k4.k = 4;
131 arg_h0k4.base = 0;
132 arg_h0k4.maxdepth = 20;
133 arg_h0k4.buf_size = arg->buf_size - h48size;
134 arg_h0k4.buf = (char *)arg->buf + cocsepsize + h48size;
135 arg_h0k4.h48buf = (char *)arg->h48buf + h48size;
136
137 gendata_h48h0k4(&arg_h0k4);
138
139 if (readtableinfo_n(arg->buf_size, arg->buf, 2, &h48info)
140 != NISSY_OK) {
141 LOG("gendata_h48: could not read info for h48 table\n");
142 return NISSY_ERROR_UNKNOWN;
143 }
144
145 h48info.next = h48size;
146 if (writetableinfo(&h48info, arg->buf_size - cocsepsize,
147 (char *)arg->buf + cocsepsize) != NISSY_OK) {
148 LOG("gendata_h48: could not write info for h48 table\n");
149 return NISSY_ERROR_UNKNOWN;
150 }
151 }
152
124 return size; 153 return size;
125} 154}
126 155
@@ -198,7 +227,7 @@ gendata_h48h0k4(gendata_h48_arg_t *arg)
198 } 227 }
199 228
200 arg->info.maxvalue = d - 1; 229 arg->info.maxvalue = d - 1;
201 bufsize = arg->buf_size - COCSEP_FULLSIZE - INFOSIZE; 230 bufsize = arg->buf_size - COCSEP_FULLSIZE;
202 writetableinfo(&arg->info, bufsize, arg->h48buf); 231 writetableinfo(&arg->info, bufsize, arg->h48buf);
203} 232}
204 233
@@ -377,7 +406,7 @@ gendata_h48k2(gendata_h48_arg_t *arg)
377 arg->info.distribution[t]++; 406 arg->info.distribution[t]++;
378 } 407 }
379 408
380 bufsize = arg->buf_size - COCSEP_FULLSIZE - INFOSIZE; 409 bufsize = arg->buf_size - COCSEP_FULLSIZE;
381 writetableinfo(&arg->info, bufsize, arg->h48buf); 410 writetableinfo(&arg->info, bufsize, arg->h48buf);
382} 411}
383 412
@@ -619,7 +648,6 @@ getdistribution_h48(
619 distr[val]++; 648 distr[val]++;
620 } 649 }
621} 650}
622
623STATIC const uint32_t * 651STATIC const uint32_t *
624get_cocsepdata_constptr(const void *data) 652get_cocsepdata_constptr(const void *data)
625{ 653{
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h
index 2a5e341..8f55501 100644
--- a/src/solvers/h48/solve.h
+++ b/src/solvers/h48/solve.h
@@ -11,6 +11,7 @@ typedef struct {
11 uint8_t base; 11 uint8_t base;
12 const uint32_t *cocsepdata; 12 const uint32_t *cocsepdata;
13 const uint8_t *h48data; 13 const uint8_t *h48data;
14 const uint8_t *h48data_fallback;
14 uint64_t solutions_size; 15 uint64_t solutions_size;
15 char **nextsol; 16 char **nextsol;
16 uint8_t nissbranch; 17 uint8_t nissbranch;
@@ -112,16 +113,31 @@ solve_h48_stop(dfsarg_solveh48_t *arg)
112 113
113 h48bound = get_h48_bound(arg->cube, data, arg->h, arg->k, arg->h48data); 114 h48bound = get_h48_bound(arg->cube, data, arg->h, arg->k, arg->h48data);
114 115
115 /* If the h48 bound is > 0, we add the base value. */ 116 /* If the h48 bound is > 0, we add the base value. */
116 /* Otherwise, we use the cbound value instead (fallback). */ 117 /* Otherwise, we use the fallback h0k4 value instead. */
117 h48bound += h48bound == 0 ? cbound : arg->base; 118
119 if (arg->k == 2) {
120 if (h48bound == 0) {
121 h48bound = get_h48_bound(
122 arg->cube, data, 0, 4, arg->h48data_fallback);
123 } else {
124 h48bound += arg->base;
125 }
126 }
118 if (h48bound + arg->nmoves + arg->npremoves > arg->depth) 127 if (h48bound + arg->nmoves + arg->npremoves > arg->depth)
119 return true; 128 return true;
120 if (h48bound + arg->nmoves + arg->npremoves == arg->depth) 129 if (h48bound + arg->nmoves + arg->npremoves == arg->depth)
121 arg->nissbranch = MM_INVERSEBRANCH; 130 arg->nissbranch = MM_INVERSEBRANCH;
122 131
123 h48bound_inv = get_h48_bound(arg->inverse, data_inv, arg->h, arg->k, arg->h48data); 132 h48bound_inv = get_h48_bound(arg->inverse, data_inv, arg->h, arg->k, arg->h48data);
124 h48bound_inv += h48bound_inv == 0 ? cbound_inv : arg->base; 133 if (arg->k == 2) {
134 if (h48bound_inv == 0) {
135 h48bound_inv = get_h48_bound(
136 arg->inverse, data_inv, 0, 4, arg->h48data_fallback);
137 } else {
138 h48bound_inv += arg->base;
139 }
140 }
125 if (h48bound_inv + arg->nmoves + arg->npremoves > arg->depth) 141 if (h48bound_inv + arg->nmoves + arg->npremoves > arg->depth)
126 return true; 142 return true;
127 if (h48bound_inv + arg->nmoves + arg->npremoves == arg->depth) 143 if (h48bound_inv + arg->nmoves + arg->npremoves == arg->depth)
@@ -194,12 +210,10 @@ solve_h48(
194{ 210{
195 _Atomic int64_t nsols; 211 _Atomic int64_t nsols;
196 dfsarg_solveh48_t arg; 212 dfsarg_solveh48_t arg;
197 tableinfo_t info; 213 tableinfo_t info, fbinfo;
198 214
199 if(readtableinfo_n(data_size, data, 2, &info) != NISSY_OK) { 215 if(readtableinfo_n(data_size, data, 2, &info) != NISSY_OK)
200 LOG("solve_h48: error reading table\n"); 216 goto solve_h48_error_data;
201 return NISSY_ERROR_DATA;
202 }
203 217
204 arg = (dfsarg_solveh48_t) { 218 arg = (dfsarg_solveh48_t) {
205 .cube = cube, 219 .cube = cube,
@@ -209,12 +223,23 @@ solve_h48(
209 .h = info.h48h, 223 .h = info.h48h,
210 .k = info.bits, 224 .k = info.bits,
211 .base = info.base, 225 .base = info.base,
212 .cocsepdata = get_cocsepdata_constptr(data), 226 .cocsepdata = (uint32_t *)((char *)data + INFOSIZE),
213 .h48data = get_h48data_constptr(data), 227 .h48data = (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE,
214 .solutions_size = solutions_size, 228 .solutions_size = solutions_size,
215 .nextsol = &solutions 229 .nextsol = &solutions
216 }; 230 };
217 231
232 if (info.bits == 2) {
233 if (readtableinfo_n(data_size, data, 3, &fbinfo) != NISSY_OK)
234 goto solve_h48_error_data;
235 /* We only support h0k4 as fallback table */
236 if (fbinfo.h48h != 0 || fbinfo.bits != 4)
237 goto solve_h48_error_data;
238 arg.h48data_fallback = arg.h48data + info.next;
239 } else {
240 arg.h48data_fallback = NULL;
241 }
242
218 nsols = 0; 243 nsols = 0;
219 for (arg.depth = minmoves; 244 for (arg.depth = minmoves;
220 arg.depth <= maxmoves && nsols < maxsolutions; 245 arg.depth <= maxmoves && nsols < maxsolutions;
@@ -229,4 +254,8 @@ solve_h48(
229 **arg.nextsol = '\0'; 254 **arg.nextsol = '\0';
230 (*arg.nextsol)++; 255 (*arg.nextsol)++;
231 return nsols; 256 return nsols;
257
258solve_h48_error_data:
259 LOG("solve_h48: error reading table\n");
260 return NISSY_ERROR_DATA;
232} 261}
diff --git a/src/solvers/h48/solve_multithread.h b/src/solvers/h48/solve_multithread.h
index 2e3a1e9..2755372 100644
--- a/src/solvers/h48/solve_multithread.h
+++ b/src/solvers/h48/solve_multithread.h
@@ -261,13 +261,11 @@ solve_h48_multithread(
261 _Atomic int64_t nsols = 0; 261 _Atomic int64_t nsols = 0;
262 int p_depth = 0; 262 int p_depth = 0;
263 dfsarg_solveh48_t arg; 263 dfsarg_solveh48_t arg;
264 tableinfo_t info; 264 tableinfo_t info, fbinfo;
265 pthread_t threads[THREADS]; 265 pthread_t threads[THREADS];
266 266
267 if (readtableinfo_n(data_size, data, 2, &info) != NISSY_OK) { 267 if (readtableinfo_n(data_size, data, 2, &info) != NISSY_OK)
268 LOG("solve_h48: error reading table\n"); 268 goto solve_h48_multithread_error_data;
269 return NISSY_ERROR_DATA;
270 }
271 269
272 arg = (dfsarg_solveh48_t){ 270 arg = (dfsarg_solveh48_t){
273 .cube = cube, 271 .cube = cube,
@@ -278,12 +276,23 @@ solve_h48_multithread(
278 .h = info.h48h, 276 .h = info.h48h,
279 .k = info.bits, 277 .k = info.bits,
280 .base = info.base, 278 .base = info.base,
281 .cocsepdata = get_cocsepdata_constptr(data), 279 .cocsepdata = (uint32_t *)((char *)data + INFOSIZE),
282 .h48data = get_h48data_constptr(data), 280 .h48data = (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE,
283 .solutions_size = solutions_size, 281 .solutions_size = solutions_size,
284 .nextsol = &solutions 282 .nextsol = &solutions
285 }; 283 };
286 284
285 if (info.bits == 2) {
286 if (readtableinfo_n(data_size, data, 3, &fbinfo) != NISSY_OK)
287 goto solve_h48_multithread_error_data;
288 /* We only support h0k4 as fallback table */
289 if (fbinfo.h48h != 0 || fbinfo.bits != 4)
290 goto solve_h48_multithread_error_data;
291 arg.h48data_fallback = arg.h48data + info.next;
292 } else {
293 arg.h48data_fallback = NULL;
294 }
295
287 task_queue_t q; 296 task_queue_t q;
288 init_queue(&q); 297 init_queue(&q);
289 if (solve_h48_bfs(&arg, &q, maxmoves)) 298 if (solve_h48_bfs(&arg, &q, maxmoves))
@@ -301,7 +310,8 @@ solve_h48_multithread(
301 p_depth <= maxmoves && nsols < maxsolutions; 310 p_depth <= maxmoves && nsols < maxsolutions;
302 p_depth++) 311 p_depth++)
303 { 312 {
304 LOG("Found %" PRId64 " solutions, searching at depth %" PRId8 "\n", nsols, p_depth); 313 LOG("Found %" PRId64 " solutions, "
314 "searching at depth %" PRId8 "\n", nsols, p_depth);
305 copy_queue(&q, &nq, p_depth, &nsols); 315 copy_queue(&q, &nq, p_depth, &nsols);
306 316
307 pthread_mutex_lock(&nq.mutex); 317 pthread_mutex_lock(&nq.mutex);
@@ -319,4 +329,8 @@ solve_h48_multithread(
319 **arg.nextsol = '\0'; 329 **arg.nextsol = '\0';
320 (*arg.nextsol)++; 330 (*arg.nextsol)++;
321 return nsols; 331 return nsols;
332
333solve_h48_multithread_error_data:
334 LOG("solve_h48: error reading table\n");
335 return NISSY_ERROR_DATA;
322} 336}
diff --git a/src/solvers/h48/stats.h b/src/solvers/h48/stats.h
index ca4b72e..cc51bd9 100644
--- a/src/solvers/h48/stats.h
+++ b/src/solvers/h48/stats.h
@@ -80,8 +80,8 @@ solve_h48stats(
80 80
81 arg = (dfsarg_solveh48stats_t) { 81 arg = (dfsarg_solveh48stats_t) {
82 .cube = cube, 82 .cube = cube,
83 .cocsepdata = get_cocsepdata_constptr(data), 83 .cocsepdata = (uint32_t *)((char *)data + INFOSIZE),
84 .h48data = get_h48data_constptr(data), 84 .h48data = (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE,
85 .s = solutions 85 .s = solutions
86 }; 86 };
87 87
diff --git a/tools/300_solve_small/solve_small.c b/tools/300_solve_small/solve_small.c
index 374d11a..60d1bd8 100644
--- a/tools/300_solve_small/solve_small.c
+++ b/tools/300_solve_small/solve_small.c
@@ -7,8 +7,8 @@ int64_t size = 0;
7char *buf; 7char *buf;
8 8
9char *scrambles[] = { 9char *scrambles[] = {
10 //"R D' R2 D R U2 R' D' R U2 R D R'", /* 12 optimal */ 10 "R D' R2 D R U2 R' D' R U2 R D R'", /* 12 optimal */
11 //"RLUD RLUD RLUD", /* 12 optimal */ 11 "RLUD RLUD RLUD", /* 12 optimal */
12 "R' U' F D2 L2 F R2 U2 R2 B D2 L B2 D' B2 L' R' B D2 B U2 L U2 R' U' F", /* FMC2019 A1 - 16 optimal */ 12 "R' U' F D2 L2 F R2 U2 R2 B D2 L B2 D' B2 L' R' B D2 B U2 L U2 R' U' F", /* FMC2019 A1 - 16 optimal */
13 // "R' U' F D R F2 D L F D2 F2 L' U R' L2 D' R2 F2 R2 D L2 U2 R' U' F", /* FMC2024 A1 - 19 optimal */ 13 // "R' U' F D R F2 D L F D2 F2 L' U R' L2 D' R2 F2 R2 D L2 U2 R' U' F", /* FMC2024 A1 - 19 optimal */
14 NULL 14 NULL

Generated with cgit - Back to sebastiano.tronto.net