More on Heuristics Genetic Algorithms (GA)
Terminology Chromosome –candidate solution - {x 1, x 2,...., x n } Gene –variable - x j 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( x i1, x i2, x i3,... x in ) deemed fit X i = { x i1, x i2, x i3,... x in } generation k+1: X i = { x i1, x i2, x i3,... x in } generation k: i th chromosome
Mutation X i = { x i1, x i2, x i3,... x in } generation k: i th chromosome 1. randomly select r 1 < r 2 2. For j = r 1 to r 2 x’ i,j = randomly selected value X i = { x i1, x’ i,r1, x’ i, r1+1,.. x’ i, r2,... x in } generation k+1:
Mating - one point crossover X = { x 1, x 2, x 3,... x n } generation k: Y = { y 1, y 2, y 3,... y n } Select random r such that 1 <= r <= n C 1 = { x 1, x 2,... y r, y r+1,... y n } C 2 = { y 1, y 2,... x r, x r+1,... x n }
Mating - two point crossover X = { x 1, x 2, x 3,... x n } generation k: Y = { y 1, y 2, y 3,... y n } Select random r such that 1 <= r < s <= n C 1 = { x 1, x 2,... y r, y r+1,... y s, x s+1,... x n } C 2 = { y 1, y 2,... x r, x r+1, …x s, y s+1,... y n }
Mating - random crossover X = { x 1, x 2, x 3,... x n } generation k: Y = { y 1, y 2, y 3,... y n } Create: C 1 = { u 1, u 2, … u n } and C 2 = { v 1, v 2, … v n } where
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(x 1, x 2, … x n ) + where Min f (x 1, x 2, … x n ) Subj to: g(x 1, x 2, … x n ) <=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 x j = 1 if the jth item is included; 0 otherwise If Else
Implementing the Algorithm Select initial population at random Evaluate fitness function Clone the best solutions Mutate selected solutions Mate the better solutions Continued improvement? Stop no Evaluate fitness function yes create next generation
Genetic Algorithm - KNAPSACK problem Generation Nbr= 1 CHROMOSOME VALUE WEIGHT 1 FITNESS= FITNESS= FITNESS= FITNESS= FITNESS= FITNESS= FITNESS= FITNESS= FITNESS= FITNESS=
Genetic Algorithm - KNAPSACK problem Generation Nbr= 2 CHROMOSOME VALUE WEIGHT 1 FITNESS= FITNESS= FITNESS= FITNESS= FITNESS= FITNESS= FITNESS= FITNESS= FITNESS= FITNESS=
Genetic Algorithm - KNAPSACK problem generation Nbr= 4 CHROMOSOME VALUE WEIGHT 1 FITNESS= FITNESS= FITNESS= FITNESS= FITNESS= FITNESS= FITNESS= FITNESS= FITNESS= FITNESS=
Traveling Salesman Problem 6 - city tour 6! = 720 solutions X 1 = {1,2,3,4,5,6} X 2 = {4,3,6,5,2,1} a permutation is a feasible solution fitness 1 = d 12 + d 23 + d 34 + d 45 + d 56 + d 61 fitness 2 = d 43 + d 36 + d 65 + d 52 + d 21 + d 14
Crossover with Permutations Partially matched crossover operator - PMX For t = r to s; if x t = y t, then swap x t, y t in permutation x X = { 4, 5, 6, 2, 1, 3 } Y = { 1, 2, 6, 4, 3, 5 } r = 2 and s = 5 C 1 = { 4, 2, 6, 5, 1, 3 } = { 2, 4, 6, 5, 1, 3 } = { 2, 4, 6, 5, 3, 1 } C 2 = { 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