Write for the prescribed occupied cells, with . The source’s lowercase in its coordinate bound is read as the stated board size . If two prescribed queens already attack each other, no completion exists. Each model below correctly expresses that impossibility as well as consistent inputs.
Model 1: one Boolean variable per cell. Let indicate occupancy. Requireand impose for every two distinct cells sharing a row, a column or a diagonal. Equivalently, impose exactly one queen in each row and column and at most one on each diagonal. Explicit diagonal constraints areTogether with the total-count constraint and the attacking-pair binary constraints, these force exactly the intended boards. The count and diagonal-sum constraints are legitimate many-variable constraints; this model need not be binary.
Model 2: one variable per labeled queen. Let for . Enumerate and restrict for . For every , impose the binary constraintThere are exactly variables and distinct rows, so these are distinct queens. Labeling the prescribed queens does not lose a board completion: the queens are physically indistinguishable, and any completion can be labeled to give the prescribed ones those indices. It does create redundant assignments for the remaining labels.
Model 3: one variable per row. Let be the queen’s column in row . For every , requireand impose for every . These restrictions give queens, one per row; the all-different constraint on the columns gives one per column. For nonattacking queens on rows, exactly one per row is forced by the pigeonhole principle, so no solutions are lost. Inconsistent prescribed positions in a single row give incompatible unary restrictions. All three are exact constraint satisfaction problem encodings of the queens completion problem.
Articles by others on the same topic
There are currently no matching articles.