Download presentation
Presentation is loading. Please wait.
Published byDarren Davis Modified over 9 years ago
2
More on Heuristics Genetic Algorithms (GA)
3
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
4
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
5
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
6
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
7
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:
8
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 }
9
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 }
10
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
11
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+
12
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
13
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
14
Example - knapsack problem Let x j = 1 if the jth item is included; 0 otherwise If Else
15
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
16
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 82 2 FITNESS= 84 0 1 0 0 0 0 0 1 0 1 1 0 1 84 87 3 FITNESS= -14286 0 1 1 0 1 1 0 1 1 0 0 0 0 114 112 4 FITNESS= -19476 1 0 1 0 1 0 1 1 1 1 0 0 0 124 114 5 FITNESS= -35971 1 1 1 0 0 1 0 0 0 0 1 0 1 129 119 6 FITNESS= -62371 0 0 1 1 0 1 1 0 0 1 0 0 1 129 125 7 FITNESS= -102248 1 1 1 1 1 1 0 1 0 1 1 0 1 152 132 8 FITNESS= -249847 1 0 1 1 0 0 0 1 1 1 1 1 1 153 150 9 FITNESS= -336215 0 1 0 1 0 0 0 1 0 1 1 1 1 185 158 10 FITNESS= -623935 0 1 1 1 1 1 0 1 1 1 1 0 1 165 179
17
Genetic Algorithm - KNAPSACK problem Generation Nbr= 2 CHROMOSOME VALUE WEIGHT 1 FITNESS= 103 1 1 1 0 0 1 0 0 0 0 1 0 0 103 90 2 FITNESS= 96 1 0 1 0 0 0 1 1 0 0 1 0 0 96 85 3 FITNESS= 84 0 0 1 0 0 0 1 1 0 0 1 0 0 84 82 4 FITNESS= 84 0 0 1 0 0 0 1 1 0 0 1 0 0 84 82 5 FITNESS= 82 1 1 1 0 0 1 0 0 0 0 1 0 0 82 75 6 FITNESS= -11988 0 0 1 0 1 0 1 1 1 1 0 0 0 112 111 7 FITNESS= -11990 0 0 1 0 0 0 1 1 0 0 1 0 1 110 111 8 FITNESS= -14286 0 1 1 0 1 1 0 1 1 0 0 0 0 114 112 9 FITNESS= -67469 0 0 1 0 0 0 1 1 0 0 1 0 1 131 126 10 FITNESS= -623935 0 1 1 1 1 1 0 1 1 1 1 0 1 165 179
18
Genetic Algorithm - KNAPSACK problem generation Nbr= 4 CHROMOSOME VALUE WEIGHT 1 FITNESS= 106 1 1 1 0 0 0 1 1 0 0 1 0 0 106 94 2 FITNESS= 103 1 1 1 0 0 1 0 0 0 0 1 0 0 103 90 3 FITNESS= 89 1 0 1 0 0 0 1 1 0 0 1 0 0 89 73 4 FITNESS= 89 1 0 1 0 0 0 1 1 0 0 1 0 0 89 73 5 FITNESS= 89 1 0 1 0 0 0 1 1 0 0 1 0 0 89 73 6 FITNESS= 89 1 0 1 0 0 0 1 1 0 0 1 0 0 89 73 7 FITNESS= 86 1 1 1 0 0 0 1 0 0 0 1 0 0 86 72 8 FITNESS= 86 1 1 1 0 0 0 1 0 0 0 1 0 0 86 72 9 FITNESS= 69 1 0 1 0 0 0 1 0 0 0 1 0 0 69 51 10 FITNESS= -623935 0 1 1 1 1 1 0 1 1 1 1 0 1 165 179
19
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
20
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 }
21
More on Heuristics Genetic Algorithms (GA) Return to Lesson 4
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.