AI Lecture 8
AI Lecture 8
Artificial
Intelligence
Lecture 8
Basic Genetic Algorithm
Solution to a Few Problems using
GA
Eight Queens Problem
max_fitness = ( ( ( n- 1) * n) / 2)
=((7 * 8 )/ 2)=
28
Evaluation function
For every
two queues
does not equal the if
between thetherow difference add
differencebetween
fitness function.
the one tocolumns
the
1 2 3 4 5 6 7
1
2 1
3 1 1
4 1 1 0
5 0 1 1 1
6 1 1 1 1 0
7 0 1 1 1 0 1 2 7 3 4 6 5 8 1
8 1 0 1 1 1 1 1
Fitness= 22
5 5 4 4 1 2 1
Selection
• We sort the chromosomes in the Generation by
the fitness value .then select the half of the
generation with highest value of fitness function
and duplicate it
• neglect the half with a lowest value of fitness
function.
Cross over
One Point cross over
Ex:random cross over point=3
..,.,,,,131s11l1lsl214161 ..... 1 1 1 s 7 8 2 4
-- -- --
6
3
9arf'llt2
8
4
2
6 1
7
3S P>rtntl
3
---
6 8 2 7
---
1
1 I
....,,,1 3 5 1 4 6 8 2 7
O.lwenl I I i 81 I
! 2 6 4
17 I I
S
Mutation
Random point Random point
1 2
Before l1lsl6131sl214171
• · +
« C o p ytoc.hromosome
solution
Sorting the generation rom the highest value
of fitnessfunction tot e Joweront
= +1
25 26 27 28 29 30 31 32
(i.e., 64C8) possible 33 34 35 36 37 38 39 40
arrangements 41 42 43 44 45 46 47 48
it is a brute-force 49 so 51 52 53 54 55 56
computational 57 58 59 60 61 62 63 64
12 solutions
These are called
fundamental solutions
representatives of each are shown below.
11x8 + 1x4 = 92
(where the 8 is derived from four 90" rotational positions andtheir reflections, and the 4 is
derived from two 1so•rotational positions and their reflections).
fundamental solutions
..
....
..... . .. . ,.
.. ·•- ..
:;.- ;- .,
...
• • t • • ' • "
11'"11
' .
.-·
••II.•■
" •■" •■ 'II ' ■■■'
;•• • ■■:■ ■II.,•
' ••
·• ■ ■ l ! I .
■II■■'
11 :• ti
.... a J 1 ,
...
._ '
.......
.,
·•
•
..•
·•
• II ■ •
••
. . . .. '
·. :
.
'
fundamental
1 1 1
2 0 0
3 0 0
4 1 2
5 2 10
6 1 4
7 6 40
8 12 92
9 46 352
10 92 724
........... ....................
24 28,439,272,956,934 227,514,171,973,736
25 275,986,683,743,434 2,207,893,435,808,352
26 2,789,712,466,510,289 22,317,699,616,364,044
27 29,363,495,934,315,694 234,907,967,154,122,528
□