Journal of the Operational Research Society

, Volume 65, Issue 10, pp 1602–1610

A comparison of several enumerative algorithms for Sudoku

• Leandro C Coelho
• Gilbert Laporte
General Paper

Abstract

Sudoku is a puzzle played of an n × n grid Open image in new window where n is the square of a positive integer m. The most common size is n=9. The grid is partitioned into n subgrids of size m × m. The player must place exactly one number from the set N={1, …, n} in each row and each column of Open image in new window as well as in each subgrid. A grid is provided with some numbers already in place, called givens. In this paper, some relationships between Sudoku and several operations research problems are presented. We model the problem by means of two mathematical programming formulations. The first one consists of an integer linear programming model, while the second one is a tighter non-linear integer programming formulation. We then describe several enumerative algorithms to solve the puzzle and compare their relative efficiencies. Two basic backtracking algorithms are first described for the general Sudoku. We then solve both formulations by means of constraint programming. Computational experiments are performed to compare the efficiency and effectiveness of the proposed algorithms. Our implementation of a backtracking algorithm can solve most benchmark instances of size 9 within 0.02 s, while no such instance was solved within that time by any other method. Our implementation is also much faster than an existing alternative algorithm.

Keywords

Sudoku puzzle backtracking linear and non-linear integer programming constraint programming

References

1. Applegate DL and Cook WJ (1991). A computational study of the job-shop scheduling problem. ORSA Journal on Computing 30 (2): 149–156.
2. Apt K (2003). Principles of Constraint Programming. Cambridge University Press: Cambridge.
3. Bartlett AC and Langville AN (2006). An integer programming model for the Sudoku problem. http://www.cofc.edu/~langvillea/Sudoku/sudoku2.pdf, accessed 21 May 2013.Google Scholar
4. Colbourn CJ, Colbourn MJ and Stinson DR (1984). The computational complexity of recognizing critical sets. In: Koh K and Yap H (eds). Graph Theory Singapore 1983, Volume 1073 of Lecture Notes in Mathematics. Springer: Heidelberg: pp 248–253.Google Scholar
5. Dànes J and Keedwell AD (1974). Latin Squares and their Applications. English Universities Press: London.Google Scholar
6. Felgenhauer B and Jarvis F (2005). Enumerating possible Sudoku grids. http://www.afjarvis.staff.shef.ac.uk/sudoku/sudoku.pdf, accessed 7 January 2013.
7. Garns H (1979). Number place. Dell Pencil Puzzles & Word Games (16): 6.Google Scholar
8. Golomb SW and Baumert LD (1965). Backtrack programming. Journal of the ACM 120 (4): 516–524.
9. Higgins A, Kozan E and Ferreira L (1996). Optimal scheduling of trains on a single line track. Transportation Research Part B: Methodological 300 (2): 147–161.
10. Jensen TR and Toft B (1994). Graph Coloring Problems. Vol. 39. Wiley-Interscience: New York.
11. Laporte G and Pesant G (2004). A general multi-shift scheduling system. Journal of the Operational Research Society 55 (11): 1208–1217.
12. Lewis R (2007a). On the combination of constraint programming and stochastic search: The Sudoku case. http://rhydlewis.eu/papers/HM2007.pdf, accessed 7 January 2013.
13. Lewis R (2007b). Metaheuristics can solve Sudoku puzzles. Journal of Heuristics 130 (4): 387–401.
14. Lustig IJ and Puget J-F (2001). Program does not equal program: Constraint programming and its relationship to mathematical programming. Interfaces 310 (6): 29–53.
15. Mantere T and Koljonen J (2006). Solving and rating Sudoku puzzles with genetic algorithms. In: Hyvönen E, Kauppinen T, Kortela J, Raiko T, Laukkanen M and Viljanen K (eds). New Developments in Artificial Intelligence and the Semantic Web-Proceedings of the 12th Finnish Artificial Conference. Finnish Artificial Intelligence Society: Espoo, Finland: pp 86–92.Google Scholar
16. Mantere T and Koljonen J (2007). Solving, rating and generating Sudoku puzzles with GA. In: 2007 IEEE Congress on Evolutionary Computation. IEEE: Singapore, pp 1382-1389.Google Scholar
17. McGuire G, Tugemann B and Civario G (2012). There is no 16-clue Sudoku: Solving the Sudoku minimum number of clues problem. http://arxiv.org/pdf/1201.0749v1.pdf, accessed 7 January 2013.
18. Naveh Y, Richter Y, Altshuler Y, Gresh DL and Connors DP (2007). Workforce optimization: Identification and assignment of professional workers using constraint programming. IBM Journal of Research and Development 51 (3.4): 263–279.
19. Rodgers JL and Nicewander WA (1988). Thirteen ways to look at the correlation coefficient. The American Statistician 420 (1): 59–66.
20. Rossi F, Van Beek P and Walsh T (2006). Handbook of Constraint Programming. Vol. 2. Elsevier: Amsterdam.Google Scholar
21. Royle G. Sudoku dataset: 49151 instances with 17 givens, University of Western Australia. http://school.maths.uwa.edu.au/~gordon/sudokumin.php, accessed 20 September 2013.
22. Russell E and Jarvis F (2005). There are 5472730538 essentially different Sudoku grids. http://www.afjarvis.staff.shef.ac.uk/sudoku/sudgroup.html, accessed 30 May 2013.
23. Sellmann M, Zervoudakis K, Stamatopoulos P and Fahle T (2002). Crew assignment via constraint programming: Integrating column generation and heuristic tree search. Annals of Operations Research 1150 (1): 207–225.
24. Simonis H (2005). Sudoku as a constraint program. http://4c.ucc.ie/~hsimonis/sudoku.pdf, accessed 7 January 2013.
25. Tadei R and Mancini S (2006). Sudoku game theory, models and algorithms. http://www.polito.it/polymath/htmlS/Studenti/Tesi/SudokuGame/tesi_Mancini_Simona%20SUDOKU.pdf, accessed 21 May 2013.
26. Takayuki Y and Takahiro S (2003). Complexity and completeness of finding another solution and its application to puzzles. IEICE Transactions on Fundamentals of Electronics, Communications and Computer Sciences 860 (5): 1052–1060.Google Scholar
27. Walker RJ (1960). An enumerative technique for a class of combinatorial problems. In: Bellman RE and Hall M (eds) Proceedings of Symposia in Applied Mathematics. American Mathematical Society: Providence, RI. Vol. 10, pp 91–94.Google Scholar

Authors and Affiliations

• Leandro C Coelho
• 1
• 2
• Gilbert Laporte
• 1
• 3
1. 1.CIRRELT—Interuniversity Research Center on Enterprise Networks, Logistics and TransportationQuébecCanada