aboutsummaryrefslogtreecommitdiff
path: root/src/solvers
diff options
context:
space:
mode:
authorenricotenuti <tenutz_27@outlook.it>2024-09-26 10:48:27 +0200
committerenricotenuti <tenutz_27@outlook.it>2024-09-26 10:48:27 +0200
commit3cb66440de97a787a974eed87a5fd876b46cef92 (patch)
tree9238ded2ed9daebe7b9f9669b4b2bf1dc92b35c5 /src/solvers
parent2c109db35b3b30b27e71e7811776edec1af1208e (diff)
downloadnissy-core-3cb66440de97a787a974eed87a5fd876b46cef92.tar.gz
nissy-core-3cb66440de97a787a974eed87a5fd876b46cef92.zip
Fixed solutions vector, added constants
Diffstat (limited to 'src/solvers')
-rw-r--r--src/solvers/h48/solve.h3
-rw-r--r--src/solvers/h48/thread.h21
2 files changed, 14 insertions, 10 deletions
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h
index b67aedc..4a1e961 100644
--- a/src/solvers/h48/solve.h
+++ b/src/solvers/h48/solve.h
@@ -199,6 +199,7 @@ solve_h48(
199 arg.npremoves = 0; 199 arg.npremoves = 0;
200 solve_h48_dfs(&arg); 200 solve_h48_dfs(&arg);
201 } 201 }
202 202 **arg.nextsol = '\0';
203 (*arg.nextsol)++;
203 return nsols; 204 return nsols;
204} 205}
diff --git a/src/solvers/h48/thread.h b/src/solvers/h48/thread.h
index d035b52..c76c9d6 100644
--- a/src/solvers/h48/thread.h
+++ b/src/solvers/h48/thread.h
@@ -4,7 +4,8 @@
4#include <stdio.h> 4#include <stdio.h>
5#include <stdlib.h> 5#include <stdlib.h>
6 6
7#define MAX_QUEUE_SIZE 500 7#define MAX_QUEUE_SIZE 244
8#define BFS_DEPTH 2
8typedef struct 9typedef struct
9{ 10{
10 dfsarg_solveh48_t *tasks[MAX_QUEUE_SIZE]; 11 dfsarg_solveh48_t *tasks[MAX_QUEUE_SIZE];
@@ -31,7 +32,7 @@ STATIC void
31solve_h48_appendsolution_thread(dfsarg_solveh48_t *arg, task_queue_t *tq) 32solve_h48_appendsolution_thread(dfsarg_solveh48_t *arg, task_queue_t *tq)
32{ 33{
33 pthread_mutex_lock(&tq->mutex); 34 pthread_mutex_lock(&tq->mutex);
34 int strl; 35 int strl = 0;
35 uint8_t invertedpremoves[MAXLEN]; 36 uint8_t invertedpremoves[MAXLEN];
36 char *solution = *arg->nextsol; 37 char *solution = *arg->nextsol;
37 38
@@ -168,7 +169,7 @@ solve_h48_bfs(dfsarg_solveh48_t *arg_zero, task_queue_t *tq)
168 nextarg.cube = move(arg.cube, m); 169 nextarg.cube = move(arg.cube, m);
169 nextarg.inverse = premove(arg.inverse, m); 170 nextarg.inverse = premove(arg.inverse, m);
170 171
171 if (nextarg.nmoves == 2){ 172 if (nextarg.nmoves == BFS_DEPTH){
172 dfsarg_solveh48_t *task = malloc(sizeof(dfsarg_solveh48_t)); 173 dfsarg_solveh48_t *task = malloc(sizeof(dfsarg_solveh48_t));
173 *task = nextarg; 174 *task = nextarg;
174 submit_task(tq, task); 175 submit_task(tq, task);
@@ -179,11 +180,11 @@ solve_h48_bfs(dfsarg_solveh48_t *arg_zero, task_queue_t *tq)
179 } 180 }
180 } 181 }
181 if (nodes_at_current_depth == 0){ 182 if (nodes_at_current_depth == 0){
182 depth++;
183 nodes_at_current_depth = nodes_at_next_depth; 183 nodes_at_current_depth = nodes_at_next_depth;
184 nodes_at_next_depth = 0; 184 nodes_at_next_depth = 0;
185 LOG("Found %" PRId64 " solutions, searching at depth %" PRId8 "\n", *nextarg.nsols, depth++);
185 } 186 }
186 if (depth == 2) return 0; 187 if (depth == BFS_DEPTH) return 0;
187 } 188 }
188 return 1; 189 return 1;
189} 190}
@@ -248,7 +249,7 @@ solve_h48_parent(
248{ 249{
249 int64_t nsols = 0; 250 int64_t nsols = 0;
250 int p_depth = 0; 251 int p_depth = 0;
251 dfsarg_solveh48_t bfs_arg; 252 dfsarg_solveh48_t arg;
252 tableinfo_t info; 253 tableinfo_t info;
253 pthread_t threads[THREADS]; 254 pthread_t threads[THREADS];
254 255
@@ -258,7 +259,7 @@ solve_h48_parent(
258 return 0; 259 return 0;
259 } 260 }
260 261
261 bfs_arg = (dfsarg_solveh48_t){ 262 arg = (dfsarg_solveh48_t){
262 .cube = cube, 263 .cube = cube,
263 .inverse = inverse(cube), 264 .inverse = inverse(cube),
264 .nsols = &nsols, 265 .nsols = &nsols,
@@ -271,7 +272,7 @@ solve_h48_parent(
271 272
272 task_queue_t q; 273 task_queue_t q;
273 init_queue(&q); 274 init_queue(&q);
274 if (solve_h48_bfs(&bfs_arg, &q)) 275 if (solve_h48_bfs(&arg, &q))
275 return nsols; 276 return nsols;
276 277
277 task_queue_t nq; 278 task_queue_t nq;
@@ -282,7 +283,7 @@ solve_h48_parent(
282 } 283 }
283 284
284 nsols = 0; 285 nsols = 0;
285 for (p_depth = minmoves > 2 ? minmoves : 2; 286 for (p_depth = minmoves > BFS_DEPTH ? minmoves : BFS_DEPTH;
286 p_depth <= maxmoves && nsols < maxsolutions; 287 p_depth <= maxmoves && nsols < maxsolutions;
287 p_depth++) 288 p_depth++)
288 { 289 {
@@ -301,5 +302,7 @@ solve_h48_parent(
301 for (int i = 0; i < THREADS; i++){ 302 for (int i = 0; i < THREADS; i++){
302 pthread_join(threads[i], NULL); 303 pthread_join(threads[i], NULL);
303 } 304 }
305 **arg.nextsol = '\0';
306 (*arg.nextsol)++;
304 return nsols; 307 return nsols;
305} 308}

Generated with cgit - Back to sebastiano.tronto.net