Repository navigation
🧩 Constraint Solving POTD:Problem of the Day: Rook Placement Problem #64998
Closed
Replies: 1 comment
|
This discussion has been marked as outdated by Constraint Solving — Problem of the Day. A newer discussion is available at Discussion #65305. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem Statement
The Rook Placement Problem asks: Can you place
nnon-attacking rooks on ann × nchessboard, with a constraint that each rook must respect certain forbidden positions?In the simplest variant (unrestricted), this is trivial—place one rook per row and column in any order. The interesting variant adds forbidden cells: regions or patterns where rooks cannot be placed. This transforms it into a genuine constraint satisfaction problem.
Concrete Instance (n=4, small forbidden set):
Can you place 4 rooks (one per row, one per column) avoiding all X positions?
Solution (if one exists):
One solution: (1,4), (2,2), (3,1), (4,3) assigns rooks to positions row 1 col 4, row 2 col 2, etc.
Why It Matters
Real-world applications:
Practitioners in embedded systems, robotics, and operations research encounter this repeatedly in layout and assignment problems.
Modeling Approaches
Approach 1: Explicit Permutation Model (CP)
Decision variables:
perm[i] ∈ {1..n}for each rowi, representing the column of the rook in rowi.Constraints:
alldifferent(perm[1], perm[2], ..., perm[n])— each column used exactly once(i, perm[i]) ∉ forbidden_setfor alli— rooks avoid forbidden cellsTrade-offs:
alldifferentis a strong global constraint with excellent propagation (arc consistency).Approach 2: Binary Matrix Model (MIP/SAT)
Decision variables:
x[i,j] ∈ {0,1}for each cell(i,j).Constraints:
∑_j x[i,j] = 1for all rowsi— one rook per row∑_i x[i,j] = 1for all columnsj— one rook per columnx[i,j] = 0for all(i,j) ∈ forbidden_set— no rooks on forbidden cellsTrade-offs:
n2variables instead ofn; less direct exploitation of permutation structure; linear relaxation may be weak.Example Model (MiniZinc Pseudo-code)
Key Techniques
1. Global Constraint Propagation (
alldifferent)The permutation model leverages
alldifferent, which maintains arc consistency via bipartite matching algorithms (e.g., Hungarian algorithm or augmenting paths). When domain wipeout occurs for any variable, propagation detects infeasibility early.2. Symmetry Breaking
Rook placement exhibits symmetry: permutations can be reordered without changing the underlying problem structure. Breaking symmetries via lexicographic ordering (e.g.,
perm[i] < perm[i+1]in certain contexts) or by constraining the first rook's position reduces search space.3. Constraint Propagation with Forbidden Sets
Model forbidden cells as domain restrictions: pre-process to remove forbidden
(i,j)from variable domains. Combined withalldifferentpropagation, this shrinks search space before search begins.Challenge Corner
**For you to think (redacted)
Symmetry-breaking question: The rook placement problem has multiple symmetries (row/column swaps, rotations). How would you phrase symmetry-breaking constraints that don't remove valid solutions?
Extension to partial placement: Suppose some rooks are already placed (fixed positions). How would you modify the model to verify feasibility and count solutions efficiently?
Complexity trade-off: For large
nwith sparse forbidden sets, would the permutation model or the binary matrix model scale better? Why?References
Rossi, F., van Beek, P., & Walsh, T. (Eds.). (2006). Handbook of Constraint Programming. Elsevier. — Chapter on permutation CSPs and global constraints.
Régin, J. C. (1994). "A filtering algorithm for constraints of difference in CSPs." AAAI, pp. 362–367. — Seminal work on
alldifferentpropagation.Combinatorics and Permutations: Wikipedia article on Rook Polynomials and Problème des rencontres for mathematical background on forbidden permutations.
Hooker, J. N. (2021). Integrated Methods for Optimization (2nd ed.). Springer. — Chapters on permutation problems and hybrid CP/MIP.
Next problem: Stay tuned for tomorrow's challenge in the Scheduling category. What's your favorite constraint-solving technique? Share your thoughts below!
All reactions