Genetic'Algorithms'::' ::'Algoritmi'Genetici'1 - Unict ·...

41
Genetic Algorithms :: :: Algoritmi Genetici Prof. Mario Pavone Department of Mathematics and Computer Sciecne University of Catania v.le A. Doria 6 – 95125 Catania, Italy [email protected] http://www.dmi.unict.it/mpavone/

Transcript of Genetic'Algorithms'::' ::'Algoritmi'Genetici'1 - Unict ·...

Genetic'Algorithms'::'::'Algoritmi'Genetici'1

Prof. Mario Pavone Department of Mathematics and Computer Sciecne

University of Catania v.le A. Doria 6 – 95125 Catania, Italy

[email protected] http://www.dmi.unict.it/mpavone/

Main'References:'books1•  Genetic Algorithms in Search, Optimization &

Machine Learning David E. Goldberg, Addison-Wesley Publishing Company, 1989

•  An Introduction to Genetic Algorithms (Complex Adaptive Systems)

Melanie Mitchell, MIT Press, Cambirdge Massachuttes, 1996

Outline of the Genetic Algorithm

•  Randomly generate a set of possible solutions to a problem,

representing each as a fixed length character string

•  Test each possible solution against the problem using a fitness

function to evaluate each solution

•  Keep the best solutions, and use them to generate new possible

solutions

•  Repeat the previous two steps until either an acceptable solution is

found, or until the algorithm has iterated through a given number of

cycles (generations)

The GA Cycle of Reproduction

Population

Fitness Evaluation Genetic Operators

Selection(Mating Pool)

Parents

Offspring New

Generation

Manipulation Reproduction

Decoded Strings

Issues for Genetic Algorithm practitioners

•  Choosing basic implementation issues such as

! Representation

! Population size and mutation rate

! Selection, deletion policies

! Cross over and mutation operators

•  Termination criterion

•  Performance and scalability

•  Solution is only as good as evaluation functions.

Benefits'of'Genetic'Algorithms1

•  Easy to understand •  Supports multi-objective optimisation •  Good for noisy environment •  We always get answer and answer gets better with

time •  Inherently parallel and easily distributed •  Easy to exploit for precious or alternate solutions •  Flexible in forming building blocks for hybrid

applications •  Has substantial history and range of use

Genotype space = {0,1}L Phenotype space Encoding (representation)

Decoding (inverse representation)

011101001

010001001

10010010

10010001

Representation

Basic Operators of Genetic Algorithm

•  Reproduction: It is usually the first operator applied on population. Chromosomes are selected from the population of parents to cross over and produce offspring. It is based on Darwin�s evolution theory of �Survival of the fittest�. Therefore, this operator is also known as �Selection Operator�.

•  Cross Over: After reproduction phase, population is enriched with better individuals. It makes clones of good strings but does not create new ones. Cross over operator is applied to the mating pool with a hope that it would create better strings.

•  Mutation: After cross over, the strings are subjected to mutation. Mutation of a bit involves flipping it, changing 0 to 1 and vice-versa.

Ex:'Travelling'Salesman'Problem1!"#$%&'()*+#&%,-%",.(*

� Given a list of cities to visit.

� Goal: find the shortest tour that visits each city exactly once, returning in the end to the starting point.

� Complexity: O(n!)

� NP-Hard

Ex:'Travelling'Salesman'Problem1!"#$%&'()$

What was our TSP problem?

- population of possible answers:

Possible tours����-3-5-6-7-4-2-�� - evaluate � best possible solution:

Shortest tour!

- generate a new population by combining and mutating

- ���� ��������� �������rinse, repeat�

TSP'Example1!"#$%&'()*%$

GAs Applications Domains Application Types

Control Gas pipeline, pole balancing, missile evasion, pursuit

Robotics Trajectory planning

Signal Processing Filter design

Game Playing Poker, checker, prisoner�s dilemma

Scheduling Manufacturing facility, scheduling, resource allocation

Design Semiconductor layout, aircraft design, keyboard configuration, communication networks

Combinatorial Optimisation

Set covering, travelling salesmen, routing, bin packing, graph coloring and partitioning

Basic genetic algorithms1•  Step 1: Represent the problem variable domain as a chromosome

of a fixed length, choose the size of a chromosome population N, the crossover probability pc and the mutation probability pm.

•  Step 2: Define a fitness function to measure the performance, or fitness, of an individual chromosome in the problem domain. The fitness function establishes the basis for selecting chromosomes that will be mated during reproduction.

•  Step 3: Randomly generate an initial population of chromosomes of size N: x1, x2 , . . . , xN

•  Step 4: Calculate the fitness of each individual chromosome: f (x1), f (x2), . . . , f (xN)

•  Step 5: Select a pair of chromosomes for mating from the current population. Parent` chromosomes are selected with a probability related to their fitness.

•  Step 6: Create a pair of offspring chromosomes by applying the genetic operators - crossover and mutation.

•  Step 7: Place the created offspring chromosomes in the new population.

•  Step 8: Repeat Step 5 until the size of the new chromosome population becomes equal to the size of the initial population, N.

•  Step 9: Replace the initial (parent) chromosome population with the new (offspring) population.

•  Step 10: Go to Step 4, and repeat the process until the termination criterion is satisfied.

Basic genetic algorithms1

Working Principle of GA

Mutation operator1•  Mutation represents a change in the gene.

•  Mutation is a background operator. Its role is to provide a

guarantee that the search algorithm is not trapped on a local

optimum.

•  The mutation operator flips a randomly selected gene in a

chromosome.

•  The mutation probability is quite small in nature, and is kept low

for GAs, typically in the range between 0.001 and 0.01.

0 11 1X5'i 01 0

X6'i 1 00

0 01 0X2'i 0 1

0 0

0 1 111X5i

1 1 1 X1"i1 1

X2"i0 1 0

0X1'i 1 1 1

0 1 0X2i

Mutation'Operators1!"#"$%&'()"*+$(*,-'.'/0$+$%(#'

� Mutation

� Insert / Delete / Substitute

� Mass mutation -> harmful! (e.g. genetic disorder)

� Small changes -> beneficial! -> Variations!

� Help to better adapt to changes in their environment!

Mutation'Operators1!"#"$%&'()"*+$(*,-'.'/0$+$%(#'

� Mutation

� Inversion 0 0 1 1 1 0 1 0 0 1 => 0 0 1 0 1 0 1 0 0 1

� Substitution 1 2 3 4 8 7 6 9 5 => 1 2 9 4 8 7 6 3 5

� Update 8.3 1.2 4.3 2.2 2.7 7.1 => 8.3 1.2 4.3 2.3 2.7 7.1

� Insertion 1 2 3 4 8 7 6 9 5 (select random) 1 2 3 4 9 8 7 6 5 (insert at random location)

Mutation operators for permutations

!  Normal mutation operators lead to inadmissible solutions –  e.g. bit-wise mutation : let gene i have value j –  changing to some other value k would mean that k

occurred twice and j no longer occurred

!  Therefore must change at least two values !  Mutation parameter now reflects the probability

that some operator is applied once to the whole string, rather than individually in each position

Insert Mutation for permutations

!  Pick two allele values at random !  Move the second to follow the first, shifting the

rest along to accommodate !  Note that this preserves most of the order and

the adjacency information

Swap mutation for permutations

!  Pick two alleles at random and swap their positions

!  Preserves most of adjacency information (4 links broken), disrupts order more

Inversion mutation for permutations

!  Pick two alleles at random and then invert the substring between them.

!  Preserves most adjacency information (only breaks two links) but disruptive of order information

Scramble mutation for permutations

!  Pick a subset of genes at random !  Randomly rearrange the alleles in those

positions

(note subset does not have to be contiguous)

Crossover operator1•  Once a pair of parent chromosomes is selected, the

crossover operator is applied. •  First, the crossover operator randomly chooses a

crossover point where two parent chromosomes �break�, and then exchanges the chromosome parts after that point. As a result, two new offspring are created.

•  If a pair of chromosomes does not cross over, then the chromosome cloning takes place, and the offspring are created as exact copies of each parent.

X6i 1 00 0 01 0 X2i

0 01 0X2i 0 11 1 X5i

0X1i 0 11 1 X5i1 01 0

0 10 0

11 101 0

Ex:'Crossover'Operators1!"#"$%&'()"*+$(*,-'.'/*(,,(0"*'

� Crossover

� Single Point

� Two point

� Uniform

n-point crossover

!  Choose n random crossover points !  Split along those points !  Glue parts, alternating between parents !  Generalisation of 1 point (still some positional bias)

Uniform crossover

!  Assign 'heads' to one parent, 'tails' to the other !  Flip a coin for each gene of the first child !  Make an inverse copy of the gene for the second child !  Inheritance is independent of position

!  “Normal” crossover operators will often lead to inadmissible solutions

!  Many specialised operators have been devised which focus on combining order or adjacency information from the two parents

Crossover operators for permutations

1 2 3 4 5

5 4 3 2 1

1 2 3 2 1

5 4 3 4 5

Order'Crossover'Based1•  Partially Matched Crossover (PMX) •  Order Crossover (OX) •  Cycle Crossover (CX)

•  PMX o A = 9 8 4 | 5 6 7 | 1 3 2 10 o  B = 8 7 1 | 2 3 10 | 9 5 4 6

o C = 9 8 4 | 2 3 10 | 1 6 5 7 o D = 8 10 1 | 5 6 7 | 9 2 4 3

Informal procedure for parents P1 and P2: 1.  Choose random segment and copy it from P1 2.  Starting from the first crossover point look for elements in that

segment of P2 that have not been copied 3.  For each of these i look in the offspring to see what element j has

been copied in its place from P1 4.  Place i into the position occupied j in P2, since we know that we will

not be putting j there (as is already in offspring) 5.  If the place occupied by j in P2 has already been filled in the

offspring k, put i in the position occupied by k in P2 6.  Having dealt with the elements from the crossover segment, the rest

of the offspring can be filled from P2. Second child is created analogously

Partially Mapped Crossover (PMX)

PMX example

!  Step 1

!  Step 2

!  Step 3

Order'Crossover'Based1•  OX

o  A = 9 8 4 | 5 6 7 | 1 3 2 10 o  B = 8 7 1 | 2 3 10 | 9 5 4 6

o  C = 5 6 7 | 2 3 10 | 1 9 8 4 o  D = 2 3 10 | 5 6 7 | 9 4 8 1

•  CX o  A = 9 8 2 1 7 4 5 10 6 3 o  B = 1 2 3 4 5 6 7 8 9 10

o  C = 9 2 3 1 5 4 7 8 6 10 o  D = 1 8 2 4 7 6 5 10 9 3

Cycle crossover

Basic idea: Each allele comes from one parent together with its position.

Informal procedure: 1. Make a cycle of alleles from P1 in the following way.

(a) Start with the first allele of P1. (b) Look at the allele at the same position in P2. (c) Go to the position with the same allele in P1. (d) Add this allele to the cycle. (e) Repeat step b through d until you arrive at the first allele of P1.

2. Put the alleles of the cycle in the first child on the positions they have in the first parent.

3. Take next cycle from second parent

Cycle crossover example

!  Step 1: identify cycles

!  Step 2: copy alternate cycles into offspring

Recommendations1!"#$%&$'"##$()*+,"(-%

� �� ���� good �������

� High crossover probability! ������� � Low mutation probability! (��������������� � Population size? - usually bigger is better!

� Chromosome / String size -> determines search space!

� e.g. 30 bits? -> search space = 230 = 1.07 billion points

1 01 0X1i

Generation i

0 01 0X2i0 00 1X3i1 11 0X4i0 11 1X5i f = 56

1 00 1X6i f = 54

f = 36

f = 44

f = 14

f = 14

1 00 0X1i+1

Generation (i + 1)

0 01 1X2i+1

1 10 1X3i+1

0 01 0X4i+1

0 11 0X5i+1 f = 54

0 11 1X6i+1 f = 56

f = 56

f = 50

f = 44

f = 44

Crossover

X6i 1 00 0 01 0 X2i

0 01 0X2i 0 11 1 X5i

0X1i 0 11 1 X5i1 01 0

0 10 0

11 101 0

Mutation

0 11 1X5'i 01 0

X6'i 1 00

0 01 0X2'i 0 1

0 0

0 1 111X5i

1 1 1 X1"i1 1

X2"i0 1 0

0X1'i 1 1 1

0 1 0X2i

Crossover OR mutation?

!  Decade long debate: which one is better / necessary / main-background

!  Answer (at least, rather wide agreement): –  it depends on the problem, but –  in general, it is good to have both –  both have another role –  mutation-only-EA is possible, xover-only-EA would not work

Exploration: Discovering promising areas in the search space, i.e. gaining information on the problem

Exploitation: Optimising within a promising area, i.e. using information There is co-operation AND competition between them

!  Crossover is explorative, it makes a big jump to an area somewhere “in between” two (parent) areas

!  Mutation is exploitative, it creates random small diversions, thereby staying near (in the area of ) the parent

Crossover OR mutation? (cont’d)

!  Only crossover can combine information from two parents

!  Only mutation can introduce new information (alleles)

!  Crossover does not change the allele frequencies of the population (thought experiment: 50% 0’s on first bit in the population, ?% after performing n crossovers)

!  To hit the optimum you often need a ‘lucky’ mutation

Crossover OR mutation? (cont’d)