|
8 | 8 | "source": [ |
9 | 9 | "# Sudoku Solver\n", |
10 | 10 | "\n", |
11 | | - "**Prepared by:** William Bartel ([email protected], 2024) and Andrew Brooks ([email protected], 2024)\n", |
12 | | - "\n", |
13 | | - "Adapted from material by Prof. Alexander Dowling and Elvis Eugene at the University of Notre Dame\n", |
14 | | - "\n", |
15 | | - "Nonlinear and Stochastic Optimization - Project 2" |
| 11 | + "**Prepared by:** William Bartel ([email protected], 2024) and Andrew Brooks ([email protected], 2024). Adapted from material by Prof. Alexander Dowling and Elvis Eugene at the University of Notre Dame" |
16 | 12 | ] |
17 | 13 | }, |
18 | 14 | { |
|
137 | 133 | "id": "RIoCdk4T8BP1" |
138 | 134 | }, |
139 | 135 | "source": [ |
140 | | - "**Sets:** \\\\\n", |
141 | | - "Rows $R=\\{0,1, ...,n\\}$ \\\\\n", |
142 | | - "Columns $C=\\{0,1, ...,n\\}$ \\\\\n", |
143 | | - "Values $V=\\{0,1, ...,n\\}$ \\\\\n", |
144 | | - "Subgrids $K=\\{0,1, ...,n\\}$\n", |
| 136 | + "**Sets:**\n", |
| 137 | + "* Rows $R=\\{0,1, ...,n\\}$ \\\\\n", |
| 138 | + "* Columns $C=\\{0,1, ...,n\\}$ \\\\\n", |
| 139 | + "* Values $V=\\{0,1, ...,n\\}$ \\\\\n", |
| 140 | + "* Subgrids $K=\\{0,1, ...,n\\}$\n", |
145 | 141 | "\n", |
146 | | - "**Parameters:** \\\\\n", |
147 | | - "$s_{v,i,j} = $ is value $v$ present in box located at $(i,j)$ from unsolved puzzle for $i\\in R, j\\in C, v \\in V$. (Binary) \\\\\n", |
148 | | - "$SG_{i} = $ coordinate pairs for the boxes in each subgrid for $i\\in K$ \\\\\n", |
| 142 | + "**Parameters:**\n", |
| 143 | + "* $s_{v,i,j} = $ is value $v$ present in box located at $(i,j)$ from unsolved puzzle for $i\\in R, j\\in C, v \\in V$. (Binary) \\\\\n", |
| 144 | + "* $SG_{i} = $ coordinate pairs for the boxes in each subgrid for $i\\in K$ \\\\\n", |
149 | 145 | "\n", |
150 | | - "**Variables:** \\\\\n", |
151 | | - "$y_{v,i,j} = $ is value $v$ present in box located at $(i,j)$ when creating solved puzzle for $i\\in R, j\\in C, v \\in V$. (Binary)\n", |
| 146 | + "**Variables:**\n", |
| 147 | + "* $y_{v,i,j} = $ is value $v$ present in box located at $(i,j)$ when creating solved puzzle for $i\\in R, j\\in C, v \\in V$. (Binary)\n", |
152 | 148 | "\n", |
153 | 149 | "\n", |
154 | | - "**Objective:** \\\\\n", |
155 | | - "$\\min0$\n", |
| 150 | + "**Objective:**\n", |
| 151 | + "* $\\min0$\n", |
156 | 152 | "\n", |
157 | 153 | "**Constraints:**\n", |
158 | 154 | "\n", |
159 | 155 | "$$\\sum_{i\\in R}y_{v,i,j}=1, \\forall j\\in C, v\\in V$$\n", |
| 156 | + "\n", |
160 | 157 | "$$\\sum_{j\\in C}y_{i,j,k}=1, \\forall i\\in R, v\\in V$$\n", |
| 158 | + "\n", |
161 | 159 | "$$\\sum_{(i,j)\\in SG[\\ l \\ ]}y_{v,i,j}=1, \\forall l\\in K$$\n", |
| 160 | + "\n", |
162 | 161 | "$$\\sum_{v\\in V}y_{v,i,j}=1, \\forall i\\in R, j\\in C$$\n", |
| 162 | + "\n", |
163 | 163 | "$$y_{v,i,j} * s_{v,i,j} = s_{v,i,j}, \\forall i\\in R, j\\in C, v\\in V$$\n", |
164 | 164 | "\n", |
165 | 165 | "Because the problem is a feasibility problem and there is only one possible answer, no objective is needed and thus the objective is a constant, in this case 0.\n", |
|
1008 | 1008 | "id": "1dijjD3G-gqv" |
1009 | 1009 | }, |
1010 | 1010 | "source": [ |
1011 | | - "The results show glpk and cbc are relatively the same for solving puzzles with $n=4,9,16,25,36$. After testing the solvers on multiple datasets, glpk seems slightly faster than cbc, especially on smaller puzzles. For $n=4,9,16$, the sudoku problems are relatively simple and solve time is in fractions of a second. When reasoning about these results, it is important to note that glpk is specifically designed for smaller, simpler problems while cbc is for larger and more complex problems." |
| 1011 | + "The results show glpk and cbc are relatively the same for solving puzzles with $n=4,9,16,25,36$. After testing the solvers on multiple datasets, glpk seems slightly faster than cbc, especially on smaller puzzles. For $n=4,9,16$, the sudoku problems are relatively simple and solve time is in fractions of a second. When reasoning about these results, it is important to note that glpk is specifically designed for smaller, simpler problems while cbc is for larger and more complex problems.\n", |
| 1012 | + "\n", |
| 1013 | + "Future work: remake the above figure as a log-log plot. Is the slope 3? The problem size (number of integer decisions) is proporational to $n^3$." |
1012 | 1014 | ] |
1013 | 1015 | }, |
1014 | 1016 | { |
|
1036 | 1038 | "\n", |
1037 | 1039 | "In this project, we were able to create an effective sudoku puzzle generator and solver that prints solutions. Furthermore, we tested to show there is a superlinear relationship between problem size and solver time, meaning time grows at a rate faster than the problem size." |
1038 | 1040 | ] |
| 1041 | + }, |
| 1042 | + { |
| 1043 | + "cell_type": "markdown", |
| 1044 | + "metadata": {}, |
| 1045 | + "source": [] |
1039 | 1046 | } |
1040 | 1047 | ], |
1041 | 1048 | "metadata": { |
|
0 commit comments