Solving N k Queens Using Dancing Links - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

Solving N k Queens Using Dancing Links

Description:

Began working with Chatham and Skaggs in November ... Interesting Tidbit: Sequential DLX vs. Parallel C . Questions? Thank you! Dr. Chatham ... – PowerPoint PPT presentation

Number of Views:213
Avg rating:3.0/5.0
Slides: 34
Provided by: peopleMore
Category:

less

Transcript and Presenter's Notes

Title: Solving N k Queens Using Dancing Links


1
Solving Nk Queens Using Dancing Links
  • Matthew A. Wolff
  • Morehead State University
  • May 19, 2006

2
Agenda
  • Motivation
  • Terms
  • Problem Definition
  • Timing Results for various N1 Programs
  • Future Work

3
Motivation
  • NASA EPSCoR grant
  • (Subcontract WKURF 516140-06-15)
  • Began working with Chatham and Skaggs in November
  • Doyle added DLX (Dancing Links) at beginning of
    Spring '06 semester
  • Senior Project

4
Category of Problems
  • 8 Queens
  • 8 attacking queens on an 8x8 chess board
  • N Queens
  • N attacking queens on an NxN chess board
  • N1 Queens
  • N1 attacking queens on an NxN chess board
  • 1 Pawn used to block two or more attacking queens
  • Nk Queens
  • Nk attacking queens on an NxN chess board
  • k Pawns used to block numerous attacking queens

5
Recursion
  • "To understand recursion, one must first
    understand recursion" -- Tina Mancuso
  • A function is recursive if it can be called
    while active (on the stack).
  • i.e. It calls itself

6
Recursion in Art
7
Recursion in Computer Science
  • // precondition n gt 0// postcondition n! is
    returnedfactorial (int n) if (n 1) or (n
    0) return 1 else return
    (nfactorial(n-1))

8
Backtracking
  • An example of backtracking is used in a
    depth-first search in a binary tree
  • Let t be a binary tree
  • depthfirst(t) if (t is not empty) access
    root item of t depthfirst(left(t)) depthfi
    rst(right(t))

9
Backtracking Example
  • Output A B D E H I C F - G

10
Main Focus Nk Queens
  • Why?
  • Instead of focusing on specific solutions (N1,
    N2, ...), we will be able to solve any general
    statement (Nk) of the Queens Problem.
  • Implementing a solution is rigorous and utilizes
    many important techniques in computer science
    such as parallel algorithm development,
    recursion, and backtracking

11
Chatham, Fricke, Skaggs
  • Proved Nk queens can be placed on an NxN board
    with k pawns.

12
NK what to do?
  • Nk presents a very large problem
  • 1 Pawn meant an extra for loop around everything
  • k Pawns would imply k for loops around everything
  • Dynamic for loops?
  • Search for a better way
  • Dancing Links

13
Why Dancing Links?
  • Structure Algorithm
  • Comprehendible (Open for Debate)
  • Increased performance
  • DLX is supposedly quicker than a standard
    backtracking algorithm
  • Made popular by Knuth via his circa 2000 article

14
The Universe
  • Multi-Dimensional structure composed of circular,
    doubly linked-lists
  • Each row and column is a circular, doubly
    linked-list

15
Visualization of The Universe
16
The Header node
  • The root node of the entire structure
  • Members
  • Left pointer
  • Right pointer
  • Name (H)
  • Size Number of Column Headers in its row.

17
Column Headers
  • Column Headers are nodes linked horizontally with
    the Header node
  • Members
  • Left pointer
  • Right pointer
  • Up pointer
  • Down pointer
  • Name (Rw, Fx, Ay, or Bz)
  • Size the number of Column Objects linked
    vertically in their column

18
Column Objects
  • Grouped in two ways
  • All nodes in the same column are members of the
    same Rank, File, or Diagonal on the chess board
  • Linked horizontally in sets of 4
  • Rw, Fx, Ay, or Bz
  • Each set represents a space on the chess board
  • Same members as Column Headers, but with an
    additional top pointer which points directly to
    the Column Header

19
Mapping the Chess Board
20
The Amazing TechniColor Chess Board
21
The Dance Steps
  • The entire algorithm is based off of two simple
    ideas
  • Cover remove an item
  • Node.right.left Node.left
  • Node.left.right Node.right
  • Uncover insert the item back
  • Node.right.left Node
  • Node.left.right Node

22
Dance Steps, cont.
  • void search(k) if (header.right header)
    finished else c choose_column() cover(c)
    r c.down while (r ! c) j
    r.right while (j ! r) cover(j.top) j
    j.right place next queen search(k1)
    c r.top j r.left while (j !
    r) uncover(j.top) j j.left
    completed search(k) uncover(c) finished

23
1x1 Universe Before
24
1x1 Universe After
25
Modifying for Nk Queens
  • 1 Pawn will cut its row, column, and diagonal
    into 2 separate pieces
  • Just add these 4 new Column Headers to the
    universe, along with their respective Column
    Objects
  • k Pawns will cut their rows, columns, and
    diagonals into. ? separate pieces.
  • Still need to add these extra Column Headers, but
    how many are there and how many Column Objects
    are in each?

26
It Slices, It Dices
  • Find ALL valid Pawn Placements
  • (N-2)2 choose k lots of combinations
  • Then build 4 NxN arrays
  • One for each Rank, File, and Diagonal
  • Scan through arrays
  • For Ranks scan horizontally (Files vertically,
    Diagonals diagonally)
  • Reach the end or a Pawn, increment 1

27
Example of Rank Scan
28
N1 QueensVarying Language, Algorithm
29
N1 Queens Parallel Backtracking vs. DLX
30
N1 QueensSequential DLX vs. Parallel DLX
31
Interesting TidbitSequential DLX vs. Parallel
C
32
Questions?
  • Thank you!
  • Dr. Chatham
  • Dr. Doyle
  • Mr. Skaggs

33
References
Write a Comment
User Comments (0)
About PowerShow.com