Genetic Programming Sol PDF
Genetic Programming Sol PDF
BIS4435
Question 1
Question 2
1
BIS4435 2
Question 3
Consider the problem of finding the shortest route through several cities,
such that each city is visited only once and in the end return to the starting
city (the Travelling Salesman problem). Suppose that in order to solve this
problem we use a genetic algorithm, in which genes represent links between
pairs of cities. For example, a link between London and Paris is represented
by a single gene ‘LP ’. Let also assume that the direction in which we travel
is not important, so that LP = P L.
f (x) = (a + b) − (c + d) + (e + f ) − (g + h) ,
BIS4435 3
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.
Answer:
f (x1 ) = (6 + 5) − (4 + 1) + (3 + 5) − (3 + 2) = 9
f (x2 ) = (8 + 7) − (1 + 2) + (6 + 6) − (0 + 1) = 23
f (x3 ) = (2 + 3) − (9 + 2) + (1 + 2) − (8 + 5) = −16
f (x4 ) = (4 + 1) − (8 + 5) + (2 + 0) − (9 + 4) = −19
x2 = 8 7 1 2 6 6 0 1 O = 87123532
⇒ 1
x1 = 6 5 4 1 3 5 3 2 O2 = 6 5 4 1 6 6 0 1
ii) Cross the second and third fittest individuals using a two–point
crossover (points b and f ).
x1 = 6 5 4 1 3 5 3 2 O = 65921232
⇒ 3
x3 = 2 3 9 2 1 2 8 5 O4 = 2 3 4 1 3 5 8 5
iii) Cross the first and third fittest individuals (ranked 1st and 3rd)
using a uniform crossover.
BIS4435 4
x2 = 8 7 1 2 6 6 0 1 O = 27126201
⇒ 5
x3 = 2 3 9 2 1 2 8 5 O6 = 8 3 9 2 1 6 8 5
O1 = 8 7 1 2 3 5 3 2
O2 = 6 5 4 1 6 6 0 1
O3 = 6 5 9 2 1 2 3 2
O4 = 2 3 4 1 3 5 8 5
O5 = 2 7 1 2 6 2 0 1
O6 = 8 3 9 2 1 6 8 5
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
d) By looking at the fitness function and considering that genes can only
be digits between 0 and 9 find the chromosome representing the opti-
mal solution (i.e. with the maximum fitness). Find the value of the
maximum fitness.
Answer: No, the algorithm will never reach the optimal solution
without mutation. The optimal solution is xoptimal = 9 9 0 0 9 9 0 0. If
mutation does not occur, then the only way to change genes is by
applying the crossover operator. Regardless of the way crossover is
performed, its only outcome is an exchange of genes of parents at
certain positions in the chromosome. This means that the first gene in
the chromosomes of children can only be either 6, 8, 2 or 4 (i.e. first
genes of x1 , x2 , x3 and x4 ), and because none of the individuals in the
initial population begins with gene 9, the crossover operator alone will
never be able to produce an offspring with gene 9 in the beginning.
One can easily check that a similar problem is present at several other
positions. Thus, without mutation, this GA will not be able to reach
the optimal solution.
Question 5
Question 6
A budget ariline company operates 3 plains and employs 5 cabin crews. Only
one crew can operate on any plain on a single day, and each crew cannot
work for more than two days in a row. The company uses all planes every
day. A Genetic Algorithm is used to work out the best combination of crews
on any particular day.
BIS4435 6
Genes (crews) : A, B, C, D, E
Solution 1 : AB C
Solution 2 : AB D
··· ···
Solution 10 : CDE
Solution 1 : 11100
Solution 2 : 11010
··· ···
Solution 10 : 00111
As you can see, the same problem can be encoded in many different
ways.