nissy-fmc

A Rubik's cube FMC assistant
git clone https://git.tronto.net/nissy-fmc
Download | Log | Files | Refs | README | LICENSE

commit 6c28dec4a111ad73f8ac17c89305a951371f765d
parent d8a94976ebad9c55aca6b0443c5f92d892e12dd0
Author: Sebastiano Tronto <sebastiano.tronto@gmail.com>
Date:   Fri, 10 Dec 2021 18:15:20 +0100

Added gen command and modified installation instructions for tables

Diffstat:
MINSTALL | 29+++++++++++++++++++++++------
MREADME.md | 39+++++++++++++++++++++++++++------------
MTODO.md | 8+-------
Mdoc/nissy.1 | 8++++++++
Dnissy | 0
Mnissy-2.0beta5.tar.gz | 0
Mnissy.exe | 0
Msrc/commands.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/pruning.c | 15+++++++++++++++
Msrc/pruning.h | 4++++
10 files changed, 133 insertions(+), 25 deletions(-)

diff --git a/INSTALL b/INSTALL @@ -11,7 +11,7 @@ pruning table. If so, about 200Mb should be enough. ## On Windows Try downloading and executing in a terminal the file nissy.exe, then -follow the instructions in the UNIX section below for downloading and +follow the instructions in the Tables section below for installing the pruning tables. If nissy.exe does not work, you can try following the UNIX instructions in WSL (Windows Subsystem for Linux) or in a similar environment. @@ -22,11 +22,28 @@ Sorry for the inconvenience, I don't have a Windows machine to test this on. Edit the Makefile to match your local configuration (usually not necessary, but you may want to change the PREFIX variable) and run make, followed by make install. -After that, you need to download some files and manually save them to your NISSYDATA -folder (se manual page, ENVIRONMENT section). If you don't do it nissy can compute -these files when needed and save them in the correct folders, but some of them -take hours to generate even for a powerful computer (for reference, the huge pruning -table takes about 20 hours on my laptop). +Follows the instructions below to install the pruning tables. + +## Tables +Nissy needs to generate certain large tables to work. These tables are by default +generated the first time they are needed (e.g the first time you ask to solve a +certain step) and then saved to a file. The following times nissy simply loads the +corresponding file from the hard disk. + +The very large table for optimal solving can take some time to generate (about 20 +minutes on my fairly old but decent laptop, using 8 CPU threads). All other +tables are much faster. + +You can ask nissy to generate all the tables it will ever need with the gen +command. It is recommended to use more than one thread, if your CPU has them. +For example, you can run: + +nissy gen -t 8 + +to generate all tables using 8 threads. + +Alternatively, you can simply download all the tables and copy them into the +correct folder (see manual page, ENVIRONMENT section). Choose one of the following: https://math.uni.lu/tronto/nissy/nissy-tables-full.zip https://math.uni.lu/tronto/nissy/nissy-tables-full.tar.gz diff --git a/README.md b/README.md @@ -31,7 +31,7 @@ pruning table. If so, about 200Mb should be enough. ### On Windows Try downloading and executing in a terminal the file nissy.exe, then -follow the instructions in the UNIX section below for downloading and +follow the instructions in the **Tables** section below for installing the pruning tables. If nissy.exe does not work, you can try following the UNIX instructions in WSL (Windows Subsystem for Linux) or in a similar environment. @@ -40,17 +40,32 @@ Sorry for the inconvenience, I don't have a Windows machine to test this on. ### On a UNIX system: -You can download the source code for the latest version from git or simply clone -the repo with `git clone https://github.com/sebastianotronto/nissy`. - Edit the Makefile to match your local configuration (usually not necessary, but you may want to change the `PREFIX` variable) and run `make`, followed by `make install`. -After that, you need to download some files and manually save them to your `NISSYDATA` -folder (see manual page, ENVIRONMENT section). If you don't do it nissy can compute -these files when needed and save them in the correct folders, but some of them -take hours to generate even for a powerful computer (for reference, the huge pruning -table takes about 20 hours on my laptop). +Follows the instructions below to install the pruning tables. + +### Tables +Nissy needs to generate certain large tables to work. These tables are by default +generated the first time they are needed (e.g the first time you ask to solve a +certain step) and then saved to a file. The following times nissy simply loads the +corresponding file from the hard disk. + +The very large table for optimal solving can take some time to generate (about 20 +minutes on my fairly old but decent laptop, using 8 CPU threads). All other +tables are much faster. + +You can ask nissy to generate all the tables it will ever need with the **gen** +command. It is recommended to use more than one thread, if your CPU has them. +For example, you can run: + +``` +nissy gen -t 8 +``` + +to generate all tables using 8 threads. +Alternatively, you can simply download all the tables and copy them into the +correct folder (see manual page, `ENVIRONMENT` section). Choose one of the following: | |.zip|.tar.gz| @@ -58,9 +73,9 @@ Choose one of the following: |Full (~720Mb)|[full.zip](https://math.uni.lu/tronto/nissy/nissy-tables-full.zip)|[full.tar.gz](https://math.uni.lu/tronto/nissy/nissy-tables-full.tar.gz)| |No huge table (~90Mb)|[nohuge.zip](https://math.uni.lu/tronto/nissy/nissy-tables-nohuge.zip)|[nohuge.tar.gz](https://math.uni.lu/tronto/nissy/nissy-tables-nohuge.tar.gz)| -extract the archive and copy the `tables` folder into `NISSIDATA` (paste there -the whole folder, not the single files). The `nohuge` files are much smaller and -do not contain the huge pruning table for the optimal solver. +extract the archive and copy the tables folder into `NISSIDATA` (paste there +the whole folder, not file by file). The "nohuge" files are much smaller and do not +contain the huge pruning table for the optimal solver. ## Structure of the code diff --git a/TODO.md b/TODO.md @@ -54,16 +54,10 @@ and just use previous values for all 3 axes. ## Coordinates, symmetries, pruning tables * Cleanup symcoord.c: some coordinates and symdata are never actually used; remove also sd_eofbepos and just use sd_coud for khuge (this changes the -coordinate so the whole table must be generated again!) +coordinate so the whole table must be generated again!) or viceversa * Use pruning values mod 4 instead of mod 16 (or maybe not, I like the current system) -### Memory management -* fail gracefully when there is not enough memory to load a large table -* free tables from memory when not used -* optionally run in low-memory friendly version (no tables above a few Mb); - this can be useful e.g. for embedded devices - ### Structural changes * client/server architecture: run a server process in the background so that multiple client processess can send it queries and get results; this would diff --git a/doc/nissy.1 b/doc/nissy.1 @@ -36,6 +36,14 @@ are the following: .It Nm commands List all available commands. . +.It Nm gen Op Fl t Ar N +Generate all tables used by nissy. Run this to complete your installation. +If +.Ar N +is specified, +.Ar N +CPU threads will be used (defaults to 1). +. .It Nm help Op Ar command Display help. If no .Ar command diff --git a/nissy b/nissy Binary files differ. diff --git a/nissy-2.0beta5.tar.gz b/nissy-2.0beta5.tar.gz Binary files differ. diff --git a/nissy.exe b/nissy.exe Binary files differ. diff --git a/src/commands.c b/src/commands.c @@ -3,12 +3,14 @@ /* Arg parsing functions *****************************************************/ CommandArgs * solve_parse_args(int c, char **v); +CommandArgs * gen_parse_args(int c, char **v); CommandArgs * help_parse_args(int c, char **v); CommandArgs * print_parse_args(int c, char **v); CommandArgs * parse_no_arg(int c, char **v); /* Exec functions ************************************************************/ +static void gen_exec(CommandArgs *args); static void solve_exec(CommandArgs *args); static void steps_exec(CommandArgs *args); static void commands_exec(CommandArgs *args); @@ -34,6 +36,15 @@ solve_cmd = { }; Command +gen_cmd = { + .name = "gen", + .usage = "gen [-t N]", + .description = "Generate all tables [using N threads]", + .parse_args = gen_parse_args, + .exec = gen_exec +}; + +Command steps_cmd = { .name = "steps", .usage = "steps", @@ -89,6 +100,7 @@ version_cmd = { Command *commands[NCOMMANDS] = { &commands_cmd, + &gen_cmd, &help_cmd, &print_cmd, &quit_cmd, @@ -173,6 +185,34 @@ solve_parse_args(int c, char **v) } CommandArgs * +gen_parse_args(int c, char **v) +{ + int val; + CommandArgs *a = new_args(); + + a->opts->nthreads = 1; + a->success = false; + + if (c == 0) { + a->success = true; + } else { + if (!strcmp(v[0], "-t") && c > 1) { + val = strtol(v[1], NULL, 10); + if (val < 1 || val > 64) { + fprintf(stderr, + "Invalid number of threads." + "1 <= t <= 64\n"); + return a; + } + a->opts->nthreads = val; + a->success = true; + } + } + + return a; +} + +CommandArgs * help_parse_args(int c, char **v) { int i; @@ -229,6 +269,21 @@ solve_exec(CommandArgs *args) } static void +gen_exec(CommandArgs *args) +{ + int i; + + fprintf(stderr, "Generating coordinates...\n"); + init_symcoord(); + + fprintf(stderr, "Generating pruning tables...\n"); + for (i = 0; i < NPTABLES && allpd[i] != NULL; i++) + genptable(allpd[i], args->opts->nthreads); + + fprintf(stderr, "Done!\n"); +} + +static void steps_exec(CommandArgs *args) { int i; diff --git a/src/pruning.c b/src/pruning.c @@ -84,6 +84,21 @@ pd_khuge_HTM = { .moveset = moveset_HTM, }; +PruneData * allpd[NPTABLES] = { + &pd_eofb_HTM, + &pd_coud_HTM, + &pd_cornershtr_HTM, + &pd_corners_HTM, + &pd_drud_sym16_HTM, + &pd_drud_eofb, + &pd_drudfin_noE_sym16_drud, + &pd_htr_drud, + &pd_htrfin_htr, + &pd_khuge_HTM, +}; + +/* Functions *****************************************************************/ + int findchunk(PruneData *pd, int nchunks, uint64_t i) { diff --git a/src/pruning.h b/src/pruning.h @@ -3,6 +3,8 @@ #include "symcoord.h" +#define NPTABLES 20 + extern PruneData pd_eofb_HTM; extern PruneData pd_coud_HTM; extern PruneData pd_corners_HTM; @@ -14,6 +16,8 @@ extern PruneData pd_htr_drud; extern PruneData pd_htrfin_htr; extern PruneData pd_khuge_HTM; +extern PruneData * allpd[NPTABLES]; + void genptable(PruneData *pd, int nthreads); void print_ptable(PruneData *pd); uint64_t ptablesize(PruneData *pd);