commit dc5e8188a7e29909cbdf661e9b2a80700fe0491d
parent b25a939e2d8b045c083caf3264c4e5aac1cf88fb
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Tue, 15 Apr 2025 16:00:44 +0200
Log solutions as they are found
Diffstat:
3 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h
@@ -120,7 +120,7 @@ solve_coord_dfs(dfsarg_solve_coord_t arg[static 1])
if (!coord_solution_admissible(arg))
return 0;
return appendsolution(arg->solution_moves,
- arg->solution_settings, arg->solution_list);
+ arg->solution_settings, arg->solution_list, true);
}
if (solve_coord_dfs_stop(arg))
@@ -316,7 +316,7 @@ solve_coord(
if (coord->coord(c, coord_data) == 0) {
if (minmoves == 0 && !appendsolution(
- &solution_moves, &solution_settings, &solution_list))
+ &solution_moves, &solution_settings, &solution_list, true))
goto solve_coord_error_buffer;
goto solve_coord_done;
}
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h
@@ -160,7 +160,7 @@ solve_h48_dfs(dfsarg_solve_h48_t arg[static 1])
return 0;
pthread_mutex_lock(arg->solutions_mutex);
ret = appendsolution(arg->solution_moves,
- arg->solution_settings, arg->solution_list);
+ arg->solution_settings, arg->solution_list, true);
pthread_mutex_unlock(arg->solutions_mutex);
return ret;
}
@@ -292,8 +292,8 @@ solve_h48_maketasks(
memcpy(moves.moves,
maketasks_arg->moves, maketasks_arg->nmoves);
- appret = appendsolution(&moves,
- solve_arg->solution_settings, solve_arg->solution_list);
+ appret = appendsolution(&moves, solve_arg->solution_settings,
+ solve_arg->solution_list, true);
return appret < 0 ? appret : NISSY_OK;
}
diff --git a/src/solvers/solutions.h b/src/solvers/solutions.h
@@ -7,7 +7,7 @@ STATIC bool solution_moves_equal(
STATIC bool solution_moves_is_duplicate(size_t n, const solution_moves_t[n+1]);
STATIC bool appendchar(solution_list_t [static 1], char);
STATIC int64_t appendsolution(const solution_moves_t [static 1],
- const solution_settings_t [static 1], solution_list_t [static 1]);
+ const solution_settings_t [static 1], solution_list_t [static 1], bool);
STATIC bool solutions_done(const solution_list_t [static 1],
const solution_settings_t [static 1], int8_t depth);
@@ -99,13 +99,15 @@ STATIC int64_t
appendsolution(
const solution_moves_t moves[static 1],
const solution_settings_t settings[static 1],
- solution_list_t list[static 1]
+ solution_list_t list[static 1],
+ bool log
)
{
int64_t r, strl;
int i;
uint8_t t;
solution_moves_t tsol[NTRANS];
+ char *last_start;
if (moves->nmoves + moves->npremoves > MAXLEN)
goto appendsolution_error_solution_length;
@@ -147,6 +149,8 @@ appendsolution(
if (solution_moves_is_duplicate(r, tsol))
continue;
+ last_start = list->buf + list->used;
+
/* Write moves on normal */
strl = writemoves(tsol[r].nmoves, tsol[r].moves,
list->size - list->used, list->buf + list->used);
@@ -179,6 +183,13 @@ appendsolution(
list->shortest_sol = MIN(
list->shortest_sol, tsol[r].nmoves + tsol[r].npremoves);
r++;
+
+ if (log) {
+ list->buf[list->used-1] = '\0';
+ LOG("Found solution #%" PRIu64 ": %s\n",
+ list->nsols, last_start);
+ list->buf[list->used-1] = '\n';
+ }
}
list->buf[list->used] = '\0';