Solving Sudoku Using Integer Programming

Website design By BotEap.comA 9 X 9 SUDOKU puzzle has the following rules. Each row and column must have the numbers between 1 and 9 and each of the inner boxes must have the numbers between 1 and 9.

Website design By BotEap.comLet us simply define Xijk so that all values ​​of I, j and k from 1 to 9 are 1. If cell (I, j) contains the number k where I, j and k range from 1 to 9. Here I denotes the ith row and j denotes the jth column and k denotes an integer between 1 and 9. When X134 = 1, it means that cell (1,3) contains the number 4. This would also imply that none of the other elements in the 1st row or 3rd column except cell (1,3) can be equal to 4.

Website design By BotEap.comTo model the SUDOKU we will use a total of 729 variables.

Website design By BotEap.comLet us now formulate algebraically each of the three classes of rules.

Website design By BotEap.comEach row must contain a number between 1 and 9 exactly once.

Website design By BotEap.comFor the first row, this rule would appear as (referred to as “Restriction” in the integer programming language).

Website design By BotEap.comfor each I from 1 to 9 and for each k from 1 to 9 (I is a mathematical representation of a counter variable)

Website design By BotEap.comsum (Xijk) for all j from 1 to 9 = 1;

Website design By BotEap.comWritten in detail for the first row of each number between 1 and 9

Website design By BotEap.comX111 + X121 + X131 + X141 + X151 + X161 + X171 + X181 + X191 = 1.

Website design By BotEap.comX112 + X122 + X132 + X142 + X152 + X162 + X172 + X182 + X192 = 1.

Website design By BotEap.comX113 + X123 + X133 + X143 + X153 + X163 + X173 + X183 + X193 = 1.

Website design By BotEap.comX114 + X124 + X134 + X144 + X154 + X164 + X174 + X184 + X194 = 1.

Website design By BotEap.comThese equations follow for variables beginning with X115 through X119.

Website design By BotEap.comSimilarly, let’s formulate equations for the rules for each number between 1 and 9 occurring only once in each of the 9 columns.

Website design By BotEap.comWritten in mathematical notation,

Website design By BotEap.comsum X for each j from 1 to 9 (for all I and k between 1 and 9) = 1

Website design By BotEap.comWritten in detail for some columns for each number between 1 and 9

Website design By BotEap.comcolumn 1

Website design By BotEap.comX111 + X211 + X311 + X411 + X511 + X611 + X711 + X811 + X911 = 1.

Website design By BotEap.comX112 + X212 + X312 + X412 + X512 + X612 + X712 + X812 + X912 = 1.

Website design By BotEap.comX113 + X213 + X313 + X413 + X513 + X613 + X713 + X813 + X913 = 1.

Website design By BotEap.comMust be filled in for all other numbers from 4 to 9.

Website design By BotEap.comcolumn 2

Website design By BotEap.comX121 + X221 + X321 + X421 + X521 + X621 + X721 + X821 + X921 = 1.

Website design By BotEap.comX122 + X222 + X322 + X422 + X522 + X622 + X722 + X822 + X922 = 1.

Website design By BotEap.comX123 + X223 + X323 + X423 + X523 + X623 + X723 + X823 + X923 = 1.

Website design By BotEap.comThis must be completed for all other numbers from 4 to 9.

Website design By BotEap.comLet us now represent the small boxes (3 x 3) in total 9 squares in number.

Website design By BotEap.comSo, in every 3 x 3 square, there must be only one 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 etc,

Website design By BotEap.comThe cells are located between Columns (1 to 3) and Rows (1 to 3), Columns (4 to 6) and Rows (1 to 3) Columns (7 to 9) rows (1 to 3). Also for the same set of columns they occur in rows (4 to 6) and (6 to 9). So let’s formulate the equations for a single small square located between the columns (1 to 3) and the rows (1 to 3). The corresponding decision variables for the digit “1” are (9 total)

Website design By BotEap.comX111, X121, X131, X211, X221, X231, X311, X321, X331.

Website design By BotEap.comLet’s formulate the equation that this square (3 x3) has only one “1”.

Website design By BotEap.comthen the equation is

Website design By BotEap.comX111 + X121 + X131 + X211 + X221 + X231 + X311 + X321 + X331 = 1.

Website design By BotEap.comThe above equation would imply that only one of these 9 variables or only one of these nine cells can take the value 1.

Website design By BotEap.comSimilarly, you have restrictions to formulate for the digit “2”, the digit “3” and so on up to 9.

Website design By BotEap.comFor integer programming problems, in addition to the equations describing the constraints, integer constraints must also be placed on each and every variable so that eventually, when the system of equations is solved, a 0 or a 1 as a solution for the variable Xijk. .

Website design By BotEap.comThe geometric equivalent of a linear programming problem with an objective function and some constraints is nothing more than a dimensional polyhedron where n represents the number of constraints in the problem. Usually the optimal solution will be found at the vertices of the polytope, also the rules of some methods like SIMPLEX will require the polytope to be convex so that one can traverse from vertex to vertex along the edges and find the optimal solution.

Website design By BotEap.comFurther imposing integer constraints would mean that the optimal solution will not be at the vertices of the polytope since a solution found at the vertex may not be an integer. So after taking into account that the optimal solution has to be either 0 or 1, it will mean that geometrically the solution will lie somewhere within the feasible region of the convex polytope and on one of the many straight lines originating from the hyperplane equivalent to Xi jk which has integer values.

Website design By BotEap.comNote that the above solution has used 729 decision variables and 81 row constraints. 81 column constraints and 729 small square constraints for a total of 901 constraints. There can be many objective functions, but an objective function can be formulated as finding the minimum of (sum of all 729 variables). You can reduce the number of constraints by finding some redundancy.

Website design By BotEap.comThese above equations cannot be solved using programming languages ​​such as Visual Basic, Pascal, or C. Integer programming problems can be solved using optimization software such as the CPLEX optimizer, the Excel add-in for solving linear programming problems, Lingo, etc.

Leave a Reply

Your email address will not be published. Required fields are marked *