0% found this document useful (0 votes)
33 views

Lec2 Genetic Algorithm

Uploaded by

maymuna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Lec2 Genetic Algorithm

Uploaded by

maymuna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Genetic Algorithm

Dr. Md. Golam Rabiul Alam


Associate Professor, CSE dept., BRACU
Presentation Outline:

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
The 4-Queen Problem

Once upon a time, there was a great king in India. However, it


was a matter of shame that he had 4 Queens. The Queens were
so arrogant and they didn’t even want see one another.
Therefore, the King built a castle of 4 x 4 rooms. However, he
couldn’t find way the to place the 4 Queens in 4 separate rooms,
so that they couldn’t see each others.

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.
Solution of the 4-Queen Problem
Using Backtracking Approach

Therefore , the king called Professor of an University to


solve the 4-Queen problem. And Professor solved the
4-Queen problem in backtracking approach.

Complexity: NQueens : O(N!)


The 5-Queen Problem

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.
Solution of the 5-Queen Problem
Using Backtracking Approach
6-Queen Problem

Fortunately, one month later, the King requested the professor to solve
6-Queen problem. The professor thought that the King may request him
to solve 16-Queen problem within next 10 months.

Backtracking approach will not be efficient to solve the 8 or 16-Queen


problems.

Therefore, professor invented Genetic Algorithm to solve the n-Queen


problem.
8-Queen Problem
John Holland introduced Genetic Algorithm (GA)

Genetic Algorithm Darwin’s theory of evolution

The genetic algorithm is a method for solving both constrained and unconstrained
optimization problems that is based on natural selection, the process that drives
biological evolution.
John Holland introduced Genetic Algorithm (GA)
Darwin’s theory of evolution
GA: PROCEDURE
Pseudo-code of GA:

START
Generate the initial population
Compute fitness
REPEAT
Selection
Crossover
Mutation
Compute fitness
UNTIL population has converged
STOP
Formulation of Genetic John Holland introduced Genetic
Algorithm (GA)
Darwin’s theory of evolution
Algorithm

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]
3 8 4 7 2 3 2 5 3 8 5 7 1 6 1 5 [Q1 Q8]
Fitness=28-7=21 Fitness=28-4=24 ………
[Q8 Q7]
Chromosome of Father: 3 8 4 7 2 3 2 5

Chromosome of Mother: 3 8 5 7 1 6 1 5
Crossover: Chromosome of Father: 3 8 4 7 2 3 2 5

Chromosome of Mother: 3 8 5 7 1 6 1 5
Chromosome from Father: 3 8 4 7 2 3 2 5

Chromosome from Mother: 3 8 5 7 1 6 1 5

Offspring 1: 3 8 4 7 1 6 1 5
Crossover point

Offspring2: 3 8 5 7 2 3 2 5

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:
Before Mutation:
Offspring 1: Offspring2:
Offspring 1: 3 8 4 7 1 6 1 5

Offspring2: 3 8 5 7 2 3 2 5

After Mutation:

Offspring 1: 3 8 4 7 1 6 2 5
3 8 4 7 1 6 2 5 3 8 6 7 2 3 2 5
Offspring2: 3 8 6 7 2 3 2 5 Fitness=28-0=28 Fitness=28-7=21
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
Solution of 8-Queen Problem John Holland introduced Genetic
Algorithm (GA)
using Genetic Algorithm Darwin’s theory of evolution
The 4-Queen Problem

Fitness function: number of non-attacking pairs of queens

What is the Maximum fitness value: ????


4-Queen Problem Using
Backtracking vs GA Approach

Therefore , the king called Professor John Holland of the


University of Michigan to solve the 4-Queen problem.
And solved the 4-Queen problem in backtracking
approach.

Complexity: NQueens : O(N!)

Genetic Algorithms complexity is O(g(nm + nm + n)) with g


the number of generations, n the population size and m
the size of the individuals. Therefore the complexity is on
the order of O(gnm))
Try to Solve the 4-Queen Problem Using GA?

Initial Population
GA: ANALYSIS
Order crossover is similar to that of Two Point crossover,
but in the case of Order Crossover, a part from first parent
is copied to offspring chromosome and the remaining values
are placed in the offspring by the order by which they
appear in second parent.
PARTIALLY MAPPED CROSSOVER(PMX): It is
similar to that of two – point crossover. In this method, two crossover
points are chosen among two parents and the genes between two
crossover points are exchanged, while remaining genes are filled by
partial mapping.
CYCLE CROSSOVER (CX):
In cycle crossover, a gene from one parent will be copied into an offspring, but it should inherit the position
of the other parent.
SELECTION:

METHOD 1: RECURSIVE ADAM & EVE: Killing all population


except the two fittest individuals.
METHOD 2: KILL HALF OF THE POPULATION:
Killing the worst half of the population.
METHOD 3: THE GREAT TOURNAMENT
 A tournament essentially consists in selecting randomly a
bunch of individuals and make them fight; and the result
of this battle will decide which of them survives the purge.

 The most obvious way to decide the winner is to compare


its fitness value; the victorious fighter would be he who
was the greater fitness.
MUTATION:

• Flip-Bit
• Swapping
Conclusion
Application areas of GA:
 Game programming

 Cloud resource allocation

 Job scheduling of operating systems

 Channel assignment in communication system

 Combinatorial optimization

 Creative design (NASA antenna)

 Operational research
REFERENCES
• Fraser, Alex; Burnell, Donald (1970). Computer Models in Genetics. New York: McGraw-Hill.
• Crosby, Jack L. (1973). Computer Simulation in Genetics. London: John Wiley & Sons.
• UC Berkeley's Hans Bremermann, professor emeritus and pioneer in mathematical biology, has died at
69
• Fogel, David B. (editor) (1998). Evolutionary Computation: The Fossil Record. New York: IEEE Press.
• Barricelli, Nils Aall (1963). "Numerical testing of evolution theories. Part II. Preliminary tests of
performance, symbiogenesis and terrestrial life". Acta Biotheoretica (16): 99–126.
• How to easily find the optimal solution without exhaustive search using Genetic Algorithms
RESEARCH

You might also like