Genetic Algorithm Artificial Intelligence

LamisaNoor 26 views 21 slides Sep 17, 2024
Slide 1
Slide 1 of 21
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21

About This Presentation

genetic algorithm


Slide Content

1) Introducing the 4-Queen problem
2) Activity: Solving 4-Queen problem using artifacts
3) Solution of 4-Queen problem in Backtracking approach
4) Demerits of Backtracking approach
5) Introducing 8-Queen problem
6) Discussion on Genetic Algorithm
7) Solution of 8-Queen problem using GA
8) Conclusion
Presentation Outline:

Onceuponatime,therewasagreatkinginIndia.However,it
wasamatterofshamethathehad4Queens.TheQueenswere
soarrogantandtheydidn’tevenwantseeoneanother.
Therefore,theKingbuiltacastleof4x4rooms.However,he
couldn’tfindwaythetoplacethe4Queensin4separaterooms,
sothattheycouldn’tseeeachothers.
Would, you please help the King to
place the Queens? Avoid placing
two Queens in a same row, same
column and even same diagonal
rooms.
The 4-Queen Problem

Therefore,thekingcalledProfessorofanUniversityto
solvethe4-Queenproblem.AndProfessorsolvedthe
4-Queenprobleminbacktrackingapproach.
Complexity:NQueens:O(N!)
Solution of the 4-Queen Problem
Using Backtracking Approach

One month later, Professor received a call from the great
King to solve his 5-Queen problem. Professor, solved the 5-
Queen problem in backtracking approach.
The 5-Queen Problem

Solution of the 5-Queen Problem
Using Backtracking Approach

Fortunately,onemonthlater,theKingrequestedtheprofessortosolve
6-Queenproblem.TheprofessorthoughtthattheKingmayrequesthim
tosolve16-Queenproblemwithinnext10months.
Backtrackingapproachwillnotbeefficienttosolvethe8or16-Queen
problems.
Therefore,professorinventedGeneticAlgorithmtosolvethen-Queen
problem.
6-Queen Problem

8-Queen Problem

Genetic Algorithm
Thegeneticalgorithmisamethodforsolvingbothconstrainedandunconstrained
optimizationproblemsthatisbasedonnaturalselection,theprocessthatdrives
biologicalevolution.
John Holland introducedGenetic Algorithm(GA)
Darwin’s theoryof evolution

John Holland introducedGenetic Algorithm(GA)
Darwin’s theoryof evolution

GA: PROCEDURE

START
Generate the initial population
Compute fitness
REPEAT
Selection
Crossover
Mutation
Compute fitness
UNTIL population has converged
STOP
Pseudo-code of GA:

John Holland introducedGenetic
Algorithm(GA)
Darwin’s theoryof evolution
Formulation of Genetic
Algorithm
3 8 4 7 2 3 2 53 8 5 7 1 6 1 5
Fitness function: number of non-attacking pairs of queens
Maximum number of attacking pairs: 8 ×7/2 = 28
[Q1 Q2]
[Q1 Q3]
[Q1 Q4]
[Q1 Q5]
[Q1 Q6]
[Q1 Q7]
[Q1 Q8]
………
[Q8 Q7]
3 8 4 7 2 3 2 5
3 8 5 7 1 6 1 5
Fitness=28-7=21 Fitness=28-4=24
Chromosome of Father:
Chromosome of Mother:

Crossover:
3 8 4 7 2 3 2 5
3 8 5 7 1 6 1 5
Chromosome from Father:
Chromosome from Mother:
Crossover point
3 8 4 7 1 6 1 5
3 8 5 7 2 3 2 5
Offspring 1:
Offspring2:
3 8 4 7 2 3 2 5
3 8 5 7 1 6 1 5
Chromosome of Father:
Chromosome of Mother:
3 8 4 7 2 3 2 5
3 8 5 7 1 6 1 5
2 4 4 1 5 1 2 4
3 2 5 4 3 2 1 3

Mutation:
3 8 4 7 1 6 1 5
3 8 5 7 2 3 2 5
Offspring 1:
Offspring2:
Before Mutation:
3 8 4 7 1 6 2 5
3 8 6 7 2 3 2 5
Offspring 1:
Offspring2:
After Mutation:
3 8 4 7 1 6 2 53 8 6 7 2 3 2 5
Fitness=28-0=28 Fitness=28-7=21
Offspring 1: Offspring2:

GENETIC ALGORITHMS
•Fitness function: number of non-attacking pairs of queens (min = 0, max = 8 ×7/2 = 28)
•24/(24+23+20+11) = 31%
•23/(24+23+20+11) = 29% etc

John Holland introducedGenetic
Algorithm(GA)
Darwin’s theoryof evolution
Solution of 8-Queen Problem
using Genetic Algorithm

The 4-Queen Problem
Fitness function: number of non-attacking pairs of queens
What is the Maximum fitness value: ????

Therefore,thekingcalledProfessorJohnHollandofthe
UniversityofMichigantosolvethe4-Queenproblem.
Andsolvedthe4-Queenprobleminbacktracking
approach.
Complexity:NQueens:O(N!)
GeneticAlgorithmscomplexityisO(g(nm+nm+n))withg
thenumberofgenerations,nthepopulationsizeandm
thesizeoftheindividuals.Thereforethecomplexityison
theorderofO(gnm))
4-Queen Problem Using
Backtracking vs GA Approach

Try to Solve the 4-Queen Problem Using GA?
Initial Population

GA: ANALYSIS
Tags