Nonogram line solving
Also known as Paint-by-numbers line solver
constraint constraint-search
Line solving finds every cell value of one nonogram row or column that some placement of its runs allows. A forward pass marks the states (cell i, runs placed j) that the line can reach from its start under the current domains, and a backward pass marks the states from which the rest of the line still fits. A cell keeps the value empty or filled only if a move between a reachable state and a completable state uses it; values other than 0 and 1 are removed. The result is complete for the line and costs O(n · k · L) for n cells, k runs and the longest run L. Use one per row and column under propagation, which carries each deduction to the crossing lines.
Pseudocode
algorithm Line-Solve(c₀, …, c_{n−1}, r₁, …, r_k, D)input: cells c₀, …, c_{n−1}, run lengths r₁, …, r_k, domains Doutput: D with every cell value that no placement uses removed, or failure▷ state (i, j): cells 0 to i − 1 hold runs 1 to j, and a run may start at cell i▷ moves from (i, j): leave cell i empty to (i + 1, j), or place run j + 1 from cell iF ← the states reachable from (0, 0)B ← the states from which (n, k) is reachableif (n, k) ∉ F thenreturn failureS_i ← ∅ for each cell ifor each (i, j) ∈ F with i < n doif 0 ∈ D(c_i) and (i + 1, j) ∈ B thenS_i ← S_i ∪ {0}if j < k thene ← i + r_{j+1}fits ← e ≤ n and 1 ∈ D(c_m) for each m in i, …, e − 1if fits and e = n and (n, j + 1) ∈ B thenS_m ← S_m ∪ {1} for each m in i, …, e − 1else if fits and e < n and 0 ∈ D(c_e) and (e + 1, j + 1) ∈ B thenS_m ← S_m ∪ {1} for each m in i, …, e − 1S_e ← S_e ∪ {0} ▷ the gap after the runfor i in 0, …, n − 1 doD(c_i) ← D(c_i) ∩ S_i ▷ also drops values other than 0 and 1if D(c_i) = ∅ thenreturn failurereturn DIn the crates
constraint-searchComplete propagation of one nonogram row or column: keeps exactly the cell values some placement of the runs uses.
Lineage
Comes from
builds on Constraint propagation to a fixpoint
Led to
Nothing on this site.
Papers
- Solving Nonograms by combining relaxations K. J. Batenburg, W. A. Kosters · 2009· Pattern Recognition