Professional Documents
Culture Documents
CS-451
{
initialize population;
evaluate population;
while TerminationCriteriaNotSatisfied
{
select parents for reproduction;
perform crossover and mutation;
evaluate population;
}
}
What is Genetic Algorithm
The working of a genetic algorithm is also derived from biology, which is
as shown
Genetic Algorithm
Population − It is a subset of all the possible (encoded) solutions to the given
problem.
Fitness Function − A fitness function takes the solution as input and produces the
suitability of the solution as the output.
Genetic Operators − These alter the genetic composition of the offspring. These
include crossover, mutation etc.
Example : Knapsack Problem
you are going to spend a month in the wilderness. Only thing you are
carrying is the backpack which can hold a maximum weight of 30 kg.
Now you have different survival items, each having its own “Survival
Points” (which are given for each item in the table). So, your objective is
maximise the survival points.
Example : Knapsack Problem
Population: Population is composed of individuals and individuals have
chromosomes
In GA, chromosomes are binary strings, where for this problem 1 means
that the following item is taken and 0 means that it is dropped.
So, for this problem, our chromosome will be considered as more fit when it contains
more survival points. Therefore chromosome 1 is more fit than chromosome 2.
Genetic Algorithm
population
10010101110101001010011101101110111111101
Genetic Algorithm
What's the Crossover Rate?
This is simply the chance that two chromosomes will swap their bits. Crossover is
performed by selecting a random gene along the length of the chromosomes and
swapping all the genes after that point.
Genetic Algorithm
One Point Crossover
In this one-point crossover, a random crossover point is selected
and the tails of its two parents are swapped to get new off-springs.
Swap Mutation
In swap mutation, we select two positions on the chromosome at
random, and interchange the values.
Genetic Algorithm
Mutation Operators
Inversion Mutation
In inversion mutation, we select a subset of genes like in scramble
mutation, but instead of shuffling the subset, we merely invert the
entire string in the subset.
Genetic Algorithm
Example:
So, given the target number 17, the sequence 6+5*4/2+1 would be
one possible solution.
Genetic Algorithm
Stage 1: Encoding
This will represent a gene. Each chromosome will be made up of several genes.
Four bits are required to represent the range of characters used as gene:
0: 0000
1: 0001
2: 0010
3: 0011
4: 0100
5: 0101
6: 0110
7: 0111
8: 1000
9: 1001
+: 1010
-: 1011
*: 1100
/: 1101
Genetic Algorithm
The solution mentioned above for 17, ' 6+5*4/2+1' would be
represented by nine genes like so:
6 + 5 * 4 / 2 + 1
011010100101110001001101001010100001
Genetic Algorithm
Stage 2: Deciding on a Fitness Function
Give a higher fitness score the closer a chromosome comes to solving the problem.
A fitness score can be assigned that's inversely proportional to the difference
between the solution and the value a decoded chromosome represents.
011010100101110001001101001010100001 has
As it stands, if a solution is found, a divide by zero error would occur as the fitness
would be 1/(42-42).
This is not a problem however as we have found what we were looking for... a
solution. Therefore a test can be made for this occurrence and the algorithm halted
accordingly.
Example: Optimization of a Mathematic Function
Genetic algorithm can be used to find a maximum value of a
mathematic function.
f(x) = sin(x)
c1 = (9) = 1001
c2 = (3) = 0011
c3 = (10) =1010
c4 = (5) =0101
We will assign fitness score from 0 to 100, where 0 is the least fit and
100 is the most fit.
C1 = 10 | 01
C2 = 00 | 11
C5 = 1011
C6 = 0001
Example: Optimization of a Mathematic Function
C1 = 100 | 1
C3 = 101 | 0
C7 = 1000
C8 = 1011
Example: Optimization of a Mathematic Function
This generation has produced two extremely fit chromosomes and two very unfit
chromosomes.
At this point, the termination criteria would probably determine that the run could
stop. Otherwise, the algorithm will continue to run