aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/nissy.c12
-rw-r--r--src/nissy.h7
-rw-r--r--src/solvers/coord/solve.h13
-rw-r--r--src/solvers/h48/solve.h22
-rw-r--r--src/solvers/solutions.h15
-rw-r--r--src/solvers/solutions_types_macros.h2
6 files changed, 31 insertions, 40 deletions
diff --git a/src/nissy.c b/src/nissy.c
index a7f8432..ba43e5d 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -534,8 +534,8 @@ nissy_solve(
534 unsigned minmoves, 534 unsigned minmoves,
535 unsigned maxmoves, 535 unsigned maxmoves,
536 unsigned maxsols, 536 unsigned maxsols,
537 int optimal, 537 unsigned optimal,
538 int threads, 538 unsigned threads,
539 unsigned long long data_size, 539 unsigned long long data_size,
540 const char data[data_size], 540 const char data[data_size],
541 unsigned sols_size, 541 unsigned sols_size,
@@ -546,7 +546,7 @@ nissy_solve(
546 cube_t c; 546 cube_t c;
547 long long parse_ret; 547 long long parse_ret;
548 uint8_t h, k; 548 uint8_t h, k;
549 int t, opt; 549 int t;
550 550
551 if (solver == NULL) { 551 if (solver == NULL) {
552 LOG("Error: 'solver' argument is NULL\n"); 552 LOG("Error: 'solver' argument is NULL\n");
@@ -573,8 +573,6 @@ nissy_solve(
573 return 0; 573 return 0;
574 } 574 }
575 575
576 opt = optimal < 0 ? MAXLEN : optimal;
577
578 t = threads == 0 ? THREADS : threads; 576 t = threads == 0 ? THREADS : threads;
579 if (t < 0) { 577 if (t < 0) {
580 LOG("solve: 'threads' is negative. Please provide a " 578 LOG("solve: 'threads' is negative. Please provide a "
@@ -597,10 +595,10 @@ nissy_solve(
597 if (parse_ret != NISSY_OK) 595 if (parse_ret != NISSY_OK)
598 return parse_ret; 596 return parse_ret;
599 return solve_h48(c, minmoves, maxmoves, maxsols, 597 return solve_h48(c, minmoves, maxmoves, maxsols,
600 opt, t, data_size, data, sols_size, sols, stats); 598 optimal, t, data_size, data, sols_size, sols, stats);
601 } else if (!strncmp(solver, "coord_", 6)) { 599 } else if (!strncmp(solver, "coord_", 6)) {
602 return solve_coord_dispatch(c, solver + 6, nissflag, 600 return solve_coord_dispatch(c, solver + 6, nissflag,
603 minmoves, maxmoves, maxsols, opt, t, data_size, data, 601 minmoves, maxmoves, maxsols, optimal, t, data_size, data,
604 sols_size, sols); 602 sols_size, sols);
605 } else { 603 } else {
606 LOG("solve: unknown solver '%s'\n", solver); 604 LOG("solve: unknown solver '%s'\n", solver);
diff --git a/src/nissy.h b/src/nissy.h
index b13f417..c23f338 100644
--- a/src/nissy.h
+++ b/src/nissy.h
@@ -360,8 +360,7 @@ Parameters:
360 minmoves - The minimum number of moves for a solution. 360 minmoves - The minimum number of moves for a solution.
361 maxmoves - The maximum number of moves for a solution. 361 maxmoves - The maximum number of moves for a solution.
362 maxsols - The maximum number of solutions. 362 maxsols - The maximum number of solutions.
363 optimal - If set to a non-negative value, the maximum number of moves 363 optimal - The maximum number of moves above the optimal solution length.
364 above the optimal solution length.
365 threads - The number of threads to use. Must be less than or equalt to 364 threads - The number of threads to use. Must be less than or equalt to
366 the value of the compile-time constant THREADS. If set to 0, 365 the value of the compile-time constant THREADS. If set to 0,
367 the default value THREADS will be used. 366 the default value THREADS will be used.
@@ -393,8 +392,8 @@ nissy_solve(
393 unsigned minmoves, 392 unsigned minmoves,
394 unsigned maxmoves, 393 unsigned maxmoves,
395 unsigned maxsolutions, 394 unsigned maxsolutions,
396 int optimal, 395 unsigned optimal,
397 int threads, 396 unsigned threads,
398 unsigned long long data_size, 397 unsigned long long data_size,
399 const char data[data_size], 398 const char data[data_size],
400 unsigned sols_size, 399 unsigned sols_size,
diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h
index 464f7bd..b289e3f 100644
--- a/src/solvers/coord/solve.h
+++ b/src/solvers/coord/solve.h
@@ -13,10 +13,11 @@ typedef struct {
13} dfsarg_solve_coord_t; 13} dfsarg_solve_coord_t;
14 14
15STATIC int64_t solve_coord(cube_t, coord_t [static 1], uint8_t, uint8_t, 15STATIC int64_t solve_coord(cube_t, coord_t [static 1], uint8_t, uint8_t,
16 uint8_t, uint8_t, uint64_t, int8_t, int, uint64_t, const void *, 16 uint8_t, uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, const void *,
17 size_t n, char [n]); 17 size_t n, char [n]);
18STATIC int64_t solve_coord_dispatch(cube_t, const char *, uint8_t, uint8_t, 18STATIC int64_t solve_coord_dispatch(cube_t, const char *, uint8_t, uint8_t,
19 uint8_t, uint64_t, int8_t, int, uint64_t, const void *, size_t n, char [n]); 19 uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, const void *, size_t n,
20 char [n]);
20STATIC bool coord_solution_admissible(const dfsarg_solve_coord_t [static 1]); 21STATIC bool coord_solution_admissible(const dfsarg_solve_coord_t [static 1]);
21STATIC bool solve_coord_dfs_stop(const dfsarg_solve_coord_t [static 1]); 22STATIC bool solve_coord_dfs_stop(const dfsarg_solve_coord_t [static 1]);
22STATIC bool coord_continue_onnormal(const dfsarg_solve_coord_t [static 1]); 23STATIC bool coord_continue_onnormal(const dfsarg_solve_coord_t [static 1]);
@@ -204,8 +205,8 @@ solve_coord_dispatch(
204 uint8_t minmoves, 205 uint8_t minmoves,
205 uint8_t maxmoves, 206 uint8_t maxmoves,
206 uint64_t maxsolutions, 207 uint64_t maxsolutions,
207 int8_t optimal, 208 uint8_t optimal,
208 int threads, 209 uint8_t threads,
209 uint64_t data_size, 210 uint64_t data_size,
210 const void *data, 211 const void *data,
211 size_t solutions_size, 212 size_t solutions_size,
@@ -242,8 +243,8 @@ solve_coord(
242 uint8_t minmoves, 243 uint8_t minmoves,
243 uint8_t maxmoves, 244 uint8_t maxmoves,
244 uint64_t maxsolutions, 245 uint64_t maxsolutions,
245 int8_t optimal, 246 uint8_t optimal,
246 int threads, 247 uint8_t threads,
247 uint64_t data_size, 248 uint64_t data_size,
248 const void *data, 249 const void *data,
249 size_t solutions_size, 250 size_t solutions_size,
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h
index f076f11..78b4c97 100644
--- a/src/solvers/h48/solve.h
+++ b/src/solvers/h48/solve.h
@@ -52,7 +52,7 @@ STATIC int64_t solve_h48_maketasks(
52 solve_h48_task_t [static STARTING_CUBES], int [static 1]); 52 solve_h48_task_t [static STARTING_CUBES], int [static 1]);
53STATIC void *solve_h48_runthread(void *); 53STATIC void *solve_h48_runthread(void *);
54STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t [static 1]); 54STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t [static 1]);
55STATIC int64_t solve_h48(cube_t, int8_t, int8_t, uint64_t, int8_t, int8_t, 55STATIC int64_t solve_h48(cube_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t,
56 uint64_t, const void *, size_t n, char [n], 56 uint64_t, const void *, size_t n, char [n],
57 long long [static NISSY_SIZE_SOLVE_STATS]); 57 long long [static NISSY_SIZE_SOLVE_STATS]);
58 58
@@ -67,7 +67,9 @@ solve_h48_stop(dfsarg_solve_h48_t arg[static 1])
67 n = arg->solution_moves->nmoves + arg->solution_moves->npremoves; 67 n = arg->solution_moves->nmoves + arg->solution_moves->npremoves;
68 target = arg->target_depth - n; 68 target = arg->target_depth - n;
69 if (target <= 0 || 69 if (target <= 0 ||
70 arg->solution_list->nsols == arg->solution_settings->maxsolutions) 70 arg->solution_list->nsols >= arg->solution_settings->maxsolutions ||
71 n > arg->solution_list->shortest_sol +
72 arg->solution_settings->optimal)
71 return true; 73 return true;
72 74
73 arg->movemask_normal = arg->movemask_inverse = MM_ALLMOVES; 75 arg->movemask_normal = arg->movemask_inverse = MM_ALLMOVES;
@@ -283,8 +285,8 @@ solve_h48_maketasks(
283 if (issolved(maketasks_arg->cube)) { 285 if (issolved(maketasks_arg->cube)) {
284 if (maketasks_arg->nmoves > maketasks_arg->maxmoves || 286 if (maketasks_arg->nmoves > maketasks_arg->maxmoves ||
285 maketasks_arg->nmoves < maketasks_arg->minmoves || 287 maketasks_arg->nmoves < maketasks_arg->minmoves ||
286 solve_arg->solution_list->nsols >= 288 solutions_done(solve_arg->solution_list,
287 solve_arg->solution_settings->maxsolutions) 289 solve_arg->solution_settings, maketasks_arg->nmoves))
288 return NISSY_OK; 290 return NISSY_OK;
289 291
290 solution_moves_reset(&moves); 292 solution_moves_reset(&moves);
@@ -341,11 +343,11 @@ solve_h48_maketasks(
341STATIC int64_t 343STATIC int64_t
342solve_h48( 344solve_h48(
343 cube_t cube, 345 cube_t cube,
344 int8_t minmoves, 346 uint8_t minmoves,
345 int8_t maxmoves, 347 uint8_t maxmoves,
346 uint64_t maxsolutions, 348 uint8_t maxsolutions,
347 int8_t optimal, 349 uint8_t optimal,
348 int8_t threads, 350 uint8_t threads,
349 uint64_t data_size, 351 uint64_t data_size,
350 const void *data, 352 const void *data,
351 size_t solutions_size, 353 size_t solutions_size,
@@ -448,7 +450,7 @@ solve_h48(
448 solve_h48_maketasks(&arg[0], &maketasks_arg, tasks, &ntasks); 450 solve_h48_maketasks(&arg[0], &maketasks_arg, tasks, &ntasks);
449 if (ntasks < 0) 451 if (ntasks < 0)
450 goto solve_h48_error_solutions_buffer; 452 goto solve_h48_error_solutions_buffer;
451 if (sollist.nsols >= maxsolutions) 453 if (solutions_done(&sollist, &settings, MAX(minmoves, STARTING_MOVES)))
452 goto solve_h48_done; 454 goto solve_h48_done;
453 455
454 for (i = 0; i < threads; i++) { 456 for (i = 0; i < threads; i++) {
diff --git a/src/solvers/solutions.h b/src/solvers/solutions.h
index e65f299..95c1d1a 100644
--- a/src/solvers/solutions.h
+++ b/src/solvers/solutions.h
@@ -43,8 +43,6 @@ solution_list_init(solution_list_t sols[static 1], size_t n, char buf[n])
43 sols->size = n; 43 sols->size = n;
44 sols->used = 0; 44 sols->used = 0;
45 sols->buf = buf; 45 sols->buf = buf;
46
47 /* Ensure string buffer is NULL-terminated */
48 sols->buf[0] = '\0'; 46 sols->buf[0] = '\0';
49 47
50 return true; 48 return true;
@@ -215,15 +213,8 @@ solutions_done(
215 int8_t depth 213 int8_t depth
216) 214)
217{ 215{
218 if (list->nsols >= settings->maxsolutions)
219 return true;
220
221 if (depth > settings->maxmoves)
222 return true;
223 216
224 if (list->nsols > 0 && settings->optimal >= 0 && 217 return depth > settings->maxmoves ||
225 depth > list->shortest_sol + settings->optimal) 218 depth > list->shortest_sol + settings->optimal ||
226 return true; 219 list->nsols >= settings->maxsolutions;
227
228 return false;
229} 220}
diff --git a/src/solvers/solutions_types_macros.h b/src/solvers/solutions_types_macros.h
index 06e099b..9b1431f 100644
--- a/src/solvers/solutions_types_macros.h
+++ b/src/solvers/solutions_types_macros.h
@@ -12,7 +12,7 @@ typedef struct {
12 bool unniss; 12 bool unniss;
13 uint8_t maxmoves; 13 uint8_t maxmoves;
14 uint64_t maxsolutions; 14 uint64_t maxsolutions;
15 int8_t optimal; 15 uint8_t optimal;
16} solution_settings_t; 16} solution_settings_t;
17 17
18typedef struct { 18typedef struct {

Generated with cgit - Back to sebastiano.tronto.net