You are on page 1of 11

GENETIC ALGORITHM

PART II
GENETIC ALGORITHM TO FIND RANDOM WORDS

A word is specified as the target, for example: 'BASUKI’.


If each letter is assigned a value in alphabetical order, then
the target can be expressed as a numerical quantity:
TARGET = [ 2 1 19 21 11 9]

The computer will generate a word with the same number of


letters as the target randomly, continuously until it gets the
same word as the target word.
• Individual is a word that emerges from the random
process, for example: AGHSQE or [1 7 8 19 17 5]
• An individual has n integer genes, each of which
represents an alphabetical number.
• The fitness value is the inverse of the difference

DEFINITION OF between the value of the word that appears (individual)


and the specified target. For example, the word that
INDIVIDUAL AND FITNESS appears: AGHSQE and the target is BASUKI then, the
difference value:
E = |1-2| + |7-1| + |8-18| + |19-21| + |17-11| + |5-9| =
1+6+10+2+6+4 = 29
Fitness = (26)(6) - 29 = 156-29 = 127
• Fitness defined:
fitness =
where g(k)n is the n-th gene of the k-th individual and tn
is the n-th gene of the target individual
INITIAL POPULATION
GENERATION

The initial population is


generated by generating all the
letters in a number of words
(individuals).
• Selection is done using the roulette-wheel.
• Cross-over, is done by exchanging selected genes
between two genes parent, as in binary genes.

SELECTION, CROSS-
OVER & MUTATION
• Mutations were carried out by re-randomizing the
values 1-26 of the gene that mutated.
GENETIC ALGORITHM
RESULTS
CASE STUDY GA IN TSP

Traveling Salesman Problem (TSP) is a problem where a


salesman must visit all cities where each city is only
visited once, and must return to his hometown. The
main problem faced by a TSP is how to find the
shortest route of a salesman's journey with minimum
costs.
CASE STUDY CONT…
1 2 3 4 5 6

1 0 1450 47 643 223 62


• The table shows an example of an illustration of
2 1450 0 1417 833 1634 4451
the result of converting point coordinate data x, y
into distances between cities or points, where there 3 47 1417 0 605 233 3034

are 6 cities in it. 4 643 833 605 0 807 3624

5 223 1634 233 807 0 2817

6 62 4451 3034 3624 2817 0


POPULATION
Chromosome Route

1 (5-1-2-4-3-6)
Chromosomes contain information on the solution
of the many possible solutions to the problem at 2 (1-4-5-3-6-2)

hand. In TSP problems, chromosomes are shown as


3 (3-1-2-5-6-4)
travel routes or can be said in one individual
consisting of several genes which are represented 4 (3-5-2-1-4-6)

in the form of numbers. Where each number


5 (2-1-3-5-4-6)
represents the points (places) of the destination to
be traversed
HOW TO SOLVE TSP PROBLEM WITH
GA?
1. Evaluate chromosomes (individual)
Tip: After the chromosomes are formed, each chromosome is calculated for
its fitness value.
You must define fitness formula first!

2. Chromosome Selection
Tip: you can use the roulette wheel method

3. Crossover
Tip: At this stage the chromosomes cannot have the same genes or cities.
Therefore, an ordered crossover method can be used by randomly selecting
several genes in parent 1, then the remaining genes in parent 1 will be filled
by parent 2 where the genes cannot be the same.

Parent 1 5 1 2 4 3 6
Parent 2 2 1 3 5 4 6

Parent 1 5 1 3 5 3 6
Parent 2 2 1 2 4 4 6
CROSSOVER RESULT
HOW TO SOLVE TSP PROBLEM WITH
GA? Cont…
Chromosome Distance Fitness

4. Mutation (5-1-2-4-3-6) 6145 0,00016273


Tip: After the crossover occurs, the chromosomes will be mutated according
(1-4-5-3-6-2) 9168 0,00010908
to the probability of mutation using the reciprocal exchange mutation
method, namely by choosing two positions at random and then exchanging
(3-5-2-4-1-6) 3405 0,00029369
the two values.
(3-5-2-1-4-6) 7584 0,00013186
Children 3 1 2 4 5 6

Mutation 3 5 2 4 1 6 (2-1-3-5-4-6) 6161 0,00016231

5. Regeneration
Tip: After the mutation process is complete, the result of the process
becomes a new population or new generation. Then the generation will be
reprocessed from the first stage to the end. In Table is an example of a new
population or new generation.

You might also like