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

Size: px
Start display at page:

Download "Genetic'Algorithms'::' ::'Algoritmi'Genetici'1"

Transcription

1 Genetic'Algorithms'::' ::'Algoritmi'Genetici'1 Prof. Mario Pavone Department of Mathematics and Computer Sciecne University of Catania v.le A. Doria Catania, Italy mpavone@dmi.unict.it

2 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

3 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)

4 The GA Cycle of Reproduction Offspring New Generation Population Decoded Strings Genetic Operators Fitness Evaluation Parents Manipulation Selection(Mating Pool) Reproduction

5 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.

6 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

7 Representation Phenotype space Genotype space = {0,1} L Encoding (representation) Decoding (inverse representation)

8 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 Darwins 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.

9 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

10 Ex:'Travelling'Salesman' Problem1 What was our TSP problem? - population of possible answers: Possible tours evaluate best possible solution: Shortest tour! - generate a new population by combining and mutating - rinse, repeat

11 TSP'Example1

12 GAs Applications Control Robotics Domains Signal Processing Game Playing Scheduling Design Combinatorial Optimisation Application Types Gas pipeline, pole balancing, missile evasion, pursuit Trajectory planning Filter design Poker, checker, prisoners dilemma Manufacturing facility, scheduling, resource allocation Semiconductor layout, aircraft design, keyboard configuration, communication networks Set covering, travelling salesmen, routing, bin packing, graph coloring and partitioning

13 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 p c and the mutation probability p m. 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: x 1, x 2,..., x N Step 4: Calculate the fitness of each individual chromosome: f (x 1 ), f (x 2 ),..., f (x N )

14 Basic genetic algorithms1 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.

15 Working Principle of GA

16 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 and 0.01.

17 X6' i X2' i X1' i X1" i X5' i X2 i X2" i X5 i

18 Mutation'Operators1 Mutation Insert / Delete / Substitute Mass mutation -> harmful! (e.g. genetic disorder) Small changes -> beneficial! -> Variations! Help to better adapt to changes in their environment!

19 Mutation'Operators1 Mutation Inversion => Substitution => Update => Insertion (select random) (insert at random location)

20 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

21 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

22 Swap mutation for permutations! Pick two alleles at random and swap their positions! Preserves most of adjacency information (4 links broken), disrupts order more

23 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

24 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)

25 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.

26 X6 i X2 i X1 i X5 i X2 i X5 i

27 Ex:'Crossover'Operators1 Crossover Single Point Two point Uniform

28 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)

29 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

30 Crossover operators for permutations! 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

31 Order'Crossover'Based1 Partially Matched Crossover (PMX) Order Crossover (OX) Cycle Crossover (CX) PMX o A = o B = o C = o D =

32 Partially Mapped Crossover (PMX) 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

33 PMX example! Step 1! Step 2! Step 3

34 Order'Crossover'Based1 OX o A = o B = o C = o D = CX o A = o B = o C = o D =

35 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

36 Cycle crossover example! Step 1: identify cycles! Step 2: copy alternate cycles into offspring

37 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 = 2 30 = 1.07 billion points

38 X1 i Generation i f = 36 X2 i f = 44 X3 i f = 14 X4 i f = 14 X5 i f = 56 X6 i f = 54 X1 i+1 Generation (i + 1) f = 56 X2 i f = 50 X3 i f = 44 X4 i f = 44 X5 i f = 54 X6 i f = 56 Crossover X6 i X2 i X1 i X5 i X2 i X5 i X6' i X2' i X1' i X5' i X2 i Mutation X1" i X2" i X5 i

39 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

40 Crossover OR mutation? (cont d) 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

41 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