AI L5 - Genetic Algorithms
AI L5 - Genetic Algorithms
1 2 3
4 5 6
1
7/24/2024
Fibonacci Sort DFS Dynamic BFS Finonacci Newton Evolutionary strategies Genetic algorithms
Programming
Parallel Sequential • The concepts of Genetic Algorithms are directly derived
Tabu Search Hill Simulated Evolutionary from natural evolution.
Centralized Distributed Steady-state Generational
Climbing Anealing Algorithms
• In the early 70’s a person named John Holland
Genetic Genetic introduced the concept of genetic algorithms (Holland,
Programming Algorithms 7 1975).
7 8 9
Introduction to Genetic
Algorithms
10 11 12
2
7/24/2024
15
13 14 15
http://ib-poland.virtualave.net/ee/genetic1/3geneticalgorithms.htm
• Like in real life, the process is not done on the solution • The idea is that you represent the solution to your
(individual), but on its representation (chromosome). problem in a structured way
• the simplest is a string
• this is not necessarily the best representation, but it is simple to explain
• Therefore we don’t use knowledge we have about the
problem.
• Very often, based on strings. (but not always), like biological • We then build a population of random solutions and
chromosomes. let them ”breed” using genetic operators
• at each generation we apply ” survival of the
fittest ” and hopefully better and better solutions evolve
over time
• the best solutions are more likely to survive and more likely
to produce even better solutions
16 17 18
3
7/24/2024
Each cycle of GA produces a new population of The cycles run while the performance is improved
1. Population individuals with better performance Once the performance becomes stable (e.g., all roses
of individuals In the example of selecting red roses, this means became red), the GA terminates
that the proportion of red roses becomes greater
and grey less (because the grey roses are not Termination
4. Genetic 2. Evaluation of
Performance
selected for the next seed) point
Manipulation performance
3. Selection of Best
best individuals Cycles
19 20 21
19 20 21
A population is often named generation Individuals can be coded into bit-strings which are Typically, genetic manipulation on selection of
A new population of individuals, created as a result also named chromosomes individuals consists of 2 operators: crossover
of the genetic manipulation, is often called offspring The bits are often named genes and mutation
The performance of individuals in the given An example of string (chromosome) consisting of 5 The crossover operator recombines bits of two
environment are also called fitness bits (genes): selected strings at the crossover point
For example, if our aim is select horses for racing, The crossover points are assigned randomly among
the performance (fitness) can be evaluated in terms 10010
the bits of strings
of speed
One or more crossover points can be given
22 23 24
22 23 24
4
7/24/2024
25 26 27
25 26 27
An example of the recombination of 2 parent The mutation operator alters one or more
strings into 2 offspring when the crossover point is bits at the randomly selected positions of ■ Assume a function f(x) = x2 which should be
given after the 3rd bit; the string maximised in the interval 0 ≤ x ≤ 31
So that the 4th and 5th bits are recombined An example of mutation at the 4th bit is ■ In this example the fitness function is function
below f(x) itself - the larger its values, the better its
Crossover point fitness
■ The number of bits in strings must be equal to
Parents: 100 10 010 00 Parent: 10010 5 because x varies between 0 and 31
28 29 30
28 29 30
5
7/24/2024
4 10011 19 361
Sum 1170
31 32 33
31 32 33
34 35 36
34 35 36
6
7/24/2024
37 38 39
37 38 39
40
40 41 42
7
7/24/2024
Stochastic operators
Introduction to Genetic
Algorithms
43 44 45
4
6
47 48
46 47 48
8
7/24/2024
49 50 51
49 50 51
P2 (1 1 0 1 1 0 1 0) (1 1 0 0 1 0 0 0) C2
Before: (1.38 -69.4 326.44 0.1)
1 2 3 4 5 6 7 After: (1.38 -67.5 326.44 0.1) Crossover is a critical feature of genetic
1 0 1 1 0 1 0
■ Causes movement in the search space algorithms:
(local or global) – It greatly accelerates search early in evolution of a
population
■ Restores lost information to the population – It leads to effective combination of schemata
(subsolutions on different chromosomes)
52 53 54
52 53 54
9
7/24/2024
GA - Evolution Population
Reproduction
Generation X Generation X+1
children population
reproduction
Mutation
parents
Chromosomes could be:
population – Bit strings (0101 ... 1100)
– Real numbers (43.2 -33.1 ... 0.0 89.2)
Parents are selected at random with selection – Permutations of element (E11 E3 E7 ... E1 E15)
chances biased in relation to chromosome – Lists of rules (R1 R2 R3 ... R22 R23)
evaluations Selection – Program elements (genetic programming)
M=10 Cross-over – ... any data structure ...
55 56 57
55 56 57
58 59 60
58 59 60
10
7/24/2024
61 62 63
61 62 63
Introduction to Genetic
Algorithms
64 65 66
11
7/24/2024
GA overview (cont)
6
7
Introduction to Genetic
Algorithms
67 68 69
120
120
100
100
80
80
y 60
y 60
40
40
20
20
0
0 0 10 20 30 40 50 60 70 80 90 100
0 10 20 30 40 50 60 70 80 90 100
x
x
70 71 72
12
7/24/2024
73 74 75
A B C D E Offspring:
Step 2: Selection •Offspring 1: A-B-E-D-C
A 0 2 9 10 7 •Offspring 2: A-D-C-B-E
We use roulette wheel selection to choose parents for reproduction. The
B 2 0 6 4 3 probability of selecting a chromosome is inversely proportional to its tour
C 9 6 0 8 5 distance. Crossover between C2 (A-C-B-E-D) and C4 (A-E-D-C-B):
Assume the crossover points are between the first and third cities:
D 10 4 8 0 6
Fitness •Parent 1: A-C-B-E-D
E 7 3 5 6 0 Chromosome Distance Probability
(1/Distance) •Parent 2: A-E-D-C-B
C1 27 0.037 0.364
Offspring:
C2 38 0.026 0.255 •Offspring 3: A-C-D-E-B
C3 31 0.032 0.291 •Offspring 4: A-E-B-C-D
C4 36 0.028 0.290
76 77 78
13
7/24/2024
Step 6: Termination
Step 4: Mutation
We repeat the selection, crossover, mutation, and replacement steps for a predefined
We apply mutation to introduce diversity. Assume a mutation rate of 0.1 (10%). number of generations or until a stopping criterion is met (e.g., a solution with a satisfactory
We'll swap two cities in each chromosome.
Offspring 1 (A-B-E-D-C) with mutation between cities B and D:
fitness is found).
Generation 0
Overview of Performance
•A-D-E-B-C
Offspring 2 (A-D-C-B-E) with mutation between cities C and B: C1: A-B-C-D-E-A (27)
TSP30 - Overview of Performance
•A-D-B-C-E C2: A-C-B-E-D-A (38)
Offspring 3 (A-C-D-E-B) with mutation between cities C and E: C3: A-D-E-B-C-A (31) 1800
Offspring 4 (A-E-B-C-D) with mutation between cities B and D: Selected parents: C1, C3, C2, C4 1400
•A-E-D-C-B Crossover: 1200
e
Parent 1: A-B-C-D-E, Parent 2: A-D-E-B-C → Offspring 1: A-B-E-D-C, Offspring 2: A-D-C-B-E c 1000
n
Step 5: Replacement a
Parent 1: A-C-B-E-D, Parent 2: A-E-D-C-B → Offspring 3: A-C-D-E-B, Offspring 4: A-E-B-C-D t
s
i 800
We replace the old population with the new offspring. D
Mutation: 600
79 80 81
• To find the maximum Integer Binary code • Suppose that the size of the chromosome population N is 6, • The GA creates an initial population of chromosomes by filling six
1 0001
the crossover probability pc equals 0.7 and the mutation 4-bit strings with randomly generated ones and zeros.
value of the function 2 0010
probability pm equals 0.001, the fitness function in our
(15x-x2), where 3 0011
example is defined by Chromosome Chromosome Decoded Chromosome Fitness ratio
4 0100 label string integer fitness %
parameter x varies 5 0101 f(x) = (15x-x2)
X1 1100 12 36 16.5
between 0 and 15. 6 0110
82 83 84
14
7/24/2024
• Last column in the previous table shows the ratio • To select a chromosome for mating, a random
of the individual chromosome fitness to the number (between 0 and 100) is generated.
populations total fitness. •Each member of the
1 2 population is given a slice • The roulette wheel is spun and when the arrow
of the roulette wheel comes to rest on one of the segments, the
• According to the example, chromosomes X5 and 3 •The better the fitness, the corresponding chromosome is selected.
X6 have a pretty good chance of being selected bigger the slice
for mating, while X3 and X4 have a poor chance. •We then spin the wheel - • In the current case, the wheel is spun six times.
if your number comes up • The first two spins might select, X6 and X2;
4
you survive to the next
• Second two spins might select X1 and X5;
• Roulette selection wheel is the most commonly generation!
• The last two spins might select X2 and X5.
used chromosome selection technique.
85 86 87
89 90
88 89 90
15
7/24/2024
91 92 93
91 92 93
94 95 96
16
7/24/2024
■ Basically, a Memetic Algorithm is a GA with Local Search as ■ The experience is that GAs do not necessarily perform well in ■ Local Search
improvement mechanism some problem domains – Short summary
– Also known under different names ■ Using Local Search in addition to the population mechanisms ■ Genetic Algorithms
– An example of hybridization proves to be an improvement
– Population based Metaheuristic
■ A meme is a unit of cultural information transferable from ■ In a sense this elevates the population search to a search – Based on genetics:
one mind to another among locally optimal solutions, rather than among any
■ Mutation
– Sounds like gene: the unit carrying inherited information
solution in the solution space
■ Combination of chromosomes from parents
– Hybridization: Memetic Algorithm
97 98 99
97 98 99
• Interesting idea, parallelism • Slow (blind search). • It’s a big family, with a lot of possibilities
• Very easy to use • No proof (or hints) about the quality of the solution. • Easy to use
• Need no knowledge about the solution • Sometimes difficult to use them efficiently. • Efficiency ?
• Could be efficient • Tradeoff between mutation and crossover? • Areas: Graph problems (Graph coloring),
17