genetic algorithms an algorithm is a set of instructions that is repeated to solve a problem. an...

84
Genetic Algorithms Genetic Algorithms An An algorithm algorithm is a set of is a set of instructions that is repeated to instructions that is repeated to solve a problem solve a problem . . A A genetic algorithm genetic algorithm conceptually conceptually follows steps inspired by the follows steps inspired by the biological processes of evolution biological processes of evolution . . Genetic Algorithms follow the idea Genetic Algorithms follow the idea of of SURVIVAL OF THE FITTEST SURVIVAL OF THE FITTEST - Better - Better and better solutions evolve from and better solutions evolve from previous generations until a near previous generations until a near optimal solution is obtained optimal solution is obtained . .

Upload: naomi-howard

Post on 02-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Genetic AlgorithmsGenetic AlgorithmsAn An algorithmalgorithm is a set of instructions is a set of instructions

that is repeated to solve a problemthat is repeated to solve a problemA A genetic algorithmgenetic algorithm conceptually conceptually

follows steps inspired by the follows steps inspired by the biological processes of evolutionbiological processes of evolution

Genetic Algorithms follow the idea of Genetic Algorithms follow the idea of SURVIVAL OF THE FITTESTSURVIVAL OF THE FITTEST- Better - Better and better solutions evolve from and better solutions evolve from previous generations until a near previous generations until a near optimal solution is obtainedoptimal solution is obtained

Genetic AlgorithmsGenetic AlgorithmsAlso known as Also known as evolutionary algorithmsevolutionary algorithms

genetic algorithms demonstrate self genetic algorithms demonstrate self organization and adaptation similar to organization and adaptation similar to the way that the fittest biological the way that the fittest biological organism survive and reproduceorganism survive and reproduce

A genetic algorithm is an iterative A genetic algorithm is an iterative procedure that represents its candidate procedure that represents its candidate solutions as strings of genes called solutions as strings of genes called chromosomeschromosomes

Generally applied to spaces which are Generally applied to spaces which are too largetoo large

Genetic AlgorithmsGenetic AlgorithmsGenetic Algorithms are often used to Genetic Algorithms are often used to

improve the performance of other AI improve the performance of other AI methods such as expert systems or methods such as expert systems or neural networksneural networks

The method learns by producing The method learns by producing offspring that are better and better as offspring that are better and better as measured by a fitness function which is measured by a fitness function which is a measure of the objective to be a measure of the objective to be obtained (maximum or minimum)obtained (maximum or minimum)

Genetic AlgorithmGenetic Algorithm

Genetic algorithms are a part Genetic algorithms are a part of evolutionary computing of evolutionary computing which is a rapidly growing area which is a rapidly growing area of of artificial intelligenceartificial intelligence

Based on Darwinian principles Based on Darwinian principles of biological evolution of biological evolution

First proposed by Prof John First proposed by Prof John Holland and his colleague at Holland and his colleague at Univ of MichiganUniv of Michigan

ChromosomesChromosomes are strings of are strings of DNADNA and and serves as a model for the whole organismserves as a model for the whole organism

A chromosome consists of A chromosome consists of genesgenes Each gene encodes a Each gene encodes a traittrait Complete set of genetic material (all Complete set of genetic material (all

chromosomes) is called chromosomes) is called genomegenome Particular set of genes in genome is called Particular set of genes in genome is called

genotypegenotype

Biological Background 1Biological Background 1

During During reproductionreproduction first occurs first occurs recombinationrecombination (or (or crossovercrossover))

Genes from parents form in some way the whole Genes from parents form in some way the whole new chromosomenew chromosome

The new created offspring can then be mutated The new created offspring can then be mutated MutationMutation means that the elements of DNA are a means that the elements of DNA are a bit changed This changes are mainly caused by bit changed This changes are mainly caused by errors in copying genes from parents errors in copying genes from parents

The The fitness fitness of an organism is measured by success of an organism is measured by success of the organism in its lifeof the organism in its life

Biological Background 2Biological Background 2

The space of all feasible solutions (it means objects The space of all feasible solutions (it means objects among those the desired solution is) is called among those the desired solution is) is called search spacesearch space (also (also state spacestate space))

EachEach point point in the search space represent one in the search space represent one feasible solutionfeasible solution

The looking for a solution is then equal to a The looking for a solution is then equal to a looking for some looking for some extremeextreme (minimum or (minimum or maximum) in the search spacemaximum) in the search space

Search methods hill climbing tabular search Search methods hill climbing tabular search simulated annealing and genetic algorithmsimulated annealing and genetic algorithm

Search SpaceSearch Space

Simple GASimple GA initialize population evaluate population while TerminationCriteriaNotSatisfied

select parents for reproductionperform crossover and mutationrepair()

evaluate population

Every loop called generation

ConceptsConcepts

Populationset of individuals each representing a possible solution to a given problem

Genea solution to problem represented as a set of parameters these parameters known as genes

Chromosomegenes joined together to form a string of values called chromosome

Fitness score(value)every chromosome has fitness score can be inferred from the chromosome itself by using fitness function

Recombination

Stochastic operatorsStochastic operators

SelectionSelection replicates the most successful replicates the most successful solutions found in a population at a rate solutions found in a population at a rate proportional to their relative quality proportional to their relative quality

RecombinationRecombination (Crossover)(Crossover) decomposes two distinct solutions and decomposes two distinct solutions and then randomly mixes their parts to form then randomly mixes their parts to form novel solutionsnovel solutions

MutationMutation randomly perturbs a candidate randomly perturbs a candidate solutionsolution

Simulated EvolutionSimulated Evolution

We need the followingWe need the following Representation of an individualRepresentation of an individual Fitness FunctionFitness Function Reproduction MethodReproduction Method Selection CriteriaSelection Criteria

Representing an IndividualRepresenting an Individual

An individual is data structure An individual is data structure representing the representing the ldquoldquogenetic genetic structurestructurerdquordquo of a possible solution of a possible solution

Genetic structure consists of an Genetic structure consists of an alphabet (usually 01)alphabet (usually 01)

Binary EncodingBinary Encoding Most Common Most Common ndashndash string of bits 0 or 1 string of bits 0 or 1

Chrom A = 1 0 11 0 0 1 0 1 1Chrom A = 1 0 11 0 0 1 0 1 1 Chrom B = 1 1 1 1 1 1 0 0 0 0Chrom B = 1 1 1 1 1 1 0 0 0 0 Gives you many possibilitiesGives you many possibilities Example Problem Knapsack problemExample Problem Knapsack problem The problem there are things with given value The problem there are things with given value

and size The knapsack has given capacity and size The knapsack has given capacity Select things to maximize the valuesSelect things to maximize the values

Encoding Each bit says if the corresponding Encoding Each bit says if the corresponding thing is in the knapsackthing is in the knapsack

Permutation EncodingPermutation Encoding Used in Used in ldquoldquoordering problemsordering problemsrdquordquo Every chromosome is a string of Every chromosome is a string of

numbers which represents number is a numbers which represents number is a sequencesequenceChrom A 1 5 3 2 6 4 7 9 8Chrom A 1 5 3 2 6 4 7 9 8Chrom B 8 5 7 7 2 3 1 4 9Chrom B 8 5 7 7 2 3 1 4 9

Example Travelling salesman problemExample Travelling salesman problem The problem cities that must be visitedThe problem cities that must be visited Encoding says order of cities in which Encoding says order of cities in which

salesman willl visitsalesman willl visit

Another ExampleAnother Example

To find optimal quantity of three To find optimal quantity of three major ingredients (sugar milk major ingredients (sugar milk sesame oil) denoting ouncessesame oil) denoting ounces Use an alphabet of 1-9 denoting Use an alphabet of 1-9 denoting

ouncesounces Solutions might be 1-1-1 2-1-4 3-3-1Solutions might be 1-1-1 2-1-4 3-3-1

Value EncodingValue Encoding Used for complicated values (real numbers) Used for complicated values (real numbers)

and when binary coding would be difficultand when binary coding would be difficult Each chromosome is a string of some valuesEach chromosome is a string of some values

Chrom A 12323 53243 04556Chrom A 12323 53243 04556Chrom B abcdjeifjdhdierjfdChrom B abcdjeifjdhdierjfdChrom C (back) (back) (right) (forward) (left)Chrom C (back) (back) (right) (forward) (left)

Example Finding weights for neural netsExample Finding weights for neural netsThe problem find weights for networkThe problem find weights for networkEncoding Real values that represent weightsEncoding Real values that represent weights

Rule base systemRule base system Given a rule (if color=red and size=small Given a rule (if color=red and size=small

and shape=round then object=appleand shape=round then object=apple Assume that each feature has finite set of Assume that each feature has finite set of

values (eg size = smalllarge)values (eg size = smalllarge) Represent the value as a substring of length Represent the value as a substring of length

equl to the number of possible values For equl to the number of possible values For example small = 10 large = 01example small = 10 large = 01

The entire rule would be 100 10 01 0100 The entire rule would be 100 10 01 0100 ndashndash set of rules concatenating the values set of rules concatenating the values togethertogether

How offspring are How offspring are produced - produced - ReproductionReproduction

ReproductionReproduction- Through - Through reproductionreproduction genetic algorithms genetic algorithms produce new generations of produce new generations of improved solutions by selecting improved solutions by selecting parents with higher fitness ratings parents with higher fitness ratings or by giving such parents a greater or by giving such parents a greater probability of being contributors probability of being contributors and by using random selectionand by using random selection

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Genetic AlgorithmsGenetic AlgorithmsAlso known as Also known as evolutionary algorithmsevolutionary algorithms

genetic algorithms demonstrate self genetic algorithms demonstrate self organization and adaptation similar to organization and adaptation similar to the way that the fittest biological the way that the fittest biological organism survive and reproduceorganism survive and reproduce

A genetic algorithm is an iterative A genetic algorithm is an iterative procedure that represents its candidate procedure that represents its candidate solutions as strings of genes called solutions as strings of genes called chromosomeschromosomes

Generally applied to spaces which are Generally applied to spaces which are too largetoo large

Genetic AlgorithmsGenetic AlgorithmsGenetic Algorithms are often used to Genetic Algorithms are often used to

improve the performance of other AI improve the performance of other AI methods such as expert systems or methods such as expert systems or neural networksneural networks

The method learns by producing The method learns by producing offspring that are better and better as offspring that are better and better as measured by a fitness function which is measured by a fitness function which is a measure of the objective to be a measure of the objective to be obtained (maximum or minimum)obtained (maximum or minimum)

Genetic AlgorithmGenetic Algorithm

Genetic algorithms are a part Genetic algorithms are a part of evolutionary computing of evolutionary computing which is a rapidly growing area which is a rapidly growing area of of artificial intelligenceartificial intelligence

Based on Darwinian principles Based on Darwinian principles of biological evolution of biological evolution

First proposed by Prof John First proposed by Prof John Holland and his colleague at Holland and his colleague at Univ of MichiganUniv of Michigan

ChromosomesChromosomes are strings of are strings of DNADNA and and serves as a model for the whole organismserves as a model for the whole organism

A chromosome consists of A chromosome consists of genesgenes Each gene encodes a Each gene encodes a traittrait Complete set of genetic material (all Complete set of genetic material (all

chromosomes) is called chromosomes) is called genomegenome Particular set of genes in genome is called Particular set of genes in genome is called

genotypegenotype

Biological Background 1Biological Background 1

During During reproductionreproduction first occurs first occurs recombinationrecombination (or (or crossovercrossover))

Genes from parents form in some way the whole Genes from parents form in some way the whole new chromosomenew chromosome

The new created offspring can then be mutated The new created offspring can then be mutated MutationMutation means that the elements of DNA are a means that the elements of DNA are a bit changed This changes are mainly caused by bit changed This changes are mainly caused by errors in copying genes from parents errors in copying genes from parents

The The fitness fitness of an organism is measured by success of an organism is measured by success of the organism in its lifeof the organism in its life

Biological Background 2Biological Background 2

The space of all feasible solutions (it means objects The space of all feasible solutions (it means objects among those the desired solution is) is called among those the desired solution is) is called search spacesearch space (also (also state spacestate space))

EachEach point point in the search space represent one in the search space represent one feasible solutionfeasible solution

The looking for a solution is then equal to a The looking for a solution is then equal to a looking for some looking for some extremeextreme (minimum or (minimum or maximum) in the search spacemaximum) in the search space

Search methods hill climbing tabular search Search methods hill climbing tabular search simulated annealing and genetic algorithmsimulated annealing and genetic algorithm

Search SpaceSearch Space

Simple GASimple GA initialize population evaluate population while TerminationCriteriaNotSatisfied

select parents for reproductionperform crossover and mutationrepair()

evaluate population

Every loop called generation

ConceptsConcepts

Populationset of individuals each representing a possible solution to a given problem

Genea solution to problem represented as a set of parameters these parameters known as genes

Chromosomegenes joined together to form a string of values called chromosome

Fitness score(value)every chromosome has fitness score can be inferred from the chromosome itself by using fitness function

Recombination

Stochastic operatorsStochastic operators

SelectionSelection replicates the most successful replicates the most successful solutions found in a population at a rate solutions found in a population at a rate proportional to their relative quality proportional to their relative quality

RecombinationRecombination (Crossover)(Crossover) decomposes two distinct solutions and decomposes two distinct solutions and then randomly mixes their parts to form then randomly mixes their parts to form novel solutionsnovel solutions

MutationMutation randomly perturbs a candidate randomly perturbs a candidate solutionsolution

Simulated EvolutionSimulated Evolution

We need the followingWe need the following Representation of an individualRepresentation of an individual Fitness FunctionFitness Function Reproduction MethodReproduction Method Selection CriteriaSelection Criteria

Representing an IndividualRepresenting an Individual

An individual is data structure An individual is data structure representing the representing the ldquoldquogenetic genetic structurestructurerdquordquo of a possible solution of a possible solution

Genetic structure consists of an Genetic structure consists of an alphabet (usually 01)alphabet (usually 01)

Binary EncodingBinary Encoding Most Common Most Common ndashndash string of bits 0 or 1 string of bits 0 or 1

Chrom A = 1 0 11 0 0 1 0 1 1Chrom A = 1 0 11 0 0 1 0 1 1 Chrom B = 1 1 1 1 1 1 0 0 0 0Chrom B = 1 1 1 1 1 1 0 0 0 0 Gives you many possibilitiesGives you many possibilities Example Problem Knapsack problemExample Problem Knapsack problem The problem there are things with given value The problem there are things with given value

and size The knapsack has given capacity and size The knapsack has given capacity Select things to maximize the valuesSelect things to maximize the values

Encoding Each bit says if the corresponding Encoding Each bit says if the corresponding thing is in the knapsackthing is in the knapsack

Permutation EncodingPermutation Encoding Used in Used in ldquoldquoordering problemsordering problemsrdquordquo Every chromosome is a string of Every chromosome is a string of

numbers which represents number is a numbers which represents number is a sequencesequenceChrom A 1 5 3 2 6 4 7 9 8Chrom A 1 5 3 2 6 4 7 9 8Chrom B 8 5 7 7 2 3 1 4 9Chrom B 8 5 7 7 2 3 1 4 9

Example Travelling salesman problemExample Travelling salesman problem The problem cities that must be visitedThe problem cities that must be visited Encoding says order of cities in which Encoding says order of cities in which

salesman willl visitsalesman willl visit

Another ExampleAnother Example

To find optimal quantity of three To find optimal quantity of three major ingredients (sugar milk major ingredients (sugar milk sesame oil) denoting ouncessesame oil) denoting ounces Use an alphabet of 1-9 denoting Use an alphabet of 1-9 denoting

ouncesounces Solutions might be 1-1-1 2-1-4 3-3-1Solutions might be 1-1-1 2-1-4 3-3-1

Value EncodingValue Encoding Used for complicated values (real numbers) Used for complicated values (real numbers)

and when binary coding would be difficultand when binary coding would be difficult Each chromosome is a string of some valuesEach chromosome is a string of some values

Chrom A 12323 53243 04556Chrom A 12323 53243 04556Chrom B abcdjeifjdhdierjfdChrom B abcdjeifjdhdierjfdChrom C (back) (back) (right) (forward) (left)Chrom C (back) (back) (right) (forward) (left)

Example Finding weights for neural netsExample Finding weights for neural netsThe problem find weights for networkThe problem find weights for networkEncoding Real values that represent weightsEncoding Real values that represent weights

Rule base systemRule base system Given a rule (if color=red and size=small Given a rule (if color=red and size=small

and shape=round then object=appleand shape=round then object=apple Assume that each feature has finite set of Assume that each feature has finite set of

values (eg size = smalllarge)values (eg size = smalllarge) Represent the value as a substring of length Represent the value as a substring of length

equl to the number of possible values For equl to the number of possible values For example small = 10 large = 01example small = 10 large = 01

The entire rule would be 100 10 01 0100 The entire rule would be 100 10 01 0100 ndashndash set of rules concatenating the values set of rules concatenating the values togethertogether

How offspring are How offspring are produced - produced - ReproductionReproduction

ReproductionReproduction- Through - Through reproductionreproduction genetic algorithms genetic algorithms produce new generations of produce new generations of improved solutions by selecting improved solutions by selecting parents with higher fitness ratings parents with higher fitness ratings or by giving such parents a greater or by giving such parents a greater probability of being contributors probability of being contributors and by using random selectionand by using random selection

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Genetic AlgorithmsGenetic AlgorithmsGenetic Algorithms are often used to Genetic Algorithms are often used to

improve the performance of other AI improve the performance of other AI methods such as expert systems or methods such as expert systems or neural networksneural networks

The method learns by producing The method learns by producing offspring that are better and better as offspring that are better and better as measured by a fitness function which is measured by a fitness function which is a measure of the objective to be a measure of the objective to be obtained (maximum or minimum)obtained (maximum or minimum)

Genetic AlgorithmGenetic Algorithm

Genetic algorithms are a part Genetic algorithms are a part of evolutionary computing of evolutionary computing which is a rapidly growing area which is a rapidly growing area of of artificial intelligenceartificial intelligence

Based on Darwinian principles Based on Darwinian principles of biological evolution of biological evolution

First proposed by Prof John First proposed by Prof John Holland and his colleague at Holland and his colleague at Univ of MichiganUniv of Michigan

ChromosomesChromosomes are strings of are strings of DNADNA and and serves as a model for the whole organismserves as a model for the whole organism

A chromosome consists of A chromosome consists of genesgenes Each gene encodes a Each gene encodes a traittrait Complete set of genetic material (all Complete set of genetic material (all

chromosomes) is called chromosomes) is called genomegenome Particular set of genes in genome is called Particular set of genes in genome is called

genotypegenotype

Biological Background 1Biological Background 1

During During reproductionreproduction first occurs first occurs recombinationrecombination (or (or crossovercrossover))

Genes from parents form in some way the whole Genes from parents form in some way the whole new chromosomenew chromosome

The new created offspring can then be mutated The new created offspring can then be mutated MutationMutation means that the elements of DNA are a means that the elements of DNA are a bit changed This changes are mainly caused by bit changed This changes are mainly caused by errors in copying genes from parents errors in copying genes from parents

The The fitness fitness of an organism is measured by success of an organism is measured by success of the organism in its lifeof the organism in its life

Biological Background 2Biological Background 2

The space of all feasible solutions (it means objects The space of all feasible solutions (it means objects among those the desired solution is) is called among those the desired solution is) is called search spacesearch space (also (also state spacestate space))

EachEach point point in the search space represent one in the search space represent one feasible solutionfeasible solution

The looking for a solution is then equal to a The looking for a solution is then equal to a looking for some looking for some extremeextreme (minimum or (minimum or maximum) in the search spacemaximum) in the search space

Search methods hill climbing tabular search Search methods hill climbing tabular search simulated annealing and genetic algorithmsimulated annealing and genetic algorithm

Search SpaceSearch Space

Simple GASimple GA initialize population evaluate population while TerminationCriteriaNotSatisfied

select parents for reproductionperform crossover and mutationrepair()

evaluate population

Every loop called generation

ConceptsConcepts

Populationset of individuals each representing a possible solution to a given problem

Genea solution to problem represented as a set of parameters these parameters known as genes

Chromosomegenes joined together to form a string of values called chromosome

Fitness score(value)every chromosome has fitness score can be inferred from the chromosome itself by using fitness function

Recombination

Stochastic operatorsStochastic operators

SelectionSelection replicates the most successful replicates the most successful solutions found in a population at a rate solutions found in a population at a rate proportional to their relative quality proportional to their relative quality

RecombinationRecombination (Crossover)(Crossover) decomposes two distinct solutions and decomposes two distinct solutions and then randomly mixes their parts to form then randomly mixes their parts to form novel solutionsnovel solutions

MutationMutation randomly perturbs a candidate randomly perturbs a candidate solutionsolution

Simulated EvolutionSimulated Evolution

We need the followingWe need the following Representation of an individualRepresentation of an individual Fitness FunctionFitness Function Reproduction MethodReproduction Method Selection CriteriaSelection Criteria

Representing an IndividualRepresenting an Individual

An individual is data structure An individual is data structure representing the representing the ldquoldquogenetic genetic structurestructurerdquordquo of a possible solution of a possible solution

Genetic structure consists of an Genetic structure consists of an alphabet (usually 01)alphabet (usually 01)

Binary EncodingBinary Encoding Most Common Most Common ndashndash string of bits 0 or 1 string of bits 0 or 1

Chrom A = 1 0 11 0 0 1 0 1 1Chrom A = 1 0 11 0 0 1 0 1 1 Chrom B = 1 1 1 1 1 1 0 0 0 0Chrom B = 1 1 1 1 1 1 0 0 0 0 Gives you many possibilitiesGives you many possibilities Example Problem Knapsack problemExample Problem Knapsack problem The problem there are things with given value The problem there are things with given value

and size The knapsack has given capacity and size The knapsack has given capacity Select things to maximize the valuesSelect things to maximize the values

Encoding Each bit says if the corresponding Encoding Each bit says if the corresponding thing is in the knapsackthing is in the knapsack

Permutation EncodingPermutation Encoding Used in Used in ldquoldquoordering problemsordering problemsrdquordquo Every chromosome is a string of Every chromosome is a string of

numbers which represents number is a numbers which represents number is a sequencesequenceChrom A 1 5 3 2 6 4 7 9 8Chrom A 1 5 3 2 6 4 7 9 8Chrom B 8 5 7 7 2 3 1 4 9Chrom B 8 5 7 7 2 3 1 4 9

Example Travelling salesman problemExample Travelling salesman problem The problem cities that must be visitedThe problem cities that must be visited Encoding says order of cities in which Encoding says order of cities in which

salesman willl visitsalesman willl visit

Another ExampleAnother Example

To find optimal quantity of three To find optimal quantity of three major ingredients (sugar milk major ingredients (sugar milk sesame oil) denoting ouncessesame oil) denoting ounces Use an alphabet of 1-9 denoting Use an alphabet of 1-9 denoting

ouncesounces Solutions might be 1-1-1 2-1-4 3-3-1Solutions might be 1-1-1 2-1-4 3-3-1

Value EncodingValue Encoding Used for complicated values (real numbers) Used for complicated values (real numbers)

and when binary coding would be difficultand when binary coding would be difficult Each chromosome is a string of some valuesEach chromosome is a string of some values

Chrom A 12323 53243 04556Chrom A 12323 53243 04556Chrom B abcdjeifjdhdierjfdChrom B abcdjeifjdhdierjfdChrom C (back) (back) (right) (forward) (left)Chrom C (back) (back) (right) (forward) (left)

Example Finding weights for neural netsExample Finding weights for neural netsThe problem find weights for networkThe problem find weights for networkEncoding Real values that represent weightsEncoding Real values that represent weights

Rule base systemRule base system Given a rule (if color=red and size=small Given a rule (if color=red and size=small

and shape=round then object=appleand shape=round then object=apple Assume that each feature has finite set of Assume that each feature has finite set of

values (eg size = smalllarge)values (eg size = smalllarge) Represent the value as a substring of length Represent the value as a substring of length

equl to the number of possible values For equl to the number of possible values For example small = 10 large = 01example small = 10 large = 01

The entire rule would be 100 10 01 0100 The entire rule would be 100 10 01 0100 ndashndash set of rules concatenating the values set of rules concatenating the values togethertogether

How offspring are How offspring are produced - produced - ReproductionReproduction

ReproductionReproduction- Through - Through reproductionreproduction genetic algorithms genetic algorithms produce new generations of produce new generations of improved solutions by selecting improved solutions by selecting parents with higher fitness ratings parents with higher fitness ratings or by giving such parents a greater or by giving such parents a greater probability of being contributors probability of being contributors and by using random selectionand by using random selection

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Genetic AlgorithmGenetic Algorithm

Genetic algorithms are a part Genetic algorithms are a part of evolutionary computing of evolutionary computing which is a rapidly growing area which is a rapidly growing area of of artificial intelligenceartificial intelligence

Based on Darwinian principles Based on Darwinian principles of biological evolution of biological evolution

First proposed by Prof John First proposed by Prof John Holland and his colleague at Holland and his colleague at Univ of MichiganUniv of Michigan

ChromosomesChromosomes are strings of are strings of DNADNA and and serves as a model for the whole organismserves as a model for the whole organism

A chromosome consists of A chromosome consists of genesgenes Each gene encodes a Each gene encodes a traittrait Complete set of genetic material (all Complete set of genetic material (all

chromosomes) is called chromosomes) is called genomegenome Particular set of genes in genome is called Particular set of genes in genome is called

genotypegenotype

Biological Background 1Biological Background 1

During During reproductionreproduction first occurs first occurs recombinationrecombination (or (or crossovercrossover))

Genes from parents form in some way the whole Genes from parents form in some way the whole new chromosomenew chromosome

The new created offspring can then be mutated The new created offspring can then be mutated MutationMutation means that the elements of DNA are a means that the elements of DNA are a bit changed This changes are mainly caused by bit changed This changes are mainly caused by errors in copying genes from parents errors in copying genes from parents

The The fitness fitness of an organism is measured by success of an organism is measured by success of the organism in its lifeof the organism in its life

Biological Background 2Biological Background 2

The space of all feasible solutions (it means objects The space of all feasible solutions (it means objects among those the desired solution is) is called among those the desired solution is) is called search spacesearch space (also (also state spacestate space))

EachEach point point in the search space represent one in the search space represent one feasible solutionfeasible solution

The looking for a solution is then equal to a The looking for a solution is then equal to a looking for some looking for some extremeextreme (minimum or (minimum or maximum) in the search spacemaximum) in the search space

Search methods hill climbing tabular search Search methods hill climbing tabular search simulated annealing and genetic algorithmsimulated annealing and genetic algorithm

Search SpaceSearch Space

Simple GASimple GA initialize population evaluate population while TerminationCriteriaNotSatisfied

select parents for reproductionperform crossover and mutationrepair()

evaluate population

Every loop called generation

ConceptsConcepts

Populationset of individuals each representing a possible solution to a given problem

Genea solution to problem represented as a set of parameters these parameters known as genes

Chromosomegenes joined together to form a string of values called chromosome

Fitness score(value)every chromosome has fitness score can be inferred from the chromosome itself by using fitness function

Recombination

Stochastic operatorsStochastic operators

SelectionSelection replicates the most successful replicates the most successful solutions found in a population at a rate solutions found in a population at a rate proportional to their relative quality proportional to their relative quality

RecombinationRecombination (Crossover)(Crossover) decomposes two distinct solutions and decomposes two distinct solutions and then randomly mixes their parts to form then randomly mixes their parts to form novel solutionsnovel solutions

MutationMutation randomly perturbs a candidate randomly perturbs a candidate solutionsolution

Simulated EvolutionSimulated Evolution

We need the followingWe need the following Representation of an individualRepresentation of an individual Fitness FunctionFitness Function Reproduction MethodReproduction Method Selection CriteriaSelection Criteria

Representing an IndividualRepresenting an Individual

An individual is data structure An individual is data structure representing the representing the ldquoldquogenetic genetic structurestructurerdquordquo of a possible solution of a possible solution

Genetic structure consists of an Genetic structure consists of an alphabet (usually 01)alphabet (usually 01)

Binary EncodingBinary Encoding Most Common Most Common ndashndash string of bits 0 or 1 string of bits 0 or 1

Chrom A = 1 0 11 0 0 1 0 1 1Chrom A = 1 0 11 0 0 1 0 1 1 Chrom B = 1 1 1 1 1 1 0 0 0 0Chrom B = 1 1 1 1 1 1 0 0 0 0 Gives you many possibilitiesGives you many possibilities Example Problem Knapsack problemExample Problem Knapsack problem The problem there are things with given value The problem there are things with given value

and size The knapsack has given capacity and size The knapsack has given capacity Select things to maximize the valuesSelect things to maximize the values

Encoding Each bit says if the corresponding Encoding Each bit says if the corresponding thing is in the knapsackthing is in the knapsack

Permutation EncodingPermutation Encoding Used in Used in ldquoldquoordering problemsordering problemsrdquordquo Every chromosome is a string of Every chromosome is a string of

numbers which represents number is a numbers which represents number is a sequencesequenceChrom A 1 5 3 2 6 4 7 9 8Chrom A 1 5 3 2 6 4 7 9 8Chrom B 8 5 7 7 2 3 1 4 9Chrom B 8 5 7 7 2 3 1 4 9

Example Travelling salesman problemExample Travelling salesman problem The problem cities that must be visitedThe problem cities that must be visited Encoding says order of cities in which Encoding says order of cities in which

salesman willl visitsalesman willl visit

Another ExampleAnother Example

To find optimal quantity of three To find optimal quantity of three major ingredients (sugar milk major ingredients (sugar milk sesame oil) denoting ouncessesame oil) denoting ounces Use an alphabet of 1-9 denoting Use an alphabet of 1-9 denoting

ouncesounces Solutions might be 1-1-1 2-1-4 3-3-1Solutions might be 1-1-1 2-1-4 3-3-1

Value EncodingValue Encoding Used for complicated values (real numbers) Used for complicated values (real numbers)

and when binary coding would be difficultand when binary coding would be difficult Each chromosome is a string of some valuesEach chromosome is a string of some values

Chrom A 12323 53243 04556Chrom A 12323 53243 04556Chrom B abcdjeifjdhdierjfdChrom B abcdjeifjdhdierjfdChrom C (back) (back) (right) (forward) (left)Chrom C (back) (back) (right) (forward) (left)

Example Finding weights for neural netsExample Finding weights for neural netsThe problem find weights for networkThe problem find weights for networkEncoding Real values that represent weightsEncoding Real values that represent weights

Rule base systemRule base system Given a rule (if color=red and size=small Given a rule (if color=red and size=small

and shape=round then object=appleand shape=round then object=apple Assume that each feature has finite set of Assume that each feature has finite set of

values (eg size = smalllarge)values (eg size = smalllarge) Represent the value as a substring of length Represent the value as a substring of length

equl to the number of possible values For equl to the number of possible values For example small = 10 large = 01example small = 10 large = 01

The entire rule would be 100 10 01 0100 The entire rule would be 100 10 01 0100 ndashndash set of rules concatenating the values set of rules concatenating the values togethertogether

How offspring are How offspring are produced - produced - ReproductionReproduction

ReproductionReproduction- Through - Through reproductionreproduction genetic algorithms genetic algorithms produce new generations of produce new generations of improved solutions by selecting improved solutions by selecting parents with higher fitness ratings parents with higher fitness ratings or by giving such parents a greater or by giving such parents a greater probability of being contributors probability of being contributors and by using random selectionand by using random selection

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

ChromosomesChromosomes are strings of are strings of DNADNA and and serves as a model for the whole organismserves as a model for the whole organism

A chromosome consists of A chromosome consists of genesgenes Each gene encodes a Each gene encodes a traittrait Complete set of genetic material (all Complete set of genetic material (all

chromosomes) is called chromosomes) is called genomegenome Particular set of genes in genome is called Particular set of genes in genome is called

genotypegenotype

Biological Background 1Biological Background 1

During During reproductionreproduction first occurs first occurs recombinationrecombination (or (or crossovercrossover))

Genes from parents form in some way the whole Genes from parents form in some way the whole new chromosomenew chromosome

The new created offspring can then be mutated The new created offspring can then be mutated MutationMutation means that the elements of DNA are a means that the elements of DNA are a bit changed This changes are mainly caused by bit changed This changes are mainly caused by errors in copying genes from parents errors in copying genes from parents

The The fitness fitness of an organism is measured by success of an organism is measured by success of the organism in its lifeof the organism in its life

Biological Background 2Biological Background 2

The space of all feasible solutions (it means objects The space of all feasible solutions (it means objects among those the desired solution is) is called among those the desired solution is) is called search spacesearch space (also (also state spacestate space))

EachEach point point in the search space represent one in the search space represent one feasible solutionfeasible solution

The looking for a solution is then equal to a The looking for a solution is then equal to a looking for some looking for some extremeextreme (minimum or (minimum or maximum) in the search spacemaximum) in the search space

Search methods hill climbing tabular search Search methods hill climbing tabular search simulated annealing and genetic algorithmsimulated annealing and genetic algorithm

Search SpaceSearch Space

Simple GASimple GA initialize population evaluate population while TerminationCriteriaNotSatisfied

select parents for reproductionperform crossover and mutationrepair()

evaluate population

Every loop called generation

ConceptsConcepts

Populationset of individuals each representing a possible solution to a given problem

Genea solution to problem represented as a set of parameters these parameters known as genes

Chromosomegenes joined together to form a string of values called chromosome

Fitness score(value)every chromosome has fitness score can be inferred from the chromosome itself by using fitness function

Recombination

Stochastic operatorsStochastic operators

SelectionSelection replicates the most successful replicates the most successful solutions found in a population at a rate solutions found in a population at a rate proportional to their relative quality proportional to their relative quality

RecombinationRecombination (Crossover)(Crossover) decomposes two distinct solutions and decomposes two distinct solutions and then randomly mixes their parts to form then randomly mixes their parts to form novel solutionsnovel solutions

MutationMutation randomly perturbs a candidate randomly perturbs a candidate solutionsolution

Simulated EvolutionSimulated Evolution

We need the followingWe need the following Representation of an individualRepresentation of an individual Fitness FunctionFitness Function Reproduction MethodReproduction Method Selection CriteriaSelection Criteria

Representing an IndividualRepresenting an Individual

An individual is data structure An individual is data structure representing the representing the ldquoldquogenetic genetic structurestructurerdquordquo of a possible solution of a possible solution

Genetic structure consists of an Genetic structure consists of an alphabet (usually 01)alphabet (usually 01)

Binary EncodingBinary Encoding Most Common Most Common ndashndash string of bits 0 or 1 string of bits 0 or 1

Chrom A = 1 0 11 0 0 1 0 1 1Chrom A = 1 0 11 0 0 1 0 1 1 Chrom B = 1 1 1 1 1 1 0 0 0 0Chrom B = 1 1 1 1 1 1 0 0 0 0 Gives you many possibilitiesGives you many possibilities Example Problem Knapsack problemExample Problem Knapsack problem The problem there are things with given value The problem there are things with given value

and size The knapsack has given capacity and size The knapsack has given capacity Select things to maximize the valuesSelect things to maximize the values

Encoding Each bit says if the corresponding Encoding Each bit says if the corresponding thing is in the knapsackthing is in the knapsack

Permutation EncodingPermutation Encoding Used in Used in ldquoldquoordering problemsordering problemsrdquordquo Every chromosome is a string of Every chromosome is a string of

numbers which represents number is a numbers which represents number is a sequencesequenceChrom A 1 5 3 2 6 4 7 9 8Chrom A 1 5 3 2 6 4 7 9 8Chrom B 8 5 7 7 2 3 1 4 9Chrom B 8 5 7 7 2 3 1 4 9

Example Travelling salesman problemExample Travelling salesman problem The problem cities that must be visitedThe problem cities that must be visited Encoding says order of cities in which Encoding says order of cities in which

salesman willl visitsalesman willl visit

Another ExampleAnother Example

To find optimal quantity of three To find optimal quantity of three major ingredients (sugar milk major ingredients (sugar milk sesame oil) denoting ouncessesame oil) denoting ounces Use an alphabet of 1-9 denoting Use an alphabet of 1-9 denoting

ouncesounces Solutions might be 1-1-1 2-1-4 3-3-1Solutions might be 1-1-1 2-1-4 3-3-1

Value EncodingValue Encoding Used for complicated values (real numbers) Used for complicated values (real numbers)

and when binary coding would be difficultand when binary coding would be difficult Each chromosome is a string of some valuesEach chromosome is a string of some values

Chrom A 12323 53243 04556Chrom A 12323 53243 04556Chrom B abcdjeifjdhdierjfdChrom B abcdjeifjdhdierjfdChrom C (back) (back) (right) (forward) (left)Chrom C (back) (back) (right) (forward) (left)

Example Finding weights for neural netsExample Finding weights for neural netsThe problem find weights for networkThe problem find weights for networkEncoding Real values that represent weightsEncoding Real values that represent weights

Rule base systemRule base system Given a rule (if color=red and size=small Given a rule (if color=red and size=small

and shape=round then object=appleand shape=round then object=apple Assume that each feature has finite set of Assume that each feature has finite set of

values (eg size = smalllarge)values (eg size = smalllarge) Represent the value as a substring of length Represent the value as a substring of length

equl to the number of possible values For equl to the number of possible values For example small = 10 large = 01example small = 10 large = 01

The entire rule would be 100 10 01 0100 The entire rule would be 100 10 01 0100 ndashndash set of rules concatenating the values set of rules concatenating the values togethertogether

How offspring are How offspring are produced - produced - ReproductionReproduction

ReproductionReproduction- Through - Through reproductionreproduction genetic algorithms genetic algorithms produce new generations of produce new generations of improved solutions by selecting improved solutions by selecting parents with higher fitness ratings parents with higher fitness ratings or by giving such parents a greater or by giving such parents a greater probability of being contributors probability of being contributors and by using random selectionand by using random selection

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

During During reproductionreproduction first occurs first occurs recombinationrecombination (or (or crossovercrossover))

Genes from parents form in some way the whole Genes from parents form in some way the whole new chromosomenew chromosome

The new created offspring can then be mutated The new created offspring can then be mutated MutationMutation means that the elements of DNA are a means that the elements of DNA are a bit changed This changes are mainly caused by bit changed This changes are mainly caused by errors in copying genes from parents errors in copying genes from parents

The The fitness fitness of an organism is measured by success of an organism is measured by success of the organism in its lifeof the organism in its life

Biological Background 2Biological Background 2

The space of all feasible solutions (it means objects The space of all feasible solutions (it means objects among those the desired solution is) is called among those the desired solution is) is called search spacesearch space (also (also state spacestate space))

EachEach point point in the search space represent one in the search space represent one feasible solutionfeasible solution

The looking for a solution is then equal to a The looking for a solution is then equal to a looking for some looking for some extremeextreme (minimum or (minimum or maximum) in the search spacemaximum) in the search space

Search methods hill climbing tabular search Search methods hill climbing tabular search simulated annealing and genetic algorithmsimulated annealing and genetic algorithm

Search SpaceSearch Space

Simple GASimple GA initialize population evaluate population while TerminationCriteriaNotSatisfied

select parents for reproductionperform crossover and mutationrepair()

evaluate population

Every loop called generation

ConceptsConcepts

Populationset of individuals each representing a possible solution to a given problem

Genea solution to problem represented as a set of parameters these parameters known as genes

Chromosomegenes joined together to form a string of values called chromosome

Fitness score(value)every chromosome has fitness score can be inferred from the chromosome itself by using fitness function

Recombination

Stochastic operatorsStochastic operators

SelectionSelection replicates the most successful replicates the most successful solutions found in a population at a rate solutions found in a population at a rate proportional to their relative quality proportional to their relative quality

RecombinationRecombination (Crossover)(Crossover) decomposes two distinct solutions and decomposes two distinct solutions and then randomly mixes their parts to form then randomly mixes their parts to form novel solutionsnovel solutions

MutationMutation randomly perturbs a candidate randomly perturbs a candidate solutionsolution

Simulated EvolutionSimulated Evolution

We need the followingWe need the following Representation of an individualRepresentation of an individual Fitness FunctionFitness Function Reproduction MethodReproduction Method Selection CriteriaSelection Criteria

Representing an IndividualRepresenting an Individual

An individual is data structure An individual is data structure representing the representing the ldquoldquogenetic genetic structurestructurerdquordquo of a possible solution of a possible solution

Genetic structure consists of an Genetic structure consists of an alphabet (usually 01)alphabet (usually 01)

Binary EncodingBinary Encoding Most Common Most Common ndashndash string of bits 0 or 1 string of bits 0 or 1

Chrom A = 1 0 11 0 0 1 0 1 1Chrom A = 1 0 11 0 0 1 0 1 1 Chrom B = 1 1 1 1 1 1 0 0 0 0Chrom B = 1 1 1 1 1 1 0 0 0 0 Gives you many possibilitiesGives you many possibilities Example Problem Knapsack problemExample Problem Knapsack problem The problem there are things with given value The problem there are things with given value

and size The knapsack has given capacity and size The knapsack has given capacity Select things to maximize the valuesSelect things to maximize the values

Encoding Each bit says if the corresponding Encoding Each bit says if the corresponding thing is in the knapsackthing is in the knapsack

Permutation EncodingPermutation Encoding Used in Used in ldquoldquoordering problemsordering problemsrdquordquo Every chromosome is a string of Every chromosome is a string of

numbers which represents number is a numbers which represents number is a sequencesequenceChrom A 1 5 3 2 6 4 7 9 8Chrom A 1 5 3 2 6 4 7 9 8Chrom B 8 5 7 7 2 3 1 4 9Chrom B 8 5 7 7 2 3 1 4 9

Example Travelling salesman problemExample Travelling salesman problem The problem cities that must be visitedThe problem cities that must be visited Encoding says order of cities in which Encoding says order of cities in which

salesman willl visitsalesman willl visit

Another ExampleAnother Example

To find optimal quantity of three To find optimal quantity of three major ingredients (sugar milk major ingredients (sugar milk sesame oil) denoting ouncessesame oil) denoting ounces Use an alphabet of 1-9 denoting Use an alphabet of 1-9 denoting

ouncesounces Solutions might be 1-1-1 2-1-4 3-3-1Solutions might be 1-1-1 2-1-4 3-3-1

Value EncodingValue Encoding Used for complicated values (real numbers) Used for complicated values (real numbers)

and when binary coding would be difficultand when binary coding would be difficult Each chromosome is a string of some valuesEach chromosome is a string of some values

Chrom A 12323 53243 04556Chrom A 12323 53243 04556Chrom B abcdjeifjdhdierjfdChrom B abcdjeifjdhdierjfdChrom C (back) (back) (right) (forward) (left)Chrom C (back) (back) (right) (forward) (left)

Example Finding weights for neural netsExample Finding weights for neural netsThe problem find weights for networkThe problem find weights for networkEncoding Real values that represent weightsEncoding Real values that represent weights

Rule base systemRule base system Given a rule (if color=red and size=small Given a rule (if color=red and size=small

and shape=round then object=appleand shape=round then object=apple Assume that each feature has finite set of Assume that each feature has finite set of

values (eg size = smalllarge)values (eg size = smalllarge) Represent the value as a substring of length Represent the value as a substring of length

equl to the number of possible values For equl to the number of possible values For example small = 10 large = 01example small = 10 large = 01

The entire rule would be 100 10 01 0100 The entire rule would be 100 10 01 0100 ndashndash set of rules concatenating the values set of rules concatenating the values togethertogether

How offspring are How offspring are produced - produced - ReproductionReproduction

ReproductionReproduction- Through - Through reproductionreproduction genetic algorithms genetic algorithms produce new generations of produce new generations of improved solutions by selecting improved solutions by selecting parents with higher fitness ratings parents with higher fitness ratings or by giving such parents a greater or by giving such parents a greater probability of being contributors probability of being contributors and by using random selectionand by using random selection

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

The space of all feasible solutions (it means objects The space of all feasible solutions (it means objects among those the desired solution is) is called among those the desired solution is) is called search spacesearch space (also (also state spacestate space))

EachEach point point in the search space represent one in the search space represent one feasible solutionfeasible solution

The looking for a solution is then equal to a The looking for a solution is then equal to a looking for some looking for some extremeextreme (minimum or (minimum or maximum) in the search spacemaximum) in the search space

Search methods hill climbing tabular search Search methods hill climbing tabular search simulated annealing and genetic algorithmsimulated annealing and genetic algorithm

Search SpaceSearch Space

Simple GASimple GA initialize population evaluate population while TerminationCriteriaNotSatisfied

select parents for reproductionperform crossover and mutationrepair()

evaluate population

Every loop called generation

ConceptsConcepts

Populationset of individuals each representing a possible solution to a given problem

Genea solution to problem represented as a set of parameters these parameters known as genes

Chromosomegenes joined together to form a string of values called chromosome

Fitness score(value)every chromosome has fitness score can be inferred from the chromosome itself by using fitness function

Recombination

Stochastic operatorsStochastic operators

SelectionSelection replicates the most successful replicates the most successful solutions found in a population at a rate solutions found in a population at a rate proportional to their relative quality proportional to their relative quality

RecombinationRecombination (Crossover)(Crossover) decomposes two distinct solutions and decomposes two distinct solutions and then randomly mixes their parts to form then randomly mixes their parts to form novel solutionsnovel solutions

MutationMutation randomly perturbs a candidate randomly perturbs a candidate solutionsolution

Simulated EvolutionSimulated Evolution

We need the followingWe need the following Representation of an individualRepresentation of an individual Fitness FunctionFitness Function Reproduction MethodReproduction Method Selection CriteriaSelection Criteria

Representing an IndividualRepresenting an Individual

An individual is data structure An individual is data structure representing the representing the ldquoldquogenetic genetic structurestructurerdquordquo of a possible solution of a possible solution

Genetic structure consists of an Genetic structure consists of an alphabet (usually 01)alphabet (usually 01)

Binary EncodingBinary Encoding Most Common Most Common ndashndash string of bits 0 or 1 string of bits 0 or 1

Chrom A = 1 0 11 0 0 1 0 1 1Chrom A = 1 0 11 0 0 1 0 1 1 Chrom B = 1 1 1 1 1 1 0 0 0 0Chrom B = 1 1 1 1 1 1 0 0 0 0 Gives you many possibilitiesGives you many possibilities Example Problem Knapsack problemExample Problem Knapsack problem The problem there are things with given value The problem there are things with given value

and size The knapsack has given capacity and size The knapsack has given capacity Select things to maximize the valuesSelect things to maximize the values

Encoding Each bit says if the corresponding Encoding Each bit says if the corresponding thing is in the knapsackthing is in the knapsack

Permutation EncodingPermutation Encoding Used in Used in ldquoldquoordering problemsordering problemsrdquordquo Every chromosome is a string of Every chromosome is a string of

numbers which represents number is a numbers which represents number is a sequencesequenceChrom A 1 5 3 2 6 4 7 9 8Chrom A 1 5 3 2 6 4 7 9 8Chrom B 8 5 7 7 2 3 1 4 9Chrom B 8 5 7 7 2 3 1 4 9

Example Travelling salesman problemExample Travelling salesman problem The problem cities that must be visitedThe problem cities that must be visited Encoding says order of cities in which Encoding says order of cities in which

salesman willl visitsalesman willl visit

Another ExampleAnother Example

To find optimal quantity of three To find optimal quantity of three major ingredients (sugar milk major ingredients (sugar milk sesame oil) denoting ouncessesame oil) denoting ounces Use an alphabet of 1-9 denoting Use an alphabet of 1-9 denoting

ouncesounces Solutions might be 1-1-1 2-1-4 3-3-1Solutions might be 1-1-1 2-1-4 3-3-1

Value EncodingValue Encoding Used for complicated values (real numbers) Used for complicated values (real numbers)

and when binary coding would be difficultand when binary coding would be difficult Each chromosome is a string of some valuesEach chromosome is a string of some values

Chrom A 12323 53243 04556Chrom A 12323 53243 04556Chrom B abcdjeifjdhdierjfdChrom B abcdjeifjdhdierjfdChrom C (back) (back) (right) (forward) (left)Chrom C (back) (back) (right) (forward) (left)

Example Finding weights for neural netsExample Finding weights for neural netsThe problem find weights for networkThe problem find weights for networkEncoding Real values that represent weightsEncoding Real values that represent weights

Rule base systemRule base system Given a rule (if color=red and size=small Given a rule (if color=red and size=small

and shape=round then object=appleand shape=round then object=apple Assume that each feature has finite set of Assume that each feature has finite set of

values (eg size = smalllarge)values (eg size = smalllarge) Represent the value as a substring of length Represent the value as a substring of length

equl to the number of possible values For equl to the number of possible values For example small = 10 large = 01example small = 10 large = 01

The entire rule would be 100 10 01 0100 The entire rule would be 100 10 01 0100 ndashndash set of rules concatenating the values set of rules concatenating the values togethertogether

How offspring are How offspring are produced - produced - ReproductionReproduction

ReproductionReproduction- Through - Through reproductionreproduction genetic algorithms genetic algorithms produce new generations of produce new generations of improved solutions by selecting improved solutions by selecting parents with higher fitness ratings parents with higher fitness ratings or by giving such parents a greater or by giving such parents a greater probability of being contributors probability of being contributors and by using random selectionand by using random selection

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Simple GASimple GA initialize population evaluate population while TerminationCriteriaNotSatisfied

select parents for reproductionperform crossover and mutationrepair()

evaluate population

Every loop called generation

ConceptsConcepts

Populationset of individuals each representing a possible solution to a given problem

Genea solution to problem represented as a set of parameters these parameters known as genes

Chromosomegenes joined together to form a string of values called chromosome

Fitness score(value)every chromosome has fitness score can be inferred from the chromosome itself by using fitness function

Recombination

Stochastic operatorsStochastic operators

SelectionSelection replicates the most successful replicates the most successful solutions found in a population at a rate solutions found in a population at a rate proportional to their relative quality proportional to their relative quality

RecombinationRecombination (Crossover)(Crossover) decomposes two distinct solutions and decomposes two distinct solutions and then randomly mixes their parts to form then randomly mixes their parts to form novel solutionsnovel solutions

MutationMutation randomly perturbs a candidate randomly perturbs a candidate solutionsolution

Simulated EvolutionSimulated Evolution

We need the followingWe need the following Representation of an individualRepresentation of an individual Fitness FunctionFitness Function Reproduction MethodReproduction Method Selection CriteriaSelection Criteria

Representing an IndividualRepresenting an Individual

An individual is data structure An individual is data structure representing the representing the ldquoldquogenetic genetic structurestructurerdquordquo of a possible solution of a possible solution

Genetic structure consists of an Genetic structure consists of an alphabet (usually 01)alphabet (usually 01)

Binary EncodingBinary Encoding Most Common Most Common ndashndash string of bits 0 or 1 string of bits 0 or 1

Chrom A = 1 0 11 0 0 1 0 1 1Chrom A = 1 0 11 0 0 1 0 1 1 Chrom B = 1 1 1 1 1 1 0 0 0 0Chrom B = 1 1 1 1 1 1 0 0 0 0 Gives you many possibilitiesGives you many possibilities Example Problem Knapsack problemExample Problem Knapsack problem The problem there are things with given value The problem there are things with given value

and size The knapsack has given capacity and size The knapsack has given capacity Select things to maximize the valuesSelect things to maximize the values

Encoding Each bit says if the corresponding Encoding Each bit says if the corresponding thing is in the knapsackthing is in the knapsack

Permutation EncodingPermutation Encoding Used in Used in ldquoldquoordering problemsordering problemsrdquordquo Every chromosome is a string of Every chromosome is a string of

numbers which represents number is a numbers which represents number is a sequencesequenceChrom A 1 5 3 2 6 4 7 9 8Chrom A 1 5 3 2 6 4 7 9 8Chrom B 8 5 7 7 2 3 1 4 9Chrom B 8 5 7 7 2 3 1 4 9

Example Travelling salesman problemExample Travelling salesman problem The problem cities that must be visitedThe problem cities that must be visited Encoding says order of cities in which Encoding says order of cities in which

salesman willl visitsalesman willl visit

Another ExampleAnother Example

To find optimal quantity of three To find optimal quantity of three major ingredients (sugar milk major ingredients (sugar milk sesame oil) denoting ouncessesame oil) denoting ounces Use an alphabet of 1-9 denoting Use an alphabet of 1-9 denoting

ouncesounces Solutions might be 1-1-1 2-1-4 3-3-1Solutions might be 1-1-1 2-1-4 3-3-1

Value EncodingValue Encoding Used for complicated values (real numbers) Used for complicated values (real numbers)

and when binary coding would be difficultand when binary coding would be difficult Each chromosome is a string of some valuesEach chromosome is a string of some values

Chrom A 12323 53243 04556Chrom A 12323 53243 04556Chrom B abcdjeifjdhdierjfdChrom B abcdjeifjdhdierjfdChrom C (back) (back) (right) (forward) (left)Chrom C (back) (back) (right) (forward) (left)

Example Finding weights for neural netsExample Finding weights for neural netsThe problem find weights for networkThe problem find weights for networkEncoding Real values that represent weightsEncoding Real values that represent weights

Rule base systemRule base system Given a rule (if color=red and size=small Given a rule (if color=red and size=small

and shape=round then object=appleand shape=round then object=apple Assume that each feature has finite set of Assume that each feature has finite set of

values (eg size = smalllarge)values (eg size = smalllarge) Represent the value as a substring of length Represent the value as a substring of length

equl to the number of possible values For equl to the number of possible values For example small = 10 large = 01example small = 10 large = 01

The entire rule would be 100 10 01 0100 The entire rule would be 100 10 01 0100 ndashndash set of rules concatenating the values set of rules concatenating the values togethertogether

How offspring are How offspring are produced - produced - ReproductionReproduction

ReproductionReproduction- Through - Through reproductionreproduction genetic algorithms genetic algorithms produce new generations of produce new generations of improved solutions by selecting improved solutions by selecting parents with higher fitness ratings parents with higher fitness ratings or by giving such parents a greater or by giving such parents a greater probability of being contributors probability of being contributors and by using random selectionand by using random selection

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

ConceptsConcepts

Populationset of individuals each representing a possible solution to a given problem

Genea solution to problem represented as a set of parameters these parameters known as genes

Chromosomegenes joined together to form a string of values called chromosome

Fitness score(value)every chromosome has fitness score can be inferred from the chromosome itself by using fitness function

Recombination

Stochastic operatorsStochastic operators

SelectionSelection replicates the most successful replicates the most successful solutions found in a population at a rate solutions found in a population at a rate proportional to their relative quality proportional to their relative quality

RecombinationRecombination (Crossover)(Crossover) decomposes two distinct solutions and decomposes two distinct solutions and then randomly mixes their parts to form then randomly mixes their parts to form novel solutionsnovel solutions

MutationMutation randomly perturbs a candidate randomly perturbs a candidate solutionsolution

Simulated EvolutionSimulated Evolution

We need the followingWe need the following Representation of an individualRepresentation of an individual Fitness FunctionFitness Function Reproduction MethodReproduction Method Selection CriteriaSelection Criteria

Representing an IndividualRepresenting an Individual

An individual is data structure An individual is data structure representing the representing the ldquoldquogenetic genetic structurestructurerdquordquo of a possible solution of a possible solution

Genetic structure consists of an Genetic structure consists of an alphabet (usually 01)alphabet (usually 01)

Binary EncodingBinary Encoding Most Common Most Common ndashndash string of bits 0 or 1 string of bits 0 or 1

Chrom A = 1 0 11 0 0 1 0 1 1Chrom A = 1 0 11 0 0 1 0 1 1 Chrom B = 1 1 1 1 1 1 0 0 0 0Chrom B = 1 1 1 1 1 1 0 0 0 0 Gives you many possibilitiesGives you many possibilities Example Problem Knapsack problemExample Problem Knapsack problem The problem there are things with given value The problem there are things with given value

and size The knapsack has given capacity and size The knapsack has given capacity Select things to maximize the valuesSelect things to maximize the values

Encoding Each bit says if the corresponding Encoding Each bit says if the corresponding thing is in the knapsackthing is in the knapsack

Permutation EncodingPermutation Encoding Used in Used in ldquoldquoordering problemsordering problemsrdquordquo Every chromosome is a string of Every chromosome is a string of

numbers which represents number is a numbers which represents number is a sequencesequenceChrom A 1 5 3 2 6 4 7 9 8Chrom A 1 5 3 2 6 4 7 9 8Chrom B 8 5 7 7 2 3 1 4 9Chrom B 8 5 7 7 2 3 1 4 9

Example Travelling salesman problemExample Travelling salesman problem The problem cities that must be visitedThe problem cities that must be visited Encoding says order of cities in which Encoding says order of cities in which

salesman willl visitsalesman willl visit

Another ExampleAnother Example

To find optimal quantity of three To find optimal quantity of three major ingredients (sugar milk major ingredients (sugar milk sesame oil) denoting ouncessesame oil) denoting ounces Use an alphabet of 1-9 denoting Use an alphabet of 1-9 denoting

ouncesounces Solutions might be 1-1-1 2-1-4 3-3-1Solutions might be 1-1-1 2-1-4 3-3-1

Value EncodingValue Encoding Used for complicated values (real numbers) Used for complicated values (real numbers)

and when binary coding would be difficultand when binary coding would be difficult Each chromosome is a string of some valuesEach chromosome is a string of some values

Chrom A 12323 53243 04556Chrom A 12323 53243 04556Chrom B abcdjeifjdhdierjfdChrom B abcdjeifjdhdierjfdChrom C (back) (back) (right) (forward) (left)Chrom C (back) (back) (right) (forward) (left)

Example Finding weights for neural netsExample Finding weights for neural netsThe problem find weights for networkThe problem find weights for networkEncoding Real values that represent weightsEncoding Real values that represent weights

Rule base systemRule base system Given a rule (if color=red and size=small Given a rule (if color=red and size=small

and shape=round then object=appleand shape=round then object=apple Assume that each feature has finite set of Assume that each feature has finite set of

values (eg size = smalllarge)values (eg size = smalllarge) Represent the value as a substring of length Represent the value as a substring of length

equl to the number of possible values For equl to the number of possible values For example small = 10 large = 01example small = 10 large = 01

The entire rule would be 100 10 01 0100 The entire rule would be 100 10 01 0100 ndashndash set of rules concatenating the values set of rules concatenating the values togethertogether

How offspring are How offspring are produced - produced - ReproductionReproduction

ReproductionReproduction- Through - Through reproductionreproduction genetic algorithms genetic algorithms produce new generations of produce new generations of improved solutions by selecting improved solutions by selecting parents with higher fitness ratings parents with higher fitness ratings or by giving such parents a greater or by giving such parents a greater probability of being contributors probability of being contributors and by using random selectionand by using random selection

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Recombination

Stochastic operatorsStochastic operators

SelectionSelection replicates the most successful replicates the most successful solutions found in a population at a rate solutions found in a population at a rate proportional to their relative quality proportional to their relative quality

RecombinationRecombination (Crossover)(Crossover) decomposes two distinct solutions and decomposes two distinct solutions and then randomly mixes their parts to form then randomly mixes their parts to form novel solutionsnovel solutions

MutationMutation randomly perturbs a candidate randomly perturbs a candidate solutionsolution

Simulated EvolutionSimulated Evolution

We need the followingWe need the following Representation of an individualRepresentation of an individual Fitness FunctionFitness Function Reproduction MethodReproduction Method Selection CriteriaSelection Criteria

Representing an IndividualRepresenting an Individual

An individual is data structure An individual is data structure representing the representing the ldquoldquogenetic genetic structurestructurerdquordquo of a possible solution of a possible solution

Genetic structure consists of an Genetic structure consists of an alphabet (usually 01)alphabet (usually 01)

Binary EncodingBinary Encoding Most Common Most Common ndashndash string of bits 0 or 1 string of bits 0 or 1

Chrom A = 1 0 11 0 0 1 0 1 1Chrom A = 1 0 11 0 0 1 0 1 1 Chrom B = 1 1 1 1 1 1 0 0 0 0Chrom B = 1 1 1 1 1 1 0 0 0 0 Gives you many possibilitiesGives you many possibilities Example Problem Knapsack problemExample Problem Knapsack problem The problem there are things with given value The problem there are things with given value

and size The knapsack has given capacity and size The knapsack has given capacity Select things to maximize the valuesSelect things to maximize the values

Encoding Each bit says if the corresponding Encoding Each bit says if the corresponding thing is in the knapsackthing is in the knapsack

Permutation EncodingPermutation Encoding Used in Used in ldquoldquoordering problemsordering problemsrdquordquo Every chromosome is a string of Every chromosome is a string of

numbers which represents number is a numbers which represents number is a sequencesequenceChrom A 1 5 3 2 6 4 7 9 8Chrom A 1 5 3 2 6 4 7 9 8Chrom B 8 5 7 7 2 3 1 4 9Chrom B 8 5 7 7 2 3 1 4 9

Example Travelling salesman problemExample Travelling salesman problem The problem cities that must be visitedThe problem cities that must be visited Encoding says order of cities in which Encoding says order of cities in which

salesman willl visitsalesman willl visit

Another ExampleAnother Example

To find optimal quantity of three To find optimal quantity of three major ingredients (sugar milk major ingredients (sugar milk sesame oil) denoting ouncessesame oil) denoting ounces Use an alphabet of 1-9 denoting Use an alphabet of 1-9 denoting

ouncesounces Solutions might be 1-1-1 2-1-4 3-3-1Solutions might be 1-1-1 2-1-4 3-3-1

Value EncodingValue Encoding Used for complicated values (real numbers) Used for complicated values (real numbers)

and when binary coding would be difficultand when binary coding would be difficult Each chromosome is a string of some valuesEach chromosome is a string of some values

Chrom A 12323 53243 04556Chrom A 12323 53243 04556Chrom B abcdjeifjdhdierjfdChrom B abcdjeifjdhdierjfdChrom C (back) (back) (right) (forward) (left)Chrom C (back) (back) (right) (forward) (left)

Example Finding weights for neural netsExample Finding weights for neural netsThe problem find weights for networkThe problem find weights for networkEncoding Real values that represent weightsEncoding Real values that represent weights

Rule base systemRule base system Given a rule (if color=red and size=small Given a rule (if color=red and size=small

and shape=round then object=appleand shape=round then object=apple Assume that each feature has finite set of Assume that each feature has finite set of

values (eg size = smalllarge)values (eg size = smalllarge) Represent the value as a substring of length Represent the value as a substring of length

equl to the number of possible values For equl to the number of possible values For example small = 10 large = 01example small = 10 large = 01

The entire rule would be 100 10 01 0100 The entire rule would be 100 10 01 0100 ndashndash set of rules concatenating the values set of rules concatenating the values togethertogether

How offspring are How offspring are produced - produced - ReproductionReproduction

ReproductionReproduction- Through - Through reproductionreproduction genetic algorithms genetic algorithms produce new generations of produce new generations of improved solutions by selecting improved solutions by selecting parents with higher fitness ratings parents with higher fitness ratings or by giving such parents a greater or by giving such parents a greater probability of being contributors probability of being contributors and by using random selectionand by using random selection

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Simulated EvolutionSimulated Evolution

We need the followingWe need the following Representation of an individualRepresentation of an individual Fitness FunctionFitness Function Reproduction MethodReproduction Method Selection CriteriaSelection Criteria

Representing an IndividualRepresenting an Individual

An individual is data structure An individual is data structure representing the representing the ldquoldquogenetic genetic structurestructurerdquordquo of a possible solution of a possible solution

Genetic structure consists of an Genetic structure consists of an alphabet (usually 01)alphabet (usually 01)

Binary EncodingBinary Encoding Most Common Most Common ndashndash string of bits 0 or 1 string of bits 0 or 1

Chrom A = 1 0 11 0 0 1 0 1 1Chrom A = 1 0 11 0 0 1 0 1 1 Chrom B = 1 1 1 1 1 1 0 0 0 0Chrom B = 1 1 1 1 1 1 0 0 0 0 Gives you many possibilitiesGives you many possibilities Example Problem Knapsack problemExample Problem Knapsack problem The problem there are things with given value The problem there are things with given value

and size The knapsack has given capacity and size The knapsack has given capacity Select things to maximize the valuesSelect things to maximize the values

Encoding Each bit says if the corresponding Encoding Each bit says if the corresponding thing is in the knapsackthing is in the knapsack

Permutation EncodingPermutation Encoding Used in Used in ldquoldquoordering problemsordering problemsrdquordquo Every chromosome is a string of Every chromosome is a string of

numbers which represents number is a numbers which represents number is a sequencesequenceChrom A 1 5 3 2 6 4 7 9 8Chrom A 1 5 3 2 6 4 7 9 8Chrom B 8 5 7 7 2 3 1 4 9Chrom B 8 5 7 7 2 3 1 4 9

Example Travelling salesman problemExample Travelling salesman problem The problem cities that must be visitedThe problem cities that must be visited Encoding says order of cities in which Encoding says order of cities in which

salesman willl visitsalesman willl visit

Another ExampleAnother Example

To find optimal quantity of three To find optimal quantity of three major ingredients (sugar milk major ingredients (sugar milk sesame oil) denoting ouncessesame oil) denoting ounces Use an alphabet of 1-9 denoting Use an alphabet of 1-9 denoting

ouncesounces Solutions might be 1-1-1 2-1-4 3-3-1Solutions might be 1-1-1 2-1-4 3-3-1

Value EncodingValue Encoding Used for complicated values (real numbers) Used for complicated values (real numbers)

and when binary coding would be difficultand when binary coding would be difficult Each chromosome is a string of some valuesEach chromosome is a string of some values

Chrom A 12323 53243 04556Chrom A 12323 53243 04556Chrom B abcdjeifjdhdierjfdChrom B abcdjeifjdhdierjfdChrom C (back) (back) (right) (forward) (left)Chrom C (back) (back) (right) (forward) (left)

Example Finding weights for neural netsExample Finding weights for neural netsThe problem find weights for networkThe problem find weights for networkEncoding Real values that represent weightsEncoding Real values that represent weights

Rule base systemRule base system Given a rule (if color=red and size=small Given a rule (if color=red and size=small

and shape=round then object=appleand shape=round then object=apple Assume that each feature has finite set of Assume that each feature has finite set of

values (eg size = smalllarge)values (eg size = smalllarge) Represent the value as a substring of length Represent the value as a substring of length

equl to the number of possible values For equl to the number of possible values For example small = 10 large = 01example small = 10 large = 01

The entire rule would be 100 10 01 0100 The entire rule would be 100 10 01 0100 ndashndash set of rules concatenating the values set of rules concatenating the values togethertogether

How offspring are How offspring are produced - produced - ReproductionReproduction

ReproductionReproduction- Through - Through reproductionreproduction genetic algorithms genetic algorithms produce new generations of produce new generations of improved solutions by selecting improved solutions by selecting parents with higher fitness ratings parents with higher fitness ratings or by giving such parents a greater or by giving such parents a greater probability of being contributors probability of being contributors and by using random selectionand by using random selection

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Representing an IndividualRepresenting an Individual

An individual is data structure An individual is data structure representing the representing the ldquoldquogenetic genetic structurestructurerdquordquo of a possible solution of a possible solution

Genetic structure consists of an Genetic structure consists of an alphabet (usually 01)alphabet (usually 01)

Binary EncodingBinary Encoding Most Common Most Common ndashndash string of bits 0 or 1 string of bits 0 or 1

Chrom A = 1 0 11 0 0 1 0 1 1Chrom A = 1 0 11 0 0 1 0 1 1 Chrom B = 1 1 1 1 1 1 0 0 0 0Chrom B = 1 1 1 1 1 1 0 0 0 0 Gives you many possibilitiesGives you many possibilities Example Problem Knapsack problemExample Problem Knapsack problem The problem there are things with given value The problem there are things with given value

and size The knapsack has given capacity and size The knapsack has given capacity Select things to maximize the valuesSelect things to maximize the values

Encoding Each bit says if the corresponding Encoding Each bit says if the corresponding thing is in the knapsackthing is in the knapsack

Permutation EncodingPermutation Encoding Used in Used in ldquoldquoordering problemsordering problemsrdquordquo Every chromosome is a string of Every chromosome is a string of

numbers which represents number is a numbers which represents number is a sequencesequenceChrom A 1 5 3 2 6 4 7 9 8Chrom A 1 5 3 2 6 4 7 9 8Chrom B 8 5 7 7 2 3 1 4 9Chrom B 8 5 7 7 2 3 1 4 9

Example Travelling salesman problemExample Travelling salesman problem The problem cities that must be visitedThe problem cities that must be visited Encoding says order of cities in which Encoding says order of cities in which

salesman willl visitsalesman willl visit

Another ExampleAnother Example

To find optimal quantity of three To find optimal quantity of three major ingredients (sugar milk major ingredients (sugar milk sesame oil) denoting ouncessesame oil) denoting ounces Use an alphabet of 1-9 denoting Use an alphabet of 1-9 denoting

ouncesounces Solutions might be 1-1-1 2-1-4 3-3-1Solutions might be 1-1-1 2-1-4 3-3-1

Value EncodingValue Encoding Used for complicated values (real numbers) Used for complicated values (real numbers)

and when binary coding would be difficultand when binary coding would be difficult Each chromosome is a string of some valuesEach chromosome is a string of some values

Chrom A 12323 53243 04556Chrom A 12323 53243 04556Chrom B abcdjeifjdhdierjfdChrom B abcdjeifjdhdierjfdChrom C (back) (back) (right) (forward) (left)Chrom C (back) (back) (right) (forward) (left)

Example Finding weights for neural netsExample Finding weights for neural netsThe problem find weights for networkThe problem find weights for networkEncoding Real values that represent weightsEncoding Real values that represent weights

Rule base systemRule base system Given a rule (if color=red and size=small Given a rule (if color=red and size=small

and shape=round then object=appleand shape=round then object=apple Assume that each feature has finite set of Assume that each feature has finite set of

values (eg size = smalllarge)values (eg size = smalllarge) Represent the value as a substring of length Represent the value as a substring of length

equl to the number of possible values For equl to the number of possible values For example small = 10 large = 01example small = 10 large = 01

The entire rule would be 100 10 01 0100 The entire rule would be 100 10 01 0100 ndashndash set of rules concatenating the values set of rules concatenating the values togethertogether

How offspring are How offspring are produced - produced - ReproductionReproduction

ReproductionReproduction- Through - Through reproductionreproduction genetic algorithms genetic algorithms produce new generations of produce new generations of improved solutions by selecting improved solutions by selecting parents with higher fitness ratings parents with higher fitness ratings or by giving such parents a greater or by giving such parents a greater probability of being contributors probability of being contributors and by using random selectionand by using random selection

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Binary EncodingBinary Encoding Most Common Most Common ndashndash string of bits 0 or 1 string of bits 0 or 1

Chrom A = 1 0 11 0 0 1 0 1 1Chrom A = 1 0 11 0 0 1 0 1 1 Chrom B = 1 1 1 1 1 1 0 0 0 0Chrom B = 1 1 1 1 1 1 0 0 0 0 Gives you many possibilitiesGives you many possibilities Example Problem Knapsack problemExample Problem Knapsack problem The problem there are things with given value The problem there are things with given value

and size The knapsack has given capacity and size The knapsack has given capacity Select things to maximize the valuesSelect things to maximize the values

Encoding Each bit says if the corresponding Encoding Each bit says if the corresponding thing is in the knapsackthing is in the knapsack

Permutation EncodingPermutation Encoding Used in Used in ldquoldquoordering problemsordering problemsrdquordquo Every chromosome is a string of Every chromosome is a string of

numbers which represents number is a numbers which represents number is a sequencesequenceChrom A 1 5 3 2 6 4 7 9 8Chrom A 1 5 3 2 6 4 7 9 8Chrom B 8 5 7 7 2 3 1 4 9Chrom B 8 5 7 7 2 3 1 4 9

Example Travelling salesman problemExample Travelling salesman problem The problem cities that must be visitedThe problem cities that must be visited Encoding says order of cities in which Encoding says order of cities in which

salesman willl visitsalesman willl visit

Another ExampleAnother Example

To find optimal quantity of three To find optimal quantity of three major ingredients (sugar milk major ingredients (sugar milk sesame oil) denoting ouncessesame oil) denoting ounces Use an alphabet of 1-9 denoting Use an alphabet of 1-9 denoting

ouncesounces Solutions might be 1-1-1 2-1-4 3-3-1Solutions might be 1-1-1 2-1-4 3-3-1

Value EncodingValue Encoding Used for complicated values (real numbers) Used for complicated values (real numbers)

and when binary coding would be difficultand when binary coding would be difficult Each chromosome is a string of some valuesEach chromosome is a string of some values

Chrom A 12323 53243 04556Chrom A 12323 53243 04556Chrom B abcdjeifjdhdierjfdChrom B abcdjeifjdhdierjfdChrom C (back) (back) (right) (forward) (left)Chrom C (back) (back) (right) (forward) (left)

Example Finding weights for neural netsExample Finding weights for neural netsThe problem find weights for networkThe problem find weights for networkEncoding Real values that represent weightsEncoding Real values that represent weights

Rule base systemRule base system Given a rule (if color=red and size=small Given a rule (if color=red and size=small

and shape=round then object=appleand shape=round then object=apple Assume that each feature has finite set of Assume that each feature has finite set of

values (eg size = smalllarge)values (eg size = smalllarge) Represent the value as a substring of length Represent the value as a substring of length

equl to the number of possible values For equl to the number of possible values For example small = 10 large = 01example small = 10 large = 01

The entire rule would be 100 10 01 0100 The entire rule would be 100 10 01 0100 ndashndash set of rules concatenating the values set of rules concatenating the values togethertogether

How offspring are How offspring are produced - produced - ReproductionReproduction

ReproductionReproduction- Through - Through reproductionreproduction genetic algorithms genetic algorithms produce new generations of produce new generations of improved solutions by selecting improved solutions by selecting parents with higher fitness ratings parents with higher fitness ratings or by giving such parents a greater or by giving such parents a greater probability of being contributors probability of being contributors and by using random selectionand by using random selection

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Permutation EncodingPermutation Encoding Used in Used in ldquoldquoordering problemsordering problemsrdquordquo Every chromosome is a string of Every chromosome is a string of

numbers which represents number is a numbers which represents number is a sequencesequenceChrom A 1 5 3 2 6 4 7 9 8Chrom A 1 5 3 2 6 4 7 9 8Chrom B 8 5 7 7 2 3 1 4 9Chrom B 8 5 7 7 2 3 1 4 9

Example Travelling salesman problemExample Travelling salesman problem The problem cities that must be visitedThe problem cities that must be visited Encoding says order of cities in which Encoding says order of cities in which

salesman willl visitsalesman willl visit

Another ExampleAnother Example

To find optimal quantity of three To find optimal quantity of three major ingredients (sugar milk major ingredients (sugar milk sesame oil) denoting ouncessesame oil) denoting ounces Use an alphabet of 1-9 denoting Use an alphabet of 1-9 denoting

ouncesounces Solutions might be 1-1-1 2-1-4 3-3-1Solutions might be 1-1-1 2-1-4 3-3-1

Value EncodingValue Encoding Used for complicated values (real numbers) Used for complicated values (real numbers)

and when binary coding would be difficultand when binary coding would be difficult Each chromosome is a string of some valuesEach chromosome is a string of some values

Chrom A 12323 53243 04556Chrom A 12323 53243 04556Chrom B abcdjeifjdhdierjfdChrom B abcdjeifjdhdierjfdChrom C (back) (back) (right) (forward) (left)Chrom C (back) (back) (right) (forward) (left)

Example Finding weights for neural netsExample Finding weights for neural netsThe problem find weights for networkThe problem find weights for networkEncoding Real values that represent weightsEncoding Real values that represent weights

Rule base systemRule base system Given a rule (if color=red and size=small Given a rule (if color=red and size=small

and shape=round then object=appleand shape=round then object=apple Assume that each feature has finite set of Assume that each feature has finite set of

values (eg size = smalllarge)values (eg size = smalllarge) Represent the value as a substring of length Represent the value as a substring of length

equl to the number of possible values For equl to the number of possible values For example small = 10 large = 01example small = 10 large = 01

The entire rule would be 100 10 01 0100 The entire rule would be 100 10 01 0100 ndashndash set of rules concatenating the values set of rules concatenating the values togethertogether

How offspring are How offspring are produced - produced - ReproductionReproduction

ReproductionReproduction- Through - Through reproductionreproduction genetic algorithms genetic algorithms produce new generations of produce new generations of improved solutions by selecting improved solutions by selecting parents with higher fitness ratings parents with higher fitness ratings or by giving such parents a greater or by giving such parents a greater probability of being contributors probability of being contributors and by using random selectionand by using random selection

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Another ExampleAnother Example

To find optimal quantity of three To find optimal quantity of three major ingredients (sugar milk major ingredients (sugar milk sesame oil) denoting ouncessesame oil) denoting ounces Use an alphabet of 1-9 denoting Use an alphabet of 1-9 denoting

ouncesounces Solutions might be 1-1-1 2-1-4 3-3-1Solutions might be 1-1-1 2-1-4 3-3-1

Value EncodingValue Encoding Used for complicated values (real numbers) Used for complicated values (real numbers)

and when binary coding would be difficultand when binary coding would be difficult Each chromosome is a string of some valuesEach chromosome is a string of some values

Chrom A 12323 53243 04556Chrom A 12323 53243 04556Chrom B abcdjeifjdhdierjfdChrom B abcdjeifjdhdierjfdChrom C (back) (back) (right) (forward) (left)Chrom C (back) (back) (right) (forward) (left)

Example Finding weights for neural netsExample Finding weights for neural netsThe problem find weights for networkThe problem find weights for networkEncoding Real values that represent weightsEncoding Real values that represent weights

Rule base systemRule base system Given a rule (if color=red and size=small Given a rule (if color=red and size=small

and shape=round then object=appleand shape=round then object=apple Assume that each feature has finite set of Assume that each feature has finite set of

values (eg size = smalllarge)values (eg size = smalllarge) Represent the value as a substring of length Represent the value as a substring of length

equl to the number of possible values For equl to the number of possible values For example small = 10 large = 01example small = 10 large = 01

The entire rule would be 100 10 01 0100 The entire rule would be 100 10 01 0100 ndashndash set of rules concatenating the values set of rules concatenating the values togethertogether

How offspring are How offspring are produced - produced - ReproductionReproduction

ReproductionReproduction- Through - Through reproductionreproduction genetic algorithms genetic algorithms produce new generations of produce new generations of improved solutions by selecting improved solutions by selecting parents with higher fitness ratings parents with higher fitness ratings or by giving such parents a greater or by giving such parents a greater probability of being contributors probability of being contributors and by using random selectionand by using random selection

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Value EncodingValue Encoding Used for complicated values (real numbers) Used for complicated values (real numbers)

and when binary coding would be difficultand when binary coding would be difficult Each chromosome is a string of some valuesEach chromosome is a string of some values

Chrom A 12323 53243 04556Chrom A 12323 53243 04556Chrom B abcdjeifjdhdierjfdChrom B abcdjeifjdhdierjfdChrom C (back) (back) (right) (forward) (left)Chrom C (back) (back) (right) (forward) (left)

Example Finding weights for neural netsExample Finding weights for neural netsThe problem find weights for networkThe problem find weights for networkEncoding Real values that represent weightsEncoding Real values that represent weights

Rule base systemRule base system Given a rule (if color=red and size=small Given a rule (if color=red and size=small

and shape=round then object=appleand shape=round then object=apple Assume that each feature has finite set of Assume that each feature has finite set of

values (eg size = smalllarge)values (eg size = smalllarge) Represent the value as a substring of length Represent the value as a substring of length

equl to the number of possible values For equl to the number of possible values For example small = 10 large = 01example small = 10 large = 01

The entire rule would be 100 10 01 0100 The entire rule would be 100 10 01 0100 ndashndash set of rules concatenating the values set of rules concatenating the values togethertogether

How offspring are How offspring are produced - produced - ReproductionReproduction

ReproductionReproduction- Through - Through reproductionreproduction genetic algorithms genetic algorithms produce new generations of produce new generations of improved solutions by selecting improved solutions by selecting parents with higher fitness ratings parents with higher fitness ratings or by giving such parents a greater or by giving such parents a greater probability of being contributors probability of being contributors and by using random selectionand by using random selection

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Rule base systemRule base system Given a rule (if color=red and size=small Given a rule (if color=red and size=small

and shape=round then object=appleand shape=round then object=apple Assume that each feature has finite set of Assume that each feature has finite set of

values (eg size = smalllarge)values (eg size = smalllarge) Represent the value as a substring of length Represent the value as a substring of length

equl to the number of possible values For equl to the number of possible values For example small = 10 large = 01example small = 10 large = 01

The entire rule would be 100 10 01 0100 The entire rule would be 100 10 01 0100 ndashndash set of rules concatenating the values set of rules concatenating the values togethertogether

How offspring are How offspring are produced - produced - ReproductionReproduction

ReproductionReproduction- Through - Through reproductionreproduction genetic algorithms genetic algorithms produce new generations of produce new generations of improved solutions by selecting improved solutions by selecting parents with higher fitness ratings parents with higher fitness ratings or by giving such parents a greater or by giving such parents a greater probability of being contributors probability of being contributors and by using random selectionand by using random selection

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

How offspring are How offspring are produced - produced - ReproductionReproduction

ReproductionReproduction- Through - Through reproductionreproduction genetic algorithms genetic algorithms produce new generations of produce new generations of improved solutions by selecting improved solutions by selecting parents with higher fitness ratings parents with higher fitness ratings or by giving such parents a greater or by giving such parents a greater probability of being contributors probability of being contributors and by using random selectionand by using random selection

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

How offspring are How offspring are producedproduced (Recombination)(Recombination) Crossover Crossover- Many - Many

genetic algorithms use strings of binary genetic algorithms use strings of binary symbols for chromosomes as in our symbols for chromosomes as in our Knapsack example to represent Knapsack example to represent solutions solutions CrossoverCrossover means choosing a means choosing a random position in the string (say after 2 random position in the string (say after 2 digits) and exchanging the segments digits) and exchanging the segments either to the right or to the left of this either to the right or to the left of this point with another string partitioned point with another string partitioned similarly to produce two new off springsimilarly to produce two new off spring

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Crossover ExampleCrossover Example

Parent A 011011Parent A 011011 Parent B 101100Parent B 101100 ldquoldquoMate the parents by splitting each Mate the parents by splitting each

number as shown between the second number as shown between the second and third digits (position is randomly and third digits (position is randomly selected)selected)

011011011011 101100101100

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Crossover ExampleCrossover Example Now combine the first digits of A with the last Now combine the first digits of A with the last

digits of B and the first digits of B with the last digits of B and the first digits of B with the last digits of Adigits of A

This gives you two new offspringThis gives you two new offspring 011100011100 101011101011

If these new solutions or offspring are better If these new solutions or offspring are better solutions than the parent solutions the system will solutions than the parent solutions the system will keep these as more optimal solutions and they will keep these as more optimal solutions and they will become parents This is repeated until some become parents This is repeated until some condition (for example number of populations or condition (for example number of populations or improvement of the best solution) is satisfied improvement of the best solution) is satisfied

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

How offspring are How offspring are producedproduced

MutationMutation- - MutationMutation is an arbitrary is an arbitrary change in a situation Sometimes it change in a situation Sometimes it is used to prevent the algorithm is used to prevent the algorithm from getting stuck The procedure from getting stuck The procedure changes a 1 to a 0 to a 1 instead of changes a 1 to a 0 to a 1 instead of duplicating them This change duplicating them This change occurs with a very low probability occurs with a very low probability (say 1 in 1000)(say 1 in 1000)

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

1 0 1 0 1 1 1

1 1 0 0 0 1 1

Parent 1

Parent 2

1 0 1 0 0 1 1

1 1 0 0 1 1 0

Child 1

Child 2 Mutation

Genetic Algorithm Genetic Algorithm OperatorsOperators

Mutation and CrossoverMutation and Crossover

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Crossover OperatorsCrossover Operators SingleSingle point crossover point crossover Parent A Parent A 1 0 0 1 0| 1 1 1 0 1 1 0 0 1 0| 1 1 1 0 1 Parent B 0 1 0 1 1 |1 0 1 1 0 Parent B 0 1 0 1 1 |1 0 1 1 0

Child AB Child AB 1 0 0 1 01 0 0 1 0 1 0 1 1 0 1 0 1 1 0 Child BA 0 1 0 1 1 Child BA 0 1 0 1 1 1 1 1 0 11 1 1 0 1

TwoTwo point crossover point crossover Parent A Parent A 1 0 0|1 0 1 1| 1 0 11 0 0|1 0 1 1| 1 0 1 Parent B 0 1 0Parent B 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0

Child AB Child AB 1 0 0 11 0 0 1 1 1 0 1 1 0 1 0 11 0 1 Child BA 0 1 0 1 Child BA 0 1 0 1 0 1 10 1 1 1 1 0 1 1 0

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Uniform CrossoverUniform Crossover

- A random mask is generated- A random mask is generated

- The mask determines which bits are copied - The mask determines which bits are copied from one parent and which from the other from one parent and which from the other parentparent

- Bit density in mask determines how much - Bit density in mask determines how much material is taken from the other parentmaterial is taken from the other parent

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

ExamplesExamples

MutationMutationThe recipe exampleThe recipe example

1-2-3 may be changed to 1-3-3 or 3-2-1-2-3 may be changed to 1-3-3 or 3-2-3 giving two new offspring How 3 giving two new offspring How often How many digits change How often How many digits change How big (parameters to adjust)big (parameters to adjust)

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

More examplesMore examples

CrossoverCrossover

Recipe Recipe

Parents 1-3-3 amp 3-2-3 Crossover Parents 1-3-3 amp 3-2-3 Crossover point after the first digit Generate point after the first digit Generate two offspring 3-3-3 and 1-2-3two offspring 3-3-3 and 1-2-3

Can have one or two point crossover Can have one or two point crossover

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Crossover Crossover ndashndash Permutation Permutation EncodingEncoding

Single point crossoverSingle point crossover - one crossover point - one crossover point is selected till this point the permutation is is selected till this point the permutation is copied from the first parent then the second copied from the first parent then the second parent is scanned and if the number is not yet parent is scanned and if the number is not yet in the offspring it is addedin the offspring it is added

((1 2 3 4 5|1 2 3 4 5| 6 7 8 9) + ( 6 7 8 9) + (4 5 3 6 8|4 5 3 6 8| 9 7 2 1) = ( 9 7 2 1) = (1 2 3 4 1 2 3 4 55 6 8 9 7) 6 8 9 7)

MutationMutation Order changingOrder changing - two numbers are - two numbers are

selected and exchanged selected and exchanged

(1 (1 22 3 4 5 6 3 4 5 6 88 9 7) =gt (1 9 7) =gt (1 88 3 4 5 6 3 4 5 6 22 9 9 7) 7)

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Crossover Crossover ndashndash Value Value EncodingEncoding

CrossoverCrossover All crossovers from All crossovers from binary encoding can can

be usedbe used

MutationMutation AddingAdding a small number (for real value encoding) a small number (for real value encoding)

- to selected values is added (or subtracted) a - to selected values is added (or subtracted) a small numbersmall number

((129 129 568 568 286286 411411 555) =gt (129 555) =gt (129 568 568 273273 422422 555) 555)

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Selection CriteriaSelection Criteria Fitness proportionate selection rank Fitness proportionate selection rank

selection methods selection methods Fitness proportionate Fitness proportionate ndashndash each individual each individual II has has

the the probability probability fitness(I)sum_over_all_individual_j Fitness(jfitness(I)sum_over_all_individual_j Fitness(j) ) where where Fitness(I)Fitness(I) is the fitness function value is the fitness function value for individual for individual II

Rank selection Rank selection ndashndash sorts individual by fitness sorts individual by fitness and the probability that an individual will be and the probability that an individual will be selected is proportional to its rank in this selected is proportional to its rank in this sorted listsorted list

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Fitness FunctionFitness Function Represents a rank of the Represents a rank of the ldquoldquorepresentationrepresentationrdquordquo It is usually a real numberIt is usually a real number The function usually has a value between The function usually has a value between

0 and 1 and is monotonically increasing0 and 1 and is monotonically increasing One can have a subjective judgment (eg One can have a subjective judgment (eg

1-5 for recipe 2-1-4)1-5 for recipe 2-1-4) Similarly the length of the route in the Similarly the length of the route in the

traveling salesperson problem is a good traveling salesperson problem is a good measure because the shorter the route measure because the shorter the route the better the solutionthe better the solution

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Outline of the Basic Genetic AlgorithmOutline of the Basic Genetic Algorithm

[Start] Generate random population of [Start] Generate random population of n chromosomes (suitable solutions for n chromosomes (suitable solutions for the problem) the problem)

[Fitness] Evaluate the fitness f(x) of [Fitness] Evaluate the fitness f(x) of each chromosome x in the population each chromosome x in the population

[New population] Create a new [New population] Create a new population by repeating following population by repeating following steps until the new population is steps until the new population is complete complete

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

44 [Selection] [Selection] Select two parent chromosomes Select two parent chromosomes from a population according to their fitness (the from a population according to their fitness (the better fitness the bigger chance to be selected) better fitness the bigger chance to be selected) The idea is to choose the better parents The idea is to choose the better parents

55 [Crossover][Crossover] With a crossover probability cross With a crossover probability cross over the parents to form a new offspring over the parents to form a new offspring (children) If no crossover was performed (children) If no crossover was performed offspring is an exact copy of parents offspring is an exact copy of parents

66 [Mutation][Mutation] With a mutation probability mutate With a mutation probability mutate new offspring at each locus (position in new offspring at each locus (position in chromosome) chromosome)

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Outline of the Basic Genetic Outline of the Basic Genetic AlgorithmAlgorithm

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Flow Diagram of the Flow Diagram of the Genetic Algorithm Genetic Algorithm

ProcessProcessDescribe Problem

Generate InitialSolutions

Test is initialsolution good enough

Stop

Select parents to reproduce

Apply crossover process and create a set of offspring

Apply random mutation

Step 1

Step 2

Step 3

Step 4

Step 5

Yes

No

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Components of a GAComponents of a GA

A problem definition as input andA problem definition as input and

Encoding principles (gene Encoding principles (gene chromosome)chromosome)

Initialization procedure Initialization procedure (creation)(creation)

Selection of parents Selection of parents (reproduction)(reproduction)

Genetic operators (mutation Genetic operators (mutation recombination)recombination)

Evaluation function Evaluation function (environment)(environment)

Termination conditionTermination condition

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Representation (encoding)Representation (encoding)

Possible individualrsquos encodingPossible individualrsquos encoding Bit strings (0101 1100)Bit strings (0101 1100) Real numbers (432 -331 00 Real numbers (432 -331 00

892) 892) Permutations of element (E11 E3 E7 E1 Permutations of element (E11 E3 E7 E1

E15)E15) Lists of rules (R1 R2 R3 R22 Lists of rules (R1 R2 R3 R22

R23)R23) Program elements (genetic Program elements (genetic

programming)programming) any data structure any data structure

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Representation (cont)Representation (cont)

When choosing an encoding method rely on the following key ideas

Use a data structure as close as possible to Use a data structure as close as possible to the natural representationthe natural representation

Write appropriate genetic operators as Write appropriate genetic operators as neededneeded

If possible ensure that all genotypes If possible ensure that all genotypes correspond to feasible solutionscorrespond to feasible solutions

If possible ensure that genetic operators If possible ensure that genetic operators preserve feasibilitypreserve feasibility

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

InitializationInitialization

Start with a population of randomly generated individuals or use- A previously saved population- A set of solutions provided by

a human expert- A set of solutions provided by

another heuristic algorithm

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

SelectionSelection

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

1- Fitness Proportionate Selection1- Fitness Proportionate Selection Derived by Holland as the optimal trade-Derived by Holland as the optimal trade-

off between exploration and exploitationoff between exploration and exploitation

DrawbacksDrawbacks Different selection for Different selection for ff11(x) (x) and and ff22(x) = f(x) = f11(x) + (x) +

c c Super individualsSuper individuals cause convergence cause convergence

(that may be premature)(that may be premature)

SelectioSelection n

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

3- Tournament Selection3- Tournament Selection

Tournament Selectionndash randomly select two individuals and the onewith the highest rank goes on and reproducesndash cares only about the one with the higher ranknot the spread between the two fitness scoresndash puts an upper and lower bound on the chancesthat any individual to reproduce for the nextgeneration equal to (2s ndash 2r + 1) s2

1048698 s is the size of the population1048698 r is the rank of the winning individualndash can be generalized to select best of n individuals

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Recombination (Crossover)Recombination (Crossover)

Enables the evolutionary process to move toward promising

regions of the search space

Matches good parentsrsquo sub-solutions to construct better offspring

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

MutationMutation

PurposePurpose to simulate the effect of errors to simulate the effect of errors that happen with low probability during that happen with low probability during duplicationduplication

ResultsResults

- Movement in the search space- Movement in the search space

- Restoration of lost information to the - Restoration of lost information to the populationpopulation

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Evaluation (fitness function)Evaluation (fitness function)

Solution is only as good as the Solution is only as good as the evaluation function choosing a good evaluation function choosing a good one is often the hardest partone is often the hardest part

Similar-encoded solutions should have a Similar-encoded solutions should have a similar fitnesssimilar fitness

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Termination conditionTermination condition

ExamplesExamples

A pre-determined number of generations or A pre-determined number of generations or time has elapsedtime has elapsed

A satisfactory solution has been achievedA satisfactory solution has been achieved No improvement in solution quality has No improvement in solution quality has

taken place for a pre-determined number of taken place for a pre-determined number of generationsgenerations

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

The MAXONE Problem

Problem instance a string of l binary cells l

Objective maximize the number of ones in the string

f ii

l

( )

1

Fitness

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Fitness Proportionate Selection

Implementation ldquoRoulette Wheelrdquo

Pf

f( )

( )

Probability of being selected

2f

f

( )

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Mutation

11101 0101 0

pmut

01101 0101 1

independent Bernoulli transcription errors

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Example Recombination amp Mutation

0111011011 0111011011 0111111011 f = 80111011011 0111011011 0111011011 f = 7110|1100010 1100101100 1100101100 f = 5010|0101100 0101100010 0101100010 f = 41|100110011 1100110011 1100110011 f = 61|100110011 1100110011 1000110011 f = 50110001010 0110001010 0110001010 f = 41101011011 1101011011 1101011011 f = 7011000|1010 0110001011 0110001011 f = 5110101|1011 1101011010 1101011010 f = 6

TOTAL = 57

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Example Example Suppose a Genetic Algorithm uses chromosomes of the form Suppose a Genetic Algorithm uses chromosomes of the form

x=abcdefgh with a fixed length of eight genes Each gene x=abcdefgh with a fixed length of eight genes Each gene can be any digit between 0 and 9 Let the fitness of can be any digit between 0 and 9 Let the fitness of individual x be calculated as individual x be calculated as

f(x) =(a+b)-(c+d)+(e+f)- ( g+h)f(x) =(a+b)-(c+d)+(e+f)- ( g+h)And let the initial population consist of four individuals And let the initial population consist of four individuals

x1 x4 with the following chromosomes x1 x4 with the following chromosomes X1 = 6 5 4 1 3 5 3 2X1 = 6 5 4 1 3 5 3 2F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9F(x1) =(6+5)-(4+1)+(3+5)-(3+2) = 9X2 = 8 7 1 2 6 6 0 1X2 = 8 7 1 2 6 6 0 1F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23F(x2) = (8+7)-(1+2)+(6+6)-(0+1) = 23X3 = 2 3 9 2 1 2 8 5X3 = 2 3 9 2 1 2 8 5F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16F(x3) = (2+3)-(9+2)+(1+2)-(8+5) = -16X4= 4 1 8 5 2 0 9 4 X4= 4 1 8 5 2 0 9 4 F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19F(x4) = (4+1)-(8+5)+(2+0)-(9+4) = -19The arrangement is ( assume maximization )The arrangement is ( assume maximization )X2X2 x1x1 x3x3 x4x4( the fittest individual )( the fittest individual ) ( least fit individual )( least fit individual )

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Put the calculations in Put the calculations in table for simplicitytable for simplicity

IndividualIndividualss

String String RepresentatioRepresentatio

nn

FitnesFitnesss

Arrangement Assume Arrangement Assume maximizationmaximization

X1X1 6541353265413532 99 X2(fittest individual)X2(fittest individual)

X2X2 8712660187126601 2323 X1(second fittest X1(second fittest individual)individual)

X3X3 2392128523921285 --1616 X3 (third fittest X3 (third fittest individual)individual)

X4X4 4185209441852094 --1919 X4 (least fit individual)X4 (least fit individual)

So Average fitness -075 Best 23 Worst -19Average fitness = ( 9+23+ -16 + -19) 4 =-075

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

` X2 = 8X2 = 8 77 11 22 66 6600 11

X1 = 6X1 = 6 55 44 11 33 5533 22

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 3322

Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 0011

X1 = 6X1 = 6 55 44 11 33 5533 22

X3 = 2X3 = 2 33 99 22 11 2288 55

Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 3322

Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 8855

Middle crossover

crossover crossover

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

X2 = 8X2 = 8 77 11 22 66 66 00 11

X3 = 2X3 = 2 33 99 22 11 22 88 55

Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 8811

Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 8811

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Offspring 1 = 8Offspring 1 = 8 77 11 22 33 55 33 22F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15F (Offspring 1) =(8+7)-(1+2)+(3+5)-(3+2) = 15Offspring 2 = 6Offspring 2 = 6 55 44 11 66 66 00 11F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17F (Offspring 2) =(6+5)-(4+1)+(6+6)-(0+1) = 17Offspring 3 = 6Offspring 3 = 6 55 99 22 11 22 33 22F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2F (Offspring 3) =(6+5)-(9+2)+(1+2)-(3+2) = -2Offspring 4 = 2Offspring 4 = 2 33 44 11 33 55 88 55F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5F (Offspring 4) =(2+3)-(4+1)+(3+5)-(8+5) = -5Offspring 5 = 8Offspring 5 = 8 33 11 22 66 66 88 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11F (Offspring 5) =(8+3)-(1+2)+(6+6)-(8+1) = 11Offspring 6 = 2Offspring 6 = 2 77 11 22 66 22 88 11F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5F (Offspring 6) =(2+7)-(1+2)+(6+2)-(8+1) = 5

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

IndividualsIndividuals String RepresentationString Representation FitnessFitness

Offspring 1Offspring 1 8712353287123532 1515

OffspringOffspring 22 6541660165416601 1717

OffspringOffspring 3 3 6592123265921232 --22

Offspring 4Offspring 4 2341358523413585 --55

Offspring 5Offspring 5 8792120187921201 1111

Offspring 6Offspring 6 2392660123926601 55

Put the calculation in table for simplicity

Average fitness 6833 Best 17 Worst -5

So that the overall fitness is improved since the average is better and worst is improved

Average fitness = (15+17+ -5 + -2 + 11+5 ) 6 = 68333

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Example The Knapsack Example The Knapsack ProblemProblem You are going on an overnight hike and You are going on an overnight hike and

have a number of items that you could take have a number of items that you could take along Each item has a weight (in pounds) along Each item has a weight (in pounds) and a benefit or value to you on the and a benefit or value to you on the hike(for measurements sake lethike(for measurements sake letrsquorsquos say in US s say in US dollars) and you can take one of each item dollars) and you can take one of each item at most There is a capacity limit on the at most There is a capacity limit on the weight you can carry (constraint) This weight you can carry (constraint) This problem only illustrates one constraint but problem only illustrates one constraint but in reality there could be many constraints in reality there could be many constraints including volume time etcincluding volume time etc

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Item Item 1 2 3 4 5 6 71 2 3 4 5 6 7 BenefitBenefit 5 8 3 2 7 9 45 8 3 2 7 9 4 WeightWeight 7 8 4 7 8 4 10 4 6 410 4 6 4 Knapsack holds a maximum of 22 pounds Knapsack holds a maximum of 22 pounds Fill it to get the maximum benefitFill it to get the maximum benefit Solutions take the form of a string of 1rsquos and 0rsquosSolutions take the form of a string of 1rsquos and 0rsquos Solutions Also known as strings of genes called Solutions Also known as strings of genes called

ChromosomesChromosomes 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

GA Example The GA Example The Knapsack ProblemKnapsack Problem

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Example The Knapsack Example The Knapsack ProblemProblem We represent a solution as a string of seven 1s and 0s We represent a solution as a string of seven 1s and 0s

and the fitness function as the total benefit which is and the fitness function as the total benefit which is the sum of the gene values in a string solution times the sum of the gene values in a string solution times their representative benefit coefficienttheir representative benefit coefficient

The method generates a set of random solutions The method generates a set of random solutions (initial parents) uses total benefit as the fitness (initial parents) uses total benefit as the fitness function and selects the parents randomly to create function and selects the parents randomly to create generations of offspring by crossover and mutationgenerations of offspring by crossover and mutation

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Knapsack ExampleKnapsack Example Typically a string of 1s and 0s can Typically a string of 1s and 0s can

represent a solutionrepresent a solution Possible solutions generated by the Possible solutions generated by the

system using system using Reproduction Reproduction CrossoverCrossover or or MutationsMutations 1 01010101 0101010 2 11001002 1100100 3 01001113 0100111

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Knapsack ExampleKnapsack ExampleSolution 1Solution 1

Benefit 8 + 2 + 9 = 19Benefit 8 + 2 + 9 = 19 Weight 8 + 10 + 6 = 24Weight 8 + 10 + 6 = 24

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 11 00 11 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Knapsack ExampleKnapsack ExampleSolution 2Solution 2

Benefit 5 + 8 + 7 = 20Benefit 5 + 8 + 7 = 20 Weight 7 + 8 + 4 = 19Weight 7 + 8 + 4 = 19

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

11 11 00 00 11 00 00

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Knapsack ExampleKnapsack ExampleSolution 3Solution 3

Benefit 8 + 7 + 9 + 4 = 28Benefit 8 + 7 + 9 + 4 = 28 Weight 8 + 4 + 6 + 4 = 22Weight 8 + 4 + 6 + 4 = 22

ItemItem 11 22 33 44 55 66 77

SolutioSolutionn

00 11 00 00 11 11 11

BenefitBenefit 55 88 33 22 77 99 44

WeightWeight 77 88 44 1010 44 66 44

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Knapsack ExampleKnapsack Example Solution 3 is clearly the best solution Solution 3 is clearly the best solution

and has met our conditions therefore and has met our conditions therefore item number 2 5 6 and 7 will be taken item number 2 5 6 and 7 will be taken on the hiking trip We will be able to get on the hiking trip We will be able to get the most benefit out of these items the most benefit out of these items while still having weight equal to 22 while still having weight equal to 22 poundspounds

This is a simple example illustrating a This is a simple example illustrating a genetic algorithm approachgenetic algorithm approach

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Knapsack ProblemKnapsack Problem

To understand GA must work with the following problem

(Knap Sack Problem) Thief wants to steal gold store Thief has a bag(the bag can hold a specific weight) Every piece of gold has a specific weight and price Thief wants to steal gold with high price but the

weight must equal or less than the weight that bag can hold it

If we gave every gold piece a specific number 123hellipn(suggest n=8 in this example)1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 100 30 250 150 50 75 50 50

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

1-Encoding (representation)(genechromosome)

Chromosome Bit strings (101101010100) Real numbers (431452663110) Permutation of elements (E11 E3 E7 hellip E1 E15) Integer Numbers (111254986251) Any data structures In knap sack problem can represent any solution

as chromosome by using bit string of length 8Ex- 1 1 0 1 0 0 0 1 8 7 6 5 4 3 2 11(gene)this piece taken 0(gene)this piece

untaken

could be

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

2-Initialize population

Implementers specify population size To initialize population create

chromosomes randomly and store them in list of length the population size

In our problem lets take population size 6 chromosomes

We can initialize population a following1 10100001

2 01110011

3 11110000

4 00110011

5 01010101

6 00001111

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

3-Evaluation of population Giving every chromosome in population

fitness value by using fitness function Fitness functions will differ according to

the problem and encoding technique Fitness function returns a single

numerical(fitness) which reflex the utility or the ability of the individual which that chromosome represents

Fitness function can calculate strength weight width maximum loadcostconstruction time or combination of all these

Fitness value well be stored with chromosome

chromosome Fitness function Fitness value

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

-

In our example we will make fitness function as the sum of price of all gold pieces-To complete our example must apply fitness function on all chromosomes

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

Chromosome fitness value

1 2 3 4 5 6 7 8

weight 5 3 10 6 5 5 4 4

price 50 50 75 50 150 250 30 100

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

4-Selection of new parents(reproduction)

Individuals are selected from population randomly or by using any selection method to improve the population itself

Good individuals will probably be selected several times in a generation poor ones may not be at all

Methods of selectionRandom Best Tournament Roulette wheel

Truncation Rank Exponential Boltzman Steady state Interactive and binary tournament selection

In our example we will use Truncation selection with parameter 3

search best 3 chromosomes and then select 6 chromosomes randomly from these three chromosomes and store them as new population to be used in the next step

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

chromosome fitnes value

1 10100001 225

2 01110011 305

3 11110000 225

4 00110011 225

5 01010101 450

6 00001111 530

chromosome fitnes value

1 01110011 305

2 01010101 450

3 00001111 530

Search best 3 chromosomes

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

New population

Old population

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

5-Crossover Crossover is performed with probability Pcross

(crossover probability or crossover rate ) between two selected individuals called parents by exchanging parts of their genes to form two new individuals called offsprings

The simplest method know as single point crossover

Single point crossover take 2 individual and cut their chromosome strings at randomly chosen position to produce 2 head segments and 2 tail segments The tail segments are then swapped over to produce 2 new full length chromosomes

Pcross (crossover probability or crossover rate ) is typically between 06 and 10

There is also Multi-Point Uniform Bit Simulated Problem Centered and specialized crossover techniques

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

chromosome fitnes value

1 01010101 450

2 00001111 530

3 00001111 530

4 00001111 530

5 01110011 305

6 01010101 450

we will do it just for first two parents

Pcross=06

Select two parent(12)Generate random number between 00-10(03)

03lt=06(yes) apply crossovergenerate random number between 1-8(3)old 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1new 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 swap tailsDo this for each pair in population

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

6-Mutation Applied to each child individually after

crossover It alters some of genes in chromosome with

small probability Must specify Pmut(mutation probability that is

relatively small) therefore a few number of chromosomes will be mutated

In our examplesuppose Pmut =02generate number between 0-1 (001)

001lt=02(yes) apply mutationGenerate number between 1-8(6)

0 1 0 1 0 1 0 1 =gt 0 1 1 1 0 1 0 1Do this for each chromosome in population

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Termination CriteriaTermination CriteriaThere exist three termination

condition type1-Timein seconds in minutes and may

be in hours according to the problem that you have it

2-Number of generations in hundreds in thousands may be in millions according to the problem you have it

3-convergence when 95 of populations have the same fitness value we can say the convergence started to appear and the user can stop its genetic program to take the result

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

The Knapsack ProblemThe Knapsack Problem The knapsack The knapsack

problem problem though simple though simple has many has many important important applications applications including including determining determining what items to what items to take on a space take on a space ship missionship mission

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Another ExampleAnother ExampleThe Traveling Salesman Problem The Traveling Salesman Problem (TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point given the cost of travel between all cities how should he plan his itinerary for minimum total cost of the entire tour

TSP NP-Complete

Note we shall discuss a single possible approach to approximate the TSP by GAs

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

TSP (Representation Evaluation TSP (Representation Evaluation Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2hellip in) represents a tour (v is a permutation of 12hellipn)

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization use either some heuristics or a random sample of permutations of 12hellipn

We shall use the fitness proportionate selection

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

TSP (Crossover1)TSP (Crossover1)

OX ndash builds offspring by choosing a sub-sequence of a tour from one parent and preserving the relative order of cities from the other parent and feasibility

Example

p1 = (1 2 3 4 5 6 7 8 9) and

p2 = (4 5 2 1 8 7 6 9 3)

First the segments between cut points are copied into offspring

o1 = (x x x 4 5 6 7 x x) and

o2 = (x x x 1 8 7 6 x x)

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

TSP (Crossover2)TSP (Crossover2)

Next starting from the second cut point of one parent the cities from the other parent are copied in the same order

The sequence of the cities in the second parent is 9 ndash 3 ndash 4 ndash 5 ndash 2 ndash 1 ndash 8 ndash 7 ndash 6

After removal of cities from the first offspring we get 9 ndash 3 ndash 2 ndash 1 ndash 8

This sequence is placed in the first offspring

o1 = (2 1 8 4 5 6 7 9 3) and similarly in the second

o2 = (3 4 5 1 8 7 6 9 2)

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

The sub-string between two randomly

selected points in the path is reversed

Example

(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)

Such simple inversion guarantees that the resulting offspring is a legal tour

TSP (Inversion)TSP (Inversion)

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Genetic AlgorithmsGenetic Algorithms Genetic Algorithms are a type of machine Genetic Algorithms are a type of machine

learning for representing and solving learning for representing and solving complex problemscomplex problems

They provide a set of efficient domain-They provide a set of efficient domain-independent search heuristics for a broad independent search heuristics for a broad spectrum of applicationsspectrum of applications

A genetic algorithm interprets information A genetic algorithm interprets information that enables it to reject inferior solutions that enables it to reject inferior solutions and accumulate good ones and thus it and accumulate good ones and thus it learns about its universelearns about its universe

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas

Genetic Algorithm Genetic Algorithm Application AreasApplication Areas Dynamic process controlDynamic process control Induction of rule optimizationInduction of rule optimization Discovering new connectivity topologiesDiscovering new connectivity topologies Simulating biological models of behavior and evolutionSimulating biological models of behavior and evolution Complex design of engineering structuresComplex design of engineering structures Pattern recognitionPattern recognition SchedulingScheduling TransportationTransportation Layout and circuit designLayout and circuit design TelecommunicationTelecommunication Graph-based problemsGraph-based problems

  • Genetic Algorithms
  • Slide 2
  • Slide 3
  • Slide 4
  • Biological Background 1
  • Biological Background 2
  • Search Space
  • Simple GA
  • Concepts
  • Slide 10
  • Simulated Evolution
  • Representing an Individual
  • Binary Encoding
  • Permutation Encoding
  • Another Example
  • Value Encoding
  • Rule base system
  • How offspring are produced - Reproduction
  • How offspring are produced
  • Crossover Example
  • Slide 21
  • Slide 22
  • Slide 23
  • Crossover Operators
  • Uniform Crossover
  • Examples
  • More examples
  • Crossover ndash Permutation Encoding
  • Crossover ndash Value Encoding
  • Selection Criteria
  • Fitness Function
  • Outline of the Basic Genetic Algorithm
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • Slide 39
  • Slide 40
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • The MAXONE Problem
  • Fitness Proportionate Selection
  • Mutation
  • Example Recombination amp Mutation
  • Slide 52
  • Slide 53
  • Slide 54
  • Slide 55
  • Slide 56
  • Slide 57
  • Example The Knapsack Problem
  • GA Example The Knapsack Problem
  • Slide 60
  • Knapsack Example
  • Knapsack Example Solution 1
  • Knapsack Example Solution 2
  • Knapsack Example Solution 3
  • Slide 65
  • Knapsack Problem
  • 1-Encoding (representation)(genechromosome)
  • 2-Initialize population
  • 3-Evaluation of population
  • - In our example we will make fitness function as the sum of price of all gold pieces -To complete our example must apply fitness function on all chromosomes
  • 4-Selection of new parents(reproduction)
  • Slide 72
  • 5-Crossover
  • Slide 74
  • Slide 75
  • Termination Criteria
  • The Knapsack Problem
  • Another Example The Traveling Salesman Problem (TSP)
  • TSP (Representation Evaluation Initialization and Selection)
  • TSP (Crossover1)
  • TSP (Crossover2)
  • TSP (Inversion)
  • Slide 83
  • Genetic Algorithm Application Areas