Title: Modeling Sudoku with Integer Programs
1Modeling Sudoku with Integer Programs
- Karthik Natarajan
- Department of Mathematics (NUS)
2Sudoku
Fill in the cells in the 99 grid such that each
row, each column and each 33 sub-grid contains
numbers 1 to 9
Source http//sudoku.sourceforge.net/
3One Approach Graph Coloring Problem
2
7
4
A node is a cell. An edge connects two cells that
cannot have the same number (color). Find a
9-coloring of a graph given a partial coloring.
4Another Approach Integer Feasibility Problem
- nn Sudoku with n m2 where m is positive
integer. - (i,j) corresponds to row i and column j.
- Two possible variable definitions
j
i
Cell (4,7)
5Visualization of the Feasible Region
x12
x112
x11
x111
x13
x113
(Integer variables)
(Binary variables )
The Sudoku solution can be characterized using a
set of linear constraints and integer/binary
variables.
6Sudoku Binary Integer Feasibility Problem
7Sudoku Binary Integer Feasibility Problem
- For a nn Sudoku
- Total number of variables O(n3)
- Total number of linear constraints O(n2)
- Size of search space O( )
- Integer programming solvers can quickly search
over this large space in a smart manner.
8Solving Integer Programs (IP) Branch and Bound
Solve linear program (LP) by relaxing x ? 0,1
to x ? 0,1. Branch on the non-integral variable
xijk 0
xijk 1
Branch at each node by solving LP relaxations.
Using bounding methods to prune, we converge to
integer solution.
Infeasible
Pruned
Feasible
LP Solved using simplex, interior point methods.
IP Solved using LP relaxations.
9Using a Integer Programming Solver
- Sudoku can be solved using general purpose IP
solvers - - Xpress-MP
- - ILOG OPL, CPLEX
- - Excel
- Objective function can be arbitrary since this is
a feasibility problem. - The solver produces a feasible solution if it
exists else it indicates infeasibility
10Using the Xpress-MP solver
- Free student edition of Xpress-MP can be
downloaded from http//www.dashoptimization.com/h
ome/products/evaluation/student_request.html - This can be used to solve small size
problems. - User manual is available at
- http//www.dashoptimization.com/home/services/pub
lications/applications_book.html - Large problems can be solved with the Xpress-MP
solver online at the NEOS server - http//neos.mcs.anl.gov/neos/solvers/index.html
11Xpress-MP code sudokusolve.mos
12Variants A 1616 Sudoku
Source http//sudoku.sourceforge.net/ (Tough)
13Variants Sudoku X
The two main diagonals must also contains each of
the numbers from 1 to 9.
Source http//www.maa.org/editorial/mathgames/mat
hgames_09_05_05.html
14Variants A Samurai Sudoku
Source http//www.samurai-sudoku.com/ 1
December 2006 (Fiendish)