aboutsummaryrefslogtreecommitdiff
path: root/src/solvers
diff options
context:
space:
mode:
Diffstat (limited to 'src/solvers')
-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
4 files changed, 23 insertions, 29 deletions
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