Sudoku as a Constraint Satisfaction Problem
Sudoku is a compact CSP: every empty cell is a variable, each domain is a subset of digits 1–9, and row, column, and box constraints require distinct values.
Model
- Variables: one for each empty cell, named by row and column.
- Domains: initially {1,…,9}, reduced by clues.
- Constraints: cells in each row, column, and 3×3 box must be different.
| r1c15 | r1c23 | r1c3 | r1c4 | r1c57 | r1c6 | r1c7 | r1c8 | r1c9 |
| r2c16 | r2c2 | r2c3 | r2c41 | r2c59 | r2c65 | r2c7 | r2c8 | r2c9 |
| r3c1 | r3c29 | r3c38 | r3c4 | r3c5 | r3c6 | r3c7 | r3c86 | r3c9 |
| r4c18 | r4c2 | r4c3 | r4c4 | r4c56 | r4c6 | r4c7 | r4c8 | r4c93 |
| r5c14 | r5c2 | r5c3 | r5c48 | r5c5 | r5c63 | r5c7 | r5c8 | r5c91 |
| r6c17 | r6c2 | r6c3 | r6c4 | r6c52 | r6c6 | r6c7 | r6c8 | r6c96 |
| r7c1 | r7c26 | r7c3 | r7c4 | r7c5 | r7c6 | r7c72 | r7c88 | r7c9 |
| r8c1 | r8c2 | r8c3 | r8c44 | r8c51 | r8c69 | r8c7 | r8c8 | r8c95 |
| r9c1 | r9c2 | r9c3 | r9c4 | r9c58 | r9c6 | r9c7 | r9c87 | r9c99 |
The running puzzle
Every page uses this puzzle. Blue cells are the variables currently discussed. For example, fixed digits in row 1, column 3, and the upper-left box reduce r1c3 to {1,2,4}. The clues reduce r5c5 to the singleton {5}.
Binary and global formulations
A binary model adds Xi ≠ Xj for every pair of peers. A global model uses 27 AllDifferent constraints: nine rows, nine columns, and nine boxes.
Check: How many peers does a center cell have? Do not count a cell twice when it shares both a row and a box.