09 Ga
09 Ga
Genetic Algorithms
BIS4435
Middlesex University, Dr. Roman V Belavkin, BIS4435, Lecture 9 1
OVERVIEW
1. Combinatorial Problems
2. Natural Selection
4. Fitness Functions
7. GA Algorithm
8. Why GA work?
9. Problem Example
Middlesex University, Dr. Roman V Belavkin, BIS4435, Lecture 9 2
Cairo
The problem becomes
b.... y .......................................
London.....................
London
bY
..........
... ...............
.........Tokyo ... ............ Tokyo
harder if we increase
*b
... ........... ... ............
... b .. ... ......... .........
... .............
bµ
... . ... ......... . .
...
. ......... ..
.... ......... ................ .....
ª
... ...
...
:
... ... ....... ..
the number of cities ... ......
..
... . .......... ..............
Ub
.
Ub ............... .... b
...
..
...
...
.....
. ... .............
.................... Hong-Kong ......... Hong-Kong
(n = 4, 5, . . .). Cairo Cairo
ª
. .... ..
...
...
... ........
..
.... .
............... .....
..... (n − 1)!
Ub ... ................
b
........ Hong-Kong
Cairo
(e.g. for n = 10, (10 − 1)! = 9! = 362, 880)
Middlesex University, Dr. Roman V Belavkin, BIS4435, Lecture 9 3
NATURAL SELECTION
FITNESS FUNCTION
Fitness function is simply another word for the utility function. It is
needed to compare different solutions (individuals) and choose the
better ones. As with utility, it returns a number such that if
f (x1 ) > f (x2 ), then x1 is preferable to x2 (x1 is ‘fitter’).
Fitness f (x)
6 Maximum fitness
x4
x1
a
a x6
x2
a
a x5
a
Population P (t) = {xt , . . . , xt }
1 6
x3
-
a
Individuals xi
Middlesex University, Dr. Roman V Belavkin, BIS4435, Lecture 9 8
EXAMPLE
b.... y .......................................
London..................... London
bY
..........
... ..........
... ............... ... ............ Tokyo
*
... .........Tokyo
........... ......... ..
.............
... b ...
. ... ...........
b ..
...
..
bµ
... .
. .
... ... ......... ... .
......... ................ .....
ª
... .. ...
.. ... ..
... .. ... ..
.
. .
:
... . .
.. ... ......... ...........
Ub
... . .... b
......... ..
Ub
... ......... .
... ............... ...........
............................. Hong-Kong Hong-Kong
Cairo Cairo
x1 x2
Thus, fitness is f (x) = −length(x) and
So, we choose x1
Middlesex University, Dr. Roman V Belavkin, BIS4435, Lecture 9 9
EXAMPLE: TSP
bµ
C Cairo ...
...
.. ... .........
......... ..
...
. .
......... ................ .....
ª
... ...
...
:
... ... ...... .
... ......
..
... . .......... ..............
Ub
.
Ub
.
............... ...
...
.
...
...
...
...
. ... ..............
b
.................... Hong-Kong ......... Hong-Kong
H Hong–Kong Cairo Cairo
EXAMPLE: TIMETABLING
We can assign numbers to a teacher, to a time slot and to a room:
SELECTION
• After the fitness of the individuals of the whole population has
been calculated, we should pick some of them for reproduction.
This process is called selection.
CROSSOVER
P1 = 101 0010 O1 = 1 0 1 1 0 0 1
⇒
P2 = 011 1001 O2 = 011 0010
Middlesex University, Dr. Roman V Belavkin, BIS4435, Lecture 9 15
MUTATION
A randomly chosen gene (or several genes) is changed to some other
gene (mutate). For example, mutation of genes 3 and 5 in the
offspring O1 will give:
O1 = 1 0 1 1 0 0 1 ⇒ O1 = 1 0 0 1 1 0 1
2. Encode solutions;
4. Repeat
WHY GA WORK?
• Fitness and selection filter out bad solutions from good ones.
• Offspring inherit properties of mostly good solutions.
Middlesex University, Dr. Roman V Belavkin, BIS4435, Lecture 9 18
VARIATIONS IN GA
APPLICATION OF GA
• Transport scheduling
• Timetabling
• Circuit design
• Route optimisation (TSP)
For some classes of problems there are other specific methods that
can perform better than GA on these problems. However, when no
special method is known for your problem, then try GA and see if it
can give you a good result. GA are easily programmable and can be
applied to a wide range of problems.
Middlesex University, Dr. Roman V Belavkin, BIS4435, Lecture 9 20
PROBLEM EXAMPLE
Consider a GA with chromosomes consisting of six genes
xi = abcdef , and each gene is a number between 0 and 9.
Suppose we have the following population of four chromosomes:
x1 = 4 3 5 2 1 6 x2 = 1 7 3 9 6 5
x3 = 2 4 8 0 1 2 x4 = 9 0 8 1 2 3
and let the fitness function be f (x) = (a + c + e) − (b + d + f ).
1. Sort the chromosomes by their fitness
SOLUTION 1
f (x1 ) = (4 + 5 + 1) − (3 + 2 + 6) = −1
f (x2 ) = (1 + 3 + 6) − (7 + 9 + 5) = −11
f (x3 ) = (2 + 8 + 1) − (4 + 0 + 2) = 5
f (x4 ) = (9 + 8 + 2) − (0 + 1 + 3) = 15
SOLUTION 2
x4 = 908 123 O1 = 9 0 8 0 1 2
⇒
x3 = 248 012 O2 = 2 4 8 1 2 3
x3 = 24 80 12 O3 = 2 4 5 2 1 2
⇒
x1 = 43 52 16 O4 = 4 3 8 0 1 6
Middlesex University, Dr. Roman V Belavkin, BIS4435, Lecture 9 23
SOLUTION 3
f (O1 ) = (9 + 8 + 1) − (0 + 0 + 2) = 16
f (O2 ) = (2 + 8 + 2) − (4 + 1 + 3) = 4
f (O3 ) = (2 + 5 + 1) − (4 + 2 + 2) = 0
f (O4 ) = (4 + 8 + 1) − (3 + 0 + 6) = 4