diff options
| -rw-r--r-- | src/solvers/coord/gendata.h | 17 | ||||
| -rw-r--r-- | src/solvers/dispatch.h | 8 | ||||
| -rw-r--r-- | src/solvers/solvers.h | 3 | ||||
| -rw-r--r-- | src/solvers/twostep/twostep.h | 93 |
4 files changed, 116 insertions, 5 deletions
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( | |||
| 24 | unsigned char *buf | 24 | unsigned char *buf |
| 25 | ) | 25 | ) |
| 26 | { | 26 | { |
| 27 | size_t r; | ||
| 27 | coord_t *coord; | 28 | coord_t *coord; |
| 28 | multicoord_t *mcoord; | 29 | multicoord_t *mcoord; |
| 29 | 30 | ||
| 30 | parse_coord_and_trans(coordstr, &coord, &mcoord, NULL); | 31 | parse_coord_and_trans(coordstr, &coord, &mcoord, NULL); |
| 31 | 32 | ||
| 32 | if (coord != NULL) | 33 | if (coord != NULL) { |
| 33 | return gendata_coord(coord, buf); | 34 | if (bufsize < gendata_coord(coord, NULL)) |
| 35 | return NISSY_ERROR_BUFFER_SIZE; | ||
| 36 | r = gendata_coord(coord, buf); | ||
| 37 | return r == 0 ? NISSY_ERROR_UNKNOWN : (long long)r; | ||
| 38 | } | ||
| 34 | 39 | ||
| 35 | if (mcoord != NULL) | 40 | if (mcoord != NULL) { |
| 36 | return gendata_multicoord(mcoord, buf); | 41 | if (bufsize < gendata_multicoord(mcoord, NULL)) |
| 42 | return NISSY_ERROR_BUFFER_SIZE; | ||
| 43 | r = gendata_multicoord(mcoord, buf); | ||
| 44 | return r == 0 ? NISSY_ERROR_UNKNOWN : (long long)r; | ||
| 45 | } | ||
| 37 | 46 | ||
| 38 | LOG("Error: could not parse coordinate '%s'\n", coordstr); | 47 | LOG("Error: could not parse coordinate '%s'\n", coordstr); |
| 39 | return NISSY_ERROR_INVALID_SOLVER; | 48 | 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 | |||
| @@ -38,6 +38,13 @@ solver_dispatch_t solver_dispatchers[] = { | |||
| 38 | .solve = solve_multicoord_dispatch, | 38 | .solve = solve_multicoord_dispatch, |
| 39 | }, | 39 | }, |
| 40 | { | 40 | { |
| 41 | .prefix = "twostep", | ||
| 42 | .dataid = dataid_twostep, | ||
| 43 | .gendata = gendata_twostep, | ||
| 44 | .checkdata = checkdata_twostep, | ||
| 45 | .solve = solve_twostep, | ||
| 46 | }, | ||
| 47 | { | ||
| 41 | .prefix = NULL | 48 | .prefix = NULL |
| 42 | } | 49 | } |
| 43 | }; | 50 | }; |
| @@ -67,6 +74,7 @@ const char *solver_aliases[][2] = { | |||
| 67 | { "htr-drfb", "coord_HTR_BU" }, | 74 | { "htr-drfb", "coord_HTR_BU" }, |
| 68 | { "corners", "coord_CORNERS_UF" }, | 75 | { "corners", "coord_CORNERS_UF" }, |
| 69 | { "cornersx", "coord_CORNERSX_UF" }, | 76 | { "cornersx", "coord_CORNERSX_UF" }, |
| 77 | { "quick", "twostep" }, | ||
| 70 | { NULL, NULL } | 78 | { NULL, NULL } |
| 71 | }; | 79 | }; |
| 72 | 80 | ||
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 @@ | |||
| 3 | #include "tables_types_macros.h" | 3 | #include "tables_types_macros.h" |
| 4 | #include "tables.h" | 4 | #include "tables.h" |
| 5 | #include "distribution.h" | 5 | #include "distribution.h" |
| 6 | #include "coord/coord.h" | 6 | /*#include "coord/coord.h"*/ |
| 7 | #include "twostep/twostep.h" | ||
| 7 | #include "h48/h48.h" | 8 | #include "h48/h48.h" |
| 8 | #include "dispatch.h" | 9 | #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 @@ | |||
| 1 | #include "../coord/coord.h" | ||
| 2 | |||
| 3 | STATIC long long dataid_twostep(const char *, char [SIZE(NISSY_SIZE_DATAID)]); | ||
| 4 | STATIC long long gendata_twostep( | ||
| 5 | const char *, unsigned long long, unsigned char *); | ||
| 6 | STATIC long long checkdata_twostep( | ||
| 7 | const char *, unsigned long long, const unsigned char *); | ||
| 8 | STATIC long long solve_twostep(oriented_cube_t, const char *, unsigned, | ||
| 9 | unsigned, unsigned, unsigned, unsigned, unsigned, unsigned long long, | ||
| 10 | const unsigned char *, unsigned, char *, | ||
| 11 | long long [SIZE(NISSY_SIZE_SOLVE_STATS)], int (*)(void *), void *); | ||
| 12 | |||
| 13 | STATIC long long | ||
| 14 | dataid_twostep(const char *s, char dataid[SIZE(NISSY_SIZE_DATAID)]) | ||
| 15 | { | ||
| 16 | strcpy(dataid, "DR_DRFIN"); | ||
| 17 | return NISSY_OK; | ||
| 18 | } | ||
| 19 | |||
| 20 | STATIC long long | ||
| 21 | gendata_twostep( | ||
| 22 | const char *s, | ||
| 23 | unsigned long long bufsize, | ||
| 24 | unsigned char *buf | ||
| 25 | ) | ||
| 26 | { | ||
| 27 | size_t r, s1, s2; | ||
| 28 | |||
| 29 | s1 = gendata_coord(&coordinate_dr, NULL); | ||
| 30 | s1 = DIV_ROUND_UP(s1, 8); /* Preserve 8-byte alignment */ | ||
| 31 | s2 = gendata_multicoord(&multicoordinate_drfin, NULL); | ||
| 32 | |||
| 33 | if (buf == NULL) | ||
| 34 | goto gendata_twostep_return_size; | ||
| 35 | |||
| 36 | if (bufsize < s1 + s2) | ||
| 37 | return NISSY_ERROR_BUFFER_SIZE; | ||
| 38 | |||
| 39 | r = gendata_coord(&coordinate_dr, buf); | ||
| 40 | if (r == 0) | ||
| 41 | return NISSY_ERROR_UNKNOWN; | ||
| 42 | |||
| 43 | r = gendata_multicoord(&multicoordinate_drfin, buf + s1); | ||
| 44 | if (r != NISSY_OK) | ||
| 45 | return NISSY_ERROR_UNKNOWN; | ||
| 46 | |||
| 47 | gendata_twostep_return_size: | ||
| 48 | return s1 + s2; | ||
| 49 | } | ||
| 50 | |||
| 51 | STATIC long long | ||
| 52 | checkdata_twostep( | ||
| 53 | const char *s, | ||
| 54 | unsigned long long bufsize, | ||
| 55 | const unsigned char *buf | ||
| 56 | ) | ||
| 57 | { | ||
| 58 | long long r; | ||
| 59 | |||
| 60 | LOG("[checkdata] Checking double table for two step solver\n"); | ||
| 61 | |||
| 62 | r = checkdata_coord(&coordinate_dr, bufsize, buf); | ||
| 63 | if (r != NISSY_OK) | ||
| 64 | return r; | ||
| 65 | |||
| 66 | r = checkdata_multicoord(&multicoordinate_drfin, bufsize, buf); | ||
| 67 | if (r != NISSY_OK) | ||
| 68 | return r; | ||
| 69 | |||
| 70 | return NISSY_OK; | ||
| 71 | } | ||
| 72 | |||
| 73 | STATIC long long | ||
| 74 | solve_twostep( | ||
| 75 | oriented_cube_t oc, | ||
| 76 | const char *coord_and_trans, | ||
| 77 | unsigned nissflag, | ||
| 78 | unsigned minmoves, | ||
| 79 | unsigned maxmoves, | ||
| 80 | unsigned maxsolutions, | ||
| 81 | unsigned optimal, | ||
| 82 | unsigned threads, | ||
| 83 | unsigned long long data_size, | ||
| 84 | const unsigned char *data, | ||
| 85 | unsigned solutions_size, | ||
| 86 | char *sols, | ||
| 87 | long long stats[SIZE(NISSY_SIZE_SOLVE_STATS)], | ||
| 88 | int (*poll_status)(void *), | ||
| 89 | void *poll_status_data | ||
| 90 | ) | ||
| 91 | { | ||
| 92 | //TODO | ||
| 93 | } | ||
