The model used to solve a generic instance of a 9 by 9 Sudoku is the following:
$\begin{align}
    & \max z = \sum_{i \in I}\sum_{j \in J}\sum_{n \in N} x_{ijn}        
\end{align}$
$\text{subject to:}\\$
$\begin{align}
    & \quad \sum_{j=1}^{9} x_{ijn} = 1, \forall i, \forall n   \\
    & \quad \sum_{i=1}^{9} x_{ijn} = 1, \forall j, \forall n   \\
    & \quad \sum_{i=3r - 2}^{3r}\sum_{j=3c - 2}^{3c} x_{ijn} = 1, \forall n, \forall r, \forall c   \\
    & \quad \sum_{n=1}^{9} x_{ijn} = 1, \forall i, \forall j   \\
\end{align}
$
where $i, j$ and $n$ vary in $\{1, \dots ,9\}$, whereas $r$ and $c$ vary in $\{1, \dots ,3\}$.
The binary variables $x_{ijn}$ are equal to $1$ if cell $(i, j)$ takes value $n$, and $0$ otherwise.
Constraints $(2)$ impose that each value $n$ appears only once in a row; constraints $(3)$ impose that each value $n$ appears only once in a column; constraints $(4)$ impose that each value $n$ appears only once in a $3$ by $3$ sub-square; finally, constraints $(5)$ impose that no values assignments overlap.
Notice that the objective function in $(1)$ could also have been set constant. This formulation has been chosen in order not to cause Pyomo to emit warnings.

35513653b257c6d5a28cd6fcc5122c6bdd8cdc60
ipynb
Jupyter Notebook
model_description.ipynb
herr-schmidt/pyomo-sudoku
66f46f28694dabf9e13ace821f5d4dd478e491af
MIT
model_description.ipynb
herr-schmidt/pyomo-sudoku
66f46f28694dabf9e13ace821f5d4dd478e491af
MIT
model_description.ipynb
herr-schmidt/pyomo-sudoku
66f46f28694dabf9e13ace821f5d4dd478e491af
MIT
Qwen/Qwen-72B
1. YES
2. YES