From 0ece4b72db22139db51e8f5f37c25f24c84f3e43 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 17 Apr 2025 10:50:57 +0200 Subject: Small rework of optimal vs maxsols I wanted to make the "optimal" and "maxsolutions" options mutually exclusive, but in the end I decided there is value in keeping both (e.g. for specifying a limit to the number of solutions when asking for "all" optimal"). Now optimal cannot be negative anymore, for the same reason of maxsolutions. The interface user (shell, UI) will have to take care of handling this in a way that makes sense for the user. Usually this means setting the maximum number of solutions to UINT_MAX (or a similar very high number) when the user wants "all optimal". --- src/solvers/h48/solve.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/solvers/h48/solve.h') 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( solve_h48_task_t [static STARTING_CUBES], int [static 1]); STATIC void *solve_h48_runthread(void *); STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t [static 1]); -STATIC int64_t solve_h48(cube_t, int8_t, int8_t, uint64_t, int8_t, int8_t, +STATIC int64_t solve_h48(cube_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint64_t, const void *, size_t n, char [n], long long [static NISSY_SIZE_SOLVE_STATS]); @@ -67,7 +67,9 @@ solve_h48_stop(dfsarg_solve_h48_t arg[static 1]) n = arg->solution_moves->nmoves + arg->solution_moves->npremoves; target = arg->target_depth - n; if (target <= 0 || - arg->solution_list->nsols == arg->solution_settings->maxsolutions) + arg->solution_list->nsols >= arg->solution_settings->maxsolutions || + n > arg->solution_list->shortest_sol + + arg->solution_settings->optimal) return true; arg->movemask_normal = arg->movemask_inverse = MM_ALLMOVES; @@ -283,8 +285,8 @@ solve_h48_maketasks( if (issolved(maketasks_arg->cube)) { if (maketasks_arg->nmoves > maketasks_arg->maxmoves || maketasks_arg->nmoves < maketasks_arg->minmoves || - solve_arg->solution_list->nsols >= - solve_arg->solution_settings->maxsolutions) + solutions_done(solve_arg->solution_list, + solve_arg->solution_settings, maketasks_arg->nmoves)) return NISSY_OK; solution_moves_reset(&moves); @@ -341,11 +343,11 @@ solve_h48_maketasks( STATIC int64_t solve_h48( cube_t cube, - int8_t minmoves, - int8_t maxmoves, - uint64_t maxsolutions, - int8_t optimal, - int8_t threads, + uint8_t minmoves, + uint8_t maxmoves, + uint8_t maxsolutions, + uint8_t optimal, + uint8_t threads, uint64_t data_size, const void *data, size_t solutions_size, @@ -448,7 +450,7 @@ solve_h48( solve_h48_maketasks(&arg[0], &maketasks_arg, tasks, &ntasks); if (ntasks < 0) goto solve_h48_error_solutions_buffer; - if (sollist.nsols >= maxsolutions) + if (solutions_done(&sollist, &settings, MAX(minmoves, STARTING_MOVES))) goto solve_h48_done; for (i = 0; i < threads; i++) { -- cgit v1.3