diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-11 19:48:57 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-11 19:48:57 +0200 |
| commit | 10b65003102675bd19c0e5174ff249be2a163bc7 (patch) | |
| tree | 10388535f1395f084a1a0456094f90cc2390fc62 /src | |
| parent | e6ff0ce6926fa921a13055c9c35d8e60b691e776 (diff) | |
| download | nissy-core-10b65003102675bd19c0e5174ff249be2a163bc7.tar.gz nissy-core-10b65003102675bd19c0e5174ff249be2a163bc7.zip | |
Simplified solver
Diffstat (limited to 'src')
| -rw-r--r-- | src/nissy.c | 2 | ||||
| -rw-r--r-- | src/solvers/h48/gendata_h48.h | 3 | ||||
| -rw-r--r-- | src/solvers/h48/solve.h | 14 | ||||
| -rw-r--r-- | src/solvers/tables.h | 17 |
4 files changed, 28 insertions, 8 deletions
diff --git a/src/nissy.c b/src/nissy.c index 2d6af4b..d657d8e 100644 --- a/src/nissy.c +++ b/src/nissy.c | |||
| @@ -334,7 +334,7 @@ nissy_solve( | |||
| 334 | ret = -1; | 334 | ret = -1; |
| 335 | } else { | 335 | } else { |
| 336 | ret = solve_h48(c, minmoves, maxmoves, maxsolutions, | 336 | ret = solve_h48(c, minmoves, maxmoves, maxsolutions, |
| 337 | h, k, data, solutions); | 337 | data, solutions); |
| 338 | } | 338 | } |
| 339 | } else if (!strcmp(solver, "h48stats")) { | 339 | } else if (!strcmp(solver, "h48stats")) { |
| 340 | ret = solve_h48stats(c, maxmoves, data, solutions); | 340 | ret = solve_h48stats(c, maxmoves, data, solutions); |
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index f276eca..066c650 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h | |||
| @@ -152,13 +152,14 @@ gendata_h48(gendata_h48_arg_t *arg) | |||
| 152 | goto gendata_h48_error; | 152 | goto gendata_h48_error; |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | if (arg->buf == 0) | 155 | if (arg->buf == NULL) |
| 156 | goto gendata_h48_return_size; | 156 | goto gendata_h48_return_size; |
| 157 | 157 | ||
| 158 | if (!readtableinfo(arg->buf, &cocsepinfo)) { | 158 | if (!readtableinfo(arg->buf, &cocsepinfo)) { |
| 159 | LOG("gendata_h48: could not read info for cocsep table\n"); | 159 | LOG("gendata_h48: could not read info for cocsep table\n"); |
| 160 | goto gendata_h48_error; | 160 | goto gendata_h48_error; |
| 161 | } | 161 | } |
| 162 | |||
| 162 | cocsepinfo.next = cocsepsize; | 163 | cocsepinfo.next = cocsepsize; |
| 163 | if (!writetableinfo(&cocsepinfo, arg->buf)) { | 164 | if (!writetableinfo(&cocsepinfo, arg->buf)) { |
| 164 | LOG("gendata_h48: could not write info for cocsep table" | 165 | LOG("gendata_h48: could not write info for cocsep table" |
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index 26847b2..4bf55ca 100644 --- a/src/solvers/h48/solve.h +++ b/src/solvers/h48/solve.h | |||
| @@ -31,7 +31,7 @@ STATIC uint32_t allowednextmove_h48(uint8_t *, uint8_t, uint32_t); | |||
| 31 | STATIC void solve_h48_appendsolution(dfsarg_solveh48_t *); | 31 | STATIC void solve_h48_appendsolution(dfsarg_solveh48_t *); |
| 32 | STATIC_INLINE bool solve_h48_stop(dfsarg_solveh48_t *); | 32 | STATIC_INLINE bool solve_h48_stop(dfsarg_solveh48_t *); |
| 33 | STATIC int64_t solve_h48_dfs(dfsarg_solveh48_t *); | 33 | STATIC int64_t solve_h48_dfs(dfsarg_solveh48_t *); |
| 34 | STATIC int64_t solve_h48(cube_t, int8_t, int8_t, int8_t, uint8_t, uint8_t, const void *, char *); | 34 | STATIC int64_t solve_h48(cube_t, int8_t, int8_t, int8_t, const void *, char *); |
| 35 | 35 | ||
| 36 | STATIC int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *); | 36 | STATIC int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *); |
| 37 | STATIC int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]); | 37 | STATIC int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]); |
| @@ -176,22 +176,26 @@ solve_h48( | |||
| 176 | int8_t minmoves, | 176 | int8_t minmoves, |
| 177 | int8_t maxmoves, | 177 | int8_t maxmoves, |
| 178 | int8_t maxsolutions, | 178 | int8_t maxsolutions, |
| 179 | uint8_t h, | ||
| 180 | uint8_t k, | ||
| 181 | const void *data, | 179 | const void *data, |
| 182 | char *solutions | 180 | char *solutions |
| 183 | ) | 181 | ) |
| 184 | { | 182 | { |
| 185 | int64_t nsols; | 183 | int64_t nsols; |
| 186 | dfsarg_solveh48_t arg; | 184 | dfsarg_solveh48_t arg; |
| 185 | tableinfo_t info; | ||
| 186 | |||
| 187 | if(!readtableinfo_n(data, 2, &info)) { | ||
| 188 | LOG("solve_h48: error reading table\n"); | ||
| 189 | return 0; | ||
| 190 | } | ||
| 187 | 191 | ||
| 188 | arg = (dfsarg_solveh48_t) { | 192 | arg = (dfsarg_solveh48_t) { |
| 189 | .cube = cube, | 193 | .cube = cube, |
| 190 | .inverse = inverse(cube), | 194 | .inverse = inverse(cube), |
| 191 | .nsols = &nsols, | 195 | .nsols = &nsols, |
| 192 | .maxsolutions = maxsolutions, | 196 | .maxsolutions = maxsolutions, |
| 193 | .h = h, | 197 | .h = info.h48h, |
| 194 | .k = k, | 198 | .k = info.bits, |
| 195 | .cocsepdata = get_cocsepdata_ptr(data), | 199 | .cocsepdata = get_cocsepdata_ptr(data), |
| 196 | .h48data = get_h48data_ptr(data), | 200 | .h48data = get_h48data_ptr(data), |
| 197 | .nextsol = &solutions | 201 | .nextsol = &solutions |
diff --git a/src/solvers/tables.h b/src/solvers/tables.h index 988de52..bad3b2c 100644 --- a/src/solvers/tables.h +++ b/src/solvers/tables.h | |||
| @@ -14,7 +14,8 @@ | |||
| 14 | #define INFO_OFFSET_HASH (INFO_OFFSET_FULLSIZE + sizeof(uint64_t)) | 14 | #define INFO_OFFSET_HASH (INFO_OFFSET_FULLSIZE + sizeof(uint64_t)) |
| 15 | #define INFO_OFFSET_ENTRIES (INFO_OFFSET_HASH + sizeof(uint64_t)) | 15 | #define INFO_OFFSET_ENTRIES (INFO_OFFSET_HASH + sizeof(uint64_t)) |
| 16 | #define INFO_OFFSET_CLASSES (INFO_OFFSET_ENTRIES + sizeof(uint64_t)) | 16 | #define INFO_OFFSET_CLASSES (INFO_OFFSET_ENTRIES + sizeof(uint64_t)) |
| 17 | #define INFO_OFFSET_BITS (INFO_OFFSET_CLASSES + sizeof(uint64_t)) | 17 | #define INFO_OFFSET_H48H (INFO_OFFSET_CLASSES + sizeof(uint64_t)) |
| 18 | #define INFO_OFFSET_BITS (INFO_OFFSET_H48H + sizeof(uint8_t)) | ||
| 18 | #define INFO_OFFSET_BASE (INFO_OFFSET_BITS + sizeof(uint8_t)) | 19 | #define INFO_OFFSET_BASE (INFO_OFFSET_BITS + sizeof(uint8_t)) |
| 19 | #define INFO_OFFSET_MAXVALUE (INFO_OFFSET_BASE + sizeof(uint8_t)) | 20 | #define INFO_OFFSET_MAXVALUE (INFO_OFFSET_BASE + sizeof(uint8_t)) |
| 20 | #define INFO_OFFSET_NEXT (INFO_OFFSET_MAXVALUE + sizeof(uint8_t)) | 21 | #define INFO_OFFSET_NEXT (INFO_OFFSET_MAXVALUE + sizeof(uint8_t)) |
| @@ -28,6 +29,7 @@ typedef struct { | |||
| 28 | uint64_t hash; | 29 | uint64_t hash; |
| 29 | uint64_t entries; | 30 | uint64_t entries; |
| 30 | uint64_t classes; /* Used only by cocsepdata, for now */ | 31 | uint64_t classes; /* Used only by cocsepdata, for now */ |
| 32 | uint8_t h48h; /* Specific to H48 tables */ | ||
| 31 | uint8_t bits; | 33 | uint8_t bits; |
| 32 | uint8_t base; | 34 | uint8_t base; |
| 33 | uint8_t maxvalue; | 35 | uint8_t maxvalue; |
| @@ -36,6 +38,7 @@ typedef struct { | |||
| 36 | } tableinfo_t; | 38 | } tableinfo_t; |
| 37 | 39 | ||
| 38 | STATIC bool readtableinfo(const void *, tableinfo_t *); | 40 | STATIC bool readtableinfo(const void *, tableinfo_t *); |
| 41 | STATIC bool readtableinfo_n(const void *, uint8_t, tableinfo_t *); | ||
| 39 | STATIC bool writetableinfo(const tableinfo_t *, void *); | 42 | STATIC bool writetableinfo(const tableinfo_t *, void *); |
| 40 | 43 | ||
| 41 | STATIC bool | 44 | STATIC bool |
| @@ -59,6 +62,7 @@ readtableinfo(const void *buf, tableinfo_t *info) | |||
| 59 | info->hash = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_HASH); | 62 | info->hash = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_HASH); |
| 60 | info->entries = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES); | 63 | info->entries = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES); |
| 61 | info->classes = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_CLASSES); | 64 | info->classes = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_CLASSES); |
| 65 | info->h48h = *OFFSET(buf, INFO_OFFSET_H48H); | ||
| 62 | info->bits = *OFFSET(buf, INFO_OFFSET_BITS); | 66 | info->bits = *OFFSET(buf, INFO_OFFSET_BITS); |
| 63 | info->base = *OFFSET(buf, INFO_OFFSET_BASE); | 67 | info->base = *OFFSET(buf, INFO_OFFSET_BASE); |
| 64 | info->maxvalue = *OFFSET(buf, INFO_OFFSET_MAXVALUE); | 68 | info->maxvalue = *OFFSET(buf, INFO_OFFSET_MAXVALUE); |
| @@ -70,6 +74,16 @@ readtableinfo(const void *buf, tableinfo_t *info) | |||
| 70 | } | 74 | } |
| 71 | 75 | ||
| 72 | STATIC bool | 76 | STATIC bool |
| 77 | readtableinfo_n(const void *buf, uint8_t n, tableinfo_t *info) | ||
| 78 | { | ||
| 79 | for ( ; n > 0; n--, buf = (char *)buf + info->next) | ||
| 80 | if (!readtableinfo(buf, info)) | ||
| 81 | return false; | ||
| 82 | |||
| 83 | return true; | ||
| 84 | } | ||
| 85 | |||
| 86 | STATIC bool | ||
| 73 | writetableinfo(const tableinfo_t *info, void *buf) | 87 | writetableinfo(const tableinfo_t *info, void *buf) |
| 74 | { | 88 | { |
| 75 | int i; | 89 | int i; |
| @@ -98,6 +112,7 @@ writetableinfo(const tableinfo_t *info, void *buf) | |||
| 98 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_HASH) = info->hash; | 112 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_HASH) = info->hash; |
| 99 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES) = info->entries; | 113 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES) = info->entries; |
| 100 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_CLASSES) = info->classes; | 114 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_CLASSES) = info->classes; |
| 115 | *OFFSET(buf, INFO_OFFSET_H48H) = info->h48h; | ||
| 101 | *OFFSET(buf, INFO_OFFSET_BITS) = info->bits; | 116 | *OFFSET(buf, INFO_OFFSET_BITS) = info->bits; |
| 102 | *OFFSET(buf, INFO_OFFSET_BASE) = info->base; | 117 | *OFFSET(buf, INFO_OFFSET_BASE) = info->base; |
| 103 | *OFFSET(buf, INFO_OFFSET_MAXVALUE) = info->maxvalue; | 118 | *OFFSET(buf, INFO_OFFSET_MAXVALUE) = info->maxvalue; |
