2.1-Genetic Algorithms
2.1-Genetic Algorithms
GORITHMS
Genetic Algorithms
g
Introduction
10
1.0
S L
x
Base 1 Base 2
z 6-bit string (binary) to define the base Î 24-bit string
chromosome
h
z Initial population = 4
Design Parameters
1. Design a representation
2. Decide how to initialize a population
3
3. Design a mechanism to map the phenotype to
genotype and vice versa
4. Design a way of evaluating an individual
5. Design suitable mutation operators
6. Design suitable crossover operators
7
7. Decide how to select parents for crossover
8. Decide how to select individuals to be replaced
9. Decide when to stop p the algorithm
g
10. Decide how to manage the population
1. Designing a Representation
0.9
0.8
0.7
0.6
0.5
0 4
0.4
0.3
0.2
0.1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Binary Valued Representation
PHENOTYPE
Integer
Real Number
8 bit GENOTYPE Schedule
.
.
A thi ?
Anything?
=1*2
1*27+0*26+1*25+0*24+0*23+
0*22+1*21+1*20
= 128+32+2+1 = 163
z Phenotype can be a
real number
e.g. a numberb b
between
t
2.5 and 20.5 using 8
binaryy digits
g
solution
solution
z Usually, at random
z
z Hilb t space-filling
Hilbert filli curve
z Sometimes producing
the phenotype from the
Problem
Genotype
genotype is a obvious Data
process.
z Other times the
genotype might be a set Growth
G h
of parameters to some
algorithm, which work Function
on the problem data to
produce the phenotype.
Phenotype
For n-city Traveling Salesman Problem,
it should be straightforward for the mapping
from genotype to phenotype.
4. Evaluating an Individual
0.9
0 8
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Binary Valued Representation
b f
before 1 1 1 1 1 1 1
Grey Elephant
after 1 1 1 0 1 1 1
mutated gene
Black Elephant
Mutation probability pm, for each gene
Real Valued Representation
7 3 1 8 2 4 6 5
7 3 6 8 2 4 1 5
* *
2 * π *
r r r r
Annealing Procedure Conjecture
Whole Population:
p ...
parents
1 1 1 1 1 1 1 0 0 0 0 0 0 0
offspring
1 1 1 0 0 0 0 0 0 0 1 1 1 1
1-point crossover
Real Valued Representation
a
a b c d e f g h
gH
BCDE F GH
A B
• Intermediate recombination (arithmetic crossover):
given two parents one child is created as follows
a b c d e f
A B CDE F
↓
(a+A)/2 (b+B)/2 (c+C)/2 (d+D)/2 (e+E)/2 (f+F)/2
• o1 = p1*bias + p2*(1-bias)
o2 = p1*(1
(1-bias)
bias) + p2*bias
bias
bias toward the center between two parents
z Blend (BLX-α) Crossover:
– picking a random number between min(p1,p2)-α * Δ and
max(p1,pp2)+α * Δ,
Δ where p1 and p2 are the parents
parents, α is a
positive number (typically 0.5), and Δ is |p1 – p2|.
– This formulation allows for the BLX operator to choose a
child on a baseline that extends some distance beyond the
two parents. This allows for better placement of children
than the Arithmetic Crossover; however, the children will still
be biased to lie on baselines between sets of parents.
Therefore, children could still lack diversity.
X i1 = min( xi1 , xi2 ) − αd i d i = xi1 − xi2
X i2 = max( xi1 , xi2 ) + αd i
z Unimodal Normally Distributed (UNDX) Crossover:
– It first selects three parents at random from the population.
– Next,, it finds the midpoint
p of the first two pparents and calls it xp.
Then, it finds the difference vector of the first two parents as d = x1
– x2. The line containing the first two parents is called the primary
search line, and the value D is computed as the distance from the
third parent to the primary search lineline. These terms are then
n −1
combined to form a child xc: c
x = m + dξ + D ∑ηi ei
i =1
7, 3, 4, 6, 5
order
1 8 2 4, 3, 6, 7, 5
Child 1
7 5 1 8 2 4 3 6
Tree Based Representation
*
2 *
* r r
π + 2 * (r * r )
π * (r
( + (l / r))
))
r /
Two sub-trees
T bt are selected
l t d
for swapping.
1 r
* *
π + π *
r / r r
*
1 r 2 +
*
2 * r /
Resulting in 2 new
r r expressions 1 r
Crossover vs. Mutation
z Crossover
– modifications depend on the whole population
– decreasing effects
ff with convergence
– exploitation operator
z Mutation
– mandatoryy to escape local optima
– exploration operator
z GA emphasize
h i crossover; while
hil ES and
d EP
emphasize mutation
Exploration vs. Exploitation
Disadvantages:
z Take
T k the
th best
b t
– k is called the size of the tournament
Ranked Based Selection
z Function:
F ti h(A) = 3
3, h(B) = 5
5, h(C) = 1
z If applied, proportion on the roulette wheel:
p(A) = 11.1%,
11 1% p(B) = 33.3%,
33 3% p(C) = 55.6%
55 6%
8. Replacement Strategy
z Theory
– GA: preserve mandatory
– ES: no elitism sometimes is better
z Li it on CPU resources
Limit
z Li i on the
Limit h user’s
’ patience
i
z “What
What you test is what you get”
get , don
don’tt tune algorithm
performance on toy data and expect it to work with real
data
Box Plot
z In descriptive statistics, a boxplot (also
known as a box-and-whisker diagram or
plot) is a convenient way of graphically
depicting groups of numerical data through
th i fifive-number
their b summaries i (th
(the smallest
ll t
observation, lower quartile (Q1), median
(Q2), upper quartile (Q3), and largest
observation). A boxplot may also indicate
which observations
observations, if any
any, might be
considered outliers. The boxplot was
invented in 1977 by the American
statistician John Tukey.
z Boxplots
p can be useful to display
p y
differences between populations without
making any assumptions of the underlying
statistical distribution. The spacings
between the different parts of the box help
indicate the degree of dispersion (spread)
and skewness in the data, and identify
outliers. Boxplots can be drawn either
horizontally or vertically.
For this data set:
• smallest non
non-outlier
outlier observation = 5 (left "whisker")
whisker )
• lower (first) quartile (Q1, x.25) = 7
• median (second quartile) (Med, x.5) = 8.5
• upper (third) quartile (Q3, x.75
75) = 9
• largest non-outlier observation = 10 (right "whisker")
• the value 3.5 is a "mild" outlier, between
• the value 0.5 is an "extreme" outlier,
• the data are skewed to the left (negatively skewed)
• the mean value of the data can also be labeled with a point.
Flowchart
START 1. Generate random population of
N chromosomes (feasible
FITNESS solutions for the problem)
EVALUATION
2. E l t the
Evaluate th fitness
fit f( ) off each
f(x) h
GENERATE NEW
chromosome x in the population
POPULATION 3. Create a new population by
repeating following steps until
the new population is complete
REPLACE by means of selection and
crossover or mutation
4. Replace unfit individuals in old
NO END population by new off springs
CONDITION
SATISFIED
5. If the end condition is satisfied,
stop and return the best solution
stop,
YES
in current population
STOP else Go to step 2
Genetic Algorithm for TSP
z Selection: (rank-based)
z Replacement: (elitism)
z Stopping criteria: (number of generations- 200)
Demonstration
Case Study: 101-city TSP problem (eil101)
Total Distance:
678.854309.
Population:
50
Generations:
200
Case Study: 535-airport problem (ali535)
Total Distance:
2433.995486
Population:
50
Generations:
200
Case Study: N Queens Problem
z Population size
z Binary representation vs. real representation
z Population initialization
z N i fitness
Noisy fit function
f ti
z Stochastic fitness function (or dynamic environment)
z Fitness inheritance and fitness approximation
z Selection/ranking
Se ect o / a g st
strategy
ategy
z Crossover/Recombination operator
z Mutation operator
z Replacement strategy
z Stopping criteria
z Elitism strategy
z Benchmark test functions
z Exploration
p vs. exploitation
p dilemma
z Constraint handling
z Diversity promotion
z Population management
Homework #3- due 11/7/2009
⎡0.6606,0.9695,0.5906,0.2124,0.0398,0.1367,0.9536,0.6091,0.8767,0.8148
cities = ⎢
⎣0.9500,0.6740,0.5029,0.8274,0.9697,0.5979,0.2184,0.7148,0.2395,0.2867
0.3876,0.7041,0.0213,0.3429,0.7471,0.5449,0.9464,0.1247,0.1636,0.8668⎤
0.8200,0.3296,0.1649,0.3025,0.8192,0.9392,0.8191,0.4351,0.8646,0.6768⎥⎦
0.9
0.8
0.7
0 6
0.6
0.5
0.4
0.3
0.2
0.1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
z Problem 2 (Scalability)
Extend your genetic algorithm to solve the benchmark 101-city
symmetric TSP problem (i.e., eil101 due to Christofides and
Eilson).The benchmark problem can be found from TSPLIB
archive at
http://www.iwr.uni-heidelberg.de/groups/comopt/software/TSPLIB95/
j =1 fj i =1
⎡− 32 − 16 0 16 32 − 32 − 16 0 16 32 − 32 − 16 0 16 32 − 32 − 16 0 16 32 − 32 − 16 0 16 32⎤
aij = ⎢
⎣− 32 − 32 − 32 − 32 − 32 − 16 − 16 − 16 − 16 − 16 0 0 0 0 0 16 16 16 16 16 32 32 32 32 32⎥⎦