1 / 5

N-queens problem

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. N-queens as a CSP. Problem representation. N variables: Q1, …, QN

sora
Download Presentation

N-queens problem

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 on NxN chessboard

  2. N-queens as a CSP Problem representation • N variables: Q1, …, QN • Domain 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

  3. N-queens as a CSP More compact representation • N variables: Q1, …, QN • Domain of each variable is {1,2, …, N} (i-thqueen 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

  4. N-queens as a CSP Constraints • No queen can attack any other queen: • Vertically (for the compact representation explicit) • Horizontally: Qi ≠ Qj • Diagonally: |i-j| ≠|Qi-Qj|

More Related