Solving Sudoku
Prerequisites
- Please look at Getting Started first for the most basic functions and the setup of OPTANO.Modeling
The mathematical Model
Sets:
\begin{array}{l}
G = \text{Set of already placed numbers}\newline
\end{array}
Variables:
$$y_{ijk} =
\begin{cases}
1, \text{ if element }(i,j)\text{ of the }n\times n \text{ sudoku matrix contains the integer }k\newline
0, \text{ else}
\end{cases}$$
Objective:
$$min 0^T y \qquad \text{(the objective function is irrelevant since we only want the constraints to hold)}$$
Restrictions:
\begin{array}{l}
\sum\limits_{i=1}^{n} y_{ijk} = 1 & j=1:n, k=1:n & \text{(only one }k\text{ in each column)}\newline
\sum\limits_{j=1}^{n} y_{ijk} = 1 & j=1:n, k=1:n & \text{(only one }k\text{ in each row)}\newline
\sum\limits_{j=mq-m+1}^{mq} \sum\limits_{i=mp-m+1}^{mp} y_{ijk} = 1 & k=1:n, p=1:m, q=1:m & \text{(only one }k\text{ in each sub-matrix)}\newline
\sum\limits_{k=1}^{n} y_{ijk} = 1 & i=1:n, j=1:n & \text{(every position in matrix must be filled once)}\newline
y_{ijk}=1 & \forall (i,j,k)\in G & \text{(given elements G in matrix are set “on”)}
\end{array}
Solving Sudoku
- Step 1: Create Business objects for your Model
- Step 2: Create your Model Class
- Step 3: Retrieve the Solution of your Model