aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2021-12-08 10:49:44 +0100
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2021-12-08 10:49:44 +0100
commit131428b913a3d42f26714b8e5e873d8112db10c0 (patch)
tree07993e4a24f76ab0e74ee6a275b9779d2580d447
parent2bbd9cd6024e32009ddee908b5328918601ff9f8 (diff)
downloadnissy-131428b913a3d42f26714b8e5e873d8112db10c0.tar.gz
nissy-131428b913a3d42f26714b8e5e873d8112db10c0.zip
Faster ptable generation (but I can make it faster)
-rw-r--r--TODO.md23
-rwxr-xr-xnissybin165088 -> 165128 bytes
-rw-r--r--src/pruning.c54
3 files changed, 66 insertions, 11 deletions
diff --git a/TODO.md b/TODO.md
index 7ab3287..f6c464b 100644
--- a/TODO.md
+++ b/TODO.md
@@ -42,11 +42,31 @@ It's more of a personal reminder than anything else.
42 in non-posix systems 42 in non-posix systems
43* better man page 43* better man page
44* find a better way to distribute the large tables, especially khuge 44* find a better way to distribute the large tables, especially khuge
45(or just generate them quickly, see below)
45* webapp (cgi) 46* webapp (cgi)
46 47
47## Technical stuff 48## Technical stuff
48 49
49### Better pruning tables 50## Performance (optimal solver)
51* Khuge optimal solver: change direction of search when doing so leads to
52less branching (like nxopt). Need to add some info to EstimateData or to
53DfsData (like last moves on inverse/other scramble) and to change some of
54the logic of niss (allow for switching multiple times).
55* Light optimal solver: use drud table instead of khuge, with tricks as above
56and one more trick: if the last move is 180° avoid computing inverse cube
57and just use previous values for all 3 axes.
58
59## Coordinates, symmetries, pruning tables
60* use multiple threads to search for solutions in parallel
61* Faster pruning table generation: keep track of which positions are "nasty"
62(i.e. self-symmetric with respect to the base symmetry coordinate but not
63self-symmetric overall) by adding a function to struct coord and some datafield
64to struct symdata.
65* Faster pruning table generation: multithreading (divide table into large
66sections and use one mutex for each section to avoid too much locking)
67* Cleanup symcoord.c: some coordinates and symdata are never actually used;
68remove also sd_eofbepos and just use sd_coud for khuge (this changes the
69coordinate so the whole table must be generated again!)
50* Use pruning values mod 4 instead of mod 16 (or maybe not, I like the 70* Use pruning values mod 4 instead of mod 16 (or maybe not, I like the
51current system) 71current system)
52 72
@@ -60,4 +80,3 @@ current system)
60* client/server architecture: run a server process in the background so that 80* client/server architecture: run a server process in the background so that
61 multiple client processess can send it queries and get results; this would 81 multiple client processess can send it queries and get results; this would
62 open up the door for a web-based version or graphical clients 82 open up the door for a web-based version or graphical clients
63* use multiple threads to search for solutions in parallel
diff --git a/nissy b/nissy
index 8dae0c0..f559b2e 100755
--- a/nissy
+++ b/nissy
Binary files differ
diff --git a/src/pruning.c b/src/pruning.c
index 5073d69..716379e 100644
--- a/src/pruning.c
+++ b/src/pruning.c
@@ -144,7 +144,25 @@ genptable(PruneData *pd)
144static void 144static void
145genptable_bfs(PruneData *pd, int d, Move *ms) 145genptable_bfs(PruneData *pd, int d, Move *ms)
146{ 146{
147 int j;
147 uint64_t i; 148 uint64_t i;
149 Cube c, cc;
150
151 for (i = 0; i < pd->coord->max; i++) {
152 /*
153 * TODO: only do this if the position is "nasty",
154 * i.e. self-symmetrical with respect to the base
155 * coordinate but not overall.
156 */
157 if (ptableval_index(pd, i) == d) {
158 c = pd->coord->cube(i);
159 for (j = 0; j < pd->coord->ntrans; j++) {
160 cc = apply_trans(pd->coord->trans[j], c);
161 if (ptableval(pd, cc) > d)
162 ptable_update(pd, cc, d);
163 }
164 }
165 }
148 166
149 for (i = 0; i < pd->coord->max; i++) 167 for (i = 0; i < pd->coord->max; i++)
150 if (ptableval_index(pd, i) == d) 168 if (ptableval_index(pd, i) == d)
@@ -154,11 +172,6 @@ genptable_bfs(PruneData *pd, int d, Move *ms)
154static void 172static void
155genptable_branch(PruneData *pd, uint64_t ind, int d, Move *ms) 173genptable_branch(PruneData *pd, uint64_t ind, int d, Move *ms)
156{ 174{
157 int i, j;
158 Cube ci, cc, c;
159
160 ci = pd->coord->cube(ind);
161
162 /* 175 /*
163 * Here we deal with the following problem: 176 * Here we deal with the following problem:
164 * The set of positions reached by applying each move to 177 * The set of positions reached by applying each move to
@@ -186,6 +199,15 @@ genptable_branch(PruneData *pd, uint64_t ind, int d, Move *ms)
186 * efficient and allows for removing the ntrans and trans 199 * efficient and allows for removing the ntrans and trans
187 * field from struct coordinate. 200 * field from struct coordinate.
188 */ 201 */
202 /* Work in progress, first attempt */
203
204 /*
205 int i, j;
206 Cube ci, cc, c;
207
208
209 ci = pd->coord->cube(ind);
210
189 for (i = 0; i < pd->coord->ntrans; i++) { 211 for (i = 0; i < pd->coord->ntrans; i++) {
190 c = i == 0 ? ci : 212 c = i == 0 ? ci :
191 apply_trans(pd->coord->trans[i], ci); 213 apply_trans(pd->coord->trans[i], ci);
@@ -195,6 +217,18 @@ genptable_branch(PruneData *pd, uint64_t ind, int d, Move *ms)
195 ptable_update(pd, cc, d+1); 217 ptable_update(pd, cc, d+1);
196 } 218 }
197 } 219 }
220 */
221
222 int i;
223 Cube c, cc;
224
225 c = pd->coord->cube(ind);
226
227 for (i = 0; ms[i] != NULLMOVE; i++) {
228 cc = apply_move(ms[i], c);
229 if (ptableval(pd, cc) > d+1)
230 ptable_update(pd, cc, d+1);
231 }
198} 232}
199 233
200void 234void
@@ -225,15 +259,17 @@ ptablesize(PruneData *pd)
225static void 259static void
226ptable_update(PruneData *pd, Cube cube, int n) 260ptable_update(PruneData *pd, Cube cube, int n)
227{ 261{
228 uint64_t ind = pd->coord->index(cube); 262 ptable_update_index(pd, pd->coord->index(cube), n);
229 ptable_update_index(pd, ind, n);
230} 263}
231 264
232static void 265static void
233ptable_update_index(PruneData *pd, uint64_t ind, int n) 266ptable_update_index(PruneData *pd, uint64_t ind, int n)
234{ 267{
235 uint8_t oldval2 = pd->ptable[ind/2]; 268 uint8_t oldval2;
236 int other = (ind % 2) ? oldval2 % 16 : oldval2 / 16; 269 int other;
270
271 oldval2 = pd->ptable[ind/2];
272 other = (ind % 2) ? oldval2 % 16 : oldval2 / 16;
237 273
238 pd->ptable[ind/2] = (ind % 2) ? 16*n + other : 16*other + n; 274 pd->ptable[ind/2] = (ind % 2) ? 16*n + other : 16*other + n;
239 pd->n++; 275 pd->n++;

Generated with cgit - Back to sebastiano.tronto.net