diff options
Diffstat (limited to 'src/solvers')
| -rw-r--r-- | src/solvers/coord/checkdata.h | 65 | ||||
| -rw-r--r-- | src/solvers/coord/coord.h | 1 | ||||
| -rw-r--r-- | src/solvers/coord/dr.h | 16 | ||||
| -rw-r--r-- | src/solvers/coord/dreo.h | 14 | ||||
| -rw-r--r-- | src/solvers/coord/eo.h | 11 | ||||
| -rw-r--r-- | src/solvers/coord/gendata.h | 2 | ||||
| -rw-r--r-- | src/solvers/coord/solve.h | 3 | ||||
| -rw-r--r-- | src/solvers/coord/types_macros.h | 2 | ||||
| -rw-r--r-- | src/solvers/coord/utils.h | 28 | ||||
| -rw-r--r-- | src/solvers/dispatch.h | 6 | ||||
| -rw-r--r-- | src/solvers/distribution.h | 27 | ||||
| -rw-r--r-- | src/solvers/h48/checkdata.h | 234 | ||||
| -rw-r--r-- | src/solvers/h48/gendata_eoesep.h | 4 | ||||
| -rw-r--r-- | src/solvers/h48/gendata_h48.h | 90 | ||||
| -rw-r--r-- | src/solvers/h48/h48.h | 1 |
15 files changed, 392 insertions, 112 deletions
diff --git a/src/solvers/coord/checkdata.h b/src/solvers/coord/checkdata.h new file mode 100644 index 0000000..81394c7 --- /dev/null +++ b/src/solvers/coord/checkdata.h | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | STATIC long long checkdata_coord( | ||
| 2 | const char *, unsigned long long n, const unsigned char [n]); | ||
| 3 | |||
| 4 | STATIC long long | ||
| 5 | checkdata_coord( | ||
| 6 | const char *solver, | ||
| 7 | unsigned long long data_size, | ||
| 8 | const unsigned char data[data_size] | ||
| 9 | ) | ||
| 10 | { | ||
| 11 | coord_t *coord; | ||
| 12 | const unsigned char *table; | ||
| 13 | tableinfo_t info; | ||
| 14 | int64_t err; | ||
| 15 | uint64_t actual_distribution[INFO_DISTRIBUTION_LEN]; | ||
| 16 | |||
| 17 | if ((size_t)data % 8 != 0) { | ||
| 18 | LOG("[checkdata] Error: buffer is not 8-byte aligned\n"); | ||
| 19 | return NISSY_ERROR_DATA; | ||
| 20 | } | ||
| 21 | |||
| 22 | parse_coord_and_axis(solver, &coord, NULL); | ||
| 23 | if (coord == NULL) { | ||
| 24 | LOG("[cehckdata] Unknown coordinate solver '%s'\n", solver); | ||
| 25 | return NISSY_ERROR_DATA; | ||
| 26 | } | ||
| 27 | |||
| 28 | table = data + INFOSIZE; | ||
| 29 | err = readtableinfo(data_size, data, &info); | ||
| 30 | if (err != NISSY_OK) { | ||
| 31 | LOG("[checkdata] Data is corrupt\n"); | ||
| 32 | return err; | ||
| 33 | } | ||
| 34 | |||
| 35 | if (info.type != TABLETYPE_PRUNING) { | ||
| 36 | LOG("[checkdata] Skipping '%s'\n", info.solver); | ||
| 37 | table += info.next; | ||
| 38 | err = readtableinfo_n(data_size, data, 2, &info); | ||
| 39 | if (err != NISSY_OK) { | ||
| 40 | LOG("[checkdata] Data is corrupt\n"); | ||
| 41 | return err; | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | LOG("[checkdata] Checking distribution for '%s' from " | ||
| 46 | "table preamble\n", info.solver); | ||
| 47 | if (!distribution_equal(coord->pruning_distribution, | ||
| 48 | info.distribution, coord->pruning_max)) { | ||
| 49 | LOG("[checkdata] Distribution from the table preamble does " | ||
| 50 | "not match the expected one\n"); | ||
| 51 | return NISSY_ERROR_DATA; | ||
| 52 | } | ||
| 53 | |||
| 54 | LOG("\n[checkdata] Checking distribution for '%s' from " | ||
| 55 | "actual table\n", info.solver); | ||
| 56 | getdistribution(table, actual_distribution, &info); | ||
| 57 | if (!distribution_equal(coord->pruning_distribution, | ||
| 58 | actual_distribution, coord->pruning_max)) { | ||
| 59 | LOG("[checkdata] Distribution from the actual table does " | ||
| 60 | "not match the expected one\n"); | ||
| 61 | return NISSY_ERROR_DATA; | ||
| 62 | } | ||
| 63 | |||
| 64 | return NISSY_OK; | ||
| 65 | } | ||
diff --git a/src/solvers/coord/coord.h b/src/solvers/coord/coord.h index 2f24035..da93439 100644 --- a/src/solvers/coord/coord.h +++ b/src/solvers/coord/coord.h | |||
| @@ -6,4 +6,5 @@ | |||
| 6 | #include "list.h" | 6 | #include "list.h" |
| 7 | #include "utils.h" | 7 | #include "utils.h" |
| 8 | #include "gendata.h" | 8 | #include "gendata.h" |
| 9 | #include "checkdata.h" | ||
| 9 | #include "solve.h" | 10 | #include "solve.h" |
diff --git a/src/solvers/coord/dr.h b/src/solvers/coord/dr.h index 607cc39..d986742 100644 --- a/src/solvers/coord/dr.h +++ b/src/solvers/coord/dr.h | |||
| @@ -32,6 +32,22 @@ STATIC coord_t coordinate_dr = { | |||
| 32 | }, | 32 | }, |
| 33 | .is_admissible = &solution_lastqt_cw, | 33 | .is_admissible = &solution_lastqt_cw, |
| 34 | .is_solvable = &is_eoco_solvable, | 34 | .is_solvable = &is_eoco_solvable, |
| 35 | .pruning_distribution = { | ||
| 36 | [0] = 1, | ||
| 37 | [1] = 1, | ||
| 38 | [2] = 5, | ||
| 39 | [3] = 44, | ||
| 40 | [4] = 487, | ||
| 41 | [5] = 5841, | ||
| 42 | [6] = 68364, | ||
| 43 | [7] = 776568, | ||
| 44 | [8] = 7950748, | ||
| 45 | [9] = 52098876, | ||
| 46 | [10] = 76236234, | ||
| 47 | [11] = 3771112, | ||
| 48 | [12] = 129, | ||
| 49 | }, | ||
| 50 | .pruning_max = 12, | ||
| 35 | .sym = { | 51 | .sym = { |
| 36 | .classes = DREOESEP_CLASSES, | 52 | .classes = DREOESEP_CLASSES, |
| 37 | .max = DREOESEP_MAX, | 53 | .max = DREOESEP_MAX, |
diff --git a/src/solvers/coord/dreo.h b/src/solvers/coord/dreo.h index 1cce4e2..f6fa3e9 100644 --- a/src/solvers/coord/dreo.h +++ b/src/solvers/coord/dreo.h | |||
| @@ -27,6 +27,20 @@ STATIC coord_t coordinate_dreo = { | |||
| 27 | }, | 27 | }, |
| 28 | .is_admissible = &solution_lastqt_cw, | 28 | .is_admissible = &solution_lastqt_cw, |
| 29 | .is_solvable = &is_dreo_solvable, | 29 | .is_solvable = &is_dreo_solvable, |
| 30 | .pruning_distribution = { | ||
| 31 | [0] = 1, | ||
| 32 | [1] = 1, | ||
| 33 | [2] = 4, | ||
| 34 | [3] = 22, | ||
| 35 | [4] = 160, | ||
| 36 | [5] = 1286, | ||
| 37 | [6] = 8550, | ||
| 38 | [7] = 42152, | ||
| 39 | [8] = 90748, | ||
| 40 | [9] = 33466, | ||
| 41 | [10] = 757, | ||
| 42 | }, | ||
| 43 | .pruning_max = 10, | ||
| 30 | .sym = { | 44 | .sym = { |
| 31 | .classes = DRESEP_CLASSES, | 45 | .classes = DRESEP_CLASSES, |
| 32 | .max = COMB_12_4, | 46 | .max = COMB_12_4, |
diff --git a/src/solvers/coord/eo.h b/src/solvers/coord/eo.h index 51dfb29..7735319 100644 --- a/src/solvers/coord/eo.h +++ b/src/solvers/coord/eo.h | |||
| @@ -20,6 +20,17 @@ STATIC coord_t coordinate_eo = { | |||
| 20 | }, | 20 | }, |
| 21 | .is_admissible = &solution_lastqt_cw, | 21 | .is_admissible = &solution_lastqt_cw, |
| 22 | .is_solvable = &is_eo_even, | 22 | .is_solvable = &is_eo_even, |
| 23 | .pruning_distribution = { | ||
| 24 | [0] = 1, | ||
| 25 | [1] = 2, | ||
| 26 | [2] = 25, | ||
| 27 | [3] = 202, | ||
| 28 | [4] = 620, | ||
| 29 | [5] = 900, | ||
| 30 | [6] = 285, | ||
| 31 | [7] = 13, | ||
| 32 | }, | ||
| 33 | .pruning_max = 7, | ||
| 23 | .sym = {0}, | 34 | .sym = {0}, |
| 24 | }; | 35 | }; |
| 25 | 36 | ||
diff --git a/src/solvers/coord/gendata.h b/src/solvers/coord/gendata.h index 1b65f49..0cc012e 100644 --- a/src/solvers/coord/gendata.h +++ b/src/solvers/coord/gendata.h | |||
| @@ -22,7 +22,7 @@ gendata_coord_dispatch( | |||
| 22 | { | 22 | { |
| 23 | coord_t *coord; | 23 | coord_t *coord; |
| 24 | 24 | ||
| 25 | parse_coord_and_axis(strlen(coordstr), coordstr, &coord, NULL); | 25 | parse_coord_and_axis(coordstr, &coord, NULL); |
| 26 | 26 | ||
| 27 | if (coord == NULL) { | 27 | if (coord == NULL) { |
| 28 | LOG("Error: could not parse coordinate '%s'\n", coordstr); | 28 | LOG("Error: could not parse coordinate '%s'\n", coordstr); |
diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h index df0f6ff..659040c 100644 --- a/src/solvers/coord/solve.h +++ b/src/solvers/coord/solve.h | |||
| @@ -222,8 +222,7 @@ solve_coord_dispatch( | |||
| 222 | coord_t *coord; | 222 | coord_t *coord; |
| 223 | uint8_t axis; | 223 | uint8_t axis; |
| 224 | 224 | ||
| 225 | parse_coord_and_axis( | 225 | parse_coord_and_axis(coord_and_axis, &coord, &axis); |
| 226 | strlen(coord_and_axis), coord_and_axis, &coord, &axis); | ||
| 227 | 226 | ||
| 228 | if (coord == NULL) { | 227 | if (coord == NULL) { |
| 229 | LOG("Error: could not parse coordinate from '%s'\n", | 228 | LOG("Error: could not parse coordinate from '%s'\n", |
diff --git a/src/solvers/coord/types_macros.h b/src/solvers/coord/types_macros.h index a5ac7f3..0c7a3a2 100644 --- a/src/solvers/coord/types_macros.h +++ b/src/solvers/coord/types_macros.h | |||
| @@ -26,6 +26,8 @@ typedef struct { | |||
| 26 | uint8_t axistrans[3]; | 26 | uint8_t axistrans[3]; |
| 27 | bool (*is_admissible)(const solution_moves_t[static 1]); | 27 | bool (*is_admissible)(const solution_moves_t[static 1]); |
| 28 | bool (*is_solvable)(cube_t); | 28 | bool (*is_solvable)(cube_t); |
| 29 | uint64_t pruning_distribution[INFO_DISTRIBUTION_LEN]; | ||
| 30 | uint8_t pruning_max; | ||
| 29 | struct { | 31 | struct { |
| 30 | size_t classes; | 32 | size_t classes; |
| 31 | uint64_t max; | 33 | uint64_t max; |
diff --git a/src/solvers/coord/utils.h b/src/solvers/coord/utils.h index aa4d74c..6066049 100644 --- a/src/solvers/coord/utils.h +++ b/src/solvers/coord/utils.h | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | STATIC coord_t *parse_coord(size_t n, const char [n]); | 1 | STATIC coord_t *parse_coord(size_t n, const char [n]); |
| 2 | STATIC uint8_t parse_axis(size_t n, const char [n]); | 2 | STATIC uint8_t parse_axis(const char [static 2]); |
| 3 | STATIC void parse_coord_and_axis( | 3 | STATIC void parse_coord_and_axis(const char *, coord_t **, uint8_t *); |
| 4 | size_t n, const char [n], coord_t **, uint8_t *); | ||
| 5 | STATIC long long dataid_coord(const char *, char [static NISSY_SIZE_DATAID]); | 4 | STATIC long long dataid_coord(const char *, char [static NISSY_SIZE_DATAID]); |
| 6 | 5 | ||
| 7 | STATIC coord_t * | 6 | STATIC coord_t * |
| @@ -17,13 +16,13 @@ parse_coord(size_t n, const char coord[n]) | |||
| 17 | } | 16 | } |
| 18 | 17 | ||
| 19 | STATIC uint8_t | 18 | STATIC uint8_t |
| 20 | parse_axis(size_t n, const char axis[n]) | 19 | parse_axis(const char axis[static 2]) |
| 21 | { | 20 | { |
| 22 | if (!strncmp(axis, "UD", n) || !strncmp(axis, "DU", n)) { | 21 | if (!strcmp(axis, "UD") || !strcmp(axis, "DU")) { |
| 23 | return AXIS_UD; | 22 | return AXIS_UD; |
| 24 | } else if (!strncmp(axis, "RL", n) || !strncmp(axis, "LR", n)) { | 23 | } else if (!strcmp(axis, "RL") || !strcmp(axis, "LR")) { |
| 25 | return AXIS_RL; | 24 | return AXIS_RL; |
| 26 | } else if (!strncmp(axis, "FB", n) || !strncmp(axis, "BF", n)) { | 25 | } else if (!strcmp(axis, "FB") || !strcmp(axis, "BF")) { |
| 27 | return AXIS_FB; | 26 | return AXIS_FB; |
| 28 | } | 27 | } |
| 29 | 28 | ||
| @@ -32,25 +31,22 @@ parse_axis(size_t n, const char axis[n]) | |||
| 32 | 31 | ||
| 33 | STATIC void | 32 | STATIC void |
| 34 | parse_coord_and_axis( | 33 | parse_coord_and_axis( |
| 35 | size_t n, | 34 | const char *str, |
| 36 | const char str[n], | ||
| 37 | coord_t **coord, | 35 | coord_t **coord, |
| 38 | uint8_t *axis | 36 | uint8_t *axis |
| 39 | ) | 37 | ) |
| 40 | { | 38 | { |
| 41 | const char *s; | ||
| 42 | size_t i; | 39 | size_t i; |
| 43 | 40 | ||
| 44 | s = str + 6; | 41 | for (i = 6; i < strlen(str); i++) |
| 45 | for (i = 0; i < n; i++) | 42 | if (str[i] == '_') |
| 46 | if (s[i] == '_') | ||
| 47 | break; | 43 | break; |
| 48 | 44 | ||
| 49 | if (coord != NULL) | 45 | if (coord != NULL) |
| 50 | *coord = parse_coord(i, s); | 46 | *coord = parse_coord(i-6, str+6); |
| 51 | 47 | ||
| 52 | if (axis != NULL) | 48 | if (axis != NULL) |
| 53 | *axis = i == n ? UINT8_ERROR : parse_axis(n-i-1, s+i+1); | 49 | *axis = i == strlen(str) ? UINT8_ERROR : parse_axis(str+i+1); |
| 54 | } | 50 | } |
| 55 | 51 | ||
| 56 | STATIC long long | 52 | STATIC long long |
| @@ -58,7 +54,7 @@ dataid_coord(const char *ca, char dataid[static NISSY_SIZE_DATAID]) | |||
| 58 | { | 54 | { |
| 59 | coord_t *c; | 55 | coord_t *c; |
| 60 | 56 | ||
| 61 | parse_coord_and_axis(strlen(ca), ca, &c, NULL); | 57 | parse_coord_and_axis(ca, &c, NULL); |
| 62 | 58 | ||
| 63 | if (c == NULL) { | 59 | if (c == NULL) { |
| 64 | LOG("Error: cannot parse coordinate from '%s'\n", ca); | 60 | LOG("Error: cannot parse coordinate from '%s'\n", ca); |
diff --git a/src/solvers/dispatch.h b/src/solvers/dispatch.h index 0cfbc3b..7cf4441 100644 --- a/src/solvers/dispatch.h +++ b/src/solvers/dispatch.h | |||
| @@ -2,7 +2,9 @@ typedef struct { | |||
| 2 | const char *prefix; | 2 | const char *prefix; |
| 3 | long long (*dataid)(const char *, char [static NISSY_SIZE_DATAID]); | 3 | long long (*dataid)(const char *, char [static NISSY_SIZE_DATAID]); |
| 4 | long long (*gendata)( | 4 | long long (*gendata)( |
| 5 | const char *, unsigned long long, unsigned char *); | 5 | const char *, unsigned long long n, unsigned char [n]); |
| 6 | long long (*checkdata)( | ||
| 7 | const char *, unsigned long long, const unsigned char *); | ||
| 6 | long long (*solve)(oriented_cube_t, const char *, unsigned, unsigned, | 8 | long long (*solve)(oriented_cube_t, const char *, unsigned, unsigned, |
| 7 | unsigned, unsigned, unsigned, unsigned, unsigned long long, | 9 | unsigned, unsigned, unsigned, unsigned, unsigned long long, |
| 8 | const unsigned char *, unsigned, char *, | 10 | const unsigned char *, unsigned, char *, |
| @@ -17,12 +19,14 @@ solver_dispatch_t solver_dispatchers[] = { | |||
| 17 | .prefix = "h48", | 19 | .prefix = "h48", |
| 18 | .dataid = dataid_h48, | 20 | .dataid = dataid_h48, |
| 19 | .gendata = gendata_h48_dispatch, | 21 | .gendata = gendata_h48_dispatch, |
| 22 | .checkdata = checkdata_h48, | ||
| 20 | .solve = solve_h48_dispatch, | 23 | .solve = solve_h48_dispatch, |
| 21 | }, | 24 | }, |
| 22 | { | 25 | { |
| 23 | .prefix = "coord_", | 26 | .prefix = "coord_", |
| 24 | .dataid = dataid_coord, | 27 | .dataid = dataid_coord, |
| 25 | .gendata = gendata_coord_dispatch, | 28 | .gendata = gendata_coord_dispatch, |
| 29 | .checkdata = checkdata_coord, | ||
| 26 | .solve = solve_coord_dispatch, | 30 | .solve = solve_coord_dispatch, |
| 27 | }, | 31 | }, |
| 28 | { | 32 | { |
diff --git a/src/solvers/distribution.h b/src/solvers/distribution.h index 1a3719c..3c006a7 100644 --- a/src/solvers/distribution.h +++ b/src/solvers/distribution.h | |||
| @@ -13,6 +13,8 @@ typedef struct { | |||
| 13 | STATIC void *getdistribution_runthread(void *); | 13 | STATIC void *getdistribution_runthread(void *); |
| 14 | STATIC void getdistribution(const unsigned char *, | 14 | STATIC void getdistribution(const unsigned char *, |
| 15 | uint64_t [static INFO_DISTRIBUTION_LEN], const tableinfo_t [static 1]); | 15 | uint64_t [static INFO_DISTRIBUTION_LEN], const tableinfo_t [static 1]); |
| 16 | STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], | ||
| 17 | const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); | ||
| 16 | 18 | ||
| 17 | STATIC void * | 19 | STATIC void * |
| 18 | getdistribution_runthread(void *arg) | 20 | getdistribution_runthread(void *arg) |
| @@ -75,3 +77,28 @@ getdistribution( | |||
| 75 | distr[pval]++; | 77 | distr[pval]++; |
| 76 | } | 78 | } |
| 77 | } | 79 | } |
| 80 | |||
| 81 | STATIC bool | ||
| 82 | distribution_equal( | ||
| 83 | const uint64_t expected[static INFO_DISTRIBUTION_LEN], | ||
| 84 | const uint64_t actual[static INFO_DISTRIBUTION_LEN], | ||
| 85 | uint8_t maxvalue | ||
| 86 | ) | ||
| 87 | { | ||
| 88 | int wrong; | ||
| 89 | uint8_t i; | ||
| 90 | |||
| 91 | for (i = 0, wrong = 0; i <= MIN(maxvalue, 20); i++) { | ||
| 92 | if (expected[i] != actual[i]) { | ||
| 93 | wrong++; | ||
| 94 | LOG("[checkdata] Value for depth %" PRIu8 | ||
| 95 | ": expected %" PRIu64 ", found %" PRIu64 "\n", | ||
| 96 | i, expected[i], actual[i]); | ||
| 97 | } else { | ||
| 98 | LOG("[checkdata] Value for depth %" PRIu8 | ||
| 99 | " is correct (%" PRIu64 ")\n", i, actual[i]); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 103 | return wrong == 0; | ||
| 104 | } | ||
diff --git a/src/solvers/h48/checkdata.h b/src/solvers/h48/checkdata.h new file mode 100644 index 0000000..53e616b --- /dev/null +++ b/src/solvers/h48/checkdata.h | |||
| @@ -0,0 +1,234 @@ | |||
| 1 | STATIC long long checkdata_h48( | ||
| 2 | const char *, unsigned long long n, const unsigned char [n]); | ||
| 3 | |||
| 4 | /* | ||
| 5 | Currently unused. | ||
| 6 | TODO: re-introduce check on cocsep table | ||
| 7 | */ | ||
| 8 | uint64_t expected_cocsep[21] = { | ||
| 9 | [0] = 1, | ||
| 10 | [1] = 6, | ||
| 11 | [2] = 63, | ||
| 12 | [3] = 468, | ||
| 13 | [4] = 3068, | ||
| 14 | [5] = 15438, | ||
| 15 | [6] = 53814, | ||
| 16 | [7] = 71352, | ||
| 17 | [8] = 8784, | ||
| 18 | [9] = 96 | ||
| 19 | }; | ||
| 20 | |||
| 21 | struct { | ||
| 22 | uint8_t max; | ||
| 23 | uint64_t table[21]; | ||
| 24 | } expected_h48[12][9] = { | ||
| 25 | [0] = { | ||
| 26 | [2] = { | ||
| 27 | .max = 3, | ||
| 28 | .table = { | ||
| 29 | [0] = 5473562, | ||
| 30 | [1] = 34776317, | ||
| 31 | [2] = 68566704, | ||
| 32 | [3] = 8750867, | ||
| 33 | }, | ||
| 34 | }, | ||
| 35 | [4] = { | ||
| 36 | .max = 12, | ||
| 37 | .table = { | ||
| 38 | [0] = 1, | ||
| 39 | [1] = 1, | ||
| 40 | [2] = 4, | ||
| 41 | [3] = 34, | ||
| 42 | [4] = 331, | ||
| 43 | [5] = 3612, | ||
| 44 | [6] = 41605, | ||
| 45 | [7] = 474128, | ||
| 46 | [8] = 4953846, | ||
| 47 | [9] = 34776317, | ||
| 48 | [10] = 68566704, | ||
| 49 | [11] = 8749194, | ||
| 50 | [12] = 1673, | ||
| 51 | }, | ||
| 52 | }, | ||
| 53 | }, | ||
| 54 | [1] = { | ||
| 55 | [2] = { | ||
| 56 | .max = 3, | ||
| 57 | .table = { | ||
| 58 | [0] = 6012079, | ||
| 59 | [1] = 45822302, | ||
| 60 | [2] = 142018732, | ||
| 61 | [3] = 41281787, | ||
| 62 | }, | ||
| 63 | }, | ||
| 64 | }, | ||
| 65 | [2] = { | ||
| 66 | [2] = { | ||
| 67 | .max = 3, | ||
| 68 | .table = { | ||
| 69 | [0] = 6391286, | ||
| 70 | [1] = 55494785, | ||
| 71 | [2] = 252389935, | ||
| 72 | [3] = 155993794, | ||
| 73 | }, | ||
| 74 | }, | ||
| 75 | }, | ||
| 76 | [3] = { | ||
| 77 | [2] = { | ||
| 78 | .max = 3, | ||
| 79 | .table = { | ||
| 80 | [0] = 6686828, | ||
| 81 | [1] = 63867852, | ||
| 82 | [2] = 392789689, | ||
| 83 | [3] = 477195231, | ||
| 84 | }, | ||
| 85 | }, | ||
| 86 | }, | ||
| 87 | [4] = { | ||
| 88 | [2] = { | ||
| 89 | .max = 3, | ||
| 90 | .table = { | ||
| 91 | [0] = 77147213, | ||
| 92 | [1] = 543379415, | ||
| 93 | [2] = 1139570251, | ||
| 94 | [3] = 120982321, | ||
| 95 | }, | ||
| 96 | }, | ||
| 97 | }, | ||
| 98 | [5] = { | ||
| 99 | [2] = { | ||
| 100 | .max = 3, | ||
| 101 | .table = { | ||
| 102 | [0] = 82471284, | ||
| 103 | [1] = 687850732, | ||
| 104 | [2] = 2345840746, | ||
| 105 | [3] = 645995638, | ||
| 106 | }, | ||
| 107 | }, | ||
| 108 | }, | ||
| 109 | [6] = { | ||
| 110 | [2] = { | ||
| 111 | .max = 3, | ||
| 112 | .table = { | ||
| 113 | [0] = 85941099, | ||
| 114 | [1] = 804752968, | ||
| 115 | [2] = 4077248182, | ||
| 116 | [3] = 2556374551, | ||
| 117 | }, | ||
| 118 | }, | ||
| 119 | }, | ||
| 120 | [7] = { | ||
| 121 | [2] = { | ||
| 122 | .max = 3, | ||
| 123 | .table = { | ||
| 124 | [0] = 88529761, | ||
| 125 | [1] = 897323475, | ||
| 126 | [2] = 6126260791, | ||
| 127 | [3] = 7936519573, | ||
| 128 | }, | ||
| 129 | }, | ||
| 130 | }, | ||
| 131 | [8] = { | ||
| 132 | [2] = { | ||
| 133 | .max = 3, | ||
| 134 | .table = { | ||
| 135 | [0] = 1051579940, | ||
| 136 | [1] = 8136021316, | ||
| 137 | [2] = 19024479822, | ||
| 138 | [3] = 18851861220, | ||
| 139 | }, | ||
| 140 | }, | ||
| 141 | }, | ||
| 142 | [9] = { | ||
| 143 | [2] = { | ||
| 144 | .max = 3, | ||
| 145 | .table = { | ||
| 146 | [0] = 1102038189, | ||
| 147 | [1] = 9888265242, | ||
| 148 | [2] = 38299375805, | ||
| 149 | [3] = 10904855164, | ||
| 150 | }, | ||
| 151 | }, | ||
| 152 | }, | ||
| 153 | [10] = { | ||
| 154 | [2] = { | ||
| 155 | .max = 3, | ||
| 156 | .table = { | ||
| 157 | [0] = 1133240039, | ||
| 158 | [1] = 11196285614, | ||
| 159 | [2] = 64164702961, | ||
| 160 | [3] = 43894840186, | ||
| 161 | }, | ||
| 162 | }, | ||
| 163 | }, | ||
| 164 | [11] = { | ||
| 165 | [2] = { | ||
| 166 | .max = 3, | ||
| 167 | .table = { | ||
| 168 | [0] = 1150763161, | ||
| 169 | [1] = 12045845660, | ||
| 170 | [2] = 91163433330, | ||
| 171 | [3] = 136418095449, | ||
| 172 | }, | ||
| 173 | }, | ||
| 174 | }, | ||
| 175 | }; | ||
| 176 | |||
| 177 | STATIC long long | ||
| 178 | checkdata_h48( | ||
| 179 | const char *solver, | ||
| 180 | unsigned long long data_size, | ||
| 181 | const unsigned char data[data_size] | ||
| 182 | ) | ||
| 183 | { | ||
| 184 | const unsigned char *table; | ||
| 185 | tableinfo_t info; | ||
| 186 | int64_t err; | ||
| 187 | uint64_t actual_distribution[INFO_DISTRIBUTION_LEN]; | ||
| 188 | uint8_t em; | ||
| 189 | uint64_t *ed; | ||
| 190 | |||
| 191 | if ((size_t)data % 8 != 0) { | ||
| 192 | LOG("[checkdata] Error: buffer is not 8-byte aligned\n"); | ||
| 193 | return NISSY_ERROR_DATA; | ||
| 194 | } | ||
| 195 | |||
| 196 | do { | ||
| 197 | err = readtableinfo(data_size, data, &info); | ||
| 198 | if (err != NISSY_OK) { | ||
| 199 | LOG("[checkdata] Data is corrupt\n"); | ||
| 200 | return NISSY_ERROR_DATA; | ||
| 201 | } | ||
| 202 | |||
| 203 | table = data + INFOSIZE; | ||
| 204 | data += info.next; | ||
| 205 | data_size -= info.next; | ||
| 206 | |||
| 207 | if (info.type != TABLETYPE_PRUNING) { | ||
| 208 | LOG("[checkdata] Skipping '%s'\n", info.solver); | ||
| 209 | continue; | ||
| 210 | } | ||
| 211 | |||
| 212 | ed = expected_h48[info.h48h][info.bits].table; | ||
| 213 | em = expected_h48[info.h48h][info.bits].max; | ||
| 214 | |||
| 215 | LOG("[checkdata] Checking distribution for '%s' from " | ||
| 216 | "table preamble\n", info.solver); | ||
| 217 | if (!distribution_equal(ed, info.distribution, em)) { | ||
| 218 | LOG("[checkdata] Distribution from the table preamble " | ||
| 219 | "does not matche the expected one\n"); | ||
| 220 | return NISSY_ERROR_DATA; | ||
| 221 | } | ||
| 222 | |||
| 223 | LOG("[checkdata] Checking distribution for '%s' from " | ||
| 224 | "actual table\n", info.solver); | ||
| 225 | getdistribution(table, actual_distribution, &info); | ||
| 226 | if (!distribution_equal(ed, actual_distribution, em)) { | ||
| 227 | LOG("[checkdata] Distribution from the actual table " | ||
| 228 | "does not match the expected one\n"); | ||
| 229 | return NISSY_ERROR_DATA; | ||
| 230 | } | ||
| 231 | } while (info.next != 0); | ||
| 232 | |||
| 233 | return NISSY_OK; | ||
| 234 | } | ||
diff --git a/src/solvers/h48/gendata_eoesep.h b/src/solvers/h48/gendata_eoesep.h index f1e3d4c..52e2b8b 100644 --- a/src/solvers/h48/gendata_eoesep.h +++ b/src/solvers/h48/gendata_eoesep.h | |||
| @@ -79,7 +79,7 @@ gendata_eoesep(unsigned char *buf, uint8_t maxdepth) | |||
| 79 | if (buf == NULL) | 79 | if (buf == NULL) |
| 80 | goto gendata_eoesep_return_size; | 80 | goto gendata_eoesep_return_size; |
| 81 | 81 | ||
| 82 | LOG("Computing eoesep data\n"); | 82 | LOG("[H48 gendata] Computing eoesep data\n"); |
| 83 | memset(buf, 0xFF, EOESEP_FULLSIZE); | 83 | memset(buf, 0xFF, EOESEP_FULLSIZE); |
| 84 | esep_classes = (uint32_t *)(buf + INFOSIZE); | 84 | esep_classes = (uint32_t *)(buf + INFOSIZE); |
| 85 | buf8 = buf + INFOSIZE + 4*ESEP_MAX; | 85 | buf8 = buf + INFOSIZE + 4*ESEP_MAX; |
| @@ -111,7 +111,7 @@ gendata_eoesep(unsigned char *buf, uint8_t maxdepth) | |||
| 111 | 111 | ||
| 112 | writetableinfo(&info, EOESEP_FULLSIZE, buf); | 112 | writetableinfo(&info, EOESEP_FULLSIZE, buf); |
| 113 | 113 | ||
| 114 | LOG("eoesep data computed\n"); | 114 | LOG("[H48 gendata] eoesep data computed\n"); |
| 115 | 115 | ||
| 116 | gendata_eoesep_return_size: | 116 | gendata_eoesep_return_size: |
| 117 | return EOESEP_FULLSIZE; | 117 | return EOESEP_FULLSIZE; |
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index 644ddc2..d1ab3bd 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h | |||
| @@ -25,8 +25,6 @@ STATIC_INLINE uint8_t get_h48_pval_atomic( | |||
| 25 | STATIC_INLINE void set_h48_pval_atomic( | 25 | STATIC_INLINE void set_h48_pval_atomic( |
| 26 | _Atomic unsigned char *, int64_t, uint8_t, uint8_t); | 26 | _Atomic unsigned char *, int64_t, uint8_t, uint8_t); |
| 27 | 27 | ||
| 28 | size_t gendata_h48_derive(uint8_t, const unsigned char *, unsigned char *); | ||
| 29 | |||
| 30 | STATIC long long | 28 | STATIC long long |
| 31 | gendata_h48_dispatch( | 29 | gendata_h48_dispatch( |
| 32 | const char *solver, | 30 | const char *solver, |
| @@ -711,91 +709,3 @@ set_h48_pval_atomic( | |||
| 711 | table[H48_INDEX(i, k)] = (table[H48_INDEX(i, k)] & (~H48_MASK(i, k))) | 709 | table[H48_INDEX(i, k)] = (table[H48_INDEX(i, k)] & (~H48_MASK(i, k))) |
| 712 | | (val << H48_SHIFT(i, k)); | 710 | | (val << H48_SHIFT(i, k)); |
| 713 | } | 711 | } |
| 714 | |||
| 715 | size_t | ||
| 716 | gendata_h48_derive(uint8_t h, const unsigned char *fulltable, unsigned char *buf) | ||
| 717 | { | ||
| 718 | size_t cocsepsize, h48size; | ||
| 719 | uint8_t val_full, val_derive; | ||
| 720 | const unsigned char *h48full; | ||
| 721 | unsigned char *h48derive; | ||
| 722 | int64_t i, j, h48max; | ||
| 723 | uint64_t bufsize; | ||
| 724 | gendata_h48_arg_t arg; | ||
| 725 | tableinfo_t cocsepinfo, fulltableinfo; | ||
| 726 | |||
| 727 | /* Initializing values in case of error */ | ||
| 728 | /* TODO cleanup this */ | ||
| 729 | fulltableinfo.h48h = 11; | ||
| 730 | fulltableinfo.bits = 2; | ||
| 731 | fulltableinfo.base = 8; | ||
| 732 | |||
| 733 | int64_t TODOlarge = 999999999999; /* TODO: cleanup here */ | ||
| 734 | |||
| 735 | readtableinfo_n(TODOlarge, fulltable, 2, &fulltableinfo); | ||
| 736 | arg.h = h; | ||
| 737 | arg.k = fulltableinfo.bits; | ||
| 738 | arg.maxdepth = 20; | ||
| 739 | arg.buf = buf; | ||
| 740 | arg.cocsepdata = (uint32_t *)(buf + INFOSIZE); | ||
| 741 | arg.base = fulltableinfo.base; | ||
| 742 | arg.info = makeinfo_h48k2(&arg); | ||
| 743 | |||
| 744 | /* Technically this step is redundant, except that we | ||
| 745 | need selfsim and crep */ | ||
| 746 | cocsepsize = gendata_cocsep(buf, arg.selfsim, arg.crep); | ||
| 747 | arg.h48buf = (_Atomic unsigned char *)buf + cocsepsize; | ||
| 748 | h48size = H48_TABLESIZE(h, arg.k) + INFOSIZE; | ||
| 749 | |||
| 750 | if (buf == NULL) | ||
| 751 | goto gendata_h48_derive_return_size; | ||
| 752 | |||
| 753 | bufsize = COCSEP_FULLSIZE + INFOSIZE; | ||
| 754 | if (readtableinfo(bufsize, buf, &cocsepinfo) != NISSY_OK) { | ||
| 755 | LOG("[H48 derive gendata] Error: could not read info for " | ||
| 756 | "cocsep table\n"); | ||
| 757 | goto gendata_h48_derive_error; | ||
| 758 | } | ||
| 759 | |||
| 760 | cocsepinfo.next = cocsepsize; | ||
| 761 | bufsize = COCSEP_FULLSIZE + INFOSIZE; | ||
| 762 | if (writetableinfo(&cocsepinfo, bufsize, buf) != NISSY_OK) { | ||
| 763 | LOG("[H48 derive gendata] Error: could not write info for " | ||
| 764 | "cocsep table with updated 'next' value\n"); | ||
| 765 | goto gendata_h48_derive_error; | ||
| 766 | } | ||
| 767 | |||
| 768 | h48full = fulltable + cocsepsize + INFOSIZE; | ||
| 769 | h48derive = (unsigned char *)arg.h48buf + INFOSIZE; | ||
| 770 | memset(h48derive, 0xFF, H48_TABLESIZE(h, arg.k)); | ||
| 771 | memset(arg.info.distribution, 0, | ||
| 772 | INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); | ||
| 773 | |||
| 774 | h48max = H48_COORDMAX(fulltableinfo.h48h); | ||
| 775 | for (i = 0; i < h48max; i++) { | ||
| 776 | if (i % INT64_C(1000000000) == 0 && i > 0) | ||
| 777 | LOG("[H48 derive gendata] Processing %" PRId64 | ||
| 778 | "th coordinate\n", i); | ||
| 779 | j = i >> (int64_t)(fulltableinfo.h48h - h); | ||
| 780 | val_full = get_h48_pval(h48full, i, arg.k); | ||
| 781 | val_derive = get_h48_pval(h48derive, j, arg.k); | ||
| 782 | set_h48_pval( | ||
| 783 | h48derive, j, arg.k, MIN(val_full, val_derive)); | ||
| 784 | } | ||
| 785 | |||
| 786 | getdistribution(h48derive, arg.info.distribution, &arg.info); | ||
| 787 | |||
| 788 | bufsize = arg.buf_size - COCSEP_FULLSIZE - INFOSIZE; | ||
| 789 | if (writetableinfo(&arg.info, bufsize, (unsigned char *)arg.h48buf) | ||
| 790 | != NISSY_OK) { | ||
| 791 | LOG("H48 derive gendata] Error: could not write info " | ||
| 792 | "for table\n"); | ||
| 793 | goto gendata_h48_derive_error; | ||
| 794 | } | ||
| 795 | |||
| 796 | gendata_h48_derive_return_size: | ||
| 797 | return cocsepsize + h48size; | ||
| 798 | |||
| 799 | gendata_h48_derive_error: | ||
| 800 | return 0; | ||
| 801 | } | ||
diff --git a/src/solvers/h48/h48.h b/src/solvers/h48/h48.h index 79d2583..44fdb59 100644 --- a/src/solvers/h48/h48.h +++ b/src/solvers/h48/h48.h | |||
| @@ -7,4 +7,5 @@ | |||
| 7 | #include "gendata_cocsep.h" | 7 | #include "gendata_cocsep.h" |
| 8 | #include "gendata_eoesep.h" | 8 | #include "gendata_eoesep.h" |
| 9 | #include "gendata_h48.h" | 9 | #include "gendata_h48.h" |
| 10 | #include "checkdata.h" | ||
| 10 | #include "solve.h" | 11 | #include "solve.h" |
