Crates.io | nonogrid |
lib.rs | nonogrid |
version | 0.7.3 |
source | src |
created_at | 2019-05-19 12:59:16.110378 |
updated_at | 2021-11-05 20:59:58.882832 |
description | Efficient nonogram solver |
homepage | |
repository | https://github.com/tsionyx/nonogrid |
max_upload_size | |
id | 135247 |
size | 623,662 |
$ wget -qO- https://webpbn.com/export.cgi --post-data "id=32480&fmt=nin&go=1" | cargo run
solves binary (blank-and-white) and colored (<32 colors) nonograms;
supports wide variety of formats:
ini
feature);xml
feature);combines several solving methods to achieve speed for various puzzle types:
very simple puzzles solved line-by-line (line
+ propagation
);
if the puzzle cannot be solved, the probing
phase begins, where some assumptions
made about every unsolved cell following by the analysis of the impact they bring;
if the puzzle not solvable even here, the searching algorithms enabled:
by default backtracking
is used that colors a cell, then another one, and go on,
until the solution(s) is found. There is another option (with sat
feature):
special SAT-solver, that uses the results of previous phases to more effectively
explore the solution space.
By default, the --features="args std_time logger ini"
are enabled, but you can disable almost anything
to speed up and/or shrink the size of the binary.
To support command-line arguments, the args
feature enabled by default.
You can disable it, but then you will not able to set solving timeout or maximum number of solutions to find.
It also can be disabled when using the solver as a library in another projects,
e.g.
By default, you can provide the --timeout
option to stop backtracking after reaching the specified time limit.
You can disable this feature (std_time
), and the timeout option will simply be ignored.
To support pretty formatted logs the env_logger
crate enabled by default.
The simplest way to view them is to provide environment variable RUST_LOG=nonogrid=<log_level>
.
For example, in the benchmarks script, the RUST_LOG=nonogrid=warn
is used to inspect the intermediate results of solving.
As always, you can disable the option by skipping
the --features=logger
while building.
My custom TOML-based format is supported by default via feature ini
.
It can be disabled when using the solver as a library in another projects,
e.g.
By default, the backtracking algorithm used for solving hard puzzles.
The feature sat
allows to use the SAT
solver for such a job.
The most of hard puzzles solved significantly faster with this option.
The latest benchmarks show that the SAT-solver is very effective for the hardest webpbn puzzles (actually, only two puzzles found that solved longer than an hour: 25820 and 26520).
The Jan Wolter's XML format supported via feature xml
.
You can enable it by building with the --features=xml
.
You can enable the feature colors
to allow printing colored nonograms with real terminal colors:
wget -qO- https://webpbn.com/export.cgi --post-data "fmt=olsak&go=1&id=2192" |
cargo run --no-default-features --features=colors
Solved puzzles can be automatically downloaded from the Internet with the reqwest
library,
but it requires too many dependencies and increases compile time, so it's optional by default.
Enable it as simple as:
cargo run --features=web,xml -- --webpbn 5933
By default, the solver and all the algorithms are single-threaded. To use the solver's structures
in multi-threaded environment, provide the threaded
feature. In essence, this feature
replaces every occurrence of Rc/RefCell
with Arc/RwLock
.
When the 'logical' solving (line/propagation
) gets stuck, the probing
phase starting which tries every variant
for every unsolved cells. It does this by calculating the priority for each cell:
P = N + R + C,
where 0<=N<=4 - number of neighbours which are solved cells or puzzle edges.
For example, the cell which has all 4 heighboring cells solved, has N = 4.
The upper left cell of the puzzle without any neighbours solved, has N = 2,
since it has 2 edges of the puzzle.
0<=R<=1 - row solution rate, the ratio of solved cells in the row to total number of cells (width)
0<=C<=1 - column solution rate, the ratio of solved cells in the column to total number of cells (height)
By default, every cell with P>=0
checked, but you can customize the threshold by specifying
the LOW_PRIORITY
environment variable.
For example, running
LOW_PRIORITY=1 nonogrid puzzles/6574.xml
can be solved 3 times faster than standard way, by skipping the probing of cells with P < 1
.
cargo build --features="xml"
# solve puzzle https://webpbn.com/2992
wget 'https://webpbn.com/XMLpuz.cgi?id=2992' -O 2992.xml
target/debug/nonogrid 2992.xml
# with pipe
wget -qO- 'https://webpbn.com/XMLpuz.cgi?id=2992' | target/debug/nonogrid
cargo build --features="web,xml"
# solve puzzle https://webpbn.com/5933
target/debug/nonogrid -w 5933
cargo build
# solve puzzle https://webpbn.com/2992
wget -qO- 'https://www.nonograms.org/nonograms/i/2581' | grep 'var d=' > 2581.js
target/debug/nonogrid 2581.js
# with pipe
wget -qO- 'https://www.nonograms.org/nonograms/i/2581' | target/debug/nonogrid
cargo build --features="web"
# solve puzzle https://www.nonograms.org/nonograms/i/13588
target/debug/nonogrid -o 13588
# solve puzzle https://www.nonograms.org/nonograms2/i/10270
target/debug/nonogrid -o 10270
cargo build
target/debug/nonogrid examples/hello.toml
wget -qO- https://webpbn.com/export.cgi --post-data "fmt=syro&go=1&id=2040" |
cargo run --no-default-features
RUST_BACKTRACE=1 RUST_LOG=nonogrid=info cargo run -- examples/hello.toml