aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-15 08:29:37 +0100
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-15 08:29:37 +0100
commit20ac0e60d7174114965d4419af0bb3028db8e447 (patch)
treeb94184b39965aa3cd74f4e5e2cec988603f224f4
parent44beaa88e54d60d5c576380534cf5ebb8dd44709 (diff)
downloadnissy-20ac0e60d7174114965d4419af0bb3028db8e447.tar.gz
nissy-20ac0e60d7174114965d4419af0bb3028db8e447.zip
Load all necessary pruning tables for a step before the actual solving process
starts. This is in preparation for multi-threaded solving (but don't get hyped, it will take time).
-rw-r--r--src/cubetypes.h2
-rw-r--r--src/pruning.c7
-rw-r--r--src/solve.c29
-rw-r--r--src/solve.h1
-rw-r--r--src/steps.c142
-rw-r--r--src/steps.h2
6 files changed, 162 insertions, 21 deletions
diff --git a/src/cubetypes.h b/src/cubetypes.h
index da8ab6b..4997f3a 100644
--- a/src/cubetypes.h
+++ b/src/cubetypes.h
@@ -268,6 +268,8 @@ step
268 Moveset moveset; 268 Moveset moveset;
269 Trans pre_trans; 269 Trans pre_trans;
270 TransDetector detect; 270 TransDetector detect;
271 int ntables;
272 PruneData * tables[10];
271}; 273};
272 274
273struct 275struct
diff --git a/src/pruning.c b/src/pruning.c
index 6165e71..11705c5 100644
--- a/src/pruning.c
+++ b/src/pruning.c
@@ -338,8 +338,13 @@ ptableval(PruneData *pd, Cube cube)
338static int 338static int
339ptableval_index(PruneData *pd, uint64_t ind) 339ptableval_index(PruneData *pd, uint64_t ind)
340{ 340{
341 if (!pd->generated) 341 if (!pd->generated) {
342 fprintf(stderr, "Warning: request pruning table value"
343 " for uninitialized table %s.\n It's fine, but it"
344 " should not happen. Please report bug.\n",
345 pd->filename);
342 genptable(pd); 346 genptable(pd);
347 }
343 348
344 return (ind % 2) ? pd->ptable[ind/2] / 16 : pd->ptable[ind/2] % 16; 349 return (ind % 2) ? pd->ptable[ind/2] / 16 : pd->ptable[ind/2] % 16;
345} 350}
diff --git a/src/solve.c b/src/solve.c
index 1f4a155..29f614b 100644
--- a/src/solve.c
+++ b/src/solve.c
@@ -127,47 +127,36 @@ AlgList *
127solve(Cube cube, Step *step, SolveOptions *opts) 127solve(Cube cube, Step *step, SolveOptions *opts)
128{ 128{
129 AlgListNode *node; 129 AlgListNode *node;
130 AlgList *sols = new_alglist(); 130 DfsData dd;
131 Cube c; 131 Cube c;
132 132
133 prepare_step(step, &dd);
134
133 if (step->detect != NULL) 135 if (step->detect != NULL)
134 step->pre_trans = step->detect(cube); 136 step->pre_trans = step->detect(cube);
135 c = apply_trans(step->pre_trans, cube); 137 c = apply_trans(step->pre_trans, cube);
136 138
137 DfsData dd = {
138 .m = 0,
139 .niss = false,
140 .lb = -1,
141 .last1 = NULLMOVE,
142 .last2 = NULLMOVE,
143 .sols = sols,
144 .current_alg = new_alg("")
145 };
146
147 if (step->ready != NULL && !step->ready(c)) { 139 if (step->ready != NULL && !step->ready(c)) {
148 fprintf(stderr, "Cube not ready for solving step: "); 140 fprintf(stderr, "Cube not ready for solving step: ");
149 fprintf(stderr, "%s\n", step->ready_msg); 141 fprintf(stderr, "%s\n", step->ready_msg);
150 return sols; 142 return dd.sols;
151 } 143 }
152 144
153 moveset_to_list(step->moveset, dd.sorted_moves);
154 movelist_to_position(dd.sorted_moves, dd.move_position);
155
156 for (dd.d = opts->min_moves; 145 for (dd.d = opts->min_moves;
157 dd.d <= opts->max_moves && 146 dd.d <= opts->max_moves &&
158 !(sols->len && opts->optimal_only) && 147 !(dd.sols->len && opts->optimal_only) &&
159 sols->len < opts->max_solutions; 148 dd.sols->len < opts->max_solutions;
160 dd.d++) { 149 dd.d++) {
161 if (opts->verbose) 150 if (opts->verbose)
162 fprintf(stderr, 151 fprintf(stderr,
163 "Found %d solutions, searching depth %d...\n", 152 "Found %d solutions, searching depth %d...\n",
164 sols->len, dd.d); 153 dd.sols->len, dd.d);
165 dfs(c, step, opts, &dd); 154 dfs(c, step, opts, &dd);
166 } 155 }
167 156
168 for (node = sols->first; node != NULL; node = node->next) 157 for (node = dd.sols->first; node != NULL; node = node->next)
169 transform_alg(inverse_trans(step->pre_trans), node->alg); 158 transform_alg(inverse_trans(step->pre_trans), node->alg);
170 159
171 free_alg(dd.current_alg); 160 free_alg(dd.current_alg);
172 return sols; 161 return dd.sols;
173} 162}
diff --git a/src/solve.h b/src/solve.h
index ff84e7e..668cd9a 100644
--- a/src/solve.h
+++ b/src/solve.h
@@ -2,6 +2,7 @@
2#define SOLVE_H 2#define SOLVE_H
3 3
4#include "moves.h" 4#include "moves.h"
5#include "steps.h"
5#include "trans.h" 6#include "trans.h"
6 7
7AlgList * solve(Cube cube, Step *step, SolveOptions *opts); 8AlgList * solve(Cube cube, Step *step, SolveOptions *opts);
diff --git a/src/steps.c b/src/steps.c
index f6b7403..012e4cd 100644
--- a/src/steps.c
+++ b/src/steps.c
@@ -56,6 +56,9 @@ optimal_HTM = {
56 .moveset = moveset_HTM, 56 .moveset = moveset_HTM,
57 57
58 .pre_trans = uf, 58 .pre_trans = uf,
59
60 .tables = {&pd_khuge_HTM, &pd_corners_HTM},
61 .ntables = 2,
59}; 62};
60 63
61/* EO steps **************************/ 64/* EO steps **************************/
@@ -71,6 +74,9 @@ eoany_HTM = {
71 .moveset = moveset_HTM, 74 .moveset = moveset_HTM,
72 75
73 .pre_trans = uf, 76 .pre_trans = uf,
77
78 .tables = {&pd_eofb_HTM},
79 .ntables = 1,
74}; 80};
75 81
76Step 82Step
@@ -85,6 +91,9 @@ eofb_HTM = {
85 .moveset = moveset_HTM, 91 .moveset = moveset_HTM,
86 92
87 .pre_trans = uf, 93 .pre_trans = uf,
94
95 .tables = {&pd_eofb_HTM},
96 .ntables = 1,
88}; 97};
89 98
90Step 99Step
@@ -99,6 +108,9 @@ eorl_HTM = {
99 .moveset = moveset_HTM, 108 .moveset = moveset_HTM,
100 109
101 .pre_trans = ur, 110 .pre_trans = ur,
111
112 .tables = {&pd_eofb_HTM},
113 .ntables = 1,
102}; 114};
103 115
104Step 116Step
@@ -113,6 +125,9 @@ eoud_HTM = {
113 .moveset = moveset_HTM, 125 .moveset = moveset_HTM,
114 126
115 .pre_trans = fd, 127 .pre_trans = fd,
128
129 .tables = {&pd_eofb_HTM},
130 .ntables = 1,
116}; 131};
117 132
118/* CO steps **************************/ 133/* CO steps **************************/
@@ -127,6 +142,9 @@ coany_HTM = {
127 .moveset = moveset_HTM, 142 .moveset = moveset_HTM,
128 143
129 .pre_trans = uf, 144 .pre_trans = uf,
145
146 .tables = {&pd_coud_HTM},
147 .ntables = 1,
130}; 148};
131 149
132Step 150Step
@@ -140,6 +158,9 @@ coud_HTM = {
140 .moveset = moveset_HTM, 158 .moveset = moveset_HTM,
141 159
142 .pre_trans = uf, 160 .pre_trans = uf,
161
162 .tables = {&pd_coud_HTM},
163 .ntables = 1,
143}; 164};
144 165
145Step 166Step
@@ -153,6 +174,9 @@ corl_HTM = {
153 .moveset = moveset_HTM, 174 .moveset = moveset_HTM,
154 175
155 .pre_trans = rf, 176 .pre_trans = rf,
177
178 .tables = {&pd_coud_HTM},
179 .ntables = 1,
156}; 180};
157 181
158Step 182Step
@@ -166,6 +190,9 @@ cofb_HTM = {
166 .moveset = moveset_HTM, 190 .moveset = moveset_HTM,
167 191
168 .pre_trans = fd, 192 .pre_trans = fd,
193
194 .tables = {&pd_coud_HTM},
195 .ntables = 1,
169}; 196};
170 197
171Step 198Step
@@ -179,6 +206,9 @@ coany_URF = {
179 .moveset = moveset_URF, 206 .moveset = moveset_URF,
180 207
181 .pre_trans = uf, 208 .pre_trans = uf,
209
210 .tables = {&pd_coud_HTM},
211 .ntables = 1,
182}; 212};
183 213
184Step 214Step
@@ -192,6 +222,9 @@ coud_URF = {
192 .moveset = moveset_URF, 222 .moveset = moveset_URF,
193 223
194 .pre_trans = uf, 224 .pre_trans = uf,
225
226 .tables = {&pd_coud_HTM},
227 .ntables = 1,
195}; 228};
196 229
197Step 230Step
@@ -205,6 +238,9 @@ corl_URF = {
205 .moveset = moveset_URF, 238 .moveset = moveset_URF,
206 239
207 .pre_trans = rf, 240 .pre_trans = rf,
241
242 .tables = {&pd_coud_HTM},
243 .ntables = 1,
208}; 244};
209 245
210Step 246Step
@@ -218,6 +254,9 @@ cofb_URF = {
218 .moveset = moveset_URF, 254 .moveset = moveset_URF,
219 255
220 .pre_trans = fd, 256 .pre_trans = fd,
257
258 .tables = {&pd_coud_HTM},
259 .ntables = 1,
221}; 260};
222 261
223/* Misc corner steps *****************/ 262/* Misc corner steps *****************/
@@ -232,6 +271,9 @@ cornershtr_HTM = {
232 .moveset = moveset_HTM, 271 .moveset = moveset_HTM,
233 272
234 .pre_trans = uf, 273 .pre_trans = uf,
274
275 .tables = {&pd_cornershtr_HTM},
276 .ntables = 1,
235}; 277};
236 278
237Step 279Step
@@ -245,6 +287,9 @@ cornershtr_URF = {
245 .moveset = moveset_URF, 287 .moveset = moveset_URF,
246 288
247 .pre_trans = uf, 289 .pre_trans = uf,
290
291 .tables = {&pd_cornershtr_HTM},
292 .ntables = 1,
248}; 293};
249 294
250Step 295Step
@@ -258,6 +303,9 @@ corners_HTM = {
258 .moveset = moveset_HTM, 303 .moveset = moveset_HTM,
259 304
260 .pre_trans = uf, 305 .pre_trans = uf,
306
307 .tables = {&pd_corners_HTM},
308 .ntables = 1,
261}; 309};
262 310
263Step 311Step
@@ -271,6 +319,9 @@ corners_URF = {
271 .moveset = moveset_URF, 319 .moveset = moveset_URF,
272 320
273 .pre_trans = uf, 321 .pre_trans = uf,
322
323 .tables = {&pd_corners_HTM},
324 .ntables = 1,
274}; 325};
275 326
276/* DR steps **************************/ 327/* DR steps **************************/
@@ -286,6 +337,9 @@ drany_HTM = {
286 .moveset = moveset_HTM, 337 .moveset = moveset_HTM,
287 338
288 .pre_trans = uf, 339 .pre_trans = uf,
340
341 .tables = {&pd_drud_sym16_HTM},
342 .ntables = 1,
289}; 343};
290 344
291Step 345Step
@@ -300,6 +354,9 @@ drud_HTM = {
300 .moveset = moveset_HTM, 354 .moveset = moveset_HTM,
301 355
302 .pre_trans = uf, 356 .pre_trans = uf,
357
358 .tables = {&pd_drud_sym16_HTM},
359 .ntables = 1,
303}; 360};
304 361
305Step 362Step
@@ -314,6 +371,9 @@ drrl_HTM = {
314 .moveset = moveset_HTM, 371 .moveset = moveset_HTM,
315 372
316 .pre_trans = rf, 373 .pre_trans = rf,
374
375 .tables = {&pd_drud_sym16_HTM},
376 .ntables = 1,
317}; 377};
318 378
319Step 379Step
@@ -328,6 +388,9 @@ drfb_HTM = {
328 .moveset = moveset_HTM, 388 .moveset = moveset_HTM,
329 389
330 .pre_trans = fd, 390 .pre_trans = fd,
391
392 .tables = {&pd_drud_sym16_HTM},
393 .ntables = 1,
331}; 394};
332 395
333/* DR from EO */ 396/* DR from EO */
@@ -343,6 +406,9 @@ dr_eo = {
343 .moveset = moveset_eofb, 406 .moveset = moveset_eofb,
344 407
345 .detect = detect_pretrans_eofb, 408 .detect = detect_pretrans_eofb,
409
410 .tables = {&pd_drud_eofb},
411 .ntables = 1,
346}; 412};
347 413
348Step 414Step
@@ -357,6 +423,9 @@ dr_eofb = {
357 .moveset = moveset_eofb, 423 .moveset = moveset_eofb,
358 424
359 .pre_trans = uf, 425 .pre_trans = uf,
426
427 .tables = {&pd_drud_eofb},
428 .ntables = 1,
360}; 429};
361 430
362Step 431Step
@@ -371,6 +440,9 @@ dr_eorl = {
371 .moveset = moveset_eofb, 440 .moveset = moveset_eofb,
372 441
373 .pre_trans = ur, 442 .pre_trans = ur,
443
444 .tables = {&pd_drud_eofb},
445 .ntables = 1,
374}; 446};
375 447
376Step 448Step
@@ -385,6 +457,9 @@ dr_eoud = {
385 .moveset = moveset_eofb, 457 .moveset = moveset_eofb,
386 458
387 .pre_trans = fd, 459 .pre_trans = fd,
460
461 .tables = {&pd_drud_eofb},
462 .ntables = 1,
388}; 463};
389 464
390Step 465Step
@@ -399,6 +474,9 @@ drud_eofb = {
399 .moveset = moveset_eofb, 474 .moveset = moveset_eofb,
400 475
401 .pre_trans = uf, 476 .pre_trans = uf,
477
478 .tables = {&pd_drud_eofb},
479 .ntables = 1,
402}; 480};
403 481
404Step 482Step
@@ -413,6 +491,9 @@ drrl_eofb = {
413 .moveset = moveset_eofb, 491 .moveset = moveset_eofb,
414 492
415 .pre_trans = rf, 493 .pre_trans = rf,
494
495 .tables = {&pd_drud_eofb},
496 .ntables = 1,
416}; 497};
417 498
418Step 499Step
@@ -427,6 +508,9 @@ drud_eorl = {
427 .moveset = moveset_eofb, 508 .moveset = moveset_eofb,
428 509
429 .pre_trans = ur, 510 .pre_trans = ur,
511
512 .tables = {&pd_drud_eofb},
513 .ntables = 1,
430}; 514};
431 515
432Step 516Step
@@ -441,6 +525,9 @@ drfb_eorl = {
441 .moveset = moveset_eofb, 525 .moveset = moveset_eofb,
442 526
443 .pre_trans = fr, 527 .pre_trans = fr,
528
529 .tables = {&pd_drud_eofb},
530 .ntables = 1,
444}; 531};
445 532
446Step 533Step
@@ -455,6 +542,9 @@ drfb_eoud = {
455 .moveset = moveset_eofb, 542 .moveset = moveset_eofb,
456 543
457 .pre_trans = fd, 544 .pre_trans = fd,
545
546 .tables = {&pd_drud_eofb},
547 .ntables = 1,
458}; 548};
459 549
460Step 550Step
@@ -469,6 +559,9 @@ drrl_eoud = {
469 .moveset = moveset_eofb, 559 .moveset = moveset_eofb,
470 560
471 .pre_trans = rd, 561 .pre_trans = rd,
562
563 .tables = {&pd_drud_eofb},
564 .ntables = 1,
472}; 565};
473 566
474/* DR finish steps */ 567/* DR finish steps */
@@ -484,6 +577,9 @@ dranyfin_DR = {
484 .moveset = moveset_drud, 577 .moveset = moveset_drud,
485 578
486 .detect = detect_pretrans_drud, 579 .detect = detect_pretrans_drud,
580
581 .tables = {&pd_drudfin_noE_sym16_drud},
582 .ntables = 1,
487}; 583};
488 584
489Step 585Step
@@ -498,6 +594,9 @@ drudfin_drud = {
498 .moveset = moveset_drud, 594 .moveset = moveset_drud,
499 595
500 .pre_trans = uf, 596 .pre_trans = uf,
597
598 .tables = {&pd_drudfin_noE_sym16_drud},
599 .ntables = 1,
501}; 600};
502 601
503Step 602Step
@@ -512,6 +611,9 @@ drrlfin_drrl = {
512 .moveset = moveset_drud, 611 .moveset = moveset_drud,
513 612
514 .pre_trans = rf, 613 .pre_trans = rf,
614
615 .tables = {&pd_drudfin_noE_sym16_drud},
616 .ntables = 1,
515}; 617};
516 618
517Step 619Step
@@ -526,6 +628,9 @@ drfbfin_drfb = {
526 .moveset = moveset_drud, 628 .moveset = moveset_drud,
527 629
528 .pre_trans = fd, 630 .pre_trans = fd,
631
632 .tables = {&pd_drudfin_noE_sym16_drud},
633 .ntables = 1,
529}; 634};
530 635
531/* HTR from DR */ 636/* HTR from DR */
@@ -541,6 +646,9 @@ htr_any = {
541 .moveset = moveset_drud, 646 .moveset = moveset_drud,
542 647
543 .detect = detect_pretrans_drud, 648 .detect = detect_pretrans_drud,
649
650 .tables = {&pd_htr_drud},
651 .ntables = 1,
544}; 652};
545 653
546Step 654Step
@@ -555,6 +663,9 @@ htr_drud = {
555 .moveset = moveset_drud, 663 .moveset = moveset_drud,
556 664
557 .pre_trans = uf, 665 .pre_trans = uf,
666
667 .tables = {&pd_htr_drud},
668 .ntables = 1,
558}; 669};
559 670
560Step 671Step
@@ -569,6 +680,9 @@ htr_drrl = {
569 .moveset = moveset_drud, 680 .moveset = moveset_drud,
570 681
571 .pre_trans = rf, 682 .pre_trans = rf,
683
684 .tables = {&pd_htr_drud},
685 .ntables = 1,
572}; 686};
573 687
574Step 688Step
@@ -583,6 +697,9 @@ htr_drfb = {
583 .moveset = moveset_drud, 697 .moveset = moveset_drud,
584 698
585 .pre_trans = fd, 699 .pre_trans = fd,
700
701 .tables = {&pd_htr_drud},
702 .ntables = 1,
586}; 703};
587 704
588/* HTR finish */ 705/* HTR finish */
@@ -598,6 +715,9 @@ htrfin_htr = {
598 .moveset = moveset_htr, 715 .moveset = moveset_htr,
599 716
600 .pre_trans = uf, 717 .pre_trans = uf,
718
719 .tables = {&pd_htrfin_htr},
720 .ntables = 1,
601}; 721};
602 722
603Step *steps[NSTEPS] = { 723Step *steps[NSTEPS] = {
@@ -939,3 +1059,25 @@ detect_pretrans_drud(Cube cube)
939 1059
940 return 0; 1060 return 0;
941} 1061}
1062
1063/* Public functions **********************************************************/
1064
1065void
1066prepare_step(Step *step, DfsData *dd)
1067{
1068 int i;
1069
1070 dd->m = 0;
1071 dd->niss = false;
1072 dd->lb = -1;
1073 dd->last1 = NULLMOVE;
1074 dd->last2 = NULLMOVE;
1075 dd->sols = new_alglist();
1076 dd->current_alg = new_alg("");
1077
1078 moveset_to_list(step->moveset, dd->sorted_moves);
1079 movelist_to_position(dd->sorted_moves, dd->move_position);
1080
1081 for (i = 0; i < step->ntables; i++)
1082 genptable(step->tables[i]);
1083}
diff --git a/src/steps.h b/src/steps.h
index aa3178c..89ab168 100644
--- a/src/steps.h
+++ b/src/steps.h
@@ -7,4 +7,6 @@
7 7
8extern Step * steps[NSTEPS]; 8extern Step * steps[NSTEPS];
9 9
10void prepare_step(Step *step, DfsData *dd);
11
10#endif 12#endif

Generated with cgit - Back to sebastiano.tronto.net