19
1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller ([email protected]) John Miller ([email protected]) Dr. Doug Chatham Dr. Doug Chatham Dr. Maureen Doyle Dr. Maureen Doyle Dr. Jeffrey Ward Dr. Jeffrey Ward Amber Rogers Amber Rogers Luke Thompson Luke Thompson

1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller ([email protected]) Dr. Doug Chatham Dr. Maureen

Embed Size (px)

Citation preview

Page 1: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

1 of 19

Dancing Links and N + k Queens

Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller ([email protected])John Miller ([email protected])

Dr. Doug ChathamDr. Doug Chatham

Dr. Maureen DoyleDr. Maureen Doyle

Dr. Jeffrey WardDr. Jeffrey Ward

Amber RogersAmber Rogers

Luke ThompsonLuke Thompson

Page 2: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

2 of 19

AgendaAgenda

N Queens ProblemN Queens Problem

Dancing LinksDancing Links

N + k Queens ProblemN + k Queens Problem

Finding SolutionsFinding Solutions

ResultsResults

Future WorkFuture Work

Page 3: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

3 of 19

The N Queens ProblemThe N Queens Problem

First proposed by Max Bezzel in 1848 as First proposed by Max Bezzel in 1848 as the 8 Queens Problem.the 8 Queens Problem.

The problem has been investigated by The problem has been investigated by mathematicians since its inception, mathematicians since its inception, including Gauss and Cantorincluding Gauss and Cantor

After solutions were found in 1850 by After solutions were found in 1850 by Franz Nauk, it was expanded to the N Franz Nauk, it was expanded to the N Queens ProblemQueens Problem

Page 4: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

4 of 19

The N Queens ProblemThe N Queens Problem

How many ways can n Queens on an n x n chessboard so that no queen can attack another queen

Commonly used to introduce recursion

Page 5: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

5 of 19

What are Dancing Links?What are Dancing Links?

Dancing Links is a data structure that can be used to help Dancing Links is a data structure that can be used to help solve any full cover problem. solve any full cover problem. N + k QueensN + k Queens SudokuSudoku

Introduced in 1979 by Introduced in 1979 by Hitotumatu and Noshita .Hitotumatu and Noshita .Popularized by Knuth in 2000Popularized by Knuth in 2000

Page 6: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

6 of 19

The Dancing Links UniverseThe Dancing Links UniverseThings get complicated very quickly

For an n x n chessboard, the universe will have6n-2 columns and 4n2+6n-1 nodes

Page 7: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

7 of 19

The Dance StepsThe Dance Steps

solve( int x ) if ( x = n)

solution found return choose a row r for placing queen remove row r

for every block b in row r place queen on block b

remove b’s columnremove b’s diagonalssolve(x+1)replace b’s diagonals

replace b’s columnreplace row r

Page 8: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

8 of 19

ResultsResultsN Queens Standard Backtracking vs. Dancing

Links (DLX)

0

50

100

150

200

250

300

Backtrack

DLX

  7 8 9 10 11 12 13 14 15 16

DLX 0 0 0.016 0 0.031 0.109 0.578 3.61 20.578 117.407

Backtrack 0 0 0 0 0.031 0.156 1.063 5.594 39.422 249.5

Page 9: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

9 of 19

N + k Queens ProblemN + k Queens Problem

Consider a chessboard where we have blocked k squares. This is equivalent to placing a pawn on this square. The pawns are unable to attack by default.

This problem was first proposed in 1995 by Michael Anshel.

Page 10: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

10 of 19

N + k Queens ProblemN + k Queens Problem

We have shown that there exist integers n and k We have shown that there exist integers n and k such that we can safely place n+k queens and k such that we can safely place n+k queens and k pawns on an n x n chessboardpawns on an n x n chessboard For each positive integer k and N > max{87 + k, 25k}For each positive integer k and N > max{87 + k, 25k}

Also, no more than n + k queens can safely be Also, no more than n + k queens can safely be placed on an n x n chessboard with k pawns.placed on an n x n chessboard with k pawns.

Page 11: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

11 of 19

Approach to Solving N + k QueensApproach to Solving N + k Queens

How do we take advantage of the How do we take advantage of the universe with the pawns.universe with the pawns. Look at all pawn positions and split the Look at all pawn positions and split the

universe.universe. Can we mimic the process of removing and Can we mimic the process of removing and

replacing portions of the universe?replacing portions of the universe?

Page 12: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

12 of 19

Splitting PawnsSplitting Pawns

Before finding Solutions, we must split the Before finding Solutions, we must split the universe based on the positions of the universe based on the positions of the

pawnspawns

Given a block b to place a pawnCreate a new header blockMove everything below b into the groupRemove b from its group

Page 13: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

13 of 19

Head

X

Pawn

Y

Head

X

Pawn

Y

New Head

Before Split After Split

Notice Pawn has nothing pointing to it, butIt is still pointing to its former up and down

nodes

Splitting PawnsSplitting Pawns

Page 14: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

14 of 19

Reducing Search SpaceReducing Search Space

We have shown the followingWe have shown the following In order to place n + k queens and k pawns In order to place n + k queens and k pawns

on an n x n board…on an n x n board…No two pawns may share an edgeNo two pawns may share an edge

No pawn may be placed on the outer edge of the No pawn may be placed on the outer edge of the boardboard

No pawn may be positioned on a square No pawn may be positioned on a square adjacent to a corner square.adjacent to a corner square.

Page 15: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

15 of 19

How fast is it on n + k Queens?How fast is it on n + k Queens?

0

2

4

6

8

6 7 8 9 101

6-8

4-6

2-4

0-2

0

1000

2000

3000

4000

6 7 8 9 101

3000-4000

2000-3000

1000-2000

0-1000

  k = 1 2 3

n = 6 0.483 0.24244 0.57941

7 0.33554 0.299878 1.431793

8 0.182767 2.58031 20.5701

9 1.259398 25.70771 308.6757

10 7.87423 200.9441 3415.678

11 50.53545 1885.451  …

k = 1 2 3 4 5

n = 6 0.2268 0.488 0.27891 0.109603 0.310351

7 0.4393 0.17628 0.136313 0.84748 4.237

8 0.21151 0.61398 0.5537 4.681894 32.50463

9 0.72653 0.222866 1.892897 20.63466 190.9521

10 0.391734 0.842283 6.228658 83.95071 975.2149

11 2.31915 5.342685 27.8432 288.8836 3931.816

Results obtained on:Dual Core 64-bit Athlon Processor, running red hat v4

Page 16: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

16 of 19

How Fast is it? (cont.)How Fast is it? (cont.)

For some small values of n and k, the cost of creating the universe outweighs the benefit.For large value of and k, the speedup of DLX is invaluable.

n k BackTrack (sec) DLX (sec) Ratio

6 1 0.483 0.2268 2.12963

7 1 0.33554 0.4393 0.763806

8 1 0.182767 0.21151 0.864106

9 1 1.259398 0.72653 1.733443

10 1 7.87423 0.391734 20.10096

11 1 50.535449 2.31915 21.7905

6 2 0.24244 0.488 0.496803

7 2 0.299878 0.17628 1.701146

8 2 2.58031 0.61398 4.202596

9 2 25.707705 0.222866 115.3505

10 2 200.944142 0.842283 238.5708

11 2 1885.451144 5.342685 352.9033

6 3 0.57941 0.27891 2.077408

7 3 1.431793 0.136313 10.50372

8 3 20.570099 0.5537 37.15026

9 3 308.67571 1.892897 163.0705

10 3 3415.678017 6.228658 548.3811

Page 17: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

17 of 19

Parallel ResultsParallel ResultsApproach to implementing with MPI

4 3 6 5 7

0 5 2 7 4 6 7

1 6 1 7 3 5 6

2 7 0 6 2 4 5

3 7 0 5 1 3 4

4 6 1 4 0 2 3

5 2 3 0 1

Current results indicate a 30% speedup on a 16 node clusterWe are investigating other approaches to achieve a

More appropriate speedup

Page 18: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

18 of 19

Logic ProgrammingLogic Programming Learning when we reach a dead end…Learning when we reach a dead end…

3D Queens3D Queens Can the DLX universe be extended to a 3D Can the DLX universe be extended to a 3D

full cover problemfull cover problem

Theoretical Chess PiecesTheoretical Chess Pieces Extending movement beyond straight linesExtending movement beyond straight lines

What’s Next?What’s Next?

Page 19: 1 of 19 Dancing Links and N + k Queens Funded by: Kentucky NSF EPSCoR: UKRF 3046884400-07-419 John Miller (millerj10@nku.edu) Dr. Doug Chatham Dr. Maureen

19 of 19

ReferencesReferences

[1] CHATHAM, R. D., DOYLE, M, FRICKE, G.H., SKAGGS, R.D., AND WOLFF, M. Separating queens on the chessboard

[2] KNUTH D.E. Dancing links. Millennial Perspectivesin Computer Science.