Solving and Analyzing Sudokus with Cultural Algorithms 5/30/2008. Timo Mantere & Janne Koljonen

Similar documents
A Retrievable Genetic Algorithm for Efficient Solving of Sudoku Puzzles Seyed Mehran Kazemi, Bahare Fatemi

A Genetic Algorithm for Solving Beehive Hidato Puzzles

A Novel Multistage Genetic Algorithm Approach for Solving Sudoku Puzzle

Solving Sudoku with Genetic Operations that Preserve Building Blocks

A comparison of a genetic algorithm and a depth first search algorithm applied to Japanese nonograms

Automatically Generating Puzzle Problems with Varying Complexity

Meta-Heuristic Approach for Supporting Design-for- Disassembly towards Efficient Material Utilization

Kenken For Teachers. Tom Davis January 8, Abstract

Comparing Methods for Solving Kuromasu Puzzles

Mathematics of Magic Squares and Sudoku

ISudoku. Jonathon Makepeace Matthew Harris Jamie Sparrow Julian Hillebrand

LANDSCAPE SMOOTHING OF NUMERICAL PERMUTATION SPACES IN GENETIC ALGORITHMS

Rating and Generating Sudoku Puzzles Based On Constraint Satisfaction Problems

SudokuSplashZone. Overview 3

SUDOKU X. Samples Document. by Andrew Stuart. Moderate

Local Search: Hill Climbing. When A* doesn t work AIMA 4.1. Review: Hill climbing on a surface of states. Review: Local search and optimization

TABLE OF CONTENTS CHAPTER NO. TITLE PAGE NO. LIST OF TABLES LIST OF FIGURES LIST OF SYMBOLS AND ABBREVIATIONS

Evolutions of communication

In the game of Chess a queen can move any number of spaces in any linear direction: horizontally, vertically, or along a diagonal.

INTRODUCTION TO COMPUTER SCIENCE I PROJECT 6 Sudoku! Revision 2 [2010-May-04] 1

Part I At the top level, you will work with partial solutions (referred to as states) and state sets (referred to as State-Sets), where a partial solu

SUDOKU SURPRISE. Hosted by Logic Masters India November Puzzles set by David McNeill Tested by Tom Collyer, Yuhei Kusui and Robert Vollmert

Section Marks Agents / 8. Search / 10. Games / 13. Logic / 15. Total / 46

A Factorial Representation of Permutations and Its Application to Flow-Shop Scheduling


The remarkably popular puzzle demonstrates man versus machine, backtraking and recursion, and the mathematics of symmetry.

isudoku Computing Solutions to Sudoku Puzzles w/ 3 Algorithms by: Gavin Hillebrand Jamie Sparrow Jonathon Makepeace Matthew Harris

Vesselin K. Vassilev South Bank University London Dominic Job Napier University Edinburgh Julian F. Miller The University of Birmingham Birmingham

On the Combination of Constraint Programming and Stochastic Search: The Sudoku Case

The Mathematics Behind Sudoku Laura Olliverrie Based off research by Bertram Felgenhauer, Ed Russel and Frazer Jarvis. Abstract

Sudoku Solvers. A Different Approach. DD143X Degree Project in Computer Science, First Level CSC KTH. Supervisor: Michael Minock

ON 4-DIMENSIONAL CUBE AND SUDOKU

Take Control of Sudoku

LMI SUDOKU TEST 7X JULY 2014 BY RICHARD STOLK

An improved strategy for solving Sudoku by sparse optimization methods

Divide & conquer. Which works better for multi-cores: insertion sort or merge sort? Why?

Wire Layer Geometry Optimization using Stochastic Wire Sampling

Data Structure Analysis

CSC 396 : Introduction to Artificial Intelligence

Any items left blank for a given term means the skill is not being assessed at this time.

The Genetic Algorithm

SUDOKU1 Challenge 2013 TWINS MADNESS

FreeCiv Learner: A Machine Learning Project Utilizing Genetic Algorithms

An Intelligent Othello Player Combining Machine Learning and Game Specific Heuristics

KenKen Strategies 17+

Project: Sudoku solver

The Application of Multi-Level Genetic Algorithms in Assembly Planning

CS 441/541 Artificial Intelligence Fall, Homework 6: Genetic Algorithms. Due Monday Nov. 24.

Modeling a Rubik s Cube in 3D

Universal Cycles for Permutations Theory and Applications

Machine Learning in Iterated Prisoner s Dilemma using Evolutionary Algorithms

Cryptic Crosswords for Bright Sparks

1. The chance of getting a flush in a 5-card poker hand is about 2 in 1000.

Chapter 5 OPTIMIZATION OF BOW TIE ANTENNA USING GENETIC ALGORITHM

Investigation of Algorithmic Solutions of Sudoku Puzzles

Printer Model + Genetic Algorithm = Halftone Masks

Logic Masters India Presents

INTERACTIVE DYNAMIC PRODUCTION BY GENETIC ALGORITHMS

Improving Evolutionary Algorithm Performance on Maximizing Functional Test Coverage of ASICs Using Adaptation of the Fitness Criteria

UNIVERSITY OF NORTHERN COLORADO MATHEMATICS CONTEST

NUMERICAL SIMULATION OF SELF-STRUCTURING ANTENNAS BASED ON A GENETIC ALGORITHM OPTIMIZATION SCHEME

Wide and multi-band antenna design using the genetic algorithm to create amorphous shapes using ellipses

Applications of Advanced Mathematics (C4) Paper B: Comprehension INSERT WEDNESDAY 21 MAY 2008 Time:Upto1hour

Co-evolution for Communication: An EHW Approach

A Memory-Efficient Method for Fast Computation of Short 15-Puzzle Solutions

Adaptive Neuro-Fuzzy Controler With Genetic Training For Mobile Robot Control

Evolution of Sensor Suites for Complex Environments

Evolutionary Optimization for the Channel Assignment Problem in Wireless Mobile Network

Sudoku Book: 200 Sudoku Puzzles Of All Difficulties (Volume 2) By Djape READ ONLINE

Introduction to Genetic Algorithms

SHRIMATI INDIRA GANDHI COLLEGE

Sudoku Touch. 1-4 players, adult recommended. Sudoku Touch by. Bring your family back together!

Evolutionary robotics Jørgen Nordmoen

Cracking the Sudoku: A Deterministic Approach

I STATISTICAL TOOLS IN SIX SIGMA DMAIC PROCESS WITH MINITAB APPLICATIONS

THE problem of automating the solving of

Optimum Coordination of Overcurrent Relays: GA Approach

Rubik s Cube: the one-minute solution

MAT 409 Semester Exam: 80 points

Automated Software Engineering Writing Code to Help You Write Code. Gregory Gay CSCE Computing in the Modern World October 27, 2015

Yet Another Organized Move towards Solving Sudoku Puzzle

LMI Sudoku test Shapes and Sizes 7/8 January 2012

Past questions from the last 6 years of exams for programming 101 with answers.

Shuffled Complex Evolution

Applications of Advanced Mathematics (C4) Paper B: Comprehension WEDNESDAY 21 MAY 2008 Time:Upto1hour

Mobile SuDoKu Harvesting App

Logic Masters India Presents. April 14 16, 2012 April 2012 Monthly Sudoku Test INSTRUCTION BOOKLET

Using Artificial intelligent to solve the game of 2048

WPF SUDOKU/PUZZLE GRAND PRIX 2014 WPFSUDOKU GP 2014 COMPETITIONBOOKLET ROUND6. Puzzle authors: Bulgaria Deyan Razsadov.

puzzles may not be published without written authorization

Techniques for Generating Sudoku Instances

1 Introduction. 2 An Easy Start. KenKen. Charlotte Teachers Institute, 2015

I STATISTICAL TOOLS IN SIX SIGMA DMAIC PROCESS WITH MINITAB APPLICATIONS

Solution Algorithm to the Sam Loyd (n 2 1) Puzzle

COMP SCI 5401 FS2015 A Genetic Programming Approach for Ms. Pac-Man

Booklet SUDOKUCUP 2. Kabròáci SUDOKUCUP.COM

Reactive Planning with Evolutionary Computation

Solving Assembly Line Balancing Problem using Genetic Algorithm with Heuristics- Treated Initial Population

ECON 214 Elements of Statistics for Economists

Episode 3 8 th 12 th February Substitution and Odd Even Variations By Kishore Kumar and Ashish Kumar

Transcription:

with Cultural Algorithms Timo Mantere & Janne Koljonen University of Vaasa Department of Electrical Engineering and Automation P.O. Box, FIN- Vaasa, Finland timan@uwasa.fi & jako@uwasa.fi www.uwasa.fi/~timan/sudoku Outline Introduction to Sudoku problem Encoding of the Sudoku problem in our EAs Crossover and mutations operators Fitness function Belief space Results and their interpretation Comparison of results Conclusions Future

Introduction This paper studies the problems involved in solving and analyzing Sudokus with cultural algorithms Sudoku is a Japanese logical game that has recently become hugely popular in Europe and North-America. However, the first puzzle was published in a puzzle magazine in USA, then it circled through Japan, where it became popular in, and later it become a phenomenon in the western world circa. Sudoku has been claimed to be very popular and addictive because it is very challenging but has very simple rules. The objectives of this study were ) to test if a cultural algorithm (CA) with a belief space solves Sudoku puzzles more efficiently than a normal permutation genetic algorithm (GA), ) to see if the belief space gathers information that helps analyze the results and improve the method accordingly, ) to improve our previous Sudoku solver presented in CEC. A Sudoku puzzle example Sudoku puzzle is composed of a grid, that is divided into nine sub grids. The solution of Sudoku puzzle is such that each row, column and sub grid contains each integer from [, ] once and only once. In addition, there are some static numbers ( givens ) that must stay in their fixed position

A Sudoku puzzle example The Sudoku solution must be unique (usually) Note that each column, row and sub square of the solution contains each integer from to once The givens given in the beginning are in their original positions. Other positions have been solved. The number of givens does not determine the difficulty. Grading puzzles is one of the most difficult things in Sudoku creation, and there are approx. - factors that have an effect on the difficulty rating Genetic encoding Individual : Individual : Individual n: x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x The help array: The possible crossover points The representation of Sudoku puzzles with our GA & CA One individual is an array of numbers, which is divided into nine sub blocks of nine numbers The allowed crossover points are only between sub blocks (marked as vertical lines) The help array is used for checking fixed positions: if there is a number that is not equal to zero, that number cannot be changed

Swap mutation Sub block: Swap mutation: Illegal attempt of swap mutation: -swap mutation: Insertion mutation: The help array: Illegal attempt of insertion mutation: The mutation types used in the Sudoku optimization (removed from this version) Up left; one sub block, up right; the givens in that sub block ( and ) The mutation is applied so, that we randomly select positions inside the sub block, and then check the help array if the positions are free to change GA parameters The selected parameters for the test runs were the following: Combinatorial GA, Chromosome consist of integer numbers Uniform crossover with fixed crossover points (-point crossover) Population size N=, Elitism N e = Mutation percentage was measured to be.% per one Sudoku puzzle location Swap mutation sequences with - swaps with percentages {.,.,.,.,.} Crossover ratio New individuals generated by first doing crossover and then mutation to the new trial. We measured that.% of new individuals have been changed by mutation and.% only by crossover Stopping condition was solution found The most difficult Sudoku with the worst test run required trial evaluations

GA parameters Trials needed Selected to be parent A B C Population size D E Reasoning for population size (up) and elitism (below) Trials needed C Elitism D E A B n:th best population member We favored the best individuals as parents by selecting the mating individuals p and p with using the following Java code: for(i=pop-; i>=elit; i--){ ii=ord[i]; p = ord[i*math.random()]; p = ord[i*math.random()]; crossover(indiv[ii], indiv[p], indiv[p]); mutation(indiv[ii]); } Fitness function The fitness function was composed of three parts The first part requires that all digits {,,} must be present in each row and column, otherwise penalty P x is added The second part is aging of the best individual (adding to its fitness value each round when it remains the best) The third part requires that the same digit as some given must not appear in the same row or column as a given, otherwise penalty P g added This used only after reaching the near solution region of the search space P = x [ ( xi, j == xii, j ) + ( xi, j == xi, jj )] i= j= ii= i+ jj= j+ if (Best[generation[i]] == Best[generation[i-]]) Value[Best]+=; P g = ( xij == gij ) i = j =

Analysis of operators Count Aborting swap attempts, if it would lead too many identical digits in the rows or columns Already optimal (%) Sudoku Our version Eb Ec Ea b a GA-Ec a b a SDa Fitness value Without aging Tighter < limit Restart Looser < limit Perform swap (.%) abort swap (.%) How many times digits appear in the lines or columns P g on Generations Belief space The belief space in this case was a cube, where the first two dimensions correspond to the positions of a Sudoku puzzle, and the third dimension represents the nine possible digits for each location After each generation, the belief space is updated if: ) The fitness value of best individual is ) The best individual is not identical with the individual that updated the belief space previous time The belief space is updated so that the value of the digit that appears in the best Sudoku solution is incremented by in the belief space. This model also means that the belief space is updated only with nearoptimal solutions ( positions wrong) This information is used only in the population reinitialization process Update Fitness evaluation Population n n n Belief space Influence Reproduction When population is reinitialized, positions that have only one non-zero digit value in the belief space are considered as givens, these include the real givens and also so called hidden givens that the belief space have learned, i.e. those positions that always contain the same digit in the near-optimal solutions

Givens and hidden givens How many givens; real G and hidden H, each of our benchmark Sudoku instance had + the amount of different near solution N we found Those marked with * actually posses zero hidden givens, when analyzed of all solve runs Diff rating. E C D SD Easy Med Hard GA-E Givens (G) a b c Hidden givens (H) a b c * * * * * Near solutions (N) a b c GA-M GA-H Example of near solutions Correct: = = = = = = = = = Near sol. ( wrong) Pos. wrong: = = = = = = = = = Near sol. ( wrong) Pos. wrong: = = = = = = = = = Near sol. ( wrong) Pos. wrong: = = = = = = = = = Near sol. ( wrong) Pos. wrong: = = = = = = = = = Near sol. ( wrong) Pos. wrong: = = = = = = = = =

Results (st version of CA) Difficulty Average of Solve generations with GA Average of Solve generations with CA Improve by Rating a b c a b c % -. -. -.. -. E -. C -. D -. SD. Easy -. Med -. Hard -. GA-E -. GA-M -. GA-H -. The first version of CA (in the submitted draft paper) was slightly different than the one represented in these slides This CA version was more aggressive and obtain better solutions with easier Sudoku instances This CA was.% more efficient than GA With difficult Sudokus it performed poorly, which weighted down the advantage Results (this version) Difficulty Rating Average amount of trials needed to solve with GA a b c Average amount of trials needed to Solve with CA a b c Improve by %. -. -.. -. E. C. D. SD -. Easy. Med -. Hard. GA-E. GA-M. GA-H. Sum.

Interpretation of results We calculate the correlations between Sudoku difficulty and some numbers calculated from the Sudoku or with the help of belief space Highest correlations: ) CA results and the overall number of the near-optimal solutions that a Sudoku instance possesses N all The number of near-optimal N all solutions is the most important factor to define Sudoku puzzle difficulty, However, N all is unknown during a Sudoku solve run. Thus it cannot be employed in the optimization (it is counted from the series of solve runs) ) Number of givens G and CA solving efficiency This means that although the number of givens does not at implicitly define the difficulty of the Sudoku, it has large influence The amount of hidden givens does not have high correlation with the results The number of hidden givens adjusted with the number of free locations Ha=H/( G) in the Sudoku does not explain results better than unadjusted CA G GA. -. CA -. Improv. N... N all... M avg... H -. -. -. H all -. -. -. H avg -. -.. Ha min -. -. -. Ha all -. -. -. Ha avg -. -. -.. -. Some Sudokus were found to posses zero hidden givens. These are quite difficult since all free positions can have different values in some of the near-optimal solutions Comparison of the results Sudoku problems from www.sudoku. com Easy Easy Easy Medium Hard Our GA Unlimited trials trials The best results represented by Moraglio ea Hamming space crossovers Swap Space crossovers Hill climbers Total Our results and the best results represented by Moraglio et al in each of the three difficulty categories of Sudoku s found from www.sudoku.com. The numbers represents how many times out of test runs each method reached the optimum with each problem.

Conclusions The results show that EAs are fairly effective to solve Sudoku puzzles (however, not the fastest methods) CA is just slightly more efficient than GA, and CA seems to work better with the most difficult puzzles Our results stand quite well the comparison with the other known results with EAs (see the paper) The lack of common benchmark Sudokus complicates the comparison of results We decided to put our test Sudokus available in the web, so that anyone interested to compare their results with ours can now use the same benchmark puzzles http://www.uwasa.fi/~timan/sudoku Conclusions The difficulty ratings given for Sudoku puzzles in newspapers seems to be consistent with their difficulty in GA optimization. For some solitary puzzles the rating seems to be wrong, but the overall trend follows the ratings This means that GA can be used to rate the difficulty of a new Sudoku puzzle However, the other explanation can be that the original puzzles are also generated with computer programs, and since GA is also a computer based method, it is possible that a human solver does not necessarily experience difficulty the same way

Conclusions When some belief spaces were analyzed manually, it looked like Sudoku puzzles might possess some kind of positional bias Most of the belief spaces looked like the trials composed based on them would more likely contain small numbers in the left upper corner and larger numbers in right bottom corner We think that it is possible that Sudoku generators have some kind of positional bias when they generate new Sudoku puzzles CA belief space could potentially exploit this bias in order to generate better results. We plan to measure the possible positional biases in future and see, if it really appears or not, and if it appears only with some Sudoku generators Future, Ants? The belief space model used in this study was quite simple and can possibly be improved in future. It is likely that the gathered information could be employed more efficiently than just in the reinitialization The CA might also be improved by some kind of energy function based belief space Lately, we have solved Sudokus with Ant colony optimization (ACO) Results showed that ACO is more effective than CA with / benchmark Sudokus (including easiest), but it fails to find solution efficiently with difficult instances We are considering some kind of ACO/GA hybrid (cultural part is embedded to the ACO pheromone matrix)