Genetic Algorithms (GA)
Genetic Algorithms (GA)
1
What is genetic algorithm?
Genetic Genetic
Programming Algorithms
q1=2
q2=3
q3=2
q4=2
q5=4
q6=2
q7=2
q8=3
Total non-attacking pair: 24+23+20+11=78
Th-15, last number not count because 11 less than
15.
Now—
1. (24/78)*100% = 31%
2.(23/78)*100% =29%
3.(20/78)* 100% = 26%
Genetic Algorithms
Figure 4.15 The genetic algorithm. The initial population in (a) is ranked by the fitness
function in (b), resulting in pairs for mating in (c). They produce offspring in (d), which
are subject to mutation in (e).
f(x) = (a + b) - (c + d) + (e + f) - (g + h)
and let the initial population consist of four individuals with the following
chromosomes:
x1 = 6 5 4 1 3 5 3 2
x2 = 8 7 1 2 6 6 0 1
x3 = 2 3 9 2 1 2 8 5
x4 = 4 1 8 5 2 0 9 4
a) Evaluate the fitness of each individual, showing all your workings, and
arrange them in order with the fittest first and the least fit last.
f(x1) = (6 + 5) - (4 + 1) + (3 + 5) - (3 + 2) = 9
f(x2)=23
f(x3)=-16
f(x4)=-19
The order is x2, x1, x3 and x4.
29
Genetic Algorithms
f(x) = (a + b) - (c + d) + (e + f) - (g + h)
x1 = 6 5 4 1 3 5 3 2
x2 = 8 7 1 2 6 6 0 1
x3 = 2 3 9 2 1 2 8 5
x4 = 4 1 8 5 2 0 9 4
b. Cross the fittest two individuals using one–point crossover at the middle point.
30
Genetic Algorithms
f(x) = (a + b) - (c + d) + (e + f) - (g + h)
x1 = 6 5 4 1 3 5 3 2
x2 = 8 7 1 2 6 6 0 1
x3 = 2 3 9 2 1 2 8 5
x4 = 4 1 8 5 2 0 9 4
c.Cross the first and third fittest individuals (ranked 1st and 3rd) using a uniform crossover.
In the simplest case uniform crossover means just a random exchange of genes between two
parents. For example, we may swap genes at positions a, d and f of parents x2 and x3:
31
Genetic Algorithms
x1 = 6 5 4 1 3 5 3 2
f(x) = (a + b) - (c + d) + (e + f) - (g + h) x2 = 8 7 1 2 6 6 0 1 The new population is:
x3 = 2 3 9 2 1 2 8 5
x4 = 4 1 8 5 2 0 9 4
f(O1) = (8 + 7) - (1 + 2) + (3 + 5) - (3 + 2) = 15
f(O2) = (6 + 5) - (4 + 1) + (6 + 6) - (0 + 1) = 17
f(O3) = (6 + 5) - (9 + 2) + (1 + 2) - (3 + 2) = -2
f(O4) = (2 + 3) - (4 + 1) + (3 + 5) - (8 + 5) = -5
f(O5) = (2 + 7) - (1 + 2) + (6 + 2) - (0 + 1) = 13
f(O6) = (8 + 3) - (9 + 2) + (1 + 6) - (8 + 5) = -6
32