N-queens problem Original problem: How to place 8 queens on an 8x8 chessboard so that no two queens...

5
N-queens problem Original problem: How to place 8 queens on an 8x8 chessboard so that no two queens attack each other N-queen problem: Generalization for N queens on NxN chessboard

description

N-queens as a CSP N variables: Q1, …, QN Domain of each variable is {1,2, …, N} (i-th queen is in i-th column, the domain specifies available rows) Q1 = 1, Q2 = 5, Q3 = 8, Q4 = 6 Q5 = 3, Q6 = 7, Q7 = 2, Q8 = 4 Representation has 8 8 ( ) possible assignments More compact representation

Transcript of N-queens problem Original problem: How to place 8 queens on an 8x8 chessboard so that no two queens...

Page 1: N-queens problem Original problem: How to place 8 queens on an 8x8 chessboard so that no two queens attack each other N-queen problem: Generalization for.

N-queens problem

Original problem:How to place 8 queens on an 8x8 chessboard so that no two queens attack each other

N-queen problem:Generalization for N queens on NxN chessboard

Page 2: N-queens problem Original problem: How to place 8 queens on an 8x8 chessboard so that no two queens attack each other N-queen problem: Generalization for.

N-queens as a CSP

N variables: Q1, …, QNDomain of each variable is {1,2,…, N2} (for each possible field)

Q1 = 1, Q2 = 15, Q3 = 21, Q4 = 32 Q5 = 34, Q6 = 44, Q7 = 54, Q8 = 59

Representation has 648 (281 474 976 710 656) possible assignments

Problem representation

Page 3: N-queens problem Original problem: How to place 8 queens on an 8x8 chessboard so that no two queens attack each other N-queen problem: Generalization for.

N-queens as a CSP

N variables: Q1, …, QNDomain of each variable is {1,2, …, N} (i-th queen is in i-th column, the domain specifies available rows)

Q1 = 1, Q2 = 5, Q3 = 8, Q4 = 6 Q5 = 3, Q6 = 7, Q7 = 2, Q8 = 4

Representation has 88 (16 777 216) possible assignments

More compact representation

Page 4: N-queens problem Original problem: How to place 8 queens on an 8x8 chessboard so that no two queens attack each other N-queen problem: Generalization for.

N-queens as a CSP

No queen can attack any other queen:

Vertically (for the compact representation explicit)Horizontally: Qi ≠ QjDiagonally: |i-j| ≠|Qi-Qj|

Constraints

Page 5: N-queens problem Original problem: How to place 8 queens on an 8x8 chessboard so that no two queens attack each other N-queen problem: Generalization for.