Upcoming SlideShare
×

# N queen

553 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
553
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
10
0
Likes
0
Embeds 0
No embeds

No notes for slide

### N queen

1. 1. N-queengenetic algorithm
2. 2. Empty board
3. 3. G0 1select (0(0,3,1,3
4. 4. (1,1,2,0)1
5. 5. (2,3,1,1)2
6. 6. (1,2,3,0)3
7. 7. 2fitness By counting number of attack queen for eachQueen.Basic fitness=n*(n-1)=12/2=60(0,3,1,3)1+1+0+2=4/2=2 fitness=6-2=41(1,1,2,0)1+2+1+0=4/2=2 fitness=6-2=42(2,3,1,1)1+1+1+2=5/2=2.5 fitness=6-2.5=3.5 and so on
8. 8. 3SelectionSelect 2 generation random or high fitness (0,3,1,3) (2,3,1,1 )Then choose same random index for two solution index=1Replacement array1 from index+1 to n-1 with array2(1,3)< == >(1,1)(0,3,1,1) (2,3,1,3)
9. 9. (0,3,1,1) (2,3,1,3)
10. 10. 4cross over2 generation random or high fitness (0,3,1,3) (2,3,1,1 )Then choose same random index for two solution index=2Replacement this element with corresponding element on the same index1< == > 1(0,3,1,3) (2,3,1,1 )
11. 11. 5mutation• Select random solutionFor example: (0,3,1,3) select a random index and replace this element with a random value from(0,1,2,3)Index =1 replacement with 2.: solution (0,2,1,3)
12. 12. When we finished this steps if fitness==0• Then I’ have a solution