diff options
| author | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-12-25 20:57:45 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-12-25 20:57:45 +0100 |
| commit | ce4d6f93c8d00a56b9356d0c0d8489c28e1459df (patch) | |
| tree | 4f519efd1850d444ef344f6098b7e3346bcd94a8 | |
| parent | 0f81a5a70be20a82ee8495f050366a28d0be21c7 (diff) | |
| download | nissy-ce4d6f93c8d00a56b9356d0c0d8489c28e1459df.tar.gz nissy-ce4d6f93c8d00a56b9356d0c0d8489c28e1459df.zip | |
Added -O option for solve (specify number of moves within optimal)
| -rw-r--r-- | TODO.md | 5 | ||||
| -rw-r--r-- | doc/nissy.1 | 8 | ||||
| -rwxr-xr-x | nissy | bin | 318128 -> 322224 bytes | |||
| -rwxr-xr-x | nissy.exe | bin | 783308 -> 783820 bytes | |||
| -rw-r--r-- | src/commands.c | 22 | ||||
| -rw-r--r-- | src/cubetypes.h | 2 | ||||
| -rw-r--r-- | src/solve.c | 9 |
7 files changed, 34 insertions, 12 deletions
| @@ -26,11 +26,9 @@ including e.g. solutions that were not shown because -c) | |||
| 26 | * solve should try up to a small bound without loading the large pruning table | 26 | * solve should try up to a small bound without loading the large pruning table |
| 27 | * **drfin for HTR scrambles should try all 3 axis and pick the best solutions; | 27 | * **drfin for HTR scrambles should try all 3 axis and pick the best solutions; |
| 28 | in general every step that automatically detects orientation should do this** | 28 | in general every step that automatically detects orientation should do this** |
| 29 | * **solve -O N find solutions within N moves from optimal | ||
| 30 | (-o is the same as -O 0)** | ||
| 31 | 29 | ||
| 32 | ### New features | 30 | ### New features |
| 33 | * **cleanup: translate an alg to the standard HTM moveset + reorient at the end** | 31 | * cleanup: translate an alg to the standard HTM moveset + reorient at the end |
| 34 | * configurability: add an `alias` command, run config file at startup | 32 | * configurability: add an `alias` command, run config file at startup |
| 35 | * configure max ram to be used (via config file and/or command line option) | 33 | * configure max ram to be used (via config file and/or command line option) |
| 36 | * transform alg, rufify etc... | 34 | * transform alg, rufify etc... |
| @@ -43,6 +41,7 @@ including e.g. solutions that were not shown because -c) | |||
| 43 | * webapp (cgi) | 41 | * webapp (cgi) |
| 44 | * **Re-upload tables** | 42 | * **Re-upload tables** |
| 45 | * **fix README.md** | 43 | * **fix README.md** |
| 44 | * **fix examples in manpage** | ||
| 46 | 45 | ||
| 47 | ## Technical stuff | 46 | ## Technical stuff |
| 48 | 47 | ||
diff --git a/doc/nissy.1 b/doc/nissy.1 index fea5ddb..549cc4f 100644 --- a/doc/nissy.1 +++ b/doc/nissy.1 | |||
| @@ -127,6 +127,14 @@ Allow use of NISS. | |||
| 127 | .It Fl o | 127 | .It Fl o |
| 128 | Only find solutions that require the minimum number of moves. | 128 | Only find solutions that require the minimum number of moves. |
| 129 | . | 129 | . |
| 130 | .It Fl O Ar N | ||
| 131 | Only find solutions that require at most | ||
| 132 | .Ar N | ||
| 133 | moves more than the optimal solution. If | ||
| 134 | .Ar N | ||
| 135 | is 0, this is equivalent to | ||
| 136 | .It Fl o | ||
| 137 | . | ||
| 130 | .It Fl p | 138 | .It Fl p |
| 131 | Plain style: do not print the number of moves. | 139 | Plain style: do not print the number of moves. |
| 132 | . | 140 | . |
| Binary files differ | |||
| Binary files differ | |||
diff --git a/src/commands.c b/src/commands.c index 7d30c88..56ff944 100644 --- a/src/commands.c +++ b/src/commands.c | |||
| @@ -147,7 +147,7 @@ solve_parse_args(int c, char **v) | |||
| 147 | a->opts->max_moves = 20; | 147 | a->opts->max_moves = 20; |
| 148 | a->opts->max_solutions = 1; | 148 | a->opts->max_solutions = 1; |
| 149 | a->opts->nthreads = 1; | 149 | a->opts->nthreads = 1; |
| 150 | a->opts->optimal_only = false; | 150 | a->opts->optimal = -1; |
| 151 | a->opts->can_niss = false; | 151 | a->opts->can_niss = false; |
| 152 | a->opts->verbose = false; | 152 | a->opts->verbose = false; |
| 153 | a->opts->all = false; | 153 | a->opts->all = false; |
| @@ -163,7 +163,7 @@ solve_parse_args(int c, char **v) | |||
| 163 | if (val < 0 || val > 100) { | 163 | if (val < 0 || val > 100) { |
| 164 | fprintf(stderr, | 164 | fprintf(stderr, |
| 165 | "Invalid min number of moves" | 165 | "Invalid min number of moves" |
| 166 | "(0 <= m <= 100).\n"); | 166 | "(0 <= N <= 100).\n"); |
| 167 | return a; | 167 | return a; |
| 168 | } | 168 | } |
| 169 | a->opts->min_moves = val; | 169 | a->opts->min_moves = val; |
| @@ -172,7 +172,7 @@ solve_parse_args(int c, char **v) | |||
| 172 | if (val < 0 || val > 100) { | 172 | if (val < 0 || val > 100) { |
| 173 | fprintf(stderr, | 173 | fprintf(stderr, |
| 174 | "Invalid max number of moves" | 174 | "Invalid max number of moves" |
| 175 | "(0 <= M <= 100).\n"); | 175 | "(0 <= N <= 100).\n"); |
| 176 | return a; | 176 | return a; |
| 177 | } | 177 | } |
| 178 | a->opts->max_moves = val; | 178 | a->opts->max_moves = val; |
| @@ -196,7 +196,18 @@ solve_parse_args(int c, char **v) | |||
| 196 | a->opts->max_solutions = val; | 196 | a->opts->max_solutions = val; |
| 197 | fixedmsols = true; | 197 | fixedmsols = true; |
| 198 | } else if (!strcmp(v[i], "-o")) { | 198 | } else if (!strcmp(v[i], "-o")) { |
| 199 | a->opts->optimal_only = true; | 199 | a->opts->optimal = 0; |
| 200 | infinitesols = true; | ||
| 201 | } else if (!strcmp(v[i], "-O") && i+1 < c) { | ||
| 202 | val = strtol(v[++i], NULL, 10); | ||
| 203 | if (val < 0 || val > 100 || | ||
| 204 | (val == 0 && strcmp("0", v[i]))) { | ||
| 205 | fprintf(stderr, | ||
| 206 | "Invalid max number of moves" | ||
| 207 | " (0 <= N <= 100).\n"); | ||
| 208 | return a; | ||
| 209 | } | ||
| 210 | a->opts->optimal = val; | ||
| 200 | infinitesols = true; | 211 | infinitesols = true; |
| 201 | } else if (!strcmp(v[i], "-N")) { | 212 | } else if (!strcmp(v[i], "-N")) { |
| 202 | a->opts->can_niss = true; | 213 | a->opts->can_niss = true; |
| @@ -447,7 +458,8 @@ read_scramble(int c, char **v, CommandArgs *args) | |||
| 447 | for(i = 0; i < c; i++) { | 458 | for(i = 0; i < c; i++) { |
| 448 | aux = new_alg(v[i]); | 459 | aux = new_alg(v[i]); |
| 449 | if (aux->len == 0) { | 460 | if (aux->len == 0) { |
| 450 | fprintf(stderr, "Error: %s unrecognized\n", v[i]); | 461 | fprintf(stderr, "Error: %s or its argument" |
| 462 | "unrecognized\n", v[i]); | ||
| 451 | free(aux); | 463 | free(aux); |
| 452 | return false; | 464 | return false; |
| 453 | } | 465 | } |
diff --git a/src/cubetypes.h b/src/cubetypes.h index 6d8af21..1b679aa 100644 --- a/src/cubetypes.h +++ b/src/cubetypes.h | |||
| @@ -279,7 +279,7 @@ solveoptions | |||
| 279 | int max_moves; | 279 | int max_moves; |
| 280 | int max_solutions; | 280 | int max_solutions; |
| 281 | int nthreads; | 281 | int nthreads; |
| 282 | bool optimal_only; | 282 | int optimal; |
| 283 | bool can_niss; | 283 | bool can_niss; |
| 284 | bool verbose; | 284 | bool verbose; |
| 285 | bool all; | 285 | bool all; |
diff --git a/src/solve.c b/src/solve.c index 931dc02..79e421d 100644 --- a/src/solve.c +++ b/src/solve.c | |||
| @@ -373,7 +373,7 @@ niss_makes_sense(DfsArg *arg) | |||
| 373 | AlgList * | 373 | AlgList * |
| 374 | solve(Cube cube, Step *step, SolveOptions *opts) | 374 | solve(Cube cube, Step *step, SolveOptions *opts) |
| 375 | { | 375 | { |
| 376 | int d; | 376 | int d, op; |
| 377 | AlgList *sols; | 377 | AlgList *sols; |
| 378 | Cube c; | 378 | Cube c; |
| 379 | 379 | ||
| @@ -396,16 +396,19 @@ solve(Cube cube, Step *step, SolveOptions *opts) | |||
| 396 | return sols; | 396 | return sols; |
| 397 | } | 397 | } |
| 398 | 398 | ||
| 399 | op = -1; | ||
| 399 | for (d = opts->min_moves; | 400 | for (d = opts->min_moves; |
| 400 | d <= opts->max_moves && | 401 | d <= opts->max_moves && |
| 401 | !(sols->len && opts->optimal_only) && | 402 | !(opts->optimal != -1 && op != -1 && opts->optimal + op < d) && |
| 402 | sols->len < opts->max_solutions; | 403 | sols->len < opts->max_solutions; |
| 403 | d++) { | 404 | d++) { |
| 404 | if (opts->verbose) | 405 | if (opts->verbose) |
| 405 | fprintf(stderr, | 406 | fprintf(stderr, |
| 406 | "Found %d solutions, searching depth %d...\n", | 407 | "Found %d solutions, searching depth %d...\n", |
| 407 | sols->len, d); | 408 | sols->len, d); |
| 408 | multidfs(c, step, opts, sols, d); | 409 | multidfs(c, step, opts, sols, d); |
| 410 | if (sols->len > 0 && op == -1) | ||
| 411 | op = d; | ||
| 409 | } | 412 | } |
| 410 | 413 | ||
| 411 | return sols; | 414 | return sols; |
