diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-15 16:00:44 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-15 16:00:44 +0200 |
| commit | dc5e8188a7e29909cbdf661e9b2a80700fe0491d (patch) | |
| tree | 855aa22b15faa235d3b3795cbc5644244324f8c5 /src | |
| parent | b25a939e2d8b045c083caf3264c4e5aac1cf88fb (diff) | |
| download | nissy-core-dc5e8188a7e29909cbdf661e9b2a80700fe0491d.tar.gz nissy-core-dc5e8188a7e29909cbdf661e9b2a80700fe0491d.zip | |
Log solutions as they are found
Diffstat (limited to 'src')
| -rw-r--r-- | src/solvers/coord/solve.h | 4 | ||||
| -rw-r--r-- | src/solvers/h48/solve.h | 6 | ||||
| -rw-r--r-- | src/solvers/solutions.h | 15 |
3 files changed, 18 insertions, 7 deletions
diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h index 8806d17..464f7bd 100644 --- 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]) | |||
| 120 | if (!coord_solution_admissible(arg)) | 120 | if (!coord_solution_admissible(arg)) |
| 121 | return 0; | 121 | return 0; |
| 122 | return appendsolution(arg->solution_moves, | 122 | return appendsolution(arg->solution_moves, |
| 123 | arg->solution_settings, arg->solution_list); | 123 | arg->solution_settings, arg->solution_list, true); |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | if (solve_coord_dfs_stop(arg)) | 126 | if (solve_coord_dfs_stop(arg)) |
| @@ -316,7 +316,7 @@ solve_coord( | |||
| 316 | 316 | ||
| 317 | if (coord->coord(c, coord_data) == 0) { | 317 | if (coord->coord(c, coord_data) == 0) { |
| 318 | if (minmoves == 0 && !appendsolution( | 318 | if (minmoves == 0 && !appendsolution( |
| 319 | &solution_moves, &solution_settings, &solution_list)) | 319 | &solution_moves, &solution_settings, &solution_list, true)) |
| 320 | goto solve_coord_error_buffer; | 320 | goto solve_coord_error_buffer; |
| 321 | goto solve_coord_done; | 321 | goto solve_coord_done; |
| 322 | } | 322 | } |
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index fc7631f..f076f11 100644 --- 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]) | |||
| 160 | return 0; | 160 | return 0; |
| 161 | pthread_mutex_lock(arg->solutions_mutex); | 161 | pthread_mutex_lock(arg->solutions_mutex); |
| 162 | ret = appendsolution(arg->solution_moves, | 162 | ret = appendsolution(arg->solution_moves, |
| 163 | arg->solution_settings, arg->solution_list); | 163 | arg->solution_settings, arg->solution_list, true); |
| 164 | pthread_mutex_unlock(arg->solutions_mutex); | 164 | pthread_mutex_unlock(arg->solutions_mutex); |
| 165 | return ret; | 165 | return ret; |
| 166 | } | 166 | } |
| @@ -292,8 +292,8 @@ solve_h48_maketasks( | |||
| 292 | memcpy(moves.moves, | 292 | memcpy(moves.moves, |
| 293 | maketasks_arg->moves, maketasks_arg->nmoves); | 293 | maketasks_arg->moves, maketasks_arg->nmoves); |
| 294 | 294 | ||
| 295 | appret = appendsolution(&moves, | 295 | appret = appendsolution(&moves, solve_arg->solution_settings, |
| 296 | solve_arg->solution_settings, solve_arg->solution_list); | 296 | solve_arg->solution_list, true); |
| 297 | return appret < 0 ? appret : NISSY_OK; | 297 | return appret < 0 ? appret : NISSY_OK; |
| 298 | } | 298 | } |
| 299 | 299 | ||
diff --git a/src/solvers/solutions.h b/src/solvers/solutions.h index 1b5517c..e65f299 100644 --- a/src/solvers/solutions.h +++ b/src/solvers/solutions.h | |||
| @@ -7,7 +7,7 @@ STATIC bool solution_moves_equal( | |||
| 7 | STATIC bool solution_moves_is_duplicate(size_t n, const solution_moves_t[n+1]); | 7 | STATIC bool solution_moves_is_duplicate(size_t n, const solution_moves_t[n+1]); |
| 8 | STATIC bool appendchar(solution_list_t [static 1], char); | 8 | STATIC bool appendchar(solution_list_t [static 1], char); |
| 9 | STATIC int64_t appendsolution(const solution_moves_t [static 1], | 9 | STATIC int64_t appendsolution(const solution_moves_t [static 1], |
| 10 | const solution_settings_t [static 1], solution_list_t [static 1]); | 10 | const solution_settings_t [static 1], solution_list_t [static 1], bool); |
| 11 | STATIC bool solutions_done(const solution_list_t [static 1], | 11 | STATIC bool solutions_done(const solution_list_t [static 1], |
| 12 | const solution_settings_t [static 1], int8_t depth); | 12 | const solution_settings_t [static 1], int8_t depth); |
| 13 | 13 | ||
| @@ -99,13 +99,15 @@ STATIC int64_t | |||
| 99 | appendsolution( | 99 | appendsolution( |
| 100 | const solution_moves_t moves[static 1], | 100 | const solution_moves_t moves[static 1], |
| 101 | const solution_settings_t settings[static 1], | 101 | const solution_settings_t settings[static 1], |
| 102 | solution_list_t list[static 1] | 102 | solution_list_t list[static 1], |
| 103 | bool log | ||
| 103 | ) | 104 | ) |
| 104 | { | 105 | { |
| 105 | int64_t r, strl; | 106 | int64_t r, strl; |
| 106 | int i; | 107 | int i; |
| 107 | uint8_t t; | 108 | uint8_t t; |
| 108 | solution_moves_t tsol[NTRANS]; | 109 | solution_moves_t tsol[NTRANS]; |
| 110 | char *last_start; | ||
| 109 | 111 | ||
| 110 | if (moves->nmoves + moves->npremoves > MAXLEN) | 112 | if (moves->nmoves + moves->npremoves > MAXLEN) |
| 111 | goto appendsolution_error_solution_length; | 113 | goto appendsolution_error_solution_length; |
| @@ -147,6 +149,8 @@ appendsolution( | |||
| 147 | if (solution_moves_is_duplicate(r, tsol)) | 149 | if (solution_moves_is_duplicate(r, tsol)) |
| 148 | continue; | 150 | continue; |
| 149 | 151 | ||
| 152 | last_start = list->buf + list->used; | ||
| 153 | |||
| 150 | /* Write moves on normal */ | 154 | /* Write moves on normal */ |
| 151 | strl = writemoves(tsol[r].nmoves, tsol[r].moves, | 155 | strl = writemoves(tsol[r].nmoves, tsol[r].moves, |
| 152 | list->size - list->used, list->buf + list->used); | 156 | list->size - list->used, list->buf + list->used); |
| @@ -179,6 +183,13 @@ appendsolution( | |||
| 179 | list->shortest_sol = MIN( | 183 | list->shortest_sol = MIN( |
| 180 | list->shortest_sol, tsol[r].nmoves + tsol[r].npremoves); | 184 | list->shortest_sol, tsol[r].nmoves + tsol[r].npremoves); |
| 181 | r++; | 185 | r++; |
| 186 | |||
| 187 | if (log) { | ||
| 188 | list->buf[list->used-1] = '\0'; | ||
| 189 | LOG("Found solution #%" PRIu64 ": %s\n", | ||
| 190 | list->nsols, last_start); | ||
| 191 | list->buf[list->used-1] = '\n'; | ||
| 192 | } | ||
| 182 | } | 193 | } |
| 183 | 194 | ||
| 184 | list->buf[list->used] = '\0'; | 195 | list->buf[list->used] = '\0'; |
