aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-10-14 16:55:15 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-10-14 16:55:15 +0200
commit87de946c47b3b5ef0fb0c5f2289bb033bc8d9038 (patch)
tree3836b9cfa607258b506822a5691e7e6b2f7bd7cb
parentebe1ef1d2d63c245fb203878d8309f1808d75c42 (diff)
downloadnissy-core-87de946c47b3b5ef0fb0c5f2289bb033bc8d9038.tar.gz
nissy-core-87de946c47b3b5ef0fb0c5f2289bb033bc8d9038.zip
Fix solvers for k = 2, and changes to solve tool
Diffstat (limited to '')
-rw-r--r--src/solvers/h48/solve.h30
-rw-r--r--src/solvers/h48/solve_multithread.h1
-rw-r--r--tools/300_solve_small/solve_small.c16
3 files changed, 31 insertions, 16 deletions
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h
index 36b6875..2a5e341 100644
--- a/src/solvers/h48/solve.h
+++ b/src/solvers/h48/solve.h
@@ -8,6 +8,7 @@ typedef struct {
8 int64_t maxsolutions; 8 int64_t maxsolutions;
9 uint8_t h; 9 uint8_t h;
10 uint8_t k; 10 uint8_t k;
11 uint8_t base;
11 const uint32_t *cocsepdata; 12 const uint32_t *cocsepdata;
12 const uint8_t *h48data; 13 const uint8_t *h48data;
13 uint64_t solutions_size; 14 uint64_t solutions_size;
@@ -98,27 +99,32 @@ STATIC_INLINE bool
98solve_h48_stop(dfsarg_solveh48_t *arg) 99solve_h48_stop(dfsarg_solveh48_t *arg)
99{ 100{
100 uint32_t data, data_inv; 101 uint32_t data, data_inv;
101 int8_t bound; 102 int8_t cbound, cbound_inv, h48bound, h48bound_inv;
102 103
103 arg->nissbranch = MM_NORMAL; 104 arg->nissbranch = MM_NORMAL;
104 bound = get_h48_cdata(arg->cube, arg->cocsepdata, &data); 105 cbound = get_h48_cdata(arg->cube, arg->cocsepdata, &data);
105 if (bound + arg->nmoves + arg->npremoves > arg->depth) 106 if (cbound + arg->nmoves + arg->npremoves > arg->depth)
106 return true; 107 return true;
107 108
108 bound = get_h48_cdata(arg->inverse, arg->cocsepdata, &data_inv); 109 cbound_inv = get_h48_cdata(arg->inverse, arg->cocsepdata, &data_inv);
109 if (bound + arg->nmoves + arg->npremoves > arg->depth) 110 if (cbound_inv + arg->nmoves + arg->npremoves > arg->depth)
110 return true; 111 return true;
111 112
112 bound = get_h48_bound(arg->cube, data, arg->h, arg->k, arg->h48data); 113 h48bound = get_h48_bound(arg->cube, data, arg->h, arg->k, arg->h48data);
113 if (bound + arg->nmoves + arg->npremoves > arg->depth) 114
115 /* If the h48 bound is > 0, we add the base value. */
116 /* Otherwise, we use the cbound value instead (fallback). */
117 h48bound += h48bound == 0 ? cbound : arg->base;
118 if (h48bound + arg->nmoves + arg->npremoves > arg->depth)
114 return true; 119 return true;
115 if (bound + arg->nmoves + arg->npremoves == arg->depth) 120 if (h48bound + arg->nmoves + arg->npremoves == arg->depth)
116 arg->nissbranch = MM_INVERSEBRANCH; 121 arg->nissbranch = MM_INVERSEBRANCH;
117 122
118 bound = get_h48_bound(arg->inverse, data_inv, arg->h, arg->k, arg->h48data); 123 h48bound_inv = get_h48_bound(arg->inverse, data_inv, arg->h, arg->k, arg->h48data);
119 if (bound + arg->nmoves + arg->npremoves > arg->depth) 124 h48bound_inv += h48bound_inv == 0 ? cbound_inv : arg->base;
125 if (h48bound_inv + arg->nmoves + arg->npremoves > arg->depth)
120 return true; 126 return true;
121 if (bound + arg->nmoves + arg->npremoves == arg->depth) 127 if (h48bound_inv + arg->nmoves + arg->npremoves == arg->depth)
122 arg->nissbranch = MM_NORMALBRANCH; 128 arg->nissbranch = MM_NORMALBRANCH;
123 129
124 return false; 130 return false;
@@ -144,7 +150,6 @@ solve_h48_dfs(dfsarg_solveh48_t *arg)
144 return 1; 150 return 1;
145 } 151 }
146 152
147 /* TODO: avoid copy, change arg and undo changes after recursion */
148 nextarg = *arg; 153 nextarg = *arg;
149 ret = 0; 154 ret = 0;
150 uint32_t allowed; 155 uint32_t allowed;
@@ -203,6 +208,7 @@ solve_h48(
203 .maxsolutions = maxsolutions, 208 .maxsolutions = maxsolutions,
204 .h = info.h48h, 209 .h = info.h48h,
205 .k = info.bits, 210 .k = info.bits,
211 .base = info.base,
206 .cocsepdata = get_cocsepdata_constptr(data), 212 .cocsepdata = get_cocsepdata_constptr(data),
207 .h48data = get_h48data_constptr(data), 213 .h48data = get_h48data_constptr(data),
208 .solutions_size = solutions_size, 214 .solutions_size = solutions_size,
diff --git a/src/solvers/h48/solve_multithread.h b/src/solvers/h48/solve_multithread.h
index d8c81af..2e3a1e9 100644
--- a/src/solvers/h48/solve_multithread.h
+++ b/src/solvers/h48/solve_multithread.h
@@ -277,6 +277,7 @@ solve_h48_multithread(
277 .maxsolutions = maxsolutions, 277 .maxsolutions = maxsolutions,
278 .h = info.h48h, 278 .h = info.h48h,
279 .k = info.bits, 279 .k = info.bits,
280 .base = info.base,
280 .cocsepdata = get_cocsepdata_constptr(data), 281 .cocsepdata = get_cocsepdata_constptr(data),
281 .h48data = get_h48data_constptr(data), 282 .h48data = get_h48data_constptr(data),
282 .solutions_size = solutions_size, 283 .solutions_size = solutions_size,
diff --git a/tools/300_solve_small/solve_small.c b/tools/300_solve_small/solve_small.c
index 622c36e..374d11a 100644
--- a/tools/300_solve_small/solve_small.c
+++ b/tools/300_solve_small/solve_small.c
@@ -2,13 +2,13 @@
2 2
3#define SOL_BUFFER_LEN 1000 3#define SOL_BUFFER_LEN 1000
4 4
5const char *solver = "h48h0k4"; 5char *solver;
6int64_t size = 0; 6int64_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
@@ -37,12 +37,20 @@ void run(void) {
37 } 37 }
38} 38}
39 39
40int main(void) { 40int main(int argc, char **argv) {
41 char filename[255]; 41 char filename[255];
42 42
43 if (argc < 2) {
44 printf("Error: not enough arguments. "
45 "A solver must be given.\n");
46 return 1;
47 }
48
49 solver = argv[1];
43 srand(time(NULL)); 50 srand(time(NULL));
44 nissy_setlogger(log_stderr); 51 nissy_setlogger(log_stderr);
45 52
53
46 sprintf(filename, "tables/%s", solver); 54 sprintf(filename, "tables/%s", solver);
47 if (getdata(solver, &buf, filename) != 0) 55 if (getdata(solver, &buf, filename) != 0)
48 return 1; 56 return 1;

Generated with cgit - Back to sebastiano.tronto.net