Electronic Notes in Discrete Mathematics 20 (2005) 281–297 www.elsevier.com/locate/endm
Reconstruction of binary matrices under adjacency constraints M.-C. Costa 1 CEDRIC CNAM 292 rue Saint Martin 75003 Paris, France
F. Jarray, C.Picouleau 2 CEDRIC CNAM 292 rue Saint Martin 75003 Paris, France
Abstract We consider a generalization of the classical binary matrix reconstruction problem by considering adjacency constraints between the cells: if a given cell is of value 1 then all its neighbors are of value 0. This problem arises especially on statistical physics. We consider several definitions of neighborhood and for each one we give complexity results, necessary and/or sufficient conditions for the existence of a solution and in some cases, polynomial time algorithms. Keywords: Discrete tomography, binary matrix reconstruction, adjacency constraint, network flow, polynomial time algorithm, NP-complete
1 2
Email:
[email protected] Email: {fethi.jarray|chp}@cnam.fr
1571-0653/$ – see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.endm.2005.05.069
282
1
M.-C. Costa et al. / Electronic Notes in Discrete Mathematics 20 (2005) 281–297
Introduction
Reconstructing a binary matrix from its row and column sum is a classical problem in discrete tomography (refer to the book of Hermann and Kuba [9] for further informations on the theory, algorithms and applications). It is wellknown that the basic problem where the only constraints to verify are both projections, can be solved polynomially [13]. Recently, several generalizations of this problem, relative to different applications, have been studied: for instance, the reconstruction of periodic binary matrices [6], the reconstruction of convex sets [8] or the reconstruction of binary matrices from their absorbed projections ([10,11]). Here we study another generalization of this problem by considering some “non-adjacency” constraints: if a cell value is 1 then the values of each one of its neighbors must be 0. This problem arises especially in statistical physics to determine the microscopic properties (energy, density, entropy). In the model of Hard Square Gas, two adjacent cells cannot be occupied simultaneously by particles because the energy of repulsion between them is very high (see for instance [3] or [4]). In this paper, we consider several definitions of the neighborhood of a given cell (i, j) of a matrix M [7]: the 2-adjacency where the two neighbors of (i, j) are (i, j + 1) and (i, j − 1), i.e. its horizontal adjacent cells; the 4adjacency where the neighbors of (i, j) are the cells (i, j −1),(i, j + 1),(i−1, j), and (i + 1, j), i.e. the horizontal and vertical adjacent cells; the 6-adjacency where, in addition to the previous ones, we add two neighbors on one diagonal : (i − 1, j − 1) and (i + 1, j + 1). Eventually, in the 8-adjacency the neighbors of (i, j) are its eight adjacent cells (on row, column and both diagonals). In the following we call “p-adjacency constraint” the non adjacency constraint in a reconstruction problem considering a neighborhood of p cells; by extension, the p-adjacency problem is the related problem. The paper is organized as follows: in sections 2 and 3 we show how solving in polynomial time the 2-adjacency problem denoted by Π2 and the 4adjacency problem when only one projection is considered, denoted by Π4h . In section 4 we propose necessary or sufficient conditions for the existence of a solution to the 4-adjacency problem, Π4 , when both orthogonal projections are considered; then we solve Π4 for matrices with two or three rows. In sections 5 and 6 we prove that the 6-adjacency problem (Π6 ) is NP-complete and that the 8-adjacency problem (Π8 ) is as difficult as the wellknown open problem of reconstructing a three colored matrix [2]. Given an m × n binary matrix M we denote by H = (h1 , ..., hm ) the horizontal projection of M, hi being the number of 1’s on row i, and by
M.-C. Costa et al. / Electronic Notes in Discrete Mathematics 20 (2005) 281–297
283
V = (v1 , ..., vn ) its verticalprojection, vj being the number of 1’s on column j. n The condition m i=1 hi = j=1 vj , denoted by (C0 ), is obviously necessary for the existence of a solution respecting both projections in all problems Πp ’s.
2
Binary matrices under 2-adjacency constraint
In this section, we show that the 2-adjacency problem Π2 where the two neighbors of a cell are it’s left and right adjacent cells is equivalent to a particular packing reconstruction problem which can be solved in polynomial time. First, let us recall what is a packing reconstruction problem: a tile is a shape as a domino (array 1 × 2 or 2 × 1), a rectangle (array a × b) or any other connected polyomino. A packing is a placement of non overlapping tiles on a m × n array respecting the orthogonal projections, i.e. a given number of distinct tiles on each row and column. Now, consider the horizontal dominoes packing problem. In this problem every tile is an horizontal oriented domino, i.e. two adjacent cells, (i, j), the left cell, and (i, j + 1), the right cell. Claim 2.1 Π2 is equivalent to the horizontal dominoes packing problem. Proof. Consider an instance of Π2 defined by H = (h1 , h2 , .., hm ) and V = (v1 , v2 , .., vn ). If vn > 0 then let us add a column to our instance with vn+1 = 0. Let us consider the instance H = (h1 , h2 , .., hm ) and V = (v1 , v2, .., vn ) with n = n if vn = 0 and n = n + 1 if vn > 0. Any solution to Π2 for this new instance is a solution to the previous one and conversely. From now, we consider only instances with vn = 0. It is wellknown that from V = (v1 , v2 , .., vn ), the vertical projection of an horizontal dominoes packing, one can easily compute the number of dominoes having their left cell in column j (see [12]), and vice versa. It is obvious that in a horizontal dominoes packing two left cells cannot be 2-adjacent. So in fact Π2 and the horizontal dominoes packing problem are the same problem (the left cells of dominoes are the 1’s of the binary matrix). 2 Since there exists a polynomial time algorithm for the horizontal dominoes packing problem [12] we can give the following theorem: Theorem 2.2 Π2 can be solved in polynomial time.
284
3
M.-C. Costa et al. / Electronic Notes in Discrete Mathematics 20 (2005) 281–297
Reconstruction respecting the horizontal projections and the 4-adjacency
In this section we search for an m×n matrix M respecting only one projection, for instance the horizontal one, under the 4-adjacency constraint. Let the horizontal projection integer vector be H = (h1 , ..., hm ) with hi ≤ n, ∀i = 1, .., m. To solve Π4h we shall use a chessboard that covers M, that is a m×n matrix D with 1 in the cells corresponding to white squares and 0 corresponding to black squares or the contrary: the value of only one cell (anyone) determines one or the other type of chessboard. Obviously a chessboard verifies the 4adjacency constraint. All the cells (i, j) such that i + j is even (resp. odd) have the same value as D(1, 1) (resp. D(2, 1)). Consider a chessboard with D(1, 1) = 1: if n is even there are n2 1’s on each row, and if n is odd there are n+1 1’s on odd rows and n−1 1’s on even rows; such a chessboard is the most 2 2 dense binary matrix respecting the 4-adjacency constraint. Now, we are going to give some necessary and sufficient conditions on H, depending on the parity of n, for the existence of a solution to Π4h . As a byproduct, we shall get a method to build M if it exists. First, note that hi 1’s are required on each row i, and so at least hi − 1 0’s: for all thus there is a solution only if hi + hi − 1 ≤ n or equivalently hi ≤ n+1 2 i. This condition, denoted by (C1 ), is necessary whatever is the parity of n. ∀i = 1, .., m is a necessary and Proposition 3.1 If n is even (C1 ): hi ≤ n+1 2 sufficient condition for the existence of a solution to Π4h . Proof. The necessity is proved above. Let us prove the sufficiency. On each row i, n being even and hi being integer, hi ≤ n+1 ⇒hi ≤ n2 . Consider a 2 chessboard on M: it has n2 1’s per row. Choosing exactly hi 1’s per row and setting the other cells to 0 we get the solution. 2 Nevertheless, this condition is not sufficient in the case where n is odd: just consider two adjacent rows with hi = hi+1 = n+1 ; the condition (C1 ) holds 2 but there are 1’s in vertically adjacent cells and the 4-adjacency constraint is violated. When n is odd, we need to introduce more definitions: a row i is said to be saturated if hi = n+1 ; that means that there must be a 1 in each 2 odd column. We said that two saturated rows i1 and i2 are consecutive if there is no saturated intermediate row between them (row i is no saturated for all i: i1 < i < i2 ). Let us denote by Mi1 i2 the submatrix of M restricted to rows i such that i1 ≤ i ≤ i2 , and by Π4h (i1 , i2 ) the corresponding subproblem.
M.-C. Costa et al. / Electronic Notes in Discrete Mathematics 20 (2005) 281–297
285
Fig. 1. Π4h when n is odd
Obviously, there is a solution to Π4h only if for any consecutive rows i1 and i2 , Π4h (i1 , i2 ) has a solution (see Figure 1). Note that, as seen above, if two adjacent rows are saturated then a solution cannot exist. Thus from now we assume that i2 > i1 + 1. Let k = i2 − i1 − 1 ≥ 1 be the number of intermediate rows in Mi1 i2 . The three following propositions give conditions on hi ’s in order that Π4h (i1 , i2 ) has a solution. These propositions are based on the parity of k. For an intermediate (unsaturated) row i, n being odd, we have hi ≤ n−1 . 2 Proposition 3.2 If n is odd and k is odd then hi ≤ n−1 ∀i, i1 < i < i2 , is a 2 necessary and sufficient condition for the existence of a solution to Π4h (i1 , i2 ). Proof. Just recall that a chessboard on Mi1 i2 has at least i1 ≤ i ≤ i2 .
n−1 2
1’s per row i, 2
When n is odd and k is even, it is not possible to cover Mi1 i2 with a chessboard
286
M.-C. Costa et al. / Electronic Notes in Discrete Mathematics 20 (2005) 281–297
(see Figure 1). In a first step we give a necessary condition for the existence of a solution: 2 −1 Proposition 3.3 If n is odd and k is even then (C2 ) : ii=i hi ≤ k2 n − n+1 2 1 +1 is a necessary condition for the existence of a solution to Π4h (i1 , i2 ). Proof. Rows i1 and i2 are saturated. On the set of intermediate rows i, i1 < i < i2 there are at most k2 1’s on an even column and k2 − 1 1’s on an odd even columns and n+1 odd columns. Hence column. n being odd there are n−1 2 2 k k the total number of 1’s on the intermediate rows is at most n−1 + n+1 −1 2 2 2 2 k n+1 2 = 2 n − 2 ; thus (C2 ) must be verified. Now, let us show that, when n is odd and k is even, (C1 ) and (C2 ) are sufficient for a solution to exist. Let f be the following integer function defined from {i = i1 , ..., i2 − 1} to [1, ..., n] by: f (i1 ) = 1 f (i1 + 1) = n − 2hi1 +1 f (i) = min(n, f (i − 1) + n − 2hi ) for i = i1 + 2, ..., i2 − 1 Without loss of generality, we assume now that i1 even. (If i1 is odd, just exchange in the following in the one hand “odd” and “even” and in the other hand “have the same parity” and “have not the same parity”.) Let ˆı be the smallest i such that f (ˆı) = n: f (i) < n for i < ˆı. Claim 3.4 ˆı is such that ˆı < i2 . f (i2 − 1) < n. By induction, f (i2 − 1) = Proof. Assume that ˆı ≥ i2 , that iis 2 −1 2 −1 hi . Recall that f (i2 − 2) + n − 2hi2 −1 = ... = i=i1 +1 n − 2hi kn − 2 ii=i 1 +1 i2 −1 n+1 k (C2 ) is n − ; hence, we get n + 1 ≤ f (i h ≤ 2 − 1) < n, a i=i1 +1 i 2 2 contradiction. 2 Claim 3.5 f (i1 + 1) ≥ f (i1 ) and f is increasing on {i1 + 1, ..,ˆı}. i.e. n − 2hi ≥ 1. Then f (i1 + 1) = Proof. For i1 < i < i2 , we have hi ≤ n−1 2 n − 2hi1 +1 ≥ f (i1 ) = 1 and f (i) = f (i − 1) + n − 2hi > f (i − 1) for all i = i1 + 1, ...,ˆı. 2 Claim 3.6 For each i such that i1 < i < ˆı, i and f (i) have the same parity. Proof. Recall that i1 is even. Since n is odd f (i1 + 1) is odd and the relation is satisfied for i = i1 + 1. For i > i1 + 1, f (i) =f (i − 1) + n − 2hi , then by induction i and f (i) have the same parity. 2 Now, set to 0 all the cells in {(i, j); i = i1 + 1, ...,ˆı; j = f (i − 1), ..., f (i)}. That defines “stairs” from column 1 to column n, splitting up the subma-
M.-C. Costa et al. / Electronic Notes in Discrete Mathematics 20 (2005) 281–297
287
trix Mi1 i2 into two parts separated by these 0’s (see Figure 1). Let us cover the right up part by a partial chessboard with D(i1 , 1) = 1 and the left down part by another partial chessboard with D(i2 , 1) = 1. i1 is even, i2 = i1 + k + 1 and k is even, thus i2 is odd: the right up partial chessboard has 1’s on the cells (i, j) such that i + j is odd whereas the left down partial chessboard has 1’s on the cells such that i + j is even. Clearly, the obtained binary matrix satisfies the 4-adjacency constraint. Claim 3.7 For i, i1 < i < ˆı, there are exactly hi 1’s on each row i. Proof. Let us consider a row i with i1 < i < ˆı. There is a stair of 0’s covering cells from column f (i−1) to column f (i). The cells (i, 1), (i, 2), ..., (i, f (i−1)− 1), are on the left of the stairs and belong to the left down partial chessboard; note that for i = i1 + 1 there is no cells on the left side. The cells (i, f (i) + 1), (i, f (i) + 2), ..., (i, n) are on the right of the stair and belong to the right up partial chessboard. The cell (i, f (i − 1) − 1) is adjacent to the stair by the left and from claim 3.6, i+f (i−1)−1 is even and the cell (i, f (i)+1) is adjacent to the stair by the right andfrom claim 3.6, i+f (i)+1 is odd: thus, both cells have f (i−1)−1 n−f (i) a 1. There are 1’s on the left of the stair, and 1’s on the 2 2 n−f (i) + right of the stair. Thus the total number of 1’s on row i is f (i−1)−1 2 2 f (i−1)−1 2hi −f (i−1) f (i−1)−1 −f (i−1) 2 = + = hi + + =hi . 2 2 2 2 Claim 3.8 There are at least hi 1’s on each row i for ˆı ≤ i ≤ i2 − 1. Proof. Firstly, consider the row ˆı. Since ˆı and f (ˆı − 1) − 1 have the same f (ˆı−1)−1 parity, there is a 1 on the cell (ˆı, f (ˆı − 1) − 1). So there are 1’s on 2 the left side of the stair on therow ˆı.We have f (ˆ ı) = n ≤ f (ˆı − 1) + n − 2hˆı ; f (ˆı−1) f (ˆı−1)−1 thus 2hˆı ≤ f (ˆı − 1) ⇒ hˆı ≤ = . Secondly, on each row i, 2 2 ˆı < i ≤ i2 − 1 there are at least . have hi ≤ n−1 2
n−1 2
1’s. These rows being no saturated, we 2
We are ready to establish the following proposition: Proposition 3.9 If n is odd and k is even then it exists a solution to Π4h (i1 , i2 ) if and only if 2 −1 (C1 ) hi ≤ n+1 ∀i = i1 , ..., i2 and (C2 ) ii=i hi ≤ k2 n − n+1 . 2 2 1 +1 Proof. (C1 ) and (C2 ) are necessary conditions. Now, if (C1 ) and (C2 ) are satisfied, to get a solution to Π4h (i1 , i2 ) we have to build the stairs of 0’s as explained above. Then from claim 3.7 and claim 3.8 each row i, i1 ≤ i ≤ i2 ,
288
M.-C. Costa et al. / Electronic Notes in Discrete Mathematics 20 (2005) 281–297
has at least hi 1’s; one can select exactly hi 1’s to get a solution to Π4h (i1 , i2 ).2 Now let the row r be the first saturated row of M and, if r = 1 consider the subproblem Π4h (1, r) corresponding to the r first rows: it has a solution if and only if the condition (C1 ) is verified for i = 1, ..., r. The proof is the same as the proof given for propositions 3.1 and 3.2. In addition, the subproblem Π4h (s, m), where s < m is the last saturated row, can be solved as well. Eventually, when n is odd, to solve Π4h we have to study each subproblem Π4h (i1 , i2 ) where i1 and i2 are two consecutive saturated rows. If they all have a solution, that provides a solution to Π4h ; otherwise, Π4h has no solution. We obtain the following result: Theorem 3.10 A solution to Π4h exists if and only if (C1 ) holds and if n is odd, (C2 ) holds for each pair (i1 , i2 ) of consecutive saturated row such that i2 − i1 − 1 is even. Note that if it exists a solution to Π4h then it can be obtained in a linear time from chessboards covering M as indicated in the proofs above. All the results obtained in this section can be settled symmetrically for the problem Π4v where instead of a vector H of horizontal projections we are given a vector V of vertical projections.
4
Reconstruction respecting the orthogonal projections and the 4-adjacency constraint
Let us denote this problem by Π4 . It seems that the complexity of Π4 is still an open problem. We first propose conditions (necessary or sufficient) for the existence of a solution to Π4 , then we solve the problem in the special cases m = 2 and m = 3. 4.1 Sufficient conditions for the existence of a solution to Π4 n Let HO = (h1 , h3 , ..., h2p−1 ), p = m2 , and
m VO = (v1 , v3 , ..., v2q−1 ), q = 2 (respectively HE = (h2 , h4 , ..., h2p ), p = 2 , and VE = (v2 , v4 , ..., v2q ), q =
n ), bethe projections of the odd (resp. even) rows and columns. 2
If it exists a m2 × n2 binary matrix satisfying HO and VO and a m2 × n2 binary matrix satisfying HE and VE then it exists a solution to Π4 . Indeed, this solution is obtained by aggregating the two binary matrices: it obviously satisfies the projections and the 4-adjacency constraint holds since the 1’s are on cells (i, j) such that i + j is even.
M.-C. Costa et al. / Electronic Notes in Discrete Mathematics 20 (2005) 281–297
289
Fig. 2. Π4 with 2 rows
In the same way, if the two subproblems restricted first to odd rows and even columns and second to even rows and odd columns both have a solution then Π4 has a solution: in that case, the 1’s are on cells (i, j) such that i + j is odd. However, these conditions are not necessary; just consider the following instance: m = 3, n = 4, H = (2, 1, 2) and V = (2, 1, 1, 1). 4.2 Necessary conditions for the existence of a solution to Π4 Following the definitions of problems Π4h , Π4v and Π2 , we have the obvious necessary condition: if a solution to Π4 exists then there exists a solution to the corresponding instances of Π4h , Π4v and Π2 . Nevertheless, these conditions are not sufficient as shown by the following instance: m = n = 4, H = (2, 1, 2, 1) and V = (1, 2, 2, 1). Now, we will focus on two particular cases: m = 2 and m = 3. 4.3 Solving Π4 when m = 2 In this case vj ∈ {0, 1} for all j, otherwise the 4-adjacency constraint cannot be satisfied. From the columns such that vj = 1, we make K blocks B k where each B k is a maximal set of consecutive columns with unary vertical projection (see Figure 2). Let lk denotes the number of columns in B k , k = 1, .., K. Since the columns j which are not into a block are such that vj = 0 we have: K k n k=1 l = j=1 vj . Now we can give the following proposition: Proposition 4.1 If M has two rows, there exists a solution to Π4 if and only if: (C0 ) h1 + h2 = Σnj=1 vj (C1 ) hi ≤ n+1 for i = 1, 2 2 (C2 ) vj ∈ {0, 1} for all j = 1, .., n
290
M.-C. Costa et al. / Electronic Notes in Discrete Mathematics 20 (2005) 281–297
(C3 ) hi ≥ ΣK k=1
k l 2
for i = 1, 2.
is Proof. (C0 ) and (C2 ) are obviously necessary as explained before. hi ≤ n+1 2 the condition (C1 ) necessary for Π4h (see section 3): any solution to Π4 being a solution to Π4h , (C1 ) is is also necessary for Π4 . Eventually, for each block Bk there must be a 1oneach column; to respect the 4-adjacency constraint there k must be at least l2 1’s on each row of each block B k and (C3 ) is necessary. Now, k assume that the conditions are all satisfied. (C3 ) implies that hi − l k ≥ 0; the number of blocks of odd length is equal to ΣK k=1 l − 2 k k k k l l l l n K K = h1 + h2 −2ΣK + 2ΣK k=1 2 = Σj=1 vj −2Σk=1 2 k=1 2 = h1 − Σk=1 2 k l h2 − ΣK ≥ 0. Then we can obtain a solution to Π4 in the following k=1 2 way: step 1 Renumber the columns of each block from 1 to l k , k = 1, .., K; step 2 On the first row:
ΣK k=1
k l 2
2.1 “select” the first h1 − ΣK k=1
lk 2
blocks of odd length and set
+ 1 cells on the odd columns to 1 in these blocks. k 2.2 on all the other blocks, set l2 cells on the even columns to 1.
step 3 On the second row: set a 1 on each column of each block B k without 1 on the first row. Doing so we get exactly a 1 on each column of each block as required and our solution verify the adjacency constraint. In addition, on kthe first row we lk l K get 2 1’s on each block and one more 1 on h1 − Σk=1 2 blocks. That k k l l K gives ΣK − Σ + h = h1 1’s on the first row. Since the 1 k=1 2 k=1 2 k k l l K + h , total number of blocks of odd length is h1 − ΣK − Σ 2 k=1 2 k=1 2 k l there are h2 − ΣK odd blocks not selected at step 2.1. These blocks k=1 2 are treated at step k 2.2 and have 1’s on the first row on even columns; from step 3, they get l2 + 1 1’s on the second row on odd columns while the other k k l l K 1’s on the second row. Finally, we have Σ + blocks get ΣK k=1 k=1 2 k 2 l 2 h2 − ΣK = h2 1’s on the second row. k=1 2
M.-C. Costa et al. / Electronic Notes in Discrete Mathematics 20 (2005) 281–297
291
4.4 Solving Π4 when m = 3 If the matrix M has three rows the problem has a solution only if vj ∈ {0, 1, 2} for all j = 1, .., n, since the 4-adjacency constraint cannot be verified if vj = 3 for some j. There is no 1 on columns j such that vj = 0 and there must be a 1 on the first and third rows on column j such that vj = 2. In order to satisfy the 4-adjacency constraint there is no column j such that vj = vj+1 = 2 for 1 ≤ j < n. Thus the condition that follows must be satisfied : (C2 ) vj ∈ {0, 1, 2} for all j = 1, .., n and vj + vj+1 < 4 for all j = 1, .., n − 1. In the sequel we suppose that (C2 ) holds. We have now to study columns with vj = 1: they can be grouped in K blocks B k of maximal length lk as in section 4.3. Note that if there is a column j such that vj = 1 and (vj+1 = 2 or vj−1 = 2) the 1 of column j lies in the second row. In a first step, let Πk4 be the 4-adjacency subproblem associated with a block B k . We denote by H k = (hk1 , hk2 , hk3 ) its horizontal projections. Note that at this stage H k is unknown. We are going to give some conditions on H k for a solution to Πk4 to exist. We consider three cases: a block B k is adjacent to zero, to one or to two columns with vj = 2. Proposition 4.2 It exists a solution to Πk4 if and only if (C0 ) hk1 + hk2 + hk3 = lk and case 1 B k is adjacent to two columns with vj = 0 then (C4 ) hki ≤
lk 2
for i = 1, 2, 3
k
case 2 B is adjacent to a column with vj = 0 and to a column with vj = 2 then k k (C5 ) hki ≤ l2 for i = 1, 3 and 1 ≤ hk2 ≤ l2 case 3 B k is adjacent to two columns with vj = 2 then k k k k k k (C6 ) l = 2 and if l = 1then (h1 = h3 = 0 and h2 = 1) else k hki ≤ l 2−1 for i = 1, 3 and 2 ≤ hk2 ≤ l2 . Proof. First let us prove the necessity of these conditions. hk1 + hk2 + hk3 = Σnj=1 vj = lk is the necessary condition (C0 ). k The adjacency implies (condition (C1 )) that hki ≤ l2 , i = 1, 2, 3, must be satisfied for any case 1, 2, 3. Thus, for the case 1 (C4 ) is a necessary condition. For the case 2, without loss of generality, we assume that the column adjacent to the left of B k has a vertical projection equal to two and that the
292
M.-C. Costa et al. / Electronic Notes in Discrete Mathematics 20 (2005) 281–297
column adjacent to the right of B k has a vertical projection equal to zero. As noted above, there must be a 0 on the first and third row and thus a 1 on the second row of the first column of B k . Thus the conditions of case 2 must be verified. Eventually, in the case 3, as noted above, there must be a 0 on the first and third row and a 1 on the second row in the first and last columns of B k . It follows that the 4-adjacency cannot be satisfied if l k = 2. If lk = 1 k the necessity of the condition (C6 ) is trivial. If lk ≥ 3we must have h2 ≥ 2 k k and for the rows 1 and 3 the condition (C1 ) is hki ≤ l 2−2 = l 2−1 . The conditions of the case 3 must be verified. Now, assume that these conditions are satisfied. Let us denote by j and j the first and the last columns of B k , respectively. The rows are numbered such that hki ≥ hˆı ≥ hki . We propose the following procedure to build a solution: step 1: If vj −1 = 2 then assign a 1 to the cell (2, j ) and do vj = 0 and update hk2 to hk2 − 1; If vj +1 = 2 then assign a 1 to the cell (2, j ) and do vj = 0 and update hk2 to hk2 − 1; step 2: While hki = 0 do : let j be the leftmost column of B k such that vj = 1 and (i, j) is not 4-adjacent to a cell which contains a 1; assign 1 to (i, j) and do vj = 0 and update hki to hki − 1; (row i is fill from the left) step 3: While hˆık = 0 do : let j be the rightmost column of B k such that vj = 1 and (i, j) is not 4-adjacent to a cell which contains a 1; assign a 1 to (ˆı, j) and do vj = 0 and hˆık ← hˆık − 1; (row ˆı is fill from the right) step 4: Assign a 1 to the cells (i , j) such that vj = 1. Let us prove the validity of our procedure: (C5 ) and (C6 ) ensure that we can perform the step 1. The conditions (C4 ), (C5 ) and (C6 ) ensure that we can perform the step 2 whatever is the row i. Note that after this step there is no successive columns j and j + 1 with vj = vj+1 = 0. Thus the step 3 can be performed. One can remark that after the step 3 the 1’s cannot be 4-adjacent. Now from condition (C0 ) the step 4 can be executed. So it remains to show that the 4-adjacency is always satisfied after this last step. Since in the step 4 the 1’s are assigned to the cells (i , j) with vj = 1, we have to prove that at the beginning of this step there are no columns j and j +1 such that vj = vj+1 = 1. In order to obtain a contradiction let us suppose that there are such two columns. Let j1 , respectively j2 , be the last column where a 1 is assigned on row i (step 2), respectively row ˆı (step 3). Following the manner the step 2 and j ≥ j1 + 1 and j + 1 ≤ j2 − 1. step k 3 work, wek have h h +hk hk Thus we have hki ≥ 2i + 2ˆı + 2 > i 2 ˆı . Since hki ≥ hˆık ≥ hki we get a contradiction. 2
M.-C. Costa et al. / Electronic Notes in Discrete Mathematics 20 (2005) 281–297
293
Fig. 3. Π4 with 3 rows: determination of the H k ’s
Now, in order to solve the whole problem, for each block B k , we have to determine a projection H k satisfying, first the conditions of proposition 4.2, k K k and second ΣK k=1 h2 = h2 and Σk=1 hi − n2 = hi for i = 1, 3, where n2 is the number of columns of M with vj = 2. We propose to determine these H k ’s by searching for a flow in a complete bipartite network G = (X, Y, E) defined as follows (see Figure 3): X = {R1 , R2 , R3 }, where the node Ri is associated to the row i; Y = bk , k = 1, .., K , where the node bk is associated to the block B k . We add a source node S and three arcs (S, Ri ). The capacities of these arcs are set to h2 for i = 2, and to hi − n2 for i = 1, 3. We add a sink node T and K arcs (bk , T ). These arcs have capacity l k for k = 1, .., K. Eventually, k the capacities of the arcs (Ri , bk ) are as follows : if i = 2 or B k is a block as in the case 1 of proposition 4.2 then the capacity is equal to l2 ; if i = 1 or k 3 and B k is as in the case 2 then the capacity is equal to l2 ; finally, if i = 1 k or 3 and B k is as in the case 3 then it is equal to l 2−1 . We also have a lower bound for the arcs (R2 , bk ): if B k is as in the case 2 then the lower bound is 1; if B k is as in the case 3 and lk = 1 then the lower bound is set to 2. The lower bound of every other arc is 0.
Theorem 4.3 For m = 3, there exists a solution to the problem Π4 if and k only if it exists a flow of total value ΣK k=1 l in the network G.
294
M.-C. Costa et al. / Electronic Notes in Discrete Mathematics 20 (2005) 281–297
Proof. If there exists such a flow in G, let hki be equal to the flow on the arc (Ri , bk ) for all i and all k. On the one hand, for each block B k , the flow of the arcs (bk , T ) is lk , k = 1, . . . , K that means that hk1 + hk2 + hk3 = lk (condition (C0 )) and as remarked above the other conditions of proposition 4.2 are satisfied. Now using the algorithm designed in the proof of proposition 4.2 we know how to assign the 1’s on each block B k . On the other hand, since k the value of the flow is ΣK k=1 l = h1 + h2 + h3 − 2n2 , the matrix M satisfies the horizontal projection and then M is a solution of Π4 . Reciprocally, if there exists a matrix M solution of Π4 , then H k = (hk1 , hk2 , hk3 ) is known for each block B k , k = 1, . . . , K. Thus setting the value hki for the k flow of the arc (Ri , bk ) we obtain a feasible flow with value ΣK k=1 l in the network G. 2 Corollary 4.4 For m = 3, the problem Π4 can be solved in polynomial time. Proof. The computation of the flow in G can be done in polynomial time (see [1]). Clearly, the algorithm given in the proof of proposition 4.2 is polynomial. Eventually, one can check the necessary conditions in polynomial time. 2
5
Binary matrices under 6-adjacency constraint
In this section we prove that the problem of reconstructing a binary matrix under 6-adjacency constraint, denoted by Π6 , is NP -complete. To do that we show that a special case of Π6 is equivalent to a L − tile packing problem defined as follows: a L − tile is a polyomino with three cells as shown by the Figure 4. In addition, the left down cell has a 1 and the two other cells have a 0. The projections are the number of 1’s lying on each line (a cell not covered by a L − tile has a 0). The problem is to find L − tile packing with given projections H = (h1 , ..., hm ) and V = (v1 , ..., vn ). Obviously, a L − tile packing exists only if h1 = vn = 0. Henceforth we are concerned with Π6 the subproblem of Π6 restricted to the instances with h1 = vn = 0. Claim 5.1 Π6 is equivalent to the L − tile packing problem. Proof. Consider an instance H = (0, h2 , .., hm ) and V = (v1 , .., vn−1 , 0) common to both problems. Let S1 be a solution to Π6 . A solution S2 to the L − tile packing problem can be obtained by assigning the 1’s of S1 to S2 . Indeed, since in S1 two 1’s are not 6-adjacent, two L − tiles cannot overlap in S2 . Conversely, a solution S1 to Π6 can be obtained from a solution S2 to the L − tile packing problem, as well. 2
M.-C. Costa et al. / Electronic Notes in Discrete Mathematics 20 (2005) 281–297 2
0
1
1
0
2
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
2
1
0
0
1
0
1
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
1
0
0
2
1
0
0
1
0
1
1
0
0
0
0
L−tile packing
295
Square packing
Fig. 4. 6-adjacency and 8-adjacency constraints and their tile packings
The L − tile packing problem is known to be NP -complete [5] : we deduce the following theorem: Theorem 5.2 Π6 is NP -complete.
6
Binary matrices under 8-adjacency constraint
In this section, we study the problem of reconstructing a binary matrix under the 8-adjacency constraint, denoted by Π8 . We first prove that a special case of Π8 is equivalent to the problem of 2 × 2 squares packing defined as follows: a 2 × 2 square is a polyomino with four cells as shown by the Figure 4. The left down cell has a 1 and the other cells have a 0. The projections correspond to the number of 1’s on each line (a cell not covered has a 0). The problem is to find a 2 × 2 square packing with given projections H = (h1 , ..., hm ) and V = (v1 , ..., vn ). Obviously, a 2 × 2 square packing is possible only if h1 = vn = 0. Now, consider the problem Π8 corresponding to Π8 restricted to instances with h1 = vn = 0. Claim 6.1 Π8 is equivalent to the 2 × 2 square packing problem. Proof. The proof use the same arguments as the proof of the claim 5.1.
2
The 2 × 2 square packing problem has been proved to be as difficult as the three colored image reconstruction problem which is still an open problem [2]. We deduce the following theorem: Proof. Π8 is as difficult as the three colored image reconstruction problem.2
296
7
M.-C. Costa et al. / Electronic Notes in Discrete Mathematics 20 (2005) 281–297
Conclusion
In this paper we have studied new binary matrices reconstruction problems by considering non adjacency constraints. We have studied four type of adjacency and given polynomial time algorithms to solve the 2-adjacency problem and the 4-adjacency problem in the case where only one projection has to be satisfied. Also we give polynomial time algorithms for the 4-adjacency problem for m = 2 and m = 3. We have proved that for the 6-adjacency the decision problem is NP -complete. Nevertheless, the complexity status of the 4-adjacency problem for m > 3 as well as the 8-adjacency problem remains an open question.
References [1] Ahuja, R.K., Magnanti, T.L., and Orlin, J.B., “ Network flows,” Prentice Hall, 1993. [2] Chrobak, M. and C. D¨ urr, Reconstructing Polyatomic Structures from X-Rays: NP Completness Proof for three Atoms, Theor. Comp. Sc. 259 (2001), 81-98. [3] Baxter R. J., Planar lattice gases with nearest-neighbour exclusion, Annals of Combinatorics 3 (1999), 191-203. [4] Calkin N.J. and H. S. Wilf, The number of independent sets in a grid graph, SIAM J. on Discr. Math. 11 (1998), 54-60. [5] Chrobak M., P. Couperus, C. D¨ urr, and G. Woeginger, 2003. A note on tiling under tomographic constraints, Theor. Comp. Sc. 290 (2003), 2125-2136. [6] Del Lungo A., A. Frosini, M. Nivat, and L. Vuillon, Reconstruction under Periodicity Constraints, LNCS 2380 (2002), 38-56, Proc. of the 29th Int. Coll. on Automata, Languages and Programming, Springer-Verlag. [7] Jarray F., “R´esolution de probl`emes de tomographie discr`ete. Applications a` la planification de personnel,” Ph. D. thesis, CNAM, Paris, France, 2004. [8] Kuba A. and E. Balogh, Reconstruction of convex 2D discrete sets in polynomial time Theor. Comput. Sc. 283 (2000), 223-242. [9] Kuba, A., and G. T. Herman, “Discrete Tomography: Foundations, Algorithms and Applications,” Birkhauser, 1999. [10] Kuba A., A. Nagy, and E. Balogh, Reconstruction of hv−convex binary matrices from their absorbed projections, Disc. App. Math. 139 (2004), 137-148.
M.-C. Costa et al. / Electronic Notes in Discrete Mathematics 20 (2005) 281–297
297
[11] Kuba A., and M. Nivat, Reconstruction of discrete sets with absorption, Linear Algebra and Its Applications 339 (2001), 171-194. [12] Picouleau, C., Reconstruction of domino tiling from its two orthogonal projections, Theor. Comp. Sc. 255 (1) (2001), 437-447. [13] Ryser, H.J., Combinatorial properties of matrices of zeros and ones, Canad. J. Math. 9 (1957), 371-377.