Parallel Sudoku Solver Elliot Weiser and Steven Hwang

  • Slides: 12
Download presentation
Parallel Sudoku Solver Elliot Weiser and Steven Hwang

Parallel Sudoku Solver Elliot Weiser and Steven Hwang

Background • • • Sudoku is a logic puzzle using 9 x 9 matrix

Background • • • Sudoku is a logic puzzle using 9 x 9 matrix of numbers The goal is to fill the board given some initial configuration such that all rows, columns, and boxes contain the digits 1 -9. Puzzles are solved by eliminating a cell's possibilities until only one possibility remains There are several strategies that can help humans and computers solve the puzzle Guessing is the last line of defense. .

 • • • Objective Our goal is to create an efficient, scalable sudokusolving

• • • Objective Our goal is to create an efficient, scalable sudokusolving algorithm Basic Idea for multi-threading o When forced to guess the value of a cell, branch into as many threads as there are possibilities o Most advantageous for sudoku boards that require a large amount of guessing (i. e. large boards, boards with very few cells solved) Evaluation of strategies o Guessing is undesirable because it is computationally more expensive o We can run multiple strategies to reduce the number of guesses we need to make o Can be run in parallel on the same board

 • • Our Sudoku Solver Normal Sequential Sudoku Solver o Run depth-first search,

• • Our Sudoku Solver Normal Sequential Sudoku Solver o Run depth-first search, continuously guessing the next cell's entry until the board is either solved or invalid. o Evaluate different strategies to reduce guessing (optimization) Parallel Sudoku Solver o 2 pools of threads: guess threads and strategy threads o Guessing § Branch into multiple threads when forced to guess § When number of branch threads exceeded, revert to normal depth-first search o Strategies § Evaluate strategies in parallel when strategy threads are available. If not, run them sequentially.

Our Sudoku Solver (cont) Using either DFS or threads within threads, we explore all

Our Sudoku Solver (cont) Using either DFS or threads within threads, we explore all paths toward solving the board, in case there are multiple solutions. This means that even if we have already found a solution, we keep going until all possibilities have been exhausted.

Implementation of DFS 8 Key: Cell (0, 3) Possibles: 5 Key: Cell (0, 3)

Implementation of DFS 8 Key: Cell (0, 3) Possibles: 5 Key: Cell (0, 3) Possibles: 1 Key: Cell (0, 2) Possibles: 4 Key: Cell (0, 2) Possibles: 7 Key: Cell (0, 2) Possibles: 8 1. When guessing a cell, push as many copies of the cell as there are possibilities on to a stack 2. Pop a cell with its next possibility off the stack, set the same cell in the board with that value. 3. Evaluate any entries that are forced to have a single possibility. 4. If the board is valid but unsolved the board automatically finds a new cell on which to guess. 5. If either solved or invalid, rewind the board up to the state characterized by the cell at the top of the stack 6. Continue until the stack is empty

Backtrace Key: Cell (0, 3) Possibles: {1, 5} Key: Cell (0, 2) Possibles: {4,

Backtrace Key: Cell (0, 3) Possibles: {1, 5} Key: Cell (0, 2) Possibles: {4, 7, 8}

Strategies to Reduce Possibilities Example of "Naked Pair" in row 0, grid 0, and

Strategies to Reduce Possibilities Example of "Naked Pair" in row 0, grid 0, and row 2

Road-Blocks • • • Both the recursive version of DFS and our threadswithin-threads model

Road-Blocks • • • Both the recursive version of DFS and our threadswithin-threads model would lead to a stack overflow for hitting maximum recursion depth on a 25 x 25 board. Needed to implement a messier but more memoryefficient iterative DFS that doesn't consume too much stack space. Instead of constantly spawning more threads for the growing number of guesses we needed to make, we decided to cap off the number of threads we would use, and rely on that pool of threads only when they were available.

Some unofficial results. . . - Can solve boards of sizes up to size

Some unofficial results. . . - Can solve boards of sizes up to size 16 x 16 without complaints of stack-overflow. - Can find all 288 solutions to the empty 4 x 4 board - Evaluating strategies to solve the board takes less time than strictly guessing - 25 x 25 boards are painful. .

Acknowledgments • Tia Newhall

Acknowledgments • Tia Newhall

Works Cited [1] Hajj, Hazem and Ali Tarhini. “Parallel Sudoku Solver Algorithm” [2] Cheng,

Works Cited [1] Hajj, Hazem and Ali Tarhini. “Parallel Sudoku Solver Algorithm” [2] Cheng, John et al. “Sudoku Madness” [3] Marwala, Tshilidzi and Meir Perez. “Stochastic Optimization Approaches for solving Sudoku” [4] Kuchcinski, Krzysztof and Carl Christian Rolf. “Combining Task and Data Parallelism in Constraint Programming”