aboutsummaryrefslogtreecommitdiff
path: root/src/pruning.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-12 19:59:18 +0100
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-12 19:59:18 +0100
commite864e23e3ec315d5969281c51f24521cde30792a (patch)
tree3b25152fc4a645b26a4c82f9b0b350b766b8b7f6 /src/pruning.c
parent89268e911e51a7b1c413cfae1520b2db6e60086f (diff)
downloadnissy-e864e23e3ec315d5969281c51f24521cde30792a.tar.gz
nissy-e864e23e3ec315d5969281c51f24521cde30792a.zip
I tried to remove the dependence on antindex in order to get rid of them
once and for all. I successfully removed from the pruning table generation part by using an alternative (slower) method, but then I realized that I also use antindexes when generating symmetry data. So I reverted to the original pruning table computation method, but I left the alternative way there, commented.
Diffstat (limited to '')
-rw-r--r--src/pruning.c157
1 files changed, 136 insertions, 21 deletions
diff --git a/src/pruning.c b/src/pruning.c
index b7fedd4..ca6f57a 100644
--- a/src/pruning.c
+++ b/src/pruning.c
@@ -1,7 +1,20 @@
1#include "pruning.h" 1#include "pruning.h"
2 2
3/*
4 * The commented functions are a way to generate a pruning table
5 * without using anti-indexes. It does not matter too much because
6 * we still need anti-indexes in gensym.
7 */
8/*
9static bool dfs_get_visited(PruneData *pd, DfsData *dd, Cube c);
10static bool dfs_get_visited_index(DfsData *dd, uint64_t ind);
11static void dfs_set_visited(PruneData *pd, DfsData *dd, Cube c, bool b);
12static void dfs_set_visited_index(DfsData *dd, uint64_t ind, bool b);
13static void genptable_dfs(Cube c, PruneData *pd, DfsData *dd);
14*/
15
3static void genptable_bfs(PruneData *pd, int d, Move *ms); 16static void genptable_bfs(PruneData *pd, int d, Move *ms);
4static void genptable_branch(PruneData *pd, uint64_t i, int d, Move *m); 17static void genptable_branch(PruneData *pd,uint64_t ind,int d,Move *ms);
5static void ptable_update(PruneData *pd, Cube cube, int m); 18static void ptable_update(PruneData *pd, Cube cube, int m);
6static void ptable_update_index(PruneData *pd, uint64_t ind, int m); 19static void ptable_update_index(PruneData *pd, uint64_t ind, int m);
7static int ptableval_index(PruneData *pd, uint64_t ind); 20static int ptableval_index(PruneData *pd, uint64_t ind);
@@ -78,6 +91,54 @@ pd_khuge_HTM = {
78 .moveset = moveset_HTM, 91 .moveset = moveset_HTM,
79}; 92};
80 93
94/*
95void
96genptable(PruneData *pd)
97{
98 Move ms[NMOVES];
99 uint64_t j, oldn;
100 DfsData dd;
101
102 if (pd->generated)
103 return;
104
105 pd->ptable = malloc(ptablesize(pd) * sizeof(uint8_t));
106
107 if (read_ptable_file(pd)) {
108 pd->generated = true;
109 return;
110 }
111 pd->generated = true;
112
113 fprintf(stderr, "Cannot load %s, generating it\n", pd->filename);
114
115 moveset_to_list(pd->moveset, ms);
116
117 for (j = 0; j < pd->coord->max; j++)
118 ptable_update_index(pd, j, 15);
119
120 dd = (DfsData) { .m = 0 };
121 dd.visited = malloc((ptablesize(pd)/4 + 1) * sizeof(uint8_t));
122 moveset_to_list(pd->moveset, dd.sorted_moves);
123 oldn = 0;
124 pd->n = 0;
125
126 for (dd.d = 0; dd.d < 15 && pd->n < pd->coord->max; dd.d++) {
127 for (j = 0; j < pd->coord->max; j++)
128 dfs_set_visited_index(&dd, j, false);
129 genptable_dfs((Cube){0}, pd, &dd);
130 fprintf(stderr, "Depth %d done, generated %lu\t(%lu/%lu)\n",
131 dd.d+1, pd->n - oldn, pd->n, pd->coord->max);
132 oldn = pd->n;
133 }
134
135 if (!write_ptable_file(pd))
136 fprintf(stderr, "Error writing ptable file\n");
137
138 free(dd.visited);
139}
140*/
141
81void 142void
82genptable(PruneData *pd) 143genptable(PruneData *pd)
83{ 144{
@@ -105,13 +166,6 @@ genptable(PruneData *pd)
105 for (j = 0; j < pd->coord->max; j++) 166 for (j = 0; j < pd->coord->max; j++)
106 ptable_update_index(pd, j, 15); 167 ptable_update_index(pd, j, 15);
107 168
108 for (j = 0; j < pd->coord->max; j++)
109 if (ptableval_index(pd, j) != 15) {
110 printf("Error, non-max value at index %lu!\n", j);
111 break;
112 }
113 printf("Table set, ready to start\n");
114
115 ptable_update(pd, (Cube){0}, 0); 169 ptable_update(pd, (Cube){0}, 0);
116 pd->n = 1; 170 pd->n = 1;
117 oldn = 0; 171 oldn = 0;
@@ -127,7 +181,81 @@ genptable(PruneData *pd)
127 181
128 if (!write_ptable_file(pd)) 182 if (!write_ptable_file(pd))
129 fprintf(stderr, "Error writing ptable file\n"); 183 fprintf(stderr, "Error writing ptable file\n");
184
185}
186
187/*
188static void
189genptable_dfs(Cube c, PruneData *pd, DfsData *dd)
190{
191 int i, j, pv;
192 Move mm;
193 Cube cc;
194
195 if (pd->coord->index(c) > 2*ptablesize(pd)) {
196 printf("error! %lu > %lu\n", pd->coord->index(c), 2*ptablesize(pd));
197 print_cube(c);
198 exit(1);
199 }
200 pv = ptableval(pd, c);
201
202 if (pv < dd->m || dd->m > dd->d)
203 return;
204
205 if (dfs_get_visited(pd, dd, c))
206 return;
207 dfs_set_visited(pd, dd, c, true);
208
209 if (pv != dd->m)
210 ptable_update(pd, c, dd->m);
211
212 for (i = 0; i < pd->coord->ntrans; i++) {
213 cc = i == 0 ? c :
214 apply_trans(pd->coord->trans[i], c);
215 for (j = 0; dd->sorted_moves[j] != NULLMOVE; j++) {
216 mm = dd->sorted_moves[j];
217 dd->m++;
218 genptable_dfs(apply_move(mm, cc), pd, dd);
219 dd->m--;
220 }
221 }
222}
223*/
224
225/*
226static bool
227dfs_get_visited(PruneData *pd, DfsData *dd, Cube c)
228{
229 return dfs_get_visited_index(dd, pd->coord->index(c));
230}
231*/
232
233/*
234static bool
235dfs_get_visited_index(DfsData *dd, uint64_t ind)
236{
237 return dd->visited[ind/8] & ((uint8_t)1 << (ind % 8));
238}
239*/
240
241/*
242static void
243dfs_set_visited(PruneData *pd, DfsData *dd, Cube c, bool b)
244{
245 dfs_set_visited_index(dd, pd->coord->index(c), b);
246}
247*/
248
249/*
250static void
251dfs_set_visited_index(DfsData *dd, uint64_t ind, bool b)
252{
253 if (b)
254 dd->visited[ind/8] |= ((uint8_t)1 << (ind % 8));
255 else
256 dd->visited[ind/8] &= ~((uint8_t)1 << (ind % 8));
130} 257}
258*/
131 259
132static void 260static void
133genptable_bfs(PruneData *pd, int d, Move *ms) 261genptable_bfs(PruneData *pd, int d, Move *ms)
@@ -145,22 +273,9 @@ genptable_branch(PruneData *pd, uint64_t ind, int d, Move *ms)
145 int i, j; 273 int i, j;
146 Cube ci, cc, c; 274 Cube ci, cc, c;
147 275
148 /*
149 * This is the only line of the whole program where we REALLY need an
150 * anti-indexer function. We could get rid of it if only we could save
151 * a cube object for each index value as we go, but then we would need
152 * an incredible amount of memory to generate each ptable: assuming
153 * fields in struct cube are 32 bit ints that would take 88 times the
154 * memory of the table to be generated, more than 120Gb for
155 * ptable_khuge for example!
156 *
157 * TODO: it would be nice to get rid of this...
158 *
159 */
160 ci = pd->coord->cube(ind); 276 ci = pd->coord->cube(ind);
161 277
162 for (i = 0; i < pd->coord->ntrans; i++) { 278 for (i = 0; i < pd->coord->ntrans; i++) {
163 /* For simplicity trans[] is NULL when ntrans = 1 */
164 c = i == 0 ? ci : 279 c = i == 0 ? ci :
165 apply_trans(pd->coord->trans[i], ci); 280 apply_trans(pd->coord->trans[i], ci);
166 for (j = 0; ms[j] != NULLMOVE; j++) { 281 for (j = 0; ms[j] != NULLMOVE; j++) {

Generated with cgit - Back to sebastiano.tronto.net