From 2f9d00075b0d236ecd8431761bb045e6aa088001 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 17 Sep 2026 21:20:22 +0200 Subject: twostep solver (wip) --- src/solvers/coord/gendata.h | 17 ++++++-- src/solvers/dispatch.h | 8 ++++ src/solvers/solvers.h | 3 +- src/solvers/twostep/twostep.h | 93 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 5 deletions(-) create mode 100644 src/solvers/twostep/twostep.h (limited to 'src/solvers') diff --git a/src/solvers/coord/gendata.h b/src/solvers/coord/gendata.h index edf6ce6..81ab842 100644 --- a/src/solvers/coord/gendata.h +++ b/src/solvers/coord/gendata.h @@ -24,16 +24,25 @@ gendata_coord_dispatch( unsigned char *buf ) { + size_t r; coord_t *coord; multicoord_t *mcoord; parse_coord_and_trans(coordstr, &coord, &mcoord, NULL); - if (coord != NULL) - return gendata_coord(coord, buf); + if (coord != NULL) { + if (bufsize < gendata_coord(coord, NULL)) + return NISSY_ERROR_BUFFER_SIZE; + r = gendata_coord(coord, buf); + return r == 0 ? NISSY_ERROR_UNKNOWN : (long long)r; + } - if (mcoord != NULL) - return gendata_multicoord(mcoord, buf); + if (mcoord != NULL) { + if (bufsize < gendata_multicoord(mcoord, NULL)) + return NISSY_ERROR_BUFFER_SIZE; + r = gendata_multicoord(mcoord, buf); + return r == 0 ? NISSY_ERROR_UNKNOWN : (long long)r; + } LOG("Error: could not parse coordinate '%s'\n", coordstr); return NISSY_ERROR_INVALID_SOLVER; diff --git a/src/solvers/dispatch.h b/src/solvers/dispatch.h index 810247f..f6d2bee 100644 --- a/src/solvers/dispatch.h +++ b/src/solvers/dispatch.h @@ -37,6 +37,13 @@ solver_dispatch_t solver_dispatchers[] = { .checkdata = checkdata_coord_dispatch, .solve = solve_multicoord_dispatch, }, +{ + .prefix = "twostep", + .dataid = dataid_twostep, + .gendata = gendata_twostep, + .checkdata = checkdata_twostep, + .solve = solve_twostep, +}, { .prefix = NULL } @@ -67,6 +74,7 @@ const char *solver_aliases[][2] = { { "htr-drfb", "coord_HTR_BU" }, { "corners", "coord_CORNERS_UF" }, { "cornersx", "coord_CORNERSX_UF" }, + { "quick", "twostep" }, { NULL, NULL } }; diff --git a/src/solvers/solvers.h b/src/solvers/solvers.h index e19b08a..f9f2287 100644 --- a/src/solvers/solvers.h +++ b/src/solvers/solvers.h @@ -3,6 +3,7 @@ #include "tables_types_macros.h" #include "tables.h" #include "distribution.h" -#include "coord/coord.h" +/*#include "coord/coord.h"*/ +#include "twostep/twostep.h" #include "h48/h48.h" #include "dispatch.h" diff --git a/src/solvers/twostep/twostep.h b/src/solvers/twostep/twostep.h new file mode 100644 index 0000000..8947a50 --- /dev/null +++ b/src/solvers/twostep/twostep.h @@ -0,0 +1,93 @@ +#include "../coord/coord.h" + +STATIC long long dataid_twostep(const char *, char [SIZE(NISSY_SIZE_DATAID)]); +STATIC long long gendata_twostep( + const char *, unsigned long long, unsigned char *); +STATIC long long checkdata_twostep( + const char *, unsigned long long, const unsigned char *); +STATIC long long solve_twostep(oriented_cube_t, const char *, unsigned, + unsigned, unsigned, unsigned, unsigned, unsigned, unsigned long long, + const unsigned char *, unsigned, char *, + long long [SIZE(NISSY_SIZE_SOLVE_STATS)], int (*)(void *), void *); + +STATIC long long +dataid_twostep(const char *s, char dataid[SIZE(NISSY_SIZE_DATAID)]) +{ + strcpy(dataid, "DR_DRFIN"); + return NISSY_OK; +} + +STATIC long long +gendata_twostep( + const char *s, + unsigned long long bufsize, + unsigned char *buf +) +{ + size_t r, s1, s2; + + s1 = gendata_coord(&coordinate_dr, NULL); + s1 = DIV_ROUND_UP(s1, 8); /* Preserve 8-byte alignment */ + s2 = gendata_multicoord(&multicoordinate_drfin, NULL); + + if (buf == NULL) + goto gendata_twostep_return_size; + + if (bufsize < s1 + s2) + return NISSY_ERROR_BUFFER_SIZE; + + r = gendata_coord(&coordinate_dr, buf); + if (r == 0) + return NISSY_ERROR_UNKNOWN; + + r = gendata_multicoord(&multicoordinate_drfin, buf + s1); + if (r != NISSY_OK) + return NISSY_ERROR_UNKNOWN; + +gendata_twostep_return_size: + return s1 + s2; +} + +STATIC long long +checkdata_twostep( + const char *s, + unsigned long long bufsize, + const unsigned char *buf +) +{ + long long r; + + LOG("[checkdata] Checking double table for two step solver\n"); + + r = checkdata_coord(&coordinate_dr, bufsize, buf); + if (r != NISSY_OK) + return r; + + r = checkdata_multicoord(&multicoordinate_drfin, bufsize, buf); + if (r != NISSY_OK) + return r; + + return NISSY_OK; +} + +STATIC long long +solve_twostep( + oriented_cube_t oc, + const char *coord_and_trans, + unsigned nissflag, + unsigned minmoves, + unsigned maxmoves, + unsigned maxsolutions, + unsigned optimal, + unsigned threads, + unsigned long long data_size, + const unsigned char *data, + unsigned solutions_size, + char *sols, + long long stats[SIZE(NISSY_SIZE_SOLVE_STATS)], + int (*poll_status)(void *), + void *poll_status_data +) +{ +//TODO +} -- cgit v1.3