How To Solve A Sudoku Puzzle With An All Different Operator And An Integer Programming Problem



Similar documents
10 th POLISH SUDOKU CHAMPIONSHIP INSTRUCTION BOOKLET. February 22, 2015 IMPORTANT INFORMATION:

5 INTEGER LINEAR PROGRAMMING (ILP) E. Amaldi Fondamenti di R.O. Politecnico di Milano 1

Sudoku puzzles and how to solve them

Sudoku as a SAT Problem

Integer Programming Formulation

An Integer Programming Model for the Sudoku Problem

A search based Sudoku solver

Sport Timetabling. Outline DM87 SCHEDULING, TIMETABLING AND ROUTING. Outline. Lecture Problem Definitions

Lecture 3: Finding integer solutions to systems of linear equations

Battleship. Big bands

A Review of Sudoku Solving using Patterns

Optimal Scheduling for Dependent Details Processing Using MS Excel Solver

Minimally Infeasible Set Partitioning Problems with Balanced Constraints

Sudoku Puzzles Generating: from Easy to Evil

Mathematical Induction

Methods for Solving Sudoku Puzzles

Practical Guide to the Simplex Method of Linear Programming

8 Primes and Modular Arithmetic

Scheduling Shop Scheduling. Tim Nieberg

A Robust Formulation of the Uncertain Set Covering Problem

Linear Programming for Optimization. Mark A. Schulze, Ph.D. Perceptive Scientific Instruments, Inc.

Solutions to Homework 6

What is Linear Programming?

Transportation Polytopes: a Twenty year Update

Offline sorting buffers on Line

HYBRID GENETIC ALGORITHMS FOR SCHEDULING ADVERTISEMENTS ON A WEB PAGE

Determining Degree Of Difficulty In Rogo, A TSP-based Paper Puzzle

Cost Models for Vehicle Routing Problems Stanford Boulevard, Suite 260 R. H. Smith School of Business

Patterns in Pascal s Triangle

Genetic Algorithms and Sudoku

Stiffie's On Line Scheduling Algorithm

MATH10212 Linear Algebra. Systems of Linear Equations. Definition. An n-dimensional vector is a row or a column of n numbers (or letters): a 1.

A CP Scheduler for High-Performance Computers

Offline 1-Minesweeper is NP-complete

Notes on Determinant

The Characteristic Polynomial

Sensitivity Analysis 3.1 AN EXAMPLE FOR ANALYSIS

1 Introduction. Linear Programming. Questions. A general optimization problem is of the form: choose x to. max f(x) subject to x S. where.

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

Local periods and binary partial words: An algorithm

MINIMAL BOOKS OF RATIONALES

Branch-and-Price Approach to the Vehicle Routing Problem with Time Windows

MapReduce With Columnar Storage

Creating Synthetic Temporal Document Collections for Web Archive Benchmarking

Hadoop on a Low-Budget General Purpose HPC Cluster in Academia

Observation on Sums of Powers of Integers Divisible by Four

Sample Induction Proofs

ABSORBENCY OF PAPER TOWELS

SHARP BOUNDS FOR THE SUM OF THE SQUARES OF THE DEGREES OF A GRAPH

The Bi-Objective Pareto Constraint

Scheduling Algorithm with Optimization of Employee Satisfaction

Enumerating possible Sudoku grids

Linear Programming. March 14, 2014

Unit 1. Today I am going to discuss about Transportation problem. First question that comes in our mind is what is a transportation problem?

Math 231b Lecture 35. G. Quick

ISO Revisions Whitepaper

Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products

Lecture 11: 0-1 Quadratic Program and Lower Bounds

CHAPTER 9. Integer Programming

160 CHAPTER 4. VECTOR SPACES

4.6 Linear Programming duality

Completion Time Scheduling and the WSRPT Algorithm

Sudoku as a Constraint Problem

Why are thesis proposals necessary? The Purpose of having thesis proposals is threefold. First, it is to ensure that you are prepared to undertake the

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

3. Linear Programming and Polyhedral Combinatorics

Smart Graphics: Methoden 3 Suche, Constraints

Automated SEO. A Market Brew White Paper

Analysis of an Artificial Hormone System (Extended abstract)

On Data Recovery in Distributed Databases

What mathematical optimization can, and cannot, do for biologists. Steven Kelk Department of Knowledge Engineering (DKE) Maastricht University, NL

A Mathematical Programming Solution to the Mars Express Memory Dumping Problem

Algebra 2 Chapter 1 Vocabulary. identity - A statement that equates two equivalent expressions.

Relational Database: Additional Operations on Relations; SQL

NP-Completeness and Cook s Theorem

Isotope distributions

Managing Variability in Software Architectures 1 Felix Bachmann*

Chapter 4 Software Lifecycle and Performance Analysis

Discuss the size of the instance for the minimum spanning tree problem.

Generating Personnel Schedules in an Industrial Setting Using a Tabu Search Algorithm

December 4, 2013 MATH 171 BASIC LINEAR ALGEBRA B. KITCHENS

1(a). How many ways are there to rearrange the letters in the word COMPUTER?

Chapter 9 Unitary Groups and SU(N)

Minimizing fleet operating costs for a container transportation company

Solution to Homework 2

School Timetabling in Theory and Practice

PRODUCTION PLANNING AND SCHEDULING Part 1

Suk-Geun Hwang and Jin-Woo Park

Factoring Algorithms

Gamesman: A Graphical Game Analysis System

PARALLELIZED SUDOKU SOLVING ALGORITHM USING OpenMP

EXCEL SOLVER TUTORIAL

Linear Programming in Matrix Form

Formulations of Model Predictive Control. Dipartimento di Elettronica e Informazione

Integrating Benders decomposition within Constraint Programming

Gambling Systems and Multiplication-Invariant Measures

INTEGRATED OPTIMIZATION OF SAFETY STOCK

Algebra of the 2x2x2 Rubik s Cube

CHAPTER 14 ORDINAL MEASURES OF CORRELATION: SPEARMAN'S RHO AND GAMMA

The Henstock-Kurzweil-Stieltjes type integral for real functions on a fractal subset of the real line

Transcription:

Sudoku and OR F. Della Croce Dipartimento di Automatica ed Informatica, Politecnico di Torino E-mail address: federico.dellacroce@polito.it Keywords: Combinatorial Optimization, Integer Programming 1 Introduction Following the description of Wikipedia the free encyclopedia [5], Sudoku can be described as a logic-based placement puzzle. The aim of the classic version of the puzzle is to enter a numerical digit from 1 through 9 in each cell of a 9 9 grid made up of 3 3 subgrids, starting with various digits given in some cells (the givens); each row, column, and region must contain only one instance of each numeral. Further only proper puzzles are considered, that is puzzles having a unique solution. Below are reported a classic Sudoku proper puzzle and the corresponding solution. 6 1 7 3 2 5 3 7 2 4 6 9 2 8 5 4 2 6 5 8 6 4 8 4 7 9 9 8 5 4 6 2 1 7 3 6 2 1 5 7 3 8 9 4 7 3 4 1 8 9 2 5 6 4 7 3 6 2 8 5 1 9 2 6 9 7 5 1 4 3 8 5 1 8 9 3 4 7 6 2 1 9 6 2 4 7 3 8 5 3 5 2 8 1 6 9 4 7 8 4 7 3 9 5 6 2 1 The Sudoku puzzle was invented in Indianapolis in 1979 but reached widespread international popularity just in 2005 after being launched at the end of 2004 by one of the leading british newspapers, The Times. A nice scientific survey of the Sudoku phenomenon was presented in [1]. Several variants have been proposed of the Sudoku puzzle. We cite among others SudokuX, where as additional constraint it is required that also the main diagonals must contain only one instance of each numeral. Alphabetical variations 1

have also emerged (the so-called wordoku): there is no functional difference in the puzzle unless the letters spell something. Some variants include one or two words reading somewhere in the grid once solved, where this/these word/s are described as in crosswords: determining the word in advance can be viewed as a solving aid. Below are reported a Wordoku puzzle using letters (A - B - C - I - K - O - S - T - U) and the corresponding solution. The current president of EURO U T C I O A I U B C T U S K A I T B B T S C U I K B K O U C A T I B S T C B I O S U K A I S A B U K O T C B K O A S C T U I C T S U I B K A O U A I T K O S C B A U K S B I C O T S B T O C U A I K O I C K T A B S U 2 Solving proper Sudoku puzzles by means of ILP modeling Every proper Sudoku puzzle can be tackled by means of various AI & OR techniques. For instance, on one hand the puzzle can be solved by means of constraint programming techniques (see [4]) such as the all-different operator, on the other hand it can be easily formulated as an ILP model. Here we focus on this latter approach. Given an initial grid where some elements (i, j) have already been filled by digits, let RQ h (h = 1,...,9) be the h-th block of the grid. An ILP formulation (P1) of the SUDOKU puzzle can be expressed as follows: Variables: x i,j,k = 1 if element (i, j) has value k (1 k 9, k integer) in the puzzle solution, else x i,j,k = 0. Objective function: there is no objective function as the purpose is just to search for a feasible solution. 2

Constraints: k=1 x i,j,k = 1 i, j (each element of the grid contains one of the digits 1-9) j=1 x i,j,k = 1 i, k (each row of the grid contains the digits 1 9 exactly once) i=1 x i,j,k = 1 j, k (each column of the grid contains the digits 1 9 exactly once) i,j:(i,j) RQ h k=1 x i,j,k = 1 h = 1,...,9 (each block of the grid contains the digits 1 9 exactly once). x i,j,k = 1 element of the entry grid (i, j) with value k. 3 Building proper Sudoku puzzles by means of ILP modeling To build a proper Sudoku puzzle, we need to derive an initial grid such that there exists a feasible Sudoku solution compatible to that grid and this solution is unique. Below (see [2]) is indicated how to check whether a solution (given an initial grid) is or not unique. Let denote by SOL(i, j) the value of element (i, j) of the grid in the feasible solution. Consider solving the following ILP model (P2): Objective function: min Z = i,j,k:sol(i,j)=k x i,j,k (we minimize the sum of all variables x i,j,k corresponding to elements (i, j) having value k in the feasible solution). Constraints (the same constraints considered in model P 1 ): k=1 x i,j,k = 1 i, j j=1 x i,j,k = 1 i, k i=1 x i,j,k = 1 j, k i,j:(i,j) RQ h k=1 x i,j,k = 1 h = 1,...,9 3

x i,j,k = 1 element of the entry grid (i, j) with value k. The solution of model P2 clearly provides a feasible solution also to model P 1 and therefore to the SUDOKU puzzle. Further, the objective function of model P 2 minimizes the sum of the elements in the grid having the same value obtained in the solution of model P 1. Hence, as each grid is composed by 81 elements, if the objective function value of model P 2 is equal to 81 (Z = 81), then the considered SUDOKU puzzle has unique solution, else the solution to the SUDOKU puzzle is not unique. A straightforward approach for building a proper Sudoku puzzle is provided by the following procedure (notice that the sequence indicated below for emptying the elements is not compulsory, but it is sufficient to handle all elements under any sequence). Procedure "Build_initial_grid": INPUT: final solution. OUTPUT: initial grid. { for i=1 to 9 for j=1 to 9 fill element (i,j) with Sol(i,j); } for i=1 to 9 for j=1 to 9 empty element (i,j); Solve model P2; if the objective function value of model P2 is < 81 (solution not unique), then fill element (i,j) with Sol(i,j); end for end for This approach guarantees that the corresponding Sudoku puzzle is also irreducible, namely no element(i,j) can be emptied, or else the solution becomes not unique. 4

4 A challenging problem for the OR community From an OR point of view, solving/building a proper sudoku puzzle is actually quite a trivial task. However a strongly challenging combinatorial problem related to the Sudoku puzzle is concerned with the minimum number of givens for proper puzzles (notice that the inverse problem, that is the maximum number of givens that can be provided while still not rendering the solution unique has a trivial solution, namely four short of a full grid). The best available solution value for this problem is 17 (see [3] for a collection of distinct Sudoku proper initial grids with 17 givens) and it is conjectured that no 16-givens initial grids exist, evidence for which stems from extensive randomised searching. On the other hand, a trivial lower bound = 8 can be determined for this problem: indeed if two numerals k, l are absent from the initial grid, then there exist at least two different solutions (it is sufficient to assign value k to all elements having value l and viceversa). However, to the author s knowledge, at the current state of the art no better lower bound is available: this induces indeed quite an impressive gap and room for extensive research! References [1] J.P. Delahaye, The Science behind Sudoku, (June 2006), Scientific American, 71-77. [2] F. Della Croce, G. Ferro, Sudoku per l estate, Mondadori, 2006 (in Italian). [3] G. Royle, Minimum Sudoku : http://www.csse.uwa.edu.au/ gordon/sudokumin.php. [4] H. Simonis, Sudoku as a constraint problem, in CP Workshop on Modeling and Reformulating Constraint Satisfaction Problems, 13-27, Sitges (Barcelona), October 2005. [5] Sudoku, from Wikipedia: http://en.wikipdia.org/sudoku. 5