|
Article on other languages:
|
In mathematics, given a set X and a collection In computer science, the exact cover problem is a decision problem to find an exact cover or else determine none exists. The exact cover problem is NP-complete[1] and is one of Karp's 21 NP-complete problems.[2] The exact cover problem is a kind of constraint satisfaction problem. An exact cover problem can be represented by an incidence matrix or a bipartite graph. The exact cover problem is equivalent to the exact hitting set problem. Finding Pentomino tilings and solving Sudoku are noteworthy examples of exact cover problems. The N queens problem is a slightly generalized exact cover problem.
Problem definitionGiven a set X and a collection
Thus an exact cover is "exact" in the sense that every element in X is contained in exactly one set in For an exact cover of X to exist, it is necessary that every element in X be contained in at least one set in
If the empty set ∅ is contained in
ExamplesLet X = {1, 2, 3, 4, 5} be a set of 5 elements and let
Then there is no exact cover—indeed, not even a cover—of X because On the other hand, there is a cover if we let X = The subcollection {N, O, E} is also an exact cover: The inclusion of the null set N = { } makes no difference, as it is disjoint with all sets and does not change the union. The subcollection {E, P} is not an exact cover. The sets E and P are not disjoint: Their intersection {2} is not empty. Moreover, the union of the sets E and P, {2, 3, 4}, is not X = {1, 2, 3, 4}: Neither E nor P contains the element 1. Detailed exampleLet X = {1, 2, 3, 4, 5, 6, 7} be a set of 7 elements and let
Then the subcollection
Moreover, {B, D, F} is the only exact cover, as the following argument demonstrates: An exact cover must cover 1 and A and B are the only sets containing 1, thus an exact cover must contain A or B, but not both. If an exact cover contains A, then it doesn't contain B, C, E, or F, as each of these sets have at least one element in common with A. Then D is the only set left to be part of an exact cover, but the collection {A, D} doesn't cover the element 2. In conclusion, there is no exact cover containing A. On the other hand, if an exact cover contains B, then it doesn't include A or C, as each of these sets have at least one element in common with B. Then D is the only remaining set that contains 5, so D must be part of the exact cover. If an exact cover contains D, then it doesn't contain E, as D and E have the elements 3 and 6 in common. Then F is the only set left to be part of the exact cover, and the collection {B, D, F} is indeed an exact cover. See the example in the article on Knuth's Algorithm X for a matrix-based version of this argument. Equivalent problemsAlthough the canonical exact cover problem involves a collection Given a set S, a set X, and a binary relation R In general, R -1 restricted to X × S* is a function, i.e., every element in X is R -1-related to exactly one element of S*: the unique element of S* that "covers" the particular element of X. In the canonical exact cover problem, X is a set of elements, S is a collection of subsets of X, R is the binary relation "contains" between sets and elements, and R -1 restricted to X × S* is the function "is contained in" from elements to sets. In general, an "abstract exact cover problem" arises whenever the goal is to select some objects in a set S such that each element in another set X is related to exactly one of the selected objects. For many interesting problems, such as pentomino tiling, Sudoku or the N queens problem, the elements of S represent choices and the elements of X represent constraints on those choices. Matrix representationAn exact cover problem can be represented by the incidence matrix of the binary relation R, as is done with Knuth's Algorithm X and its implementation Dancing Links. If S is a set of m elements and X is a set of n elements, then the relation R can be represented by an m×n matrix containing only 0s and 1s. The i-th row represents the i-th element si of S and the j-th column represents the j-th element xj of X. The entry of the matrix in the i-th row and j-th column is 1 if si is R-related to xj; the entry is 0 otherwise. In the canonical exact cover problem, the entry of the matrix in the i-th row and j-th column is 1 if i-th set Si contains the j-th element xj; the entry is 0 otherwise. Given such a matrix, an "exact cover" is a selection of rows such that every column has a 1 in exactly one of the selected rows. In other words, an exact cover is a selection of rows that sum to a row containing all 1s. The two conditions for a canonical exact cover are equivalent to:
Matrix exampleIf in the detailed example above we represent the 6 sets in
As above, the selection
The selected rows are "pairwise disjoint" in the sense that any two do not have a 1 in the same column. Also, their "union" is X in the sense that for every column there is a selected row with a 1 in that column. In brief, every constraint column is satisfied in the sense that exactly one selected row has a 1 in that column. See the example in the article on Knuth's Algorithm X for a detailed matrix-based solution to this problem. Graph representationAn exact cover problem can be represented by the bipartite graph for the binary relation R. The vertices of the bipartite graph are divided into two disjoint sets, one representing the elements of S and another representing the elements of X. An edge links the vertices for si and xj if they are R-related. Given such a bipartite graph, an "exact cover" is a selection S* of vertices in the set S such that every vertex in the set X is linked to exactly one vertex in S*. Graph exampleThe exact cover problem in the detailed example and the matrix example above can be represented by a bipartite graph with 6+7 = 13 vertices and 17 edges: As above, the selection S* = {B, D, F} of vertices is a solution to this exact cover problem: Every vertex in the set X is linked to exactly one vertex in S*. Exact hitting setThe exact hitting set problem is to find a subset of a set of elements that are contained in, or "hit", each subset in a collection of subsets exactly once. An exact hitting set problem is equivalent to an exact cover problem. In the terminology above of an abstract exact cover problem, S is a set of elements, X is a collection of subsets of the set S, and R is the binary relation "is contained in" between elements and sets. Exact hitting set exampleLet S = {1, 2, 3, 4, 5, 6} be a set of 6 elements and
This exact hitting set problem can be represented by a 6×7 matrix:
The solution is to select the 2nd, 4th and 6th rows of the matrix:
Thus S* = {2, 4, 6} is an exact hitting set because every set in
It should be clear that this exact hitting set example is essentially the same as the matrix example and the detailed example above. The interpretation may be different but the logic is the same. Finding solutionsKnuth's Algorithm X is a recursive, nondeterministic, depth-first, backtracking algorithm that finds all solutions to the exact cover problem. Dancing Links, commonly known as DLX, is the technique suggested by Knuth to efficiently implement his Algorithm X on a computer. Dancing Links uses the matrix representation of the problem. Dancing Links implements the matrix as a series of doubly-linked lists of the 1s of the matrix: each 1 element has a link to the next 1 above, below, to the left, and to the right of itself. GeneralizationsIn a standard exact cover problem, each constraint must be satisfied exactly once. It is a simple generalization to relax this requirement slightly and allow for the possibility that some "primary" constraints must be satisfied exactly once but other "secondary" constraints can be satisfied optional once or not at all. As Donald Knuth explains, a generalized exact cover problem can be converted to an equivalent exact cover problem by simply appending one row for each secondary column, containing a single 1 in that column.[4] If in a particular candidate solution a particular secondary column is satisfied, then the added row isn't needed. But if the secondary column isn't satisfied, as is allowed in the generalized problem but not the standard problem, then the added row can be selected to ensure the column is satisfied. But Knuth goes on to explain that it is better working with the generalized problem directly, because the generalized algorithm is simpler and faster: A simple change to his Algorithm X allows secondary columns to be handled directly. The N queens problem is an example of a generalized exact cover problem, as the constraints corresponding to the diagonals of the chessboard need not be satisfied. Noteworthy examplesDue to its NP-completeness, any problem in NP can be reduced to exact cover problems, which then can be solved with techniques such as Dancing Links. However, for some well known problems, the reduction is particularly direct. For instance, the problem of tiling a board with pentominoes, and solving Sudoku can both be viewed as exact cover problems. Pentomino tilingThe problem of tiling a 60-square board with pentominoes is an example of an exact cover problem, as Donald Knuth explains in his paper "Dancing links."[5][6] For example, consider the problem of tiling with pentominoes an 8×8 chessboard with the 4 central squares removed:
The matrix representing the exact cover problem has 72 columns, one for each of the 12 pentominoes and one for each of the 60 squares of the board. The matrix representing the exact cover problem has many rows, one row representing each way to place a pentomino on the board. Each row contains a single 1 in the column identifying the pentomino and five 1s in the columns identifying the squares covered by the pentomino. In the case of an 8×8 chessboard with the 4 central squares removed, there are 1568 such rows. Name the twelve pentominoes F I L P N T U V W X Y Z.[7] Name the squares in the board ij, where i is the rank and j is the file. For the 8×8 chessboard with the 4 central squares removed, following are some of the 1568 rows:
One of many solutions of this exact cover problem is the following set of 12 rows:
This set of rows of the exact cover matrix corresponds to the following solution to the pentomino tiling problem:
See also Solving Pentomino Puzzles with Backtracking. SudokuThe problem in Sudoku is to assign numbers (or digits, values, symbols) to cells (or squares) in a grid so as to satisfy certain constraints. In the standard 9×9 Sudoku variant, there are four kinds of constraints:
While the first constraint might seem trivial, it is nevertheless needed to ensure there is only one number per cell. Solving Sudoku is an exact cover problem. More precisely, solving Sudoku is an exact hitting set problem, which is equivalent to an exact cover problem (as in Example 5 above), when viewed as a problem to select possibilities such that every constraint set contains (i.e., is hit by) exactly one selected possibility. In the notation above for the (generalized) exact cover problem, X is the set of possibilities, Y is a set of constraint sets, and R is the binary relation "is contained in." Each possible assignment of a particular number to a particular cell is a possibility (or candidate). When Sudoku is played with pencil and paper, possibilities are often called pencil marks. In the standard 9×9 Sudoku variant, in which each of 9×9 cells is assigned one of 9 numbers, there are 9×9×9=729 possibilities. Using obvious notation for rows, columns and numbers, the possibilities can be labeled
The fact that each kind of constraint involves exactly one of something is what makes Sudoku an exact hitting set problem. The constraints can be represented by constraint sets. The problem is to select possibilities such that every constraint set contains (i.e., is hit by) exactly one selected possibility. In the standard 9×9 Sudoku variant, there are four kinds of constraints sets corresponding to the four kinds of constraints:
Since there are 9 rows, 9 columns, 9 boxes and 9 numbers, there are 9×9=81 row-column constraint sets, 9×9=81 row-number constraint sets, 9×9=81 column-number constraint sets, and 9×9=81 box-number constraint sets: 81+81+81+81=324 constraint sets in all. In brief, the standard 9×9 Sudoku variant is an exact hitting set problem with 729 possibilities and 324 constraint sets. Thus the problem can be represented by a 729×324 matrix. Although it is difficult to present the entire 729×324 matrix, the general nature of the matrix can be seen from several snapshots:
The complete 729×324 matrix is available from Bob Hanson. Note that the set of possibilities RxCy#z can be arranged as a 9×9×9 cube in a 3-dimensional space with coordinates x, y, and z. Then each row Rx, column Cy, or number #z is a 9×9×1 "slice" of possibilities; each box Bw is a 9x3×3 "tube" of possibilities; each row-column constraint set RxCy, row-number constraint set Rx#z, or column-number constraint set Cy#z is a 9x1×1 "strip" of possibilities; each box-number constraint set Bw#z is a 3x3×1 "square" of possibilities; and each possibility RxCy#z is a 1x1×1 "cubie" consisting of a single possibility. Moreover, each constraint set or possibility is the intersection of the component sets. For example, R1C2#3 = R1 ∩ C2 ∩ #3, where ∩ denotes set intersection. Although other Sudoku variations have different numbers of rows, columns, numbers and/or different kinds of constraints, they all involve possibilities and constraint sets, and thus can be seen as exact hitting set problems. N queens problem
The N queens problem is an example of an exact cover problem. See also
References
|
This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License.
Mercedes Car
This site monitored by SitePinger.net