Date post: | 02-Jan-2016 |
Category: |
Documents |
Upload: | darren-davis |
View: | 214 times |
Download: | 0 times |
Terminology
• Chromosome – candidate solution - {x1, x2, .... , xn }
• Gene– variable - xj
• Allele– numerical value of the gene
• Fitness measure– objective function + penalty function
• Generation– new population created from current population
• Reproduction– producing next generation
Reproduction
• Cloning– copying the best chromosomes into the new
population
• Mating – creating a new chromosome (child) from two
current chromosomes (parents)
• Mutation– randomly altering one or more genes to form a
new chromosome
Characteristic of GAs
• Global search procedure (search from a population rather than a single point)
• Technique “evolves” towards better solutions• Population may stay constant (by eliminating
the less fit) or be allowed to grow• Objective function does not need to be
continuous, differentiable, or unimodal• Initial population may be randomly generated
or selected using some criteria• Terminate procedure when several
generations produce no further improvement
Cloning
f(xi1 , xi2, xi3, . . . xin )
deemed fit
Xi = { xi1 , xi2, xi3, . . . xin }
generation k+1:
Xi = { xi1 , xi2, xi3, . . . xin }
generation k:
i th chromosome
Mutation
Xi = { xi1 , xi2, xi3, . . . xin }
generation k:
i th chromosome
1. randomly select r1 < r2 2. For j = r1 to r2
x’i,j = randomly selected value
Xi = { xi1 , x’i,r1, x’i, r1+1, . . x’i, r2, ... xin }
generation k+1:
Mating - one point crossover
X = { x1 , x2, x3, . . . xn }
generation k:
Y = { y1 , y2, y3, . . . yn }
Select random r such that 1 <= r <= n
C1 = { x1 , x2, . . . yr , yr+1 , . . . yn }
C2= { y1 , y2, . . . xr , xr+1, . . . xn }
Mating - two point crossover
X = { x1 , x2, x3, . . . xn }
generation k:
Y = { y1 , y2, y3, . . . yn }
Select random r such that 1 <= r < s <= n
C1 = { x1 , x2, ... yr , yr+1 , ... ys, xs+1, ... xn }
C2= { y1 , y2, ... xr , xr+1, …xs, ys+1, ... yn }
Mating - random crossover
X = { x1 , x2, x3, . . . xn }
generation k:
Y = { y1 , y2, y3, . . . yn }
Create:C1 = { u1, u2, … un } and C2 = { v1, v2, … vn }
where
ux with prob
y with probj
i
j
RST
1v
y with prob
x with prob
with
j
i
j
RST
1
0 1
Mating - general strategies
• May include both children in next generation• May select better child and discard (abort) the
other• Usually 60 to 90 percent of the next
generation is determined by mating pairs of parents
• Parents to mate may be selected randomly from the best of the current generation
• Initial population sizes vary from 40 to 250+
The Fitness Function
f(x1, x2, … xn ) + < g(x1, x2, … xn) >
where
RSTg xg x if g x
if g x( )
( ) ( )
( )
2 0
0 0
Min f (x1, x2, … xn )
Subj to: g(x1, x2, … xn) <=0
To Use Genetic Algorithms
• Solutions must be represented by a numeric string of constant length (vector)
• There must be a suitable fitness function
• A suitable crossover (mating) operator must exist
Example - knapsack problem
Let xj = 1 if the jth item is included; 0 otherwise
Max
subj. to:
z c x
w x W
j jj
n
j jj
n
1
1
fitness c x w x Wj jj
n
j jj
n
LNM
OQP
1 1
2
100
If w x Wj jj
n
1
Else fitness c xj jj
n
1
Implementing the Algorithm
Select initialpopulation atrandom
Evaluatefitnessfunction
Clone thebest solutions
Mutate selectedsolutions
Mate thebettersolutions
Continuedimprovement?
Stop
no
Evaluatefitnessfunction
yes
create next generation
Genetic Algorithm - KNAPSACK problem Generation Nbr= 1 CHROMOSOME VALUE WEIGHT
1 FITNESS= 84 0 0 1 0 0 0 1 1 0 0 1 0 0 84 822 FITNESS= 84 0 1 0 0 0 0 0 1 0 1 1 0 1 84 873 FITNESS= -14286 0 1 1 0 1 1 0 1 1 0 0 0 0 114 1124 FITNESS= -19476 1 0 1 0 1 0 1 1 1 1 0 0 0 124 1145 FITNESS= -35971 1 1 1 0 0 1 0 0 0 0 1 0 1 129 1196 FITNESS= -62371 0 0 1 1 0 1 1 0 0 1 0 0 1 129 1257 FITNESS= -102248 1 1 1 1 1 1 0 1 0 1 1 0 1 152 1328 FITNESS= -249847 1 0 1 1 0 0 0 1 1 1 1 1 1 153 1509 FITNESS= -336215 0 1 0 1 0 0 0 1 0 1 1 1 1 185 15810 FITNESS= -623935 0 1 1 1 1 1 0 1 1 1 1 0 1 165 179
Genetic Algorithm - KNAPSACK problemGeneration Nbr= 2 CHROMOSOME VALUE WEIGHT
1 FITNESS= 103 1 1 1 0 0 1 0 0 0 0 1 0 0 103 902 FITNESS= 96 1 0 1 0 0 0 1 1 0 0 1 0 0 96 853 FITNESS= 84 0 0 1 0 0 0 1 1 0 0 1 0 0 84 824 FITNESS= 84 0 0 1 0 0 0 1 1 0 0 1 0 0 84 825 FITNESS= 82 1 1 1 0 0 1 0 0 0 0 1 0 0 82 756 FITNESS= -11988 0 0 1 0 1 0 1 1 1 1 0 0 0 112 1117 FITNESS= -11990 0 0 1 0 0 0 1 1 0 0 1 0 1 110 1118 FITNESS= -14286 0 1 1 0 1 1 0 1 1 0 0 0 0 114 1129 FITNESS= -67469 0 0 1 0 0 0 1 1 0 0 1 0 1 131 12610 FITNESS= -623935 0 1 1 1 1 1 0 1 1 1 1 0 1 165 179
Genetic Algorithm - KNAPSACK problemgeneration Nbr= 4 CHROMOSOME VALUE WEIGHT
1 FITNESS= 106 1 1 1 0 0 0 1 1 0 0 1 0 0 106 942 FITNESS= 103 1 1 1 0 0 1 0 0 0 0 1 0 0 103 903 FITNESS= 89 1 0 1 0 0 0 1 1 0 0 1 0 0 89 734 FITNESS= 89 1 0 1 0 0 0 1 1 0 0 1 0 0 89 735 FITNESS= 89 1 0 1 0 0 0 1 1 0 0 1 0 0 89 736 FITNESS= 89 1 0 1 0 0 0 1 1 0 0 1 0 0 89 737 FITNESS= 86 1 1 1 0 0 0 1 0 0 0 1 0 0 86 728 FITNESS= 86 1 1 1 0 0 0 1 0 0 0 1 0 0 86 729 FITNESS= 69 1 0 1 0 0 0 1 0 0 0 1 0 0 69 5110 FITNESS= -623935 0 1 1 1 1 1 0 1 1 1 1 0 1 165 179
Traveling Salesman Problem
6 - city tour 6! = 720 solutionsX1 = {1,2,3,4,5,6}X2 = {4,3,6,5,2,1}a permutation is a feasible solution
fitness1 = d12 + d23 + d34 + d45 + d56 + d61
fitness2 = d43+ d36 + d65 + d52 + d21 + d14
Crossover with Permutations
Partially matched crossover operator - PMXFor t = r to s; if xt = yt , then swap xt, yt in permutation x
X = { 4, 5, 6, 2, 1, 3 }Y = { 1, 2, 6, 4, 3, 5 } r = 2 and s = 5
C1 = { 4, 2, 6, 5, 1, 3 } = { 2, 4, 6, 5, 1, 3 } = { 2, 4, 6, 5, 3, 1 }
C2 = { 1, 5, 6, 4, 3, 2 } = { 1, 5, 6, 2, 3, 4 } = { 3, 5, 6, 2, 1, 4 }
More on Heuristics
Genetic Algorithms (GA)
Return to Lesson 4