polynomial time algorithms for the n-queen problem rok sosic and jun gu

22
Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

Upload: danny-dearborn

Post on 31-Mar-2015

215 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

Polynomial Time Algorithms for the N-Queen Problem

Rok sosic and Jun Gu

Page 2: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

Outline

N-Queen Problem Previous Works Probabilistic Local Search Algorithms

QS1, QS2, QS3 and QS4 Results

Page 3: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

N-Queen Problem

A classical combinatorial problem n x n chess board n queens on the same board Queen attacks other at the same row, column

or diagonal line No 2 queens attack each other

Page 4: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

A Solution for 6-Queen

Page 5: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

Previous Works

Analytical solution Direct computation, very fast Generate only a very restricted class of

solutions Backtracking Search

Generate all possible solutions Exponential time complexity Can only solve for n<100

Page 6: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

QS1

Data Structure The i-th queen is placed at row i and column queen[i]

1 queen per row The array queen must contain a permutation of

integers {1,…,n} 1 queen per column

2 arrays, dn and dp, of size 2n-1 keep track of number of queen on negative and positive diagonal lines

The i-th queen is counted at dn[i+queen[i]] and dp[i-queen[i]]

Problem remains Resolve any collision on the diagonal lines

Page 7: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

QS1

Pseudo-code

Page 8: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

QS1

Gradient-Based Heuristic

Page 9: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

QS2

Data Structure Queen placement same as QS1 An array attack is maintained

Store the row indexes of queens that are under attack

Page 10: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

QS2

Pseudo-code

Page 11: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

QS2

Reduce cost of bookeeping

Go through the attacking queen only

C2=32 to maximize the speed for small N, no effect on large N

Page 12: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

QS3

Improvement on QS2 Random permutation generates

approximately 0.53n collisions Conflict-free initialization

The position of a new queen is randomly generated until a conflict-free place is found

After a certain of queens, m, the remaining c queens are placed randomly regardless of conflicts

Page 13: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

QS4

Algorithm same as QS1 Initialization same as QS4 The fastest algorithm

3,000,000 queens in less than one minute

Page 14: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

Results – Statistics of QS1Collisions for random permutation

Max no. and min no. of queens on the most populated diagonal in a random permutation

Permutation Statistics

Swap Statistics

Page 15: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

Results – Statistics of QS2

Permutation Statistics

Swap Statistics

Page 16: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

Results – Statistics of QS3

Swap Statistics

Number of conflict-free queens during initialization

Page 17: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

Results – Time Complexity

Page 18: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

Results – Time Complexity

Page 19: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

Results – Time Complexity

Page 20: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

Results – Time Complexity

Page 21: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

Results – Time Complexity

Page 22: Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu

References

R. Sosic, and J. Gu, “A polynomial time algorithm for the n-queens problem,” SIGART Bulletin, vol.1(3), Oct. 1990, pp.7-11.

R. Sosic, and J. Gu, “Fast Search Algorithms for the N-Queens Problem,” IEEE Transactions on Systems, Man, and Cybernetics, vol.21(6), Nov. 1991, pp.1572-1576.

R. Sosic, and J. Gu, “3,000,000 Queens in Less Than One Minute,” SIGART Bulletin, vol.2(2), Apr. 1991, pp.22-24.