0% found this document useful (0 votes)
13 views12 pages

Solving Nonograms by Combining Relaxations

This paper presents a new reasoning framework for solving Nonograms, which are logic puzzles requiring the filling of a grid based on specific row and column constraints. The authors propose combining relaxations of the Nonogram problem into a 2-Satisfiability (2-SAT) problem, enabling efficient deduction of pixel values and often allowing for complete solutions. Experimental results indicate that this method can solve a range of Nonograms that are challenging for traditional logic reasoning techniques.

Uploaded by

Tianxing Yang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views12 pages

Solving Nonograms by Combining Relaxations

This paper presents a new reasoning framework for solving Nonograms, which are logic puzzles requiring the filling of a grid based on specific row and column constraints. The authors propose combining relaxations of the Nonogram problem into a 2-Satisfiability (2-SAT) problem, enabling efficient deduction of pixel values and often allowing for complete solutions. Experimental results indicate that this method can solve a range of Nonograms that are challenging for traditional logic reasoning techniques.

Uploaded by

Tianxing Yang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Pattern Recognition 42 (2009) 1672 -- 1683

Contents lists available at ScienceDirect

Pattern Recognition
journal homepage: w w w . e l s e v i e r . c o m / l o c a t e / p r

Solving Nonograms by combining relaxations


K.J. Batenburg a,∗ , W.A. Kosters b
a
Vision Lab, Department of Physics, University of Antwerp, Universiteitsplein 1, B-2610 Wilrijk, Belgium
b
Leiden Institute of Advanced Computer Science, University of Leiden, Niels Bohrweg 1, 2333 CA Leiden, The Netherlands

A R T I C L E I N F O A B S T R A C T

Article history: Nonograms, also known as Japanese puzzles, are a specific type of logic drawing puzzles. The challenge is
Received 1 August 2008 to fill a grid with black and white pixels in such a way that a given description for each row and column,
Received in revised form 30 November 2008 indicating the lengths of consecutive segments of black pixels, is adhered to. Although the Nonograms in
Accepted 6 December 2008
puzzle books can usually be solved by hand, the general problem of solving Nonograms is NP-hard. In
Keywords: this paper, we propose a reasoning framework that can be used to determine the value of certain pixels
Nonograms in the puzzle, given a partial filling. Constraints obtained from relaxations of the Nonogram problem are
Discrete tomography combined into a 2-Satisfiability (2-SAT) problem, which is used to deduce pixel values in the Nonogram
Logic reasoning solution. By iterating this procedure, starting from an empty grid, it is often possible to solve the puzzle
2-SAT completely. All the computations involved in the solution process can be performed in polynomial time.
Our experimental results demonstrate that the approach is capable of solving a variety of Nonograms
that cannot be solved by simple logic reasoning within individual rows and columns, without resorting to
branching operations. In addition, we present statistical results on the solvability of Nonograms, obtained
by applying our method to a large number of Nonograms.
© 2008 Elsevier Ltd. All rights reserved.

1. Introduction description is given. The description indicates the lengths of the con-
secutive segments of black pixels along the corresponding line, in
Logic puzzles are very popular nowadays. The most famous ex- order. For example, the description “1 1” in the first row indicates
ample of such a puzzle is the Sudoku, where the puzzler has to in- that when traversing the pixels in that row from left to right, there
sert a series of numbers in a grid, while satisfying certain constraints should first be zero or more white pixels, followed by one black
on the placement of those numbers. A Nonogram, also known as a pixel. Then, at least one white pixel must occur, followed by ex-
Japanese puzzle in some countries, is a different kind of logic puzzle, actly one black pixel. There may be additional white pixels at the
where the goal is to draw a rectangular image that adheres to cer- end of the line. The symbol  denotes the empty description, lead-
tain row and column constraints. Usually, the image is black-and- ing to an all white line. The goal of the puzzle is to colour all pix-
white, although Nonograms with more than two grey values exist els with either black or white, in such a way that each horizontal
as well. Nonograms require (contrary to Sudoku) some elementary and vertical line is consistent with the given description. As we shall
knowledge of integer calculations, so perhaps they cannot be con- see later, when using only information concerning single rows and
sidered as pure logic puzzles. The combination of a logic problem columns, puzzles can often be solved partially, but not fully; see
with integer calculations results in a combinatorial problem that can Fig. 1(b). For instance, one can infer that the middle pixel in the
be approached using methods from combinatorial optimization, log- bottom row must be black. Using 2-Satisfiability (2-SAT) rules this
ical reasoning or both, which makes Nonograms highly suitable for elementary puzzle can be solved completely; see Fig. 1(c). More com-
educational use in Computer Science [1]. plicated puzzles require more sophisticated techniques, as we will
Fig. 1 shows an example of a Nonogram. The puzzle has a also demonstrate.
rectangular shape, which is subdivided in unit cells. We will also Nonograms can be considered as a generalization of a well-
refer to these cells as pixels. For each row and each column, a known problem in discrete tomography (DT) [2,3]: reconstructing
hv-convex sets (where the black pixels in each row and column must
be consecutive). For this DT problem, the description for each line
consists of a single number, indicating the length of the segment of
∗ Corresponding author. black pixels along that line. The problem of reconstructing hv-convex
E-mail addresses: [email protected] (K.J. Batenburg), [email protected] polyominoes can be solved in polynomial time [4,5], whereas the
(W.A. Kosters). reconstruction problem for general hv-convex sets is NP-hard [6].

0031-3203/$ - see front matter © 2008 Elsevier Ltd. All rights reserved.
doi:10.1016/j.patcog.2008.12.003
K.J. Batenburg, W.A. Kosters / Pattern Recognition 42 (2009) 1672 -- 1683 1673

1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
11 11 11

11 11 x x x x 11
3 3 x x x x 3

Fig. 1. An elementary 5 × 5 Nonogram. In the partial solution (b), the grey cells indicate which puzzle entries are still undecided. The partial solution cannot be extended
to a full solution by using only information from a single row or column at each step: (a) original puzzle; (b) partial solution; (c) final solution.

Therefore, the reconstruction problem for Nonograms is also NP- a general CSP solver can be used to solve the problem. A wide range
hard (and, clearly, NP-complete). In[7] this is shown through the of such solvers is available. Formulating a Nonogram problem as a
more general concept of parsimonious reductions. In [8], the general CSP requires a relatively large number of constraints, and its solution
DT problem (without geometric constraints) was analysed as a sim- lacks the intuitive interpretation characteristic for more specialized
plification of the Nonogram problem. The methods from this paper Nonogram solvers, such as the approach presented here.
perform well in this situation, see Section 7.2. In this paper we propose a reasoning framework for solving Nono-
The Nonogram problem can also be related to several job schedul- grams. We consider relaxations of the Nonogram problem that can be
ing problems, where each row corresponds to a single processor and solved in polynomial time and, in many cases, can already determine
the jobs for the processors are indicated by the row descriptions. the value of certain pixels in the Nonogram solution. In addition, re-
In many scheduling problems, the type of constraints that occur in lations between pairs of pixels are collected from these relaxations,
Nonograms only apply to the rows, or the columns, but usually not and combined into a 2-SAT problem. This 2-SAT problem, which may
both. The reasoning framework presented in this paper can be ex- involve information from several rows and columns, can be used to
tended to include such cases as well. Even for the Nonogram prob- deduce the value of pixels that were not determined directly by the
lem there are concrete instances, such as the following. The rows individual relaxations. By iterating this procedure, starting from an
correspond with employees that have to perform confidential tasks. empty grid, it is often possible to either solve the puzzle completely
The employees are ordered, where employees with higher row index or to determine a substantial part of the pixels. In the latter case,
perform better. Each employee has a series of work shifts, separated one can distinguish between situations where there exist different
by mandatory breaks. The columns correspond with the consecutive solutions (that can sometimes be enumerated), and situations where
time slots. For each time slot the description defines the numbers of no further information can be deduced by our solver.
employees needed for the different tasks, where the tasks are ordered The paper is organized as follows: Section 2 introduces Nono-
in increasing difficulty (needing better employees for more difficult grams in a formal, somewhat more general context; in Section 3 we
tasks). The confidentiality of the tasks requires that the groups of show solutions to some relaxed versions (i.e., single lines, and the DT
cooperating employees are physically separated. As an example, in version); we combine these techniques into a general framework in
the problem from Fig. 1 all tasks are for single employees, and the Sections 4 and 5, also incorporating 2-SAT rules. In Section 6, (non-)
best employee has a single shift of three time slots. uniqueness properties of Nonograms are discussed. Experimental re-
There can be considerable differences in the difficulty level of sults are presented in Section 7; Section 8 provides a discussion of
Nonograms. On the one hand, the Nonograms that appear in news- advantages and limitations of the proposed approach, and concludes
papers can typically be solved by applying a series of simple logical this paper. We note that this paper is an extended version of the
rules, each of which considers only a single horizontal or vertical line. conference paper [14].
Later on we will refer to them as being simple. These puzzles will
always have a unique solution. In fact, knowledge about uniqueness
of the solution of a Nonogram provides extra information. As an ex- 2. Notation and concepts
ample, for the Nonogram in Fig. 1, a symmetry argument infers the
bottom line. On the other hand, large random puzzles can be very We now define notation for a single line (i.e., row or column) of
difficult to solve, even using a computer, and may have many differ- a Nonogram. After that, we combine these into rectangular puzzles.
ent solutions—or none at all. Clearly, the fact that solving Nonograms Let  be a finite alphabet. Its elements are referred to as pixel
is NP-hard indicates that not all puzzles can be solved using simple values. In this paper we focus on the case  ={0, 1}, but most concepts
logic reasoning. apply to sets consisting of more than two elements as well. The
Although several implementations of Nonogram solvers can be symbols 0 and 1 represent the white (0) and black (1) pixels in the
found on the Internet (see [9] for a list of solvers), we have not found puzzle. In addition, we introduce a special symbol, x ∈/ , indicating
any thorough studies of this problem in the scientific literature. In that a pixel is not decided yet. Put  =  ∪ {x}. For   0, let  (resp.
[10], an evolutionary algorithm is described for solving Nonograms.  ) denote the set of all strings over  (resp. ) of length .
Although this algorithm is quite effective at solving Nonograms, it For describing a Nonogram, we introduce more general concepts
cannot be used to find all solutions, if more than one solution exists. of row and column descriptions, such that Nonograms are in fact a
A heuristic algorithm for solving Nonograms is proposed in [11]. The special case. Most of the concepts in this paper can be applied to all
related problem of generating Nonograms that are uniquely solvable logic problems that follow the more general definitions.
is discussed in [12]. A description d of length k > 0 is an ordered series (d1 , d2 , . . . , dk )
Any Nonogram problem can be considered as a constraint satis- with dj = j {aj , bj }, where j ∈  and aj , bj ∈ {0, 1, 2, . . .} with aj  bj
faction problem (CSP, see, e.g., [13, Chapter 5]). The line descriptions (j = 1, 2, . . . , k). The curly braces are used here in order to stick to the
can be translated into constraints in several different ways. One such conventions from regular expressions; so, in j {aj , bj } they do not
method will be discussed later. An advantage of this approach is that refer to a set, but to an ordered pair. Any such dj will correspond
1674 K.J. Batenburg, W.A. Kosters / Pattern Recognition 42 (2009) 1672 -- 1683

with between aj and bj characters j , as defined below. Without loss of undecided pixels on that line, it is possible to determine whether
of generality we will assume that consecutive characters j differ, or not a line is fixable with respect to its description in polynomial
so j  j+1 for j = 1, 2, . . . , k − 1. Let Dk denote the (infinite) set of time.
all descriptions of length k, and put D = ∪∞ D , where D0 consists
k=0 k
First we introduce some notations. For a string s = s1 s2 . . . s of
of the empty description . A single dj = j {aj , bj } is called a segment length  over , define its prefix of length i by s(i) =s1 s2 . . . si (1  i  ),
description. We will sometimes write ∗ as a shortcut for {0, ∞} (for so s = s() ; s(0) is the empty string. Similarly, for a description d =
 ∈ ) and + as a shortcut for {1, ∞}, where ∞ is suitably large (d1 , d2 , . . . , dk ), put d(j) = (d1 , d2 , . . . , dj ) for 1  j  k, so d = d(k) ; d(0) = 
number. We use a as a shortcut for {a, a} (a ∈ {0, 1, 2, . . .}), and we j
is the empty description. Furthermore, let Aj = p=1 ap and Bj =
sometimes omit parentheses and commas; also 0 is omitted. j
A finite string s over  adheres to a description d (as defined p=1 bp ; put A0 = B0 = 0. We note that a string of length  < Ak is
c c c certainly not fixable with respect to d, simply because it has too
above) if s = 11 22 . . . kk , where aj  cj  bj for j = 1, . . . , k. As an
few elements; similarly, a string of length  > Bk is not fixable with
example, consider the following description for  = {0, 1}:
respect to d. Finally, for  ∈ , s ∈  and 1  i  , let Li (s) denote
d = (0{0, ∞}, 1{a1 , a1 }, 0{1, ∞}, 1{a2 , a2 }, 0{1, ∞}, . . . , 1{ar , ar }, 0{0, ∞}). the largest index h  i such that sh ∈/ {, x}, if such an index exists,
and 0 otherwise. We will put Fix(i, j) = Fix(s(i) , d(j) ). The value Fix(, k)
This is precisely the Nonogram-type description a1 , a2 , . . . , ar for a then determines whether s is fixable with respect to d.
line (row or column). Note that it has length 2r + 1 and can also be The value Fix(i, j) can be expressed recursively using only terms
written as Fix(i , j ) with i < i and j < j. This allows for efficient evaluation of
Fix(i, j) by dynamic programming. As boundary values we note that
0∗ 1a1 0+ 1a2 0+ . . . 1ar 0∗ . Fix(0, j)=true if and only if Aj =0 (j=0, 1, 2, . . . , k); and Fix(i, 0)=false
for i = 1, 2, . . . , . We clearly have Fix(i, j) = false if i < Aj or i > Bj
We denote the set of all Nonogram-type descriptions by Dnonogram ⊆ (0  i  , 0  j  k), as indicated above.
D. In the sequel we will concentrate on this type of description. Our main recursion is:
Let s be a finite string over . If zero or more occurrences of x
are replaced with elements from , the resulting string is called a
Proposition 1. The function Fix satisfies
specification of s. A specification to a string over  (i.e., no longer
containing any “x” symbols) is called a fix. If a string s has a fix that
adheres to a given description d, s is called fixable with respect to min(i−aj ,Bj−1 )

d. By definition, the boolean function Fix(s, d) is true if and only if Fix(i, j) = Fix(p, j − 1). (1)
s is fixable with respect to d. In a somewhat different context, we j
p=max(i−bj ,Aj−1 ,Li (s))
also use the term fixing a pixel to indicate that a pixel has only one
possible value, and can therefore be assigned that value.
An m × n Nonogram description N consists of m > 0 row de-
This holds for i and j with 1  i  , 1  j  k and Aj  i  Bj .
scriptions r1 , r2 , . . . , rm ∈ Dnonogram and n > 0 column descriptions
c1 , c2 , . . . , cn ∈ Dnonogram . A partial filling is an m × n matrix over
. The set of all partial fillings is denoted by m×n ; its elements Note that an empty disjunction is false; this happens for exam-

can also be considered as strings of length m × n. If a partial filling ple if Li j (s)  i − aj + 1. For j = 1 we have Fix(i, 1) = true if and only
1
contains no occurrences of x, it is called a full fix. A full fix F ∈ m×n if Li (s) = 0.
adheres to the Nonogram description N if the ith row of F adheres
to ri (for all i = 1, 2, . . . , m) and the jth column of F adheres to cj (for Proof. The validity of the recursion can be shown as follows. The last
all j = 1, 2, . . . , n). We generalize the concepts of specification and part of s(i) must consist of between aj and bj characters j ; say we
fixable that were defined for single lines in the natural way to m × n want j at positions p+1, p+2, . . . , i. We then must have aj  i−p  bj .
Nonograms. Also note that all elements sp+1 , sp+2 , . . . , si must be either x or j ; this

holds exactly if Li j (s)  p. Finally, the first part of s(i) , i.e., s(p) , must
3. Partial solution methods adhere to d(j−1) . Clearly, p must be between Aj−1 and Bj−1 , otherwise
this would not be possible. 
In this section we study two relaxations of the Nonogram prob-
lem. In Section 3.1 we confine the puzzle to a single line. In Section Note that the Aj and Bj terms can be considered to represent
3.2 we only require that the total number of black pixels in each line general tomographic restrictions. It is natural to implement this re-
(i.e., row or column) adheres to its description. Clearly, any pixel that cursive formula by means of dynamic programming, using lazy eval-
can only have a single value in all solutions of the relaxation, must uation: once a true Fix(p, j − 1) is found, the others need not be
also have this same value in any solution of the complete Nono- computed.
gram. For both relaxations we show that such pixels can be found Now given a string s over  that is fixable with respect to a de-
efficiently. scription d, it is easy to find those string elements x that have the
Although in some cases these relaxations can directly yield infor- same value from  in every fix: these elements are then set at that
mation on the value of a given pixel in any solution of the Nonogram, value. Indeed, during the computation of Fix(s, d) (which of course
they can also be used to obtain information about pairs of pixels. In yields true), one can keep track of all possible specifications that
Section 4, we will show how these relations between pairs of pix- lead to a fix. In Eq. (1) those Fix(p, j − 1) that are true correspond
els obtained from the relaxed problems can be combined efficiently, with a fix, where the string elements sp+1 , sp+2 , . . . , si are all equal to
obtaining a powerful Nonogram solver. j . Now one only has to verify, for each string element of s, whether
precisely one element from  is allowed. In practice this can be re-
3.1. Solving a single line alized by using a separate string, whose elements are filled when
specifying s, and where those elements that are filled only once are
Deciding fixability for a single horizontal or vertical line is a fun- tagged. Note that for this purpose lazy evaluation is not an option,
damental operation in our approach. Although the number of possi- since we need to examine all fixes. As an example, if the descrip-
ble specifications of a line increases exponentially with the number tion for a five character string s = s1 s2 s3 s4 s5 over {0, 1, x} is 0∗ 13 0∗
K.J. Batenburg, W.A. Kosters / Pattern Recognition 42 (2009) 1672 -- 1683 1675

2 2 1

C1 C2 C3 column nodes
1 1 0 2
1 1 1 1 1 1 1 1 1
0 1 0 1 pixel arcs
1 0 1 2
2 2 1 R1 R2 R3 row nodes

2 1 2

Fig. 2. (a) DT problem and one of its solutions, where bold figures denote the linesums; (b) associated network of the DT problem.

(cf. the bottom row from the example in Section 1), one can derive if and only if the partial filling can be extended to a complete filling
that s3 must be equal to 1. The algorithm that performs this operation satisfying the DT constraints.
is called Settle, and the resulting string s is denoted by s =Settle(s, d).
2
The complexity of the computation of Fix(, k) is bounded by k ·  : 4. Combining the partial methods using 2-SAT
at most k ·  values of Fix(i, j) must be computed, and each such com-
putation can be performed in O() time, including the evaluation of The method from Section 3.1 can only take into account the de-

Li j (s). In practice, especially when using lazy evaluation, the com- scription of a single line. On the other hand, the DT approach from
plexity is much lower. Section 3.2 can deal with all lines simultaneously, but only incorpo-
If || > 2, it could be that besides deciding certain pixels as in the rates partial knowledge from the descriptions. We will now describe
example from the previous paragraph, also one or more (but perhaps how a large part of the information from different lines, and from
not || − 1) pixel values are excluded for certain pixels. In this case, different relaxations of the Nonogram problem, can be combined.
Settle can be implemented such that it yields a list of these forbidden Consider the example in Fig. 3a (which is the same as that from
values for each pixel. Formulating the Nonogram problem as a CSP, Fig. 1). Using only the information from single lines, or from the DT
for each pixel a domain is initialized to  and gradually reduced by problem, the values of the remaining undecided pixels cannot be
a search algorithm until only a single value remains. derived. Four of the undecided pixels are denoted by the variables
a, b, c and d, respectively, which can take the values 0 (false) or 1
(true).
3.2. DT problem Using the partial solution methods, dependencies can be derived
between pairs of undecided pixels. For example, on the bottom row,
The Nonogram problem can be considered as a special case of a the description dictates that c ⇒ d (or, equivalently, ¬c∨d). Similarly,
well-known problem from DT, which deals with the reconstruction one can deduce that c ⇒ ¬a (first column), ¬a ⇒ b (third row) and
of a binary image from its horizontal and vertical linesums. These b ⇒ ¬d. This provides us with both implications c ⇒ d and c ⇒ ¬d,
horizontal and vertical linesums can be easily computed from the resulting in the conclusion that c must be 0.
Nonogram descriptions, by adding the segment descriptions for each Note that any such implication relation between two variables
line. (In the more general setting from Section 2 we get lower and can be written in one of the forms x ∨ y, x ∨ ¬y, ¬x ∨ y or ¬x ∨
upper bounds for the linesums.) Suppose that we have a partially ¬y. This is the standard form of a 2-SAT clause, see [17]. The 2-SAT
filled Nonogram X ∈ m×n , which we would like to extend further. problem is to decide whether or not there exists an assignment of
Clearly, any solution of the Nonogram must also be a solution of truth values to all the variables, such that a given series of such
the corresponding DT problem. The DT problem can be solved in clauses is simultaneously satisfied. It can be solved in polynomial
polynomial time, even if an arbitrary subset of the image is kept time, using the concept of a dependency graph, as shown in Fig. 3b
fixed. It is also possible to compute the set of all pixels that must for our elementary example.
have the same value in all solutions of the DT problem in polynomial Combining partial information from different relaxations into a
time. These pixels can be fixed immediately in the partial Nonogram 2-SAT problem allows for deducing substantially more pixel values
solution. The paper [15] gives a constructive procedure for finding than can be found using the individual relaxations, even though
all such pixels. it does not capture the full puzzle specification. When solving a
Fixability to a solution of the DT problem can easily be checked Nonogram, the goal is not to find an assignment of all variables that
using network flow methods. We refer to [16] for the details of this satisfies the 2-SAT constraints. Rather, we search for variables that
model. Fig. 2a shows a small 3 × 3 DT problem. We put linesums to must have the same truth value in all satisfying assignments. Assume
the right of the rows and below the columns, to distinguish them that at least one such assignment exists. Then a variable x is false
from our earlier descriptions. This problem can be modelled as the in all satisfying assignments if and only if there is a path from x to
transportation problem in Fig. 2b, which can be solved efficiently by ¬x in the dependency graph. Alternatively, x must be true in all
network flow methods; thick arcs denote the solution. This network satisfying assignments if and only if there is such a path from ¬x to x.
has three source nodes, one for each column, and three sink nodes, Note that existence of a cycle in the dependency graph, containing
one for each row. The surplus/demand for each node is determined both x and ¬x implies that no satisfying truth assignment exists. If
by its corresponding linesum. If none of the pixels are fixed, each we can assume that a given Nonogram has at least one solution, and
pixel arc has a capacity of one. To fix a pixel at value v ∈ {0, 1}, that we only fix the value of pixels that must have the same value
we simply set the capacity of the corresponding pixel arc to 0 and in all solutions, such a cycle will never occur.
subtract/add v to the surplus/demand at the corresponding column The dependency graph model provides a polynomial-time algo-
and row nodes. The resulting transportation problem has a solution rithm for finding all variables that must have the same value in all
1676 K.J. Batenburg, W.A. Kosters / Pattern Recognition 42 (2009) 1672 -- 1683

Solver0(X,N)
begin
a ¬a
Input: Nonogram N of size m×n; partial filling X;
1 1 repeat
1 1 1 1 1 X ← FullSettle(X,N);
Collect a set S of 2-SAT clauses from relaxations;
b ¬b
1 1 X ← 2SATSolve(X,S,N);
until (no new fixed pixel(s) found) or (contradiction found);
if (contradiction found) Output: “contradiction”;
1 1 a b x x c ¬c else Output: X;
end
3 c d x x
Solver1(X,N)
begin
d ¬d Input: Nonogram N of size m×n; partial filling X;
repeat
Fig. 3. (a) Partially solved Nonogram; (b) (part of) its corresponding dependency X ← Solver0(X,N);
graph. repeat
Select an undecided pixel Xij;
for each pixel value ∈{0,1}
satisfying assignments of the 2-SAT problem. In the example from Y ← X; Yij ← ;
Fig. 3a, many more 2-SAT clauses can be found from the single rows Y ← Solver0(Y,N);
and columns, or from the DT problem. if (contradiction found) Xij ←1−;
Our procedure for combining the information from the subprob- until (new pixel value(s) found) or (all undecided pixels tried);
lems (one for each line, and a complete DT problem) is as follows: for until (no new fixed pixel(s) found);
each pair of undecided pixels (x, y) involved in the subproblem, all Output: X;
four assignments are tested. If x and y are on one line, for each assign- end
ment the fixability computation from Section 3.1 is performed. Each
such test that returns false provides an additional 2-SAT clause Fig. 4. High level overview of the Solver0 and Solver1 algorithms.
(e.g., x ∨ ¬y). Similarly, the technique from Section 3.2 can generate
clauses, also for pixels that are not on the same line. The resulting
dependency graph captures information from all subproblems si-
multaneously. If one considers this process as “guessing”, it can also descriptions from N) until no new, previously unknown pixels are
be performed in a way similar to the Settle operation. Indeed, when set. Note that we can use several heuristics to determine the order
computing the Fix value for a line, one can keep track of all pairs of in which lines are examined, but the order does not affect the result
pixels, and determine those values of pairs that cannot occur. obtained when no further elements can be fixed. The operation of
Although the 2-SAT approach is a powerful way to combine the repeatedly applying the Settle operation until no further elements
knowledge from different partial problems, it generally does not are fixed is called FullSettle: X ← FullSettle(X, N) ∈ m×n . If X now
capture all information that is present. For example, the three char- happens to be in m×n , the puzzle is solved. Such a puzzle is called
acter string s over {0, 1, x} with description d = 0∗ 11 0∗ yields rules simple.
that do not forbid the fix 000, which is not a good fix. If one intro- Note that the Settle operation, or rather the induced Fix opera-
duces clauses that can involve three variables, this leads to a clause tions, can also be used to detect certain contradictions, i.e., unsolv-
s1  0 ∨ s2  0 ∨ s3  0, which is in 3-SAT format. Although the gen- able puzzles. Indeed, if some line s of a proposed (partial) solution
eral 3-SAT problem is NP-hard, there are certain subclasses of 3- satisfies Fix(s, d) = false, there is no full solution.
SAT problems that can be solved in polynomial time [18]. For our Now, given X ∈ m×n and a Nonogram description N such that
purpose, we found the 2-SAT formulation to be both powerful and X = FullSettle(X, N), 2-SAT expressions are collected: for each relaxed
computationally efficient, yet it may be possible to create a more problem (e.g., the single rows and columns), for each pair of unde-
powerful solver by using a 3-SAT formulation that fits the type of cided pixels and for each assignment of values to these pixels, it is
3-SAT clauses obtained from the relaxed problems and can still be checked if for this value assignment the relaxed problem can still be
solved in polynomial time. solved. If this is not the case, the relation between both pixel val-
ues is captured in a 2-SAT clause. We denote the set of all 2-SAT
5. Iterative solving of Nonograms clauses found in this way by S. Subsequently, all pixels that have the
same value in all solutions of the 2-SAT problem S are fixed to these
Each relaxation of the Nonogram problem, such as the single line values, as described in Section 4. Thisoperation is called 2SATSolve:
and DT relaxations from Section 3, can be used to deduce the value X ← 2SATSolve(X, S, N). The operations FullSettle and 2SATSolve can
of certain pixels. By using such methods iteratively, filling in the be intertwined, until no further progress is made; this combination
new known pixels in each iteration, it is often possible to deduce is called Solver0: X ← Solver0(X, N), cf. Fig. 4. Again, if the resulting X
even more pixel values. For clarity, we now focus on the iterative happens to be in m×n , the puzzle is solved. Such a puzzle is called
application of the Settle operation from Section 3.1; this yields a 0−Solvable. Note that this whole process takes polynomial time (ex-
powerful approach, as will be shown in Section 7. It can even be pressed in height and width of the puzzle).
combined with other relaxations, as that from Section 3.2, to form Now suppose that X = Solver0(X, N), but the puzzle is not solved
a more complete iterative algorithm. The Settle operation produces, yet. We now consider one unknown element Xij from X. In a copy Y
given a string s over  and a description d, the string where all string of X we try both Yij = 0 and Yij = 1. If for one of these Solver0(Y, N)
elements that have the same value in every fix are set: s ← Settle(s, d). contains a contradiction, we know that Xij must have the other value.
Given X ∈ m×n and a Nonogram description N, we can repeat the We can, again in some order, examine all unknown pixels. Note that
Settle operation for all rows and columns of X (using the appropriate only those pixels that occur in a 2-SAT clause need to be examined
K.J. Batenburg, W.A. Kosters / Pattern Recognition 42 (2009) 1672 -- 1683 1677

and that the ordering of those pixels does not affect the final results of (Fig. 5, right). In the former case we have three solutions, where in
the solver. This procedure can be repeated, until no further progress between two unknowns we can only have the (0+ 1)∗ 0+ situation,
is made, again intertwined with the use of Solver0. This procedure in the latter case there are precisely two solutions—as in the u = 4
is called Solver1, cf. Fig. 4. If a Nonogram can be solved in this way, case. In all these situations, unknowns cannot touch.
it is called 1−Solvable.
Although the procedure Solver1 can be considered as a form of 7. Experimental results
backtracking, the algorithm only makes a single guess at a time (i.e.,
no recursive guesses), thereby avoiding the creation of a search tree. In this section, we present a variety of experimental results ob-
So, to summarize these efforts, Nonograms can be simple (if tained with the proposed iterative Nonogram solvers. All considered
FullSettle solves them), 0−Solvable (if Solver0 solves them), 1−Solvable puzzles will have at least one solution: the image that was used to
(if Solver1 solves them), or more complicated. Many puzzles from construct the puzzle. We mention that in our experience, most puz-
newspapers are simple; the example from Fig. 1 is 0−Solvable. In zles from newspapers are of the simple type. Although one could
Section 7, we will give several examples. Also note that FullSettle, attribute this to the relatively small size of these puzzles, this is con-
Solver0 and Solver1 are capable of providing partial solutions, where tradicted by the example from Fig. 1, which shows that small puz-
the fixed pixels that have been assigned a value from  must have zles do not have to be of simple type. On the other hand, the 80 × 50
that value in all solutions (if any) of the Nonogram. puzzle shown in Fig. 6 is rather large, but can still be solved by hand,
belonging to the simple type. Nevertheless, the larger the puzzle, the
6. Some remarks on (non-)uniqueness more complicated it can be. All puzzles of simple type can be solved
very fast by the FullSettle operation, as the dynamic programming
In this section, we examine some issues concerning (non-) approach described in Section 3.1 effectively captures all informa-
solvability of Nonograms, and we pay special attention to puzzles tion contained in the description of each single horizontal or vertical
with multiple solutions. line.
Similar to the DT problem, Nonograms can have more than one This section is structured as follows. First, we consider random
solution. However, where the non-uniqueness problem for DT al- images, presenting both characteristic examples and statistical
lows an elegant description based on elementary switching compo- results. Next, we consider the case of hv-convex images. Finally,
nents [19], the non-uniqueness problem for Nonograms appears to we provide solvability results for the set of all Nonograms of
be much more complex. The problem of deciding if another solution size 5 × 5.
of a Nonogram exists, given a particular solution, is NP-hard [7]. Unless mentioned otherwise, the experimental results have been
We now focus on cases, where only a small subset of the pixel obtained by Solver1, which is the most powerful method of those
values is not uniquely determined by the Nonogram description. described in this paper. Our focus is on the solution quality, deter-
Suppose that we have a given Nonogram, and that it is possible (using mined by the number of unknowns left after running the Nonogram
the approach of this paper, for example) to determine the value of all solver. For the hv-convex images in Section 7.2, we also present tim-
pixels, except for a small set of u > 0 unknown pixels or unknowns. ing results. For all experimental results presented, the running time
We first note that each line with unknown pixels should contain at for a single Nonogram never exceeded 60 s (and is usually much
least two unknowns. This implies that u  4 and u  5. If u = 4, the shorter) on a Pentium IV PC, running at 2.4 GHz. For general images,
unknowns form a rectangle (Fig. 5b, left), similar to the elementary there is no direct relationship between the reconstruction time and
switching component of the DT problem (i.e., four pixels, two black the size of the Nonogram, as the reconstruction time is largely de-
and two white, such that interchanging the black and the white pixels termined by the complexity properties of the particular image being
does not change the description; see Fig. 5a). However, in Nonograms reconstructed.
the existence of such switching components is not only determined
by the value of the four corner pixels, but also by the values of the 7.1. Random Nonograms
pixels along the four sides of the rectangle and by the pixels adjacent
to the four corners. On a single line with two unknowns, depicted As an illustrative example for a more difficult puzzle, consider the
from left to right, we note that left of the leftmost unknown we must 30×30 Nonogram in Fig. 7a. The Nonogram was randomly generated
have a 0 pixel (or the image boundary), and a similar observation with 50% black pixels. Using only FullSettle just 11 pixel values can
holds for the rightmost unknown. We note that we have precisely
be determined. Using Solver1 (which only takes approximately 1 s
two solutions here. Between the two unknowns we must have only
on a standard PC), the puzzle is solved but for 15 pixels. One can
1 s, or a series of solitary 1 s with variable length blocks of 0 s in verify that there are six different solutions, where it turns out that
between: in regular expression notation (0+ 1)∗ 0+ .
for all 15 unknown pixels both black and white can occur; this can
If we consider u=6, we either have two lines with three unknowns
easily be accomplished by repeatedly fixing one of the unknowns to
each (and in the other direction three lines with two unknowns
either 0 or 1, and then re-solving the puzzle. This Nonogram was
each), or three lines with two unknowns each in both directions also included in [10], where an evolutionary algorithm was used
to find one of the six solutions. A clear advantage of our reasoning
framework over the algorithm presented in the former paper is that
1 1
our current approach finds the set of all solutions (or rather those
1 pixels that have the same value in every solution), along with a
1 proof that there are no others. In addition, our method is much
× × × × × × × × × faster: seconds versus hours. On the other hand, both approaches
1 1 can be considered as complementary, as the evolutionary algorithm
1 × × × × can sometimes find a solution that cannot be deduced using our
1 × × × × × × × × ×
reasoning approach. In particular, pixels that can be either black or
white, depending on the particular solution of the Nonogram, can
Fig. 5. Switching components that can occur in Nonograms, containing up to six un- never be fixed in our approach.
knowns. (a) Elementary switching component; (b) more complex types of switching Fig. 7b shows a randomly generated 40×40 Nonogram, with 881,
components for Nonograms. i.e., 55%, black pixels. In this case the puzzle has a nearly unique
1678 K.J. Batenburg, W.A. Kosters / Pattern Recognition 42 (2009) 1672 -- 1683

Fig. 6. Large Nonogram of the simple type.

solution: there is only one elementary 2 × 2 switching component For small and large black percentages nearly all puzzles are solv-
(cf. Fig. 5a), so there are two different solutions. Again, Solver1 is able, in some cases leaving small switching components. Fig. 9 shows,
necessary: FullSettle finds 101 pixels. for each size s in {1, 2, 3, . . . , 50}, the average number of unsolved
In Fig. 8a, results for a set of 7000 images are summarized. For pixels for randomly generated square s × s Nonograms, all with 50%
each p in {1, 2, . . . , 70} the Solver1 algorithm has been run 100 times black pixels. The results are averaged over 100 runs for each graph
on a randomly generated 30 × 30 puzzle, with p% black pixels. The point. The smooth curve in Fig. 9a depicts the total number of pixels,
piecewise linear curve connects the averages of the number of un- i.e., s2 . Fig. 9b shows percentages.
solved pixels (at most 900); also plotted is the standard deviation for Fig. 10 depicts, for each size s in {10, 11, 12, . . . , 50}, the average
each point on the graph, truncated at 0 and 900. Fig. 8b shows the percentage of unsolved pixels over 20 runs, for randomly generated
results of applying the three methods FullSettle, Solver0 and Solver1 square s × s puzzles, where the percentage of black pixels ranges
to these puzzles (the graph for Solver1 being the same as that from from 40% to 60%. This percentage range has been chosen to highlight
Fig. 8a). Note that between 40% and 60% of black pixels, the be- the transition from completely unsolvable puzzles to largely solvable
haviour of the three algorithms clearly differs, where indeed Solver1 ones (cf. also Fig. 8b). Here, we compare the results for the less
performs best. powerful FullSettle solver that only uses the information from single
K.J. Batenburg, W.A. Kosters / Pattern Recognition 42 (2009) 1672 -- 1683 1679

Fig. 7. (a) Randomly generated partially solved 30 × 30 Nonogram, with 50% black pixels; the grey cells denote the unknown pixels. This Nonogram has six solutions. (b)
Randomly generated partially solved 40 × 40 Nonogram, with 881 black pixels; the four grey pixels denote an elementary switching component, leading to two solutions.

900 900
800 800
700 700
unsolved pixels

unsolved pixels

600 600
500 500
400 400
300 300
200 200
100 100
0 0
0 10 20 30 40 50 60 70 0 10 20 30 40 50 60 70
percentage black percentage black

Fig. 8. (a) Average number of unsolved pixels for randomly generated 30 × 30 puzzles, for a varying percentage of black pixels, when using Solver1; error bars indicate the
standard deviation. (b) As (a), for FullSettle (top graph), Solver0 (middle graph) and Solver1 (bottom graph), without standard deviation.

lines (Fig. 10a) with Solver1 (Fig. 10b). Even though the general shape ages, they typically contain a large number of very small hv-convex
of both graphs is similar, it is clear that the 2-SAT approach employed components. Such Nonograms often have a very high degree of non-
by Solver1 results in a significantly larger number of solved pixels. uniqueness, which makes them unattractive as test images for our
algorithms. We therefore restricted the test set to hv-convex images
7.2. hv-Convex images that have a fixed number of components, ranging from 1 up to 4.
We only considered images that contain at least one black pixel in
The class of hv-convex images forms an interesting test case for each row and column. For each number of components, and for sizes
Nonogram solvers. For such images, the Nonogram problem is iden- ranging from 10 × 10 up to 80 × 80, a set of 100 images was gener-
tical to the problem of reconstructing hv-convex images from given ated, sampled uniformly from the collection of all hv-convex images
linesums, which has been studied extensively in the DT literature. having that size and number of components.
The framework for generating certain discrete images using uni- Table 1 shows the average number of unknown pixels left by the
form distributions proposed in [20] was utilized to generate a set Solver1 algorithm for each test case. The rightmost column shows
of hv-convex test images. In preliminary experiments, it was found the average running time in seconds over all test cases of each size.
that if the test images are sampled from the set of all hv-convex im- We can observe two general patterns in the reconstruction results.
1680 K.J. Batenburg, W.A. Kosters / Pattern Recognition 42 (2009) 1672 -- 1683

2500 100

2000 80

unsolved pixels (%)


unsolved pixels

1500 60

1000 40

500 20

0 0
0 5 10 15 20 25 30 35 40 45 50 0 5 10 15 20 25 30 35 40 45 50
height = width height = width

Fig. 9. (a) Average number of unsolved pixels for randomly generated puzzles of different size, with a fixed percentage of 50% black pixels; error bars indicate the standard
deviation. (b) As (a), but now showing these values as percentage of the total number of pixels.

100 100
100 100
unsolved pixels (%)

unsolved pixels (%)

80 90 80 90
80 80
70 60 70
60 60 60
50 50
40 40 40 40
30 30
20 20
20 10 20 10
0 0
0 0
40 40
45 45
pe
pe

rc

10
rc

50 15 10
en
en

50 15
ta

20
ta

20
ge
ge

25 25
30 30
bl

55 55
bl

h
35 widt
ac

idth
ac

35 40 =
40 t=w t
k
k

60 50 45 heigh 60 50 45 heigh

Fig. 10. (a) Average percentage of unsolved pixels, for randomly generated puzzles of different size and black percentage, for FullSettle. (b) Average percentage of unsolved
pixels, for randomly generated puzzles of different size and black percentage, for Solver1.

Table 1 (and columns), any permutation matrix will be a solution. As our al-
Components size 1 2 3 4 Avg. time (s) gorithm will only determine the value of pixels that have the same
value in all solutions, this non-uniqueness directly leads to unknown
10 × 10 1.53 4.10 13.57 36.30 0.03
pixels in the reconstruction. A second explanation for the increase
20 × 20 0.72 2.13 7.15 16.40 0.1
30 × 30 0.35 2.53 4.63 9.81 0.4 of unknown pixels with the number of components is that the av-
40 × 40 0.32 1.23 4.06 5.87 1.5 erage number of black pixels on each line will decrease as the num-
50 × 50 0.29 1.29 2.79 5.77 2.7 ber of components increases. Long segments of 1's are very useful
60 × 60 0.46 1.50 2.42 4.81 7.1 in solving Nonograms, as it is usually possible to directly determine
70 × 70 0.27 1.29 2.88 3.68 15.5
80 × 80 0.56 0.81 1.74 3.49 25.4
a subset of pixels that must be 1 in any solution. An example of the
non-uniqueness problem is shown in Fig. 11a. The hv-convex com-
Reconstruction results for the Solver1 algorithm for the dataset of hv-convex images.
ponent in the top-left corner cannot be determined, even though
For each test case, the average number of unknown pixels is shown.
there is a large number of 2-SAT relations in that region. Further in-
spection reveals that there are in fact two solutions for this region,
shown in Fig. 12. In such cases, combining our reasoning frame-
Firstly, the number of unknown pixels increases with the number of work with a simple branching algorithm would easily find both so-
components in the image. Secondly, the number of unknown pixels lutions. In cases where there is no such non-uniqueness, we found
generally decreases with the image size. that our reasoning approach is nearly always capable of completely
As the number of components increases, the number of solutions solving the Nonogram. An example image of size 70 × 70 consisting
of the Nonogram will typically also increase. In fact, for the limiting of four hv-convex components that is solved completely is shown
case where the number of components equals the number of rows in Fig. 11b.
K.J. Batenburg, W.A. Kosters / Pattern Recognition 42 (2009) 1672 -- 1683 1681

Fig. 11. Two 70 × 70 Nonograms from the dataset of hv-convex images. (a) Nonogram that was not solved completely; (b) Nonogram that was solved completely.

1 2 3 3 3 3 6 5 5 6 6 4 1 1 2 3 3 3 3 6 5 5 6 6 4 1
1 1
3 3
6 6
6 6
6 6
6 6
6 6
7 7
4 4
2 2
1 1

Fig. 12. Two hv-convex images corresponding to the Nonogram description in the top-left corner of the larger hv-convex Nonogram in Fig. 11. (a) First solution; (b) second
solution.

Even though the number of unknown pixels generally decreases For the case n = 5, we have reconstructed all possible Nonograms
with the size of the image, the columns of Table 1 are not strictly using both solvers. Fig. 13 shows the number of positions leaving u
2
decreasing, because of outliers. For example, the 70 × 70 image in unknowns, for all 25 =225 =33, 554, 432 possible positions, for these
Fig. 11a with three components leads to 62 unknowns with a con- two solvers, where u > 5. The dashed line is for Solver1, the solid line
tribution of 0.62 to the table value. for FullSettle. Note that u = 1, 2, 3, 5 cannot occur, as observed before.
The running time clearly increases more than linearly with the For u = 0, i.e., the uniquely solvable situations, we have 24,976,511
number of pixels in the image. Still, rather large Nonograms con- (FullSettle) and 25,309,575 (Solver1) positions, respectively. For u = 4,
taining thousands of unknowns can be solved within 1 min. these numbers are 4,363,030 and 4,623,570, respectively. These cases
amount to 87%, resp. 89%, of all positions. Note that in general (among
7.3. Small Nonograms others) the situations with exactly one black pixel in every line give
rise to puzzles with a maximal value for u, i.e., u = n2 .
Consider Nonogram descriptions of size n × n for integer n > 1. Even if a Nonogram does have a unique solution, our approach
2
If we start with any of the 2n possible positions, say S, we can see of combining 2-SAT rules from several relaxed problems may not
whether FullSettle is capable of solving the corresponding puzzle, i.e., capture the full set of constraints present in the Nonogram and, as a
retrieving S; in this case the puzzle is clearly uniquely solvable. We consequence, get stuck prematurely without being able to make any
can also verify whether the stronger Solver1 can solve the puzzle. further deductions. This can even occur for very small Nonograms,
1682 K.J. Batenburg, W.A. Kosters / Pattern Recognition 42 (2009) 1672 -- 1683

1.4e+06 that a Nonogram puzzle is first translated into a (large) CSP, which
is further translated into a SAT problem, and finally solved by a
1.2e+06 SAT solver. For instance, for the problem from Fig. 7, a SAT problem
with 20,548 variables and 31,499 clauses is built. Solution times are
number of positions

1e+06 comparable with our approach. However, apart from but also caused
by the large intermediate problem size, the solution does not give
800000 clear clues concerning the deduction, because of the translation steps
involved.
600000 Our reasoning framework can be considered as a CSP solver tai-
lored for the specific problem category, which works directly in the
400000
original problem domain, without any translation steps involved. In
particular for puzzles of the simple type, where it is not necessary to
200000
harvest 2-SAT expressions and only the dynamic programming ap-
proach from Section 3.1 is utilized, huge Nonograms can be solved
0
6 8 10 12 14 16 18 20 22 24 26 quickly without the need to generate large numbers of constraints
as required by a standard CSP formulation.
unknown pixels
The class of Nonograms that can be solved effectively using our
Fig. 13. Number of positions for 5 ×5 Nonograms with a given number of unknowns approach includes the simple puzzles that can be found in puz-
after solving, for two different solvers: FullSettle (solid line) and Solver1 (dashed line). zle books, but also includes random images and hv-convex images,
which can often not be solved by simple logic reasoning, considering
one line at a time. For the simple puzzles the method is extremely
1 fast, even if the puzzles are very large.
2 1 1 1 1 Our framework is quite general. For example, as indicated in Sec-
tion 2, the concept of a description can be generalized in a straight-
1
forward manner. In future work, we intend to study several such
2 generalizations.
1 x
2 Acknowledgements
1
The authors are grateful to Péter Balázs for providing an exten-
Fig. 14. Partially solved 5 × 5 Nonogram, where the fact that pixel x must be white sive set of hv-convex test images, and to Naoyuki Tamura for sup-
(0) is hard to infer. Note that the grey pixels are still undecided. plying his CSP solver. The first author acknowledges the Research
Foundation Flanders (FWO) for financial support.

as demonstrated by the example in Fig. 14. Here the six white pixels References
are easily inferred, while all other pixels (coloured grey) are still un-
decided. In this case, even Solver1 cannot make any further progress, [1] S. Salcedo-Sanz, J. Portilla-Figueras, E. Ortiz-Garcia, A. Perez-Bellido, X. Yao,
Teaching advanced features of evolutionary algorithms using Japanese puzzles,
while one can still infer that the rightmost pixel in the third row IEEE Trans. Educ. 50 (2) (2007) 151–156.
must be white. Of course, such small examples could easily be solved [2] G.T. Herman, A. Kuba, Discrete Tomography: Foundations Algorithms and
by a branching algorithm. Applications, Birkhäuser, Boston, 1999.
[3] G.T. Herman, A. Kuba, Advances in Discrete Tomography and its Applications,
Birkhäuser, Boston, 2007.
8. Discussion and conclusions [4] A. Kuba, E. Balogh, Reconstruction of convex 2D discrete sets in polynomial
time, Theor. Comput. Sci. 283 (1) (2002) 223–242.
[5] E. Barcucci, A. Del Lungo, M. Nivat, R. Pinzani, Reconstructing convex
The general Nonogram problem is known to be NP-hard. How- polyominoes from horizontal and vertical projections, Theor. Comput. Sci. 155
ever, it appears that in practice many instances can be solved quickly. (1996) 321–347.
We presented a general framework for solving Nonograms. By com- [6] G. Woeginger, The reconstruction of polyominoes from their orthogonal
projections, Inf. Process. Lett. 77 (2001) 225–229.
bining several relaxations, that can each be solved in polynomial [7] N. Ueda, T. Nagao, NP-completeness results for Nonogram via parsimonious
time, a solution of the Nonogram is computed iteratively. The dif- reductions, preprint, 1996. URL: citeseer.ist.psu.edu/ueda96npcompleteness.
ferent solution methods are combined using a 2-SAT formulation. html .
[8] J. Benton, R. Snow, N. Wallach, A combinatorial problem associated with
We demonstrated that this approach can solve a variety of interest- Nonograms, Linear Algebra Appl. 412 (1) (2007) 30–38.
ing Nonograms. More importantly, the algorithm generates a logical [9] S. Simpson, Website Nonogram solver [accessed 7.7.2008], 2007. URL:
proof for all pixels that are decided. Even if the puzzle cannot be www.comp.lancs.ac.uk/∼ss/nonogram/links.html .
solved completely, it may still be possible to decide the value of a [10] K.J. Batenburg, W.A. Kosters, A discrete tomography approach to Japanese
puzzles, in: Proceedings of the 16th Belgium–Netherlands Conference on
substantial part of the pixels. The proposed method does not have Artificial Intelligence (BNAIC), 2004, pp. 243–250.
to start from scratch: if prior knowledge is available on the value of [11] S. Salcedo-Sanz, E. Ortiz-Garcia, A. Perez-Bellido, J.A. Portilla-Figueras, X. Yao,
certain pixels, it can be used to deduce the value of the remaining Solving Japanese puzzles with heuristics, in: Proceedings of the IEEE Symposium
on Computation Intelligence and Games, Honolulu, USA, 2007, pp. 224–231.
ones. [12] E. Ortiz-Garcia, S. Salcedo-Sanz, J. Leiva-Murillo, A. Perez-Bellido, J. Portilla-
The approach is closely related to the reasoning of human puz- Figueras, Automated generation and visualization of picture-logic puzzles,
zlers, in particular for puzzles of the simple type. Even for more com- Comput. Graph. 31 (2007) 750–760.
[13] S. Russell, P. Norvig, Artificial Intelligence, A Modern Approach, second ed.,
plex instances, where information from several lines is combined,
Prentice-Hall, Englewood Cliffs, NJ, 2003.
our framework yields an intuitive deduction. In this way, the method [14] K.J. Batenburg, W.A. Kosters, A reasoning framework for solving Nonograms, in:
allows for determining a difficulty level. V.E. Brimkov, R.P. Barneva, H.A. Hauptman (Eds.), Combinatorial Image Analysis,
Lecture Notes in Computer Science, vol. 4958, Springer, Berlin, 2008, pp. 372–
Alternatively, as mentioned in the Introduction, Nonograms can
383.
be considered as instances of general CSP problems. This approach [15] R. Aharoni, G. Herman, A. Kuba, Binary vectors partially determined by linear
was, e.g., explored in [21,22], where SAT solvers are employed. Note equation systems, Discrete Math. 171 (1997) 1–16.
K.J. Batenburg, W.A. Kosters / Pattern Recognition 42 (2009) 1672 -- 1683 1683

[16] K.J. Batenburg, A network flow algorithm for reconstructing binary images from [20] P. Balázs, A framework for generating some discrete sets with disjoint
discrete X-rays, J. Math. Imaging Vision 27 (2) (2007) 175–191. components using uniform distributions, Theor. Comput. Sci. 406 (2008) 15–23.
[17] M. Garey, D. Johnson, Computers and Intractability, A Guide to the Theory of [21] N. Tamura, Website Sugar [accessed 21.10.2008], 2008. URL:
NP-Completeness, W.H. Freeman, New York, 1979. bach.istc.kobe-u.ac.jp/sugar/ .
[18] D. Cohen, P. Jeavons, M. Gyssens, A unified theory of structural tractability for [22] N. Tamura, T. Tanjo, M. Banbara, System description of a SAT-based CSP solver
constraint satisfaction problems, J. Comput. Syst. Sci. 74 (5) (2008) 721–743. Sugar, in: Proceedings of the Third International CSP Solver Competition, 2008,
[19] H.J. Ryser, Combinatorial properties of matrices of zeros and ones, Can. J. Math. pp. 71–75.
9 (1957) 371–377.

About the Author—KEES JOOST BATENBURG obtained his Ph.D. in Mathematics in 2006, at the University of Leiden, The Netherlands. He currently has a researcher position
at the Vision Lab of the University of Antwerp in Belgium, where he leads the ASTRA research group (All Scale Tomographic Reconstruction Antwerp), jointly with Jan
Sijbers. His research interests include discrete tomography and related image reconstruction problems, combinatorial optimization and evolutionary algorithms.

About the Author—WALTER A. KOSTERS obtained his Ph.D. in Mathematics in 1985, at the University of Leiden, The Netherlands. He is currently Associate Professor at the
Leiden Institute of Advanced Computer Science (LIACS). His research interests include data mining, complexity analysis and artificial intelligence.

You might also like