RSOME: Robust Stochastic Optimization Made Easy
Integer Programming for Sudoku
In this section we will use a Sudoku game to illustrate how to use integer and multi-dimensional arrays in RSOME. Sudoku is a popular number puzzle. The goal is to place the digits in [1,9] on a nine-by-nine grid, with some of the digits already filled in. The solution must satisfy the following four rules:
- Each cell contains an integer in [1,9].
- Each row must contain each of the integers in [1,9].
- Each column must contain each of the integers in [1,9].
- Each of the nine 3x3 squares with bold outlines must contain each of the integers in [1,9].
The Sudoku game can be considered as a feasibility optimization problem with the objective to be zero and constraints used to fulfill above rules. Consider a binary variable x i j k ∈ { 0 , 1 } x_{ijk}\in \{0, 1\} xijk∈{ 0,1}, with i ∈ [ 0 , 8 ] i \in [0, 8] i∈[0,8], j ∈ [ 0 , 8 ] j \in [0, 8] j∈[0,8], and k ∈ [ 0 , 8 ] k \in [0, 8] k∈[0,8]. It equals to one if an integer k + 1 k+1 k+1 is placed in a cell at the i i ith row and j j jth column. Let a i j a_{ij} aij be the known number at the i i ith row and j j jth column, with ( i , j ) ∈ I × J (i, j)\in\mathcal{I}\times\mathcal{J} (i,j)∈I×J as I \mathcal{I} I and J \mathcal{J}