The Solution of Ultra Large Grid Problems

2 downloads 0 Views 281KB Size Report
that there are no rectangles with all four corners of the same color.” In comparison with ... THE PROBLEM TO SOLVE: RECTANGLE-FREE GRIDS. In order to explain the ...... Coloring of Grids. http://www.cs.umd.edu/∼gasarch/papers/grid.pdf.
The Solution of Ultra Large Grid Problems Bernd Steinbach

Christian Posthoff

Institute of Computer Science Freiberg University of Mining and Technology Freiberg, Germany Email: [email protected]

The University of The West Indies St. Augustine Campus Trinidad & Tobago Email: [email protected]

Abstract— SAT solvers have grown in power over the last decades. However, both certain intentions of their application and the complexity of the problems are still obstacles to their successful utilization. Here we are facing a problem where an extremely small fraction of solutions must be found in the unimaginably large search space of more than 10195 . Up to now SAT solvers were able to find solutions for subproblems with the size of approximately 10135 . Hence, it was our challenge to bridge the gap of 1060 . In this paper we focus on a subproblem of the basic graph coloring problem. Due to the estimated complexity it seemed to be hopeless to find solutions. However, we enjoyed this extreme challenge and studied several approaches beyond the application of SAT solvers which allowed finally to solve the so far open graph coloring problem.

I. I NTRODUCTION There is a wide field of applications of graph coloring [3]. Some examples are, for instance, the assignment of frequencies to radio stations or the state assignment for optimizing finite state machines. In [1] the problem is shortly defined as follows. ”A twodimensional grid is a set Gm,n = [m] × [n]. A grid Gm,n is c-colorable if there is a function χm,n : Gm,n → [c] such that there are no rectangles with all four corners of the same color.” In comparison with [1] we exchanged in this definition the variables m and n to get a natural alphabetic order of m rows and n columns. Trying to find the so far unknown 4-colored grid G18,18 [6] we reached in [5] already an overall improvement of 5.2 ∗ 1092 for solving the problem. In this paper we consider a subproblem of edge coloring of complete bipartite graphs. The restriction consists in assigning only a single color to the edges with the special rule that not all 4 edges of a cycle are colored by the selected color. The challenge is that we want the maximal number of edges of the graph which can be colored and hold the mentioned condition. II. T HE P ROBLEM TO S OLVE : R ECTANGLE -F REE G RIDS In order to explain the problem in a way which is easy to understand we start with a simple bipartite graph G(V, E). The set of all vertices V of the bipartite graph G is divided into two subsets R and C with V = R ∪ C and R ∩ C = ∅. It is a special property of each bipartite graph G that each edge e ∈ E connects one vertex r ∈ R with one vertex c ∈ C. There are no edges between vertices of the subset R or the subset

r1 ◦

◦ c1

r2 ◦

◦ c2

r3 ◦

◦ c3 G13,4

Fig. 1.

r1 ◦

◦ c4

◦ c1

r2 ◦

◦ c2

r3 ◦

◦ c3

◦ c4

G23,4

Graphical Representations of two Complete Bipartite Graphs

C. Due to the restriction to a single color a Boolean variable xr,c is used to define the color of the edge from the vertex r to the vertex c of the bipartite graph. The single selected color is assigned to the edge from vertex r to vertex c if xr,c = 1, and no color is assigned to this edge if xr,c = 0. In graphical representations we indicate a colored edge by a bold line while an edge without color assignment is represented by a dashed line. Only complete bipartite graphs are taken into consideration. That means that each vertex of R is connected with each vertex of C. Figure 1 shows as example two different complete bipartite graphs of three vertices in the subset R ⊂ V and four vertices in the subset C ⊂ V . The left graph G13,4 of Figure 1 contains six colored edges: {e(r1 , c2 ), e(r2 , c1 ), e(r2 , c3 ), e(r3 , c1 ), e(r3 , c3 ), e(r3 , c4 )} . Four of them {e(r2 , c1 ), e(r2 , c3 ), e(r3 , c1 ), e(r3 , c3 )} describe a completely colored subgraph K2,2 . Such a monochromatic cycle of four edges e(r2 , c1 ), e(c1 , r3 ), e(r3 , c3 ), and e(c3 , r2 ) violates the color condition. Hence, we must exclude the graph G13,4 from the set of wanted graphs. The right graph G23,4 of Figure 1 contains seven colored edges. Despite the larger number of colored edges, there is no completely colored subgraph K2,2 within the bipartite graph G23,4 . Hence, this coloring is allowed. Furthermore, it is not possible to color one more edge of the graph G23,4 without creating a completely colored subgraph K2,2 . Hence, the right graph G23,4 of Figure 1 is one of the wanted maximal colored bipartite graphs G3,4 . An alternative to the graphical representation of a bipartite graph Gm,n is an adjacency matrix. Such a matrix is also

c1 c2 c3 c4

c1 c2 c3 c4

r1 0 1 0 0 r2 1 0 1 0 r3 1 0 1 1

r1 1 0 0 1 r2 1 1 1 0 r3 0 1 0 1

G13,4 Fig. 2.

The solution of the Boolean equation (3) is the set of all rectangle-free grids of m rows and n columns. The number of values 1 in such a grid is n1 (G). Counting the values 1 in the grids of Figure 2, we get as example n1 (G13,4 ) = 6 and n1 (G23,4 ) = 7. It is our final aim to find the value amax which is the maximal value of all n1 (Gim,n ).

G23,4

III. E STIMATION OF THE C OMPLEXITY

Grids (Adjacency Matrices) of two Complete Bipartite Graphs

called a grid. We prefer this short term in the rest of this paper. The vertices ri of the subset R ⊂ V are used to label the rows of such a grid, and the vertices ck of the subset C ⊂ V label the columns, respectively. As usual for a matrix, the row numbers ri of the grid grow top down, and the column numbers ck grow from the left to the right. The elements of the grid are Boolean values. A value 1(0) in the position of row ri and column ck means that the edge e(ri , ck ) is colored (not colored) with the selected color. Figure 2 shows the same bipartite graphs G13,4 and G23,4 of Figure 1 expressed by their grids (adjacency matrices). Four positions of the left grid G13,4 of Figure 2 are framed by thick lines. These four positions describe the four edges of a complete subgraph K2,2 that violates the color condition. It can be seen that these four positions are located in the corners of a rectangle. There is a monochromatic rectangle when all four rectangle positions are labeled by values 1. The value in the grid position of the row ri and the column ck must be either 0 or 1. Hence, we use the Boolean variable xri ,ck to carry this value. There are m ∗ n such Boolean variables for the grid Gm,n . The Boolean function fecb1 (1) is equal to 1 in the forbidden case that the colors in the corners of the rectangle selected by the rows ri and rj and by the columns ck and cl are identical: fecb1 (xri ,ck , xri ,cl , xrj ,ck , xrj ,cl ) = xri ,ck ∧ xri ,cl ∧ xrj ,ck ∧ xrj ,cl .

(1)

Function (1) must be equal to 0 for each possible rectangle. The number of all possible rectangles depends on the number of rows m and the number of columns n of a grid Gm,n . Each pair of rows and columns generates one possible rectangle. Hence,     m n m(m − 1) n(n − 1) ∗ (2) nr = ∗ = 2 2 2 2

The color pattern of a grid is specified by the numbers of Boolean variables xri ,ck . There are m ∗ n Boolean variables for the grid Gm,n . Hence, in order to find the maximal number amax of values 1 of all rectangle-free grids Gm,n , ncp = 2m∗n

(4)

different color patterns must be evaluated. For each one of these ncp color patterns all nr rectangles (2) must be considered. The number of all rectangles nar (5) to be evaluated is equal to the product of ncp (4) and nr (2): m(m − 1) n(n − 1) ∗ . (5) 2 2 The evaluation of these nar rectangles of color patterns takes on an Intel Quad Core I7 processor 1.5 hours for m = n = 6, already 2.7 years for n = m = 7, but for the interesting case of m = n = 18 the estimated time is equal to 8.7 * 1084 years [9]. This number of rectangles of color patterns, extremely growing with slightly growing values of the number of rows m and columns n, can be restricted to classes of color patterns. The exchange of any pair of rows or any pair of columns does not change the existing rectangles characterized by (1). Both m! permutations of rows and n! permutations of columns of the grid do not change both the number of assigned colors and the number of monochromatic rectangles. Hence, there is a potential of m! ∗ n! improvements which grows from 518.400 for the grid G6,6 to 4 ∗ 1031 for the grid G18,18 . It is the main contribution of this paper to show how this potential of improvements can be utilized. nar = 2m∗n ∗

IV. BASIC A PPROACHES It may be expected that the problem can be easily solved as a satisfiability (SAT) problem. Using the laws of de Morgan, equation (3) can be converted into the SAT-formula: m−1 ^

m n−1 n ^ ^ ^

fecb1 (xri ,ck , xri ,cl , xrj ,ck , xrj ,cl ) = 1 .

i=1 j=i+1 k=1 l=k+1

rectangles must be checked. The grid Gm,n does not show any fully colored rectangle when the function fecb1 (1) is equal to 0 for all rectangles which can be expressed by m−1 _

m n−1 n _ _ _

fecb1 (xri ,ck , xri ,cl , xrj ,ck , xrj ,cl ) = 0 .

i=1 j=i+1 k=1 l=k+1

(3) It can be verified that the function fecb1 (1) is equal to 0 for all 18 possible rectangles of the grid G23,4 of Figure 2. Hence, this is a rectangle-free grid.

(6) Most of the SAT solvers search for a single solution. One possible solution is the assignment of values 0 to all variables of (6). Of course, in the case that no value 1 is assigned to the grid there cannot be any monochromatic rectangle. Hence, all solutions of (6) must be calculated by a SAT solver like clasp [2]. The created extremely large output file of this SAT solver is a drawback of this approach. Alternatively we solved equation (6) directly using operations of XBOOLE [4] and found the value of amax by

TABLE I VALUES amax OF G RIDS Gm,n FOR m ≤ 7 ROWS AND n ≤ 7 C OLUMNS C ALCULATED BY R ESTRICTED E VALUATION OF O RDERED S UBSPACES n 2 3 4 5 6 7

m 2 3 4 5 6 7 8

3 4 6 7 8 9 10

4 5 7 9 10 12 13

5 6 8 10 12 14 15

6 7 9 12 14 16 18

7 8 10 13 15 18 21

counting the values 1 of the valid grids. We found amax = 12 in 83.6 seconds for the grid G5,5 . Restricted by the available memory size of 2 GB no larger square grid could be solved by this basic approach. We add one more approach for comparison purposes. In [7] the search space for maximal rectangle-free grids was restricted in several ways. Instead of calculating all valid grids of a given size and counting the number of values 1 we used a controlled assignment of values 1 restricted by 1) the first created monochromatic rectangle, 2) the first subspace of a fixed number of values 1 without any valid solution, and 3) the restricted evaluation of such subspaces. This bundle of approaches allows to find amax for square grids up to m = 7 rows and n = 7 columns. In [7] is stated: ”The evaluated set of grid patterns is extended from 25∗5 to 27∗7 in comparison with the basic approach; a set could be successfully evaluated that is 224 = 16, 777, 216 = 1.678∗107 times larger.” Table I summarizes the grids for m ≤ 7 rows and n ≤ 7 columns which are known so far. V. U TILIZATION OF P ERMUTATIONS A. Potential of Improvements and Obstacles Both each pair of the m rows and the n columns of a grid can be swapped without changing the number of monochromatic rectangles. Hence, m! ∗ n! grids belong to a single equivalence class. Such a set of grids is the potential for improvements because it is sufficient to evaluate a single grid of the set. This potential grows for increasing values of m and n and has, for instance, the value 18! ∗ 18! = 6, 402, 373, 705, 728, 0002 = 40, 990, 389, 067, 797, 283, 140, 009, 984, 000, 000 for m = n = 18. This potential for improvements is at the same time an obstacle. How can a single grid be chosen as a representative of the class? How can all the other grids of the same equivalence class be excluded from the calculation of amax? In [8] the algorithm Restriction to the Representative of Permutation Classes (RRPC) is suggested. Due to the required memory for the temporarily generated complete class of grids and the selection of a well defined representative, this

algorithm allows to handle only grids up to m = 6 rows and m = 6 columns. In order to overcome this limit we suggested in the same paper [8] the algorithm Mapping onto Representatives of Permutation Classes (MRPC). It is a soft-computing algorithm to handle extremely large grids. Grids with 20 or even more rows and columns can be evaluated with the algorithm MRPC within a couple of seconds. The algorithm MRPC was used in combination with an iterative greedy algorithm. The drawback of this approach is that only a strong lower bound of amax is found. In order to calculate exact values amax of grids by utilization of permutations we developed several new approaches as explained in the following subsections. B. The Slot Principle The ncp = 2m∗n different color patterns (4) can be generated recursively. It is our aim to restrict this timeconsuming process without loss of the exact solution of amax by utilization of permutations. One approach for this restriction is the application of the slot principle. Before we give a formal definition of the term slot within a grid, we explain both the procedure to create a slot and the benefits of a slot for the remaining recursive generation of color patterns. We assume that we have a grid that is filled with values 1 such that no further value 1 can be assigned without violating the rectangle rule (3). In such a grid we can count the numbers of values 1 for each row. This horizontal checksum must be maximal for one or several rows. Out of the set of rows with the maximal horizontal checksum we select any single row and exchange their position with top row r1 of the grid. This permutation of rows does not change the number of monochromatic rectangles. Now we have a grid of the equivalence class with a unique maximal number of values 1 in the first row r1 . As next we swap the columns of the grid such that all values 1 of the row r1 are located in the leftmost columns. This permutation of columns does not change the horizontal checksums of the grid. We call the horizontal checksum of row r1 slot width sw1 . In this way we have created the slot s1 that is the leftmost subgrid of sw1 columns from c1 to csw1 . The head row of the slot is completely filled with values 1. There are two benefits of the slot s1 for the remaining recursive generation of color patterns: 1) not more than a single value 1 can be assigned in the rows ri with 1 < i ≤ m to the elements xri ,c1 , . . . , xri ,csw1 without violating the rectangle rule (3) of the grid, and 2) no value 1 can be assigned in the first row right of the slot s1 to the grid elements xr1 ,ck , . . . , xr1 ,cn , where k = sw1 + 1. Further slots si+1 can be created within the columns of the grid which are not covered by the slots s1 , . . . , si . Values 1 located in the slots s1 , . . . , si are not used for the selection of the maximal horizontal checksum of si+1 . The head row of slot si+1 is located in row ri+1 . All elements in the slot si+1 above its head row are equal to 0.

c1 c2 c3 c4 c5 r1 r2 r3 r4

1 0 1 0

1 1 0 0

0 1 1 1

0 1 0 0

0 0 1 0

c1 c2 c3 c4 c5 2 3 3 1

(a1) horizontal checksums s1

r1 r2 r3 r4

0 1 1 0

1 1 0 0

1 0 1 1

1 0 0 0

0 0 1 0

3 2 3 1

r1 r2 r3 r4

(a3) Fig. 3.

1 1 0 0

1 0 1 1

0 1 1 0

0 0 1 0

s1 , c1 ⇔ c4

0 1 1 0

0 0 1 0

0 1 2 0

1 0 0 0

1 0 1 0

1 1 0 1

0 1 1 0

0 1 0 0

0 2 1 0

(b2) r2 ⇔ r3 , sw2 = 2

c1 c2 c3 c4 c5 1 0 0 0

1 0 1 1

c1 c2 c3 c4 c5

(a2) r1 ⇔ r2 , sw1 = 3 r1 r2 r3 r4

1 1 0 0

(b1) horizontal checksums s2

c1 c2 c3 c4 c5 r1 r2 r3 r4

1 0 0 0

c1 c2 c3 c4 c5 3 2 3 1

r1 r2 r3 r4 (b3)

1 0 0 0

1 0 1 0 s1

1 1 0 1

0 1 1 0

0 1 0 0

0 2 1 0

s2

Creating Slots Within a Grid G4,5 : a) Slot s1 , b) Slot s2

Definition 1 (slot, slot width, head row): A slot is a set of columns ck of a grid Gm,n which meet the following properties: 1) each of the n columns is assigned exactly to one slot of the grid, 2) the columns of a slot are located within a closed interval, 3) the slots si , i ≥ 1 are enumerated from the left to the right, 4) the number of columns in the slot si is called slot width swi , 5) the slots are ordered based on their slot width such that swi ≥ swj for i < j, 6) all swi elements of the slot si in the row ri are equal to 1; this row is called head row of the slot, and 7) all elements of the slot si in rows rj , j < i are equal to 0. Figure 3 shows how the slots of a grid G4,5 given in part (a1) of Figure 3 will be constructed. The horizontal checksums are determined by counting and represented at the right of the grid in Figure 3 (a1). The maximal horizontal checksum 3 appears twice in rows r2 and r3 . Each of these rows can be chosen as head row. We select row r2 and exchange it with row r1 as shown in Figure 3 (a2). The slot width sw1 = 3 for the slot s1 is equal to the horizontal checksum of the new row r1 . As final step to create the slot s1 the columns must be swapped such that all values 1 in the head row of slot 1 are located at the left of the grid. This is realized by exchanging the columns c1 and c4 . The thick lines in Figure 3 (a3) emphasize the slot s1 with a slot width of sw1 = 3 and its head row.

The same procedure is used to create the slot s2 . As can be seen in Figure 3 (b1), the horizontal checksums are only counted in the remaining columns c4 and c5 . The row with the maximal horizontal checksum 2 must be used as row r2 for slot s2 with a slot width of sw2 = 2. Therefore the complete rows r2 and r3 are exchanged as shown in Figure 3 (b2). In this case the head row of slot s2 is ordered as required as closed interval of values 1. Hence, no further modifications are necessary. Both the slot s1 and the slot s2 have been emphasized by thick lines in Figure 3 (b3). C. The Head of Maximal Grids The head row identifies a slot uniquely by the values 1 which are not element of a slot of a lower number. All head rows together specify the head of a grid. Definition 2 (head of a grid): The head of a grid is built by all elements 1 of the head rows of all slots of a grid. We are searching for maximal colored grids which require maximal heads. Theorem 1: A maximal head of the grid Gm,n contain n values 1 distributed over all n columns of the grid and the rows ri , 1 ≤ i ≤ ns , where ns is the number of slots. Proof: The number of values 1 of the grid Gm,n cannot be maximal when the head of the grid contains less than n values 1. At least one additional value 1 can be assigned to each column of the grid which does not belong to the grid head because a single 1 in a column of a grid cannot violate the monochromatic rectangle rule. Due to Theorem 1, a maximal head of a grid Gm,n contains a single value 1 within each of the n columns. There are  n m nsoc = = mn (7) 1 different grids which contain exactly a single value 1 within each of the n columns. These mn grids can be transformed into an extremely smaller number of maximal heads using the allowed permutations of rows and columns. The number of all grid heads ngh is equal to the sum of all partitions of the n columns into k parts: ngh =

n X

P (n, k) .

(8)

k=1

Algorithm 1 utilizes the slot concept to find the maximal number amax of values 1 of all rectangle-free grids Gm,n . The main task of Algorithm 1 is the generation of all grid heads which can be extended to rectangle-free grids Gm,n with a maximal number amax. The used function ExtendSlotBodies(amax, a) solves the subtask of finding the maximal assignment of values 1 to the slot bodies. All possible maximal grid heads are constructed by Algorithm 1 directly within the grid Gm,n . This grid of m rows and n columns must be initialized with values 0 on all positions. The recursive Algorithm 1 is called on the top level by GenMaxGrid(1, n, 1, 0). The first parameter 1 means that the slot number 1 with the first row as head row must be constructed. The second parameter n means that the first

Algorithm 1 GenMaxGrid(hr, sw, f irst1, amax) Require: hr: the index of the head row; sw: the slot width; f irst1 the first column to which a value 1 must be assigned; amax: the so far known maximal number of assignments 1; m: the number of rows and n: the number of columns of the grid Gm,n in which all elements are initialized with values 0 Ensure: amax: the maximal number of assignments 1 in the rectangle-free grid Gm,n 1: if hr > m then {no more head row} 2: if f irst1 > n then {all columns contain a 1} 3: amax ← ExtendSlotBodies(amax, n) 4: end if 5: return(amax) 6: end if 7: last1 ← f irst1 8: for i ← 1 to sw do 9: Gm,n (hr, last1) ← 1 {create slot head} 10: last1 ← last1 + 1 11: end for 12: if last1 ≤ n then {next slot head} 13: nsw ← Minimum(n − last1 + 1, sw) 14: amax ← GenMaxGrid(hr + 1, nsw, last1, amax) 15: else {extend slot bodies} 16: amax ← ExtendSlotBodies(amax, n) 17: end if 18: for last1 ← f irst1 + sw − 1 downto 1 do 19: Gm,n (hr, last1) ← 0 {reduce slot head by 1 column} 20: if last1 > f irst1 then {next grid head} 21: nsw ← Minimum(n − last1, last1 − f irst1) 22: amax ← GenMaxGrid(hr + 1, nsw, last1, amax) 23: end if 24: end for 25: return(amax)

generated slot has a slot width of sw of all n columns. The third parameter 1 means that the slot begins in the column number 1, and the last parameter 0 is used as initial value of amax. In the cases of less rows than columns not all required slots can be created for certain slot widths. In these cases the recursion is broken within the if-statement in line 1 of Algorithm 1 because such a grid cannot contain a maximal number of values 1. In the special case that the last slot head contains the element of the last column n the slot bodies are checked for a maximal grid within the if-statement in line 2 of Algorithm 1. The creation of a single slot head is done in the for-loop of the lines from 8 to 11. If the number of the last column of the created slot is less than the number of columns n than the next slot will be created by a recursive invocation of Algorithm 1 using the row hr + 1 as head row, the next allowed slot width, and the next unused column of number last1. The next allowed slot width nsw is the minimum (see line 13 of

grid head 1 s1

grid head 2 s1 s2

grid head 3 s1 s2

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

0 1 0 0

grid head 4 s1 s2 s3

grid head 5 s1 s2 s3 s4

1 0 0 0

1 0 0 0

1 0 0 0

0 1 0 0 Fig. 4.

0 0 1 0

0 1 0 0

0 0 1 0

1 0 0 0

0 1 0 0

0 1 0 0

0 0 0 1

Sequence of all maximal grid heads of G4,4

Algorithm 1) of the last used slot width sw and the number of remaining columns n − last1 + 1. If the created slots cover all columns the completed grid head is used in the function ExtendSlotBodies(amax, a) to find maximal grids. In the final loop (the lines from 18 to 24) all further possible maximal grid heads are created. In order to do this the slot width is reduced by 1 in line 19 of Algorithm 1. The recursion must stop when the actual slot width is reduced to 0 as realized in the if-statement in line 20 of Algorithm 1. The decremented value of last1 causes different next slot widths nsw within the loop. The recursive invocation of Algorithm 1 in line 24 assures the generation of all maximal grid heads. Figure 4 shows the sequence of all 5 maximal grid heads of the grid G4,4 . It can be seen how the slot of index i is reduced successively to allow the creation of the slot of index i + 1. The slot width of the slot of index i + 1 is restricted by both the slot width of the slot of index i and by the remaining columns. The creation of the grid heads solves only a subtask of maximal monochromatic rectangle-free grids. However, this utilization of permutations of both rows and columns strongly restricts the number of grids which must be evaluated. Table II shows that all 2.05891 ∗ 1044 possible assignments of a single value 1 to each column of a grid G30,30 can be transferred into only 5, 604 grid heads by permutations of rows and columns. Hence, the grid heads save in this case the evaluation of more than 2∗1041 grids. Algorithm 1 created all grid heads for grids up to m = 30 rows and n = 30 columns in less than 1 second. It should be mentioned that Algorithm 1 is not restricted to square grids but it can be used to generate all grid heads for any number of rows and columns very fast. D. The Body of Maximal Grids Figure 4 shows that the values 1 of each head of a maximal grid separate values 0 in the north-east of the grid from values 0 in the south-west of the grid. The north-east region is empty in the special case of grid head 1. Due to item 7 of Definition

TABLE II G RID H EADS OF ALL S QUARE G RIDS UP TO m = 30 ROWS AND n = 30 C OLUMNS WITH A S INGLE VALUE 1 IN E ACH C OLUMN C ALCULATED WITH

m 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

n 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

A LGORITHM 1

number of all mn grids grid 1 4 27 256 3, 125 46, 656 823, 543 16, 777, 216 387, 420, 489 1.00000 ∗ 1010 2.85312 ∗ 1011 8.91610 ∗ 1012 3.02875 ∗ 1014 1.11120 ∗ 1016 4.37894 ∗ 1017 1.84467 ∗ 1019 8.27240 ∗ 1020 3.93464 ∗ 1022 1.97842 ∗ 1024 1.04858 ∗ 1026 5.84259 ∗ 1027 3.41428 ∗ 1029 2.08805 ∗ 1031 1, 33374 ∗ 1033 8.88178 ∗ 1034 6.15612 ∗ 1036 4.43426 ∗ 1038 3.31455 ∗ 1040 2.56769 ∗ 1042 2.05891 ∗ 1044

heads 1 2 3 5 7 11 15 22 30 42 56 77 101 135 176 231 297 385 490 627 792 1,002 1,255 1,575 1,958 2,436 3,010 3,718 3,718 5,604

time in milliseconds 1 1 1 1 1 2 2 3 3 4 4 5 8 10 16 19 25 31 41 53 73 109 122 162 201 267 334 422 529 687

1 no value 1 can be assigned within the north-est region above the head of a grid. This property strongly reduces further construction efforts. In order to find amax of the grid all heads must be extended as much as possible by values 1. The number of values 0 in the north-east region above the head of a square grid grows from 0 for grid head 1 to n ∗ (n − 1)/2 for the last grid head of the main diagonal strip. Hence, up to 2n∗(n−1)/2 assignments of values 1 can be skipped which is 8.8725 ∗ 10130 for the last grid head of the grid G30,30 . It remains the south-west region below the grid head for additional assignments of values 1 to find maximal grids. We call this region body of a grid. Definition 3 (body of a slot, body of a grid): All elements below the head row of a slot are called body of the slot. The body of a grid is the union of all bodies of the slots of the grid. We are searching for maximal colored grids. The number of possible values 1 within a slot si is limited by swi + m − 1. Theorem 2: A rectangle-free grid cannot contain more than a single value 1 within any row of the body of a slot. Proof: The head row of a slot contains the value 1 in each column. Two values 1 in any body row of a slot violate together with the fitting values 1 in the head of the slot the rectangle rule (3). Theorem 2 allows a further strong restriction of the effort

to construct maximal rectangle-free grids. The slot si , i ≥ 1, with a slot width swi of a grid of m rows contains (m − i) body rows and swi ∗ (m − i) body elements. According to Theorem 2 at most (m − i) values 1 can be assigned in the body of this slot. Hence, the possible number of assignments of values 1 to the body of the slot si can be reduced by a factor of at least 2(swi −1)∗(m−i) which is equal to 1.4663 ∗ 10253 for the first grid head of the grid G30,30 . The extreme reduction can be improved furthermore because the columns within a slot can be exchanged. Hence, the topmost value 1 within the body of a slot can be located in the leftmost column of the slot. In this way swi possible assignments of this topmost value 1 are reduced to a single one. Additional assignments of values 1 below this topmost assignment can be located in the leftmost column of the slot, too. However, two values 1 in one column of one slot can cause, together with two values 1 within a single column of another slot, a violation of the rectangle rule (3). Such a violation can be avoided by moving the value 1 in the lower row into a so far unused column of the slot. There can be several target columns where only values 0 are assigned in the body. Due to the possible permutation of slot columns we use in this case the leftmost possible slot column which restricts the possible assignments additionally. The utilization of these sources for improvements requires an easy access to information about the columns on the righthand sides of the slots and the rightmost assignments within the slots. Algorithm 2 prepares this information and calls it at the end the recursive Algorithm 3. The vector se is initialized by values −1 in the for-loop in lines from 1 to 3. Similarly, the matrix la is initialized by values −1 in the for-loops in lines from 4 to 8. The information about the end of the slots is taken from the generated grid head of Gm,n . Within the while-loop in lines from 11 to 21 both the values of the slot ends se and the number of slots nos are detected. An initial value se(i) is assigned in the alternative in lines from 12 to 16. The required value of se(i) is built by counting the values 1 of the slot i of Gm,n in the while-loop in the lines from 17 to 19. Finally, the function MaxFillUp(2, 1, amax, a) is called. The first parameter 2 selects row 2 as the top most body row of the first slot. The second parameter 1 specifies the slot in which the additional value 1 can be assigned. The third parameter is the maximal number of values 1 known so far for the rectangle-free grid Gm,n . The final parameter a is the number of assigned values 1 in the actually evaluated grid Gm,n . Algorithm 3 assigns as much as possible values 1 in the body of the grid. This Algorithm must find maximal additional assignments of values 1 to a given grid head. This is achieved in a smart restricted manner based on Theorem 2. The number of body rows of all slots nbrs is equal to nbrs =

nos ∗ (nos − 1) + nos ∗ (m − nos) . 2

(9)

Each body row of each slot can contain at most one single value 1. The body rows of the slots can be ordered from the

Algorithm 2 ExtendSlotBodies(amax, a) Require: amax: the so far found maximal number of assignments 1 in the rectangle-free grid Gm,n ; a: the number of assignments 1 in the actual rectangle-free grid Gm,n ; the grid Gm,n of m rows and n columns, initialized by a maximal grid head; Ensure: se: vector that contains the index of the last column of all slots; la: matrix initialized by values -1, for last assignments of values 1 within the slot bodies; amax: the maximal number of assignments 1 in the rectangle-free grid Gm,n ; nos: the number of slots of the grid Gm,n ; 1: for k ← 1 to n do 2: se(k) ← −1 {initial value of slot ends} 3: end for 4: for i ← 1 to m do 5: for k ← 1 to n do 6: la(i, k) ← −1 {initial value of last assignments} 7: end for 8: end for 9: i ← 1 {row index} 10: nos ← 0 {number of slots} 11: while i < m and se(i) < n do 12: if i = 1 then {the first slot} 13: se(i) ← 0 14: else 15: se(i) ← se(i − 1) 16: end if 17: while i ≤ m and se(i) ≤ n and G(i, se(i)) = 1 do 18: se(i) ← se(i) + 1 19: end while 20: nos ← nos + 1 21: end while 22: amax ← MaxFillUp(2, 1, amax, a) 23: return(amax)

highest body row of the first slot row by row down to the bottom slot at the right. As basic step we assign all binary numbers from 0 to 2nbrs − 1 to these body rows of the slots so that each bit is mapped to the leftmost column of the associated body row of a slot. If such an assignment causes a conflict with the rectangle rule (3) than we try to solve this conflict by moving one assigned value 1 within its body row to the right. Algorithm 3 realizes the assignment of the 2nbrs binary numbers to the body rows of the slots recursively. The core of this recursion is separated in Algorithm 4. The invocation of Algorithm 4 in line 4 of Algorithm 3 ensures that the upper body rows of the slots carry only values 0. Within the repeatuntil-loop one single value 1 is assigned to the body row of a slot (line 11) selected by the level of recursion. This assignment is counted by a (line 12), and the used column is stored in the matrix la (line 13). The value 1 assigned to the grid in line 11 can cause a color rule conflict which is checked by the function crc(r, c) (line 14). The rule check is restricted in this function to all rectangles in which the new

Algorithm 3 MaxFillUp(r, s, amax, a) Require: r: the index of the row of the actual recursion; s: the index of the slot of the actual recursion; amax: the so far found maximal number of assignments 1 in the rectangle-free grid Gm,n ; a: the number of assignments 1 in the actual rectangle-free grid Gm,n ; G: the grid of m rows and n columns; se: the vector of slot ends; la the matrix for last assignments of values 1 within the slot bodies; nos: the number of slots of the grid Gm,n ; Ensure: amax: the maximal number of assignments 1 in the rectangle-free grid Gm,n 1: if r > m then {break of the recursion} 2: return(amax) 3: end if 4: amax ← NextSlot(r, s, amax, a) 5: if s = 1 then {select the column for the next assignment} 6: c←1 7: else 8: c ← se(s − 1) + 1 9: end if 10: repeat 11: G(r, s) ← 1 {assign value 1} 12: a←a+1 13: la(r, s) ← c {remember the column} 14: if s > 1 and crc(r, c) then {rectangle conflict?} 15: G(r, s) ← 0 {replace assigned 1 by 0} 16: a←a−1 17: la(r, s) ← −1 {restore initial value} 18: c ← c + 1 {next column} 19: if (c > la(r − 1, s) + 2) or (c > se(s)) then 20: return(amax) {no more possible column} 21: else 22: continue {try assignment in next column} 23: end if 24: end if 25: if a > amax then {larger allowed rectangle-free grid} 26: amax ← a 27: end if 28: amax ← NextSlot(r, s, amax, a) 29: G(r, s) ← 0 {replace assigned 1 by 0} 30: a←a−1 31: la(r, s) ← −1 {restore initial value} 32: c ← c + 1 {next column} 33: until (c > la(r − 1, s) + 2) or (c > se[s]) 34: return(amax)

TABLE III E ARLY B REAK OF R ECURSION IN A LGORITHM 3 DUE TO THE R ECTANGLE -F REE C ONDITION FOR THE G RIDS G8,8 , G9,9 , AND G10,10 number of assigned values 1 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

number of detected conflicts for grid G8,8 G9,9 G10,10 0 0 0 137 0 0 1117 275 0 5298 2634 565 14924 16066 6689 40351 73595 48796 82225 227264 262336 153122 541870 1187941 206705 1267637 4202340 193196 2200083 11511211 117481 3836481 25336356 105632 5063619 53319506 87276 5327652 86332581 35345 3771029 145781391 6266 1854612 191922194 698 1212354 220620600 0 814065 186319424 0 294390 115718047 0 56279 53227679 0 5597 27424287 0 332 15174190 0 0 6060258 0 0 1444707 0 0 175683 0 0 10824 0 0 635 0 0 0

assigned value 1 on position (r, c) is involved. In the case that the rectangle condition (3) is violated by the assigned value 1 this assignment is withdrawn in lines 15 to 17. In such a case the next column to the right within the body row of the slot is selected for an alternative assignment of the value 1 in line 18. If there is no possible column (checked in line 19) the recursion must be broken (line 20); otherwise the next possible assignment of a value 1 within the body row of the slot is induced by the continue statement for the repeatuntil-loop in line 22. The break of the recursion in line 20 can occur on a high level of the recursion and restricts the necessary evaluation of the search space significantly. In the case that the rectangle condition (3) is not violated a new maximal assignment of values 1 can be found. This will be checked in line 25. In the successful case the new maximal values of assigned values 1 is remembered in line 26. Thereafter the recursive assignment of a value 1 in the remaining slots is initiated in line 28. If a conflict with the rectangle rule happens in this part of the recursion, an alternative assignment in the actual body row is prepared in lines 29 to 32 as in the case of a direct conflict in lines 15 to 18. Table III reveals the benefit of the early break of the recursion in cases of violations of the rectangle-free condition using the square grid G8,8 , G9,9 , and G10,10 as example. A violation of the rectangle-free condition (3) cannot occur when values 1 are only assigned to the grid head. Any two additionally assigned values 1 cannot cause a violation of the rectangle-free condition (3), because these two values 1 are

either in different body rows of the same slot or in body rows of different slots. Three additional values 1 can cause together with one value 1 of the slot i + 1 a violation of the rectanglefree condition (3) when two of them are located in the same column of slot i, and the third value 1 is assigned to a body row of slot i + 1. Due to this property the first break of the recursion is done for n+3 assigned values 1. The break of the recursion on this very early level strongly restricts the search space. Table III shows that the number of breaks of the recursion grows for increased numbers of assigned values 1. Both the already restricted search space and the larger number of values 1 which may cause a conflict are the reasons that the number of conflicts decreases when the number of assigned values 1 surpasses a given limit. The maximal numbers of values 1 of rectangle-free grids are amax(G8,8 ) = 24, amax(G9,9 ) = 29, and amax(G10,10 ) = 34 (see Table IV). Table III shows that any additional assignment of a value 1 to grids with these values amax causes a break of the recursion on the deepest level. Algorithm 4 NextSlot(r, s, amax, a) Require: r: the index of the row of the actual recursion; s: the index of the slot of the actual recursion; amax: the so far found maximal number of assignments 1 in the rectangle-free grid Gm,n ; a: the number of assignments 1 in the actual rectangle-free grid Gm,n ; nos: the number of slots of the grid Gm,n ; Ensure: recursive invocation of MaxFillUp(r, s, amax, a) for all body rows of all slot of a grid; amax: the maximal number of assignments 1 in the rectangle-free grid Gm,n 1: if r ≤ nos then {within the head rows} 2: if r − s < 2 then {first slot in the next row} 3: amax ← MaxFillUp(r + 1, 1, amax, a) 4: else {next slot in the same row} 5: amax ← MaxFillUp(r, s + 1, amax, a) 6: end if 7: else {below the head rows} 8: if nos − s < 2 then {first slot in the next row} 9: amax ← MaxFillUp(r + 1, 1, amax, a) 10: else {next slot in the same row} 11: amax ← MaxFillUp(r, s + 1, amax, a) 12: end if 13: end if 14: return(amax) Algorithm 4 organizes the recursive invocation of Algorithm 3 for all body rows of a grid. The number of body rows of the slots grows from 1 to nos−1 in the rows from 2 to the number of slots nos. Therefore the recursion must be distinguished between the rows of the grid head and the remaining other rows of the grid. Algorithm 4 makes this decision in line 1. The recursion for the rows of the grid head is organized in lines 2 to 6 of Algorithm 4. If there is no more slot to the right of the actual slot, Algorithm 3 is called for the first slot

TABLE IV M AXIMAL 1-A SSIGNMENTS amax TO R ECTANGLE -F REE G RIDS U TILIZING P ERMUTATIONS ; THE T IME IS M EASURED IN M ILLISECONDS m 2 3 4 5 6 7 8 9 10

n 2 3 4 5 6 7 8 9 10

v 4 9 16 25 36 49 64 81 100

size of search space 1, 60000000000000 ∗ 101 5, 12000000000000 ∗ 102 6, 55360000000000 ∗ 104 3, 35544320000000 ∗ 107 6, 87194767360000 ∗ 1010 5, 62949953421312 ∗ 1014 1, 84467440737096 ∗ 1019 2, 41785163922926 ∗ 1024 1, 26765060022823 ∗ 1030

amax 3 6 9 12 16 21 24 29 34

time 0 32 32 47 62 468 17,207 503,522 25,012,324

of the next row in line 3; otherwise the next slot to the right in the same row is used in line 5 of Algorithm 3. The recursion for the rows below the head rows of the grid is organized in lines 8 to 12 of Algorithm 4. The number of slots is used in this case for the decision whether the Algorithm 3 is called for the next slot of the same row (line 11) or the first slot of the next row (line 9). VI. E XPERIMENTAL R ESULTS In a first experiment we calculated the maximal number of assignments of values 1 to square grids. Using the basic approach of [7] is was possible to calculate the value amax = 21 for a grid G7,7 within 1,717,118 milliseconds. Table IV shows that the utilization of permutations with Algorithms 1, 2, 3, and 4 reduces this run-time to only 468 milliseconds. Hence, our suggested algorithm reduces the run-time by a factor of 3669. Furthermore, our new approach allows to find the solution amax = 34 for the grid G10,10 . The search space of 27∗7 = 5, 62949953421312 ∗ 1014 for the grid G7,7 could be successfully extended to the search space of 210∗10 = 1, 26765060022823 ∗ 1030 which is an extension by a factor of 2.2581 ∗ 1015 . There can be several different maximal grids of a fixed size with the same value amax. Figure 5 depicts examples for maximal square grid G2,2 to G10,10 . Both the emphasized slot structure and the distribution of the additional values 1 in the bodies of the slots facilitate the comprehension of our suggested approach. As a second experiment we calculated the values amax for grids up to 25 columns. We have chosen this number of columns due to the restricted width of Table V over the full width of the page. All results of Table V are calculated within seconds or few minutes. We restricted this experiment to grids of 10 rows. The given value for a grid Gm,n is valid for the grid Gn,m . The reached improvement can be measured in the maximal size of the search space for which amax could be calculated. The maximal successfully evaluated search space in the basic approach [7] is 27∗7 = 249 = 5.6295 ∗ 1014 . The maximal successfully evaluated search space in the suggested approach of the utilization of permutations is 28∗25 = 2200 = 1.60694 ∗ 1060 . Hence, the utilization of permutations extends the successfully evaluated search space by a factor of 2.8545 ∗ 1045 . Figure 6 shows a maximal colored grid G8,25 .

VII. C ONCLUSION It is a challenge to solve Boolean problems of extreme complexity especially in cases when the direct solution with most powerful computers fails for time or memory reasons. Insights into one of these problems may help in the future to solve other strongly complex problems. We investigated the problem of the maximal rectangle-free coloring of grids of several sizes for a single color which has an extreme complexity. This problem is equivalent to the edge coloring of bipartite graphs without complete subgraphs K2,2 . The number of rectangle which must be evaluated grows more than exponentially for increasing numbers of rows m and columns n. We studied an approach which restricts the search space by controlled assignments of values 1. This approach allows an improvement by a factor of more than ten million. We used this significantly improved result as basis of comparison. Sources of improvements can be the used environment or the properties of the problem itself. The first one can be some approaches of parallel computing [5]. As one of the sources of the second group we utilized in this paper the allowed permutations of both the rows and the columns of the grid. We found the slot as important substructure of the grid. The slot heads are the building blocks of the grid head. The grid head divides the grid into an empty north-west region and the region for further assignments in the south-west of the grid. We developed four algorithms in which the recursion is broken as early as possible without loss of any solution. The successfully evaluated search space could be extended by a factor of more than 1045 in comparison to [7] on a default PC. Further investigations are necessary to find the values amax for larger grids. R EFERENCES [1] Fenner, St., Gasarch, W., Glover, Ch. and Purewal, S. Rectangle Free Coloring of Grids. http://www.cs.umd.edu/∼gasarch/papers/grid.pdf. [2] Gebser, M., Kaufmann, B., Neumann, A. and Schaub, T. clasp: A ConflictDriven Answer Set Solver. in: Baral, C., Brewka, G. and Schlipf J. LPNMR 2007 (LNAI 4483), Springer, 2007, pp. 260 - 265. [3] Marx, D. Graph colouring problems and their applications in scheduling. Periodica Polytechnica, Electrical Engineering, Volume 48, Number 1, 2004, pp. 11 - 16. [4] Posthoff, Ch. and Steinbach, B. Logic Functions and Equations - Binary Models for Computer Science. Springer, Dordrecht, The Netherlands, 2004. [5] Steinbach, B., Posthoff, Ch. and Wessely, W. Approaches to Shift the Complexity Limitations of Boolean Problems. in: Computer - Aided Design of Discrete Devices - CAD DD 2010, Proceedings of the Seventh International Conference, 16 - 17 November 2010, Minsk, Belarus, pp. 84 - 91. [6] Steinbach, B. and Posthoff, Ch. Extremely Complex 4-Colored RectangleFree Grids: Solution of Open Multiple-Valued Problems. Accepted by the 42nd Symposium on Multiple-Valued Logic (ISMVL) 2012. [7] Steinbach, B. and Posthoff, Ch. Search Space Restriction for Maximal Rectangle-Free Grids. Submitted to the 10 International Workshop on Boolean Problems (IWSBP) 2012. [8] Steinbach, B. and Posthoff, Ch. Utilization of Permutation Classes for Solving Extremely Complex 4-Colorable Rectangle-free Grids Submitted to the 2012 International Conference on Systems and Informatics (ICSAI) 2012. [9] Werner, M. Algorithmische Betrachtungen zum Zarankiewicz-Problem. Seminar paper, TU Freiberg, Germany, 2012.

TABLE V VALUES amax OF G RIDS Gm,n C ALCULATED BY U TILIZATION OF P ERMUTATIONS WITH A LGORITHMS 1, 2, 3, AND 4 n

2 3 4 5 6 7 8 9 10

m 2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

3 4 5 6 7 8 9 10 11

4 6 7 8 9 10 11 12 13

5 7 9 10 12 13 14 15 16

6 8 10 12 14 15 17 18 20

7 9 12 14 16 18 19 21 22

8 10 13 15 18 21 22 24 25

9 11 14 17 19 22 24 26 28

10 12 15 18 21 24 26 29 31

11 13 16 20 22 25 28 31 34

12 14 17 21 24 27 30 33

13 15 18 22 25 28 32 36

14 16 19 23 27 30 33

15 17 20 24 28 31 35

16 18 21 25 30 33 36

17 19 22 26 31 34 38

18 20 23 27 32 36 39

19 21 24 28 33 37 41

20 22 25 29 34 39 42

21 23 26 30 35 40 44

22 24 27 31 36 42 45

23 25 28 32 37 43 47

24 26 29 33 38 44 48

25 27 30 34 39 45 50

26 28 31 35 40 46 51

1 1 1 0

1 1 0 1 0 1 0 1 1

G2,2

1 1 0 0

G3,3

amax = 3

1 0 1 0

1 0 0 1

0 1 1 1

1 1 0 0 0

G4,4

amax = 6

1 0 1 0 0

1 0 0 1 0

1 0 0 0 1

0 1 1 1 1

1 1 1 0 0 0

G5,5

amax = 9

1 0 0 1 1 0

1 0 0 0 0 1

0 1 0 1 0 1

0 1 0 0 1 0

0 0 1 0 1 1

1 1 1 0 0 0 0

G6,6 : amax = 16

amax = 12

1 0 0 1 1 0 0

1 0 0 0 0 1 1

0 1 0 1 0 1 0

0 1 0 0 1 0 1

0 0 1 1 0 0 1

0 0 1 0 1 1 0

G7,7 : amax = 21 1 1 1 0 0 0 0 0

1 0 0 1 1 0 0 0

1 0 0 0 0 1 1 0

1 0 0 0 0 0 0 1

0 1 0 0 1 1 0 0

0 1 0 0 0 0 1 1

0 0 1 1 0 1 0 1

0 0 1 0 1 0 1 0

1 1 1 0 0 0 0 0 0

G8,8 : amax = 24

1 0 0 1 1 0 0 0 0

1 0 0 0 0 1 0 1 0

1 0 0 0 0 0 1 0 1

0 1 0 1 0 1 0 0 0

0 1 0 0 1 0 1 0 0

0 1 0 0 0 0 0 1 1

0 0 1 1 0 0 1 1 0

0 0 1 0 1 1 0 0 1

1 1 1 0 0 0 0 0 0 0

G9,9 : amax = 29

1 0 0 1 1 1 0 0 0 0

1 0 0 0 0 0 1 1 0 0

1 0 0 0 0 0 0 0 1 1

0 1 0 1 0 0 1 0 0 1

0 1 0 0 1 0 0 1 0 0

0 1 0 0 0 1 0 0 1 0

0 0 1 0 1 0 1 0 1 0

G10,10 : amax = 34 Fig. 5.

1 1 0 0 0 0 0 0

1 0 1 0 0 0 0 0

1 0 0 1 0 0 0 0

1 0 0 0 1 0 0 0

Fig. 6.

Examples of Maximal Colored Grids G2,2 to G10,10 with Emphasized Slots

1 0 0 0 0 1 0 0

1 0 0 0 0 0 1 0

1 0 0 0 0 0 0 1

1 0 0 0 0 0 0 0

0 1 1 0 0 0 0 0

0 1 0 1 0 0 0 0

0 1 0 0 1 0 0 0

0 1 0 0 0 1 0 0

0 1 0 0 0 0 1 0

0 1 0 0 0 0 0 1

0 0 1 1 0 0 0 0

0 0 1 0 1 0 0 0

0 0 1 0 0 1 0 0

0 0 1 0 0 0 1 0

0 0 1 0 0 0 0 1

0 0 0 1 1 1 0 0

0 0 0 1 0 0 1 0

0 0 0 1 0 0 0 1

0 0 0 0 1 0 1 0

Example of a Maximal Colored Grid G8,25 with Emphasized Slots: amax = 51

0 0 0 0 1 0 0 1

0 0 0 0 0 1 1 1

0 0 1 0 0 1 0 1 0 1

0 0 0 1 0 0 0 1 1 0

Suggest Documents