aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nissy.c8
-rw-r--r--src/solvers/h48/solve.h26
2 files changed, 24 insertions, 10 deletions
diff --git a/src/nissy.c b/src/nissy.c
index 5d009ba..c21abc0 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -500,7 +500,7 @@ nissy_solve(
500 cube_t c; 500 cube_t c;
501 long long parse_ret; 501 long long parse_ret;
502 uint8_t h, k; 502 uint8_t h, k;
503 int t; 503 int t, opt;
504 504
505 if (solver == NULL) { 505 if (solver == NULL) {
506 LOG("Error: 'solver' argument is NULL\n"); 506 LOG("Error: 'solver' argument is NULL\n");
@@ -524,6 +524,8 @@ nissy_solve(
524 return 0; 524 return 0;
525 } 525 }
526 526
527 opt = optimal < 0 ? MAXLEN : optimal;
528
527 t = threads == 0 ? THREADS : threads; 529 t = threads == 0 ? THREADS : threads;
528 if (t < 0) { 530 if (t < 0) {
529 LOG("solve: 'threads' is negative. Please provide a " 531 LOG("solve: 'threads' is negative. Please provide a "
@@ -539,8 +541,8 @@ nissy_solve(
539 if (!strncmp(solver, "h48", 3)) { 541 if (!strncmp(solver, "h48", 3)) {
540 parse_ret = parse_h48_solver(solver, &h, &k); 542 parse_ret = parse_h48_solver(solver, &h, &k);
541 if (parse_ret == NISSY_OK) 543 if (parse_ret == NISSY_OK)
542 return solve_h48(c, minmoves, maxmoves, maxsols, t, 544 return solve_h48(c, minmoves, maxmoves, maxsols, opt,
543 data_size, data, sols_size, sols, stats); 545 t, data_size, data, sols_size, sols, stats);
544 else 546 else
545 return parse_ret; 547 return parse_ret;
546 } else { 548 } else {
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h
index 0969c45..1ca294a 100644
--- a/src/solvers/h48/solve.h
+++ b/src/solvers/h48/solve.h
@@ -23,6 +23,8 @@ typedef struct {
23 bool use_lb_inverse; 23 bool use_lb_inverse;
24 _Atomic int64_t *nsols; 24 _Atomic int64_t *nsols;
25 int64_t maxsolutions; 25 int64_t maxsolutions;
26 int8_t *shortest_sol;
27 int8_t optimal;
26 uint8_t h; 28 uint8_t h;
27 uint8_t k; 29 uint8_t k;
28 uint8_t base; 30 uint8_t base;
@@ -38,7 +40,7 @@ typedef struct {
38 int64_t nodes_visited; 40 int64_t nodes_visited;
39 int64_t table_fallbacks; 41 int64_t table_fallbacks;
40 int64_t table_lookups; 42 int64_t table_lookups;
41 int threads; 43 int8_t threads;
42 int ntasks; 44 int ntasks;
43 solve_h48_task_t *tasks; 45 solve_h48_task_t *tasks;
44 int thread_id; 46 int thread_id;
@@ -51,6 +53,7 @@ typedef struct {
51 uint8_t moves[STARTING_MOVES]; 53 uint8_t moves[STARTING_MOVES];
52 int8_t minmoves; 54 int8_t minmoves;
53 int8_t maxmoves; 55 int8_t maxmoves;
56 int8_t *shortest_sol;
54} dfsarg_solve_h48_maketasks_t; 57} dfsarg_solve_h48_maketasks_t;
55 58
56STATIC int64_t solve_h48_appendsolution(dfsarg_solve_h48_t *); 59STATIC int64_t solve_h48_appendsolution(dfsarg_solve_h48_t *);
@@ -63,8 +66,9 @@ STATIC int64_t solve_h48_maketasks(
63 solve_h48_task_t [static STARTING_CUBES], int *); 66 solve_h48_task_t [static STARTING_CUBES], int *);
64STATIC void *solve_h48_runthread(void *); 67STATIC void *solve_h48_runthread(void *);
65STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t *); 68STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t *);
66STATIC int64_t solve_h48(cube_t, int8_t, int8_t, uint64_t, int, uint64_t, 69STATIC int64_t solve_h48(cube_t, int8_t, int8_t, uint64_t, int8_t, int8_t,
67 const void *, uint64_t, char *, long long [static NISSY_SIZE_SOLVE_STATS]); 70 uint64_t, const void *, uint64_t, char *,
71 long long [static NISSY_SIZE_SOLVE_STATS]);
68 72
69STATIC int64_t 73STATIC int64_t
70solve_h48_appendsolution(dfsarg_solve_h48_t *arg) 74solve_h48_appendsolution(dfsarg_solve_h48_t *arg)
@@ -73,7 +77,8 @@ solve_h48_appendsolution(dfsarg_solve_h48_t *arg)
73 int64_t ret; 77 int64_t ret;
74 uint64_t solstart; 78 uint64_t solstart;
75 79
76 if (*arg->nsols >= arg->maxsolutions) 80 if (*arg->nsols >= arg->maxsolutions ||
81 arg->nmoves + arg->npremoves > *arg->shortest_sol + arg->optimal)
77 return 0; 82 return 0;
78 83
79 solstart = *arg->solutions_used; 84 solstart = *arg->solutions_used;
@@ -98,6 +103,8 @@ solve_h48_appendsolution(dfsarg_solve_h48_t *arg)
98 if (!solve_h48_appendchar(arg, '\n')) 103 if (!solve_h48_appendchar(arg, '\n'))
99 goto solve_h48_appendsolution_error; 104 goto solve_h48_appendsolution_error;
100 (*arg->nsols)++; 105 (*arg->nsols)++;
106 *arg->shortest_sol =
107 MIN(*arg->shortest_sol, arg->nmoves + arg->npremoves);
101 ret++; 108 ret++;
102 } 109 }
103 110
@@ -408,7 +415,8 @@ solve_h48(
408 int8_t minmoves, 415 int8_t minmoves,
409 int8_t maxmoves, 416 int8_t maxmoves,
410 uint64_t maxsolutions, 417 uint64_t maxsolutions,
411 int threads, 418 int8_t optimal,
419 int8_t threads,
412 uint64_t data_size, 420 uint64_t data_size,
413 const void *data, 421 const void *data,
414 uint64_t solutions_size, 422 uint64_t solutions_size,
@@ -417,7 +425,7 @@ solve_h48(
417) 425)
418{ 426{
419 int i, ntasks, eoesep_table_index; 427 int i, ntasks, eoesep_table_index;
420 int8_t d; 428 int8_t d, shortest_sol;
421 _Atomic int64_t nsols; 429 _Atomic int64_t nsols;
422 dfsarg_solve_h48_t arg[THREADS]; 430 dfsarg_solve_h48_t arg[THREADS];
423 solve_h48_task_t tasks[STARTING_CUBES]; 431 solve_h48_task_t tasks[STARTING_CUBES];
@@ -463,12 +471,15 @@ solve_h48(
463 fallback2 = h48data + offset; 471 fallback2 = h48data + offset;
464 472
465 symmask = symmetry_mask(cube); 473 symmask = symmetry_mask(cube);
474 shortest_sol = MAXLEN+1;
466 for (i = 0; i < threads; i++) { 475 for (i = 0; i < threads; i++) {
467 arg[i] = (dfsarg_solve_h48_t) { 476 arg[i] = (dfsarg_solve_h48_t) {
468 .start_cube = cube, 477 .start_cube = cube,
469 .cube = cube, 478 .cube = cube,
470 .symmask0 = symmask, 479 .symmask0 = symmask,
471 .nsols = &nsols, 480 .nsols = &nsols,
481 .shortest_sol = &shortest_sol,
482 .optimal = optimal,
472 .maxsolutions = maxsolutions, 483 .maxsolutions = maxsolutions,
473 .h = info.h48h, 484 .h = info.h48h,
474 .k = info.bits, 485 .k = info.bits,
@@ -517,7 +528,8 @@ solve_h48(
517 528
518 for ( 529 for (
519 d = MAX(minmoves, STARTING_MOVES + 1); 530 d = MAX(minmoves, STARTING_MOVES + 1);
520 d <= maxmoves && nsols < (int64_t)maxsolutions; 531 d <= maxmoves && nsols < (int64_t)maxsolutions
532 && !(nsols != 0 && d > shortest_sol + optimal);
521 d++ 533 d++
522 ) { 534 ) {
523 if (d >= 10) 535 if (d >= 10)

Generated with cgit - Back to sebastiano.tronto.net