Genetic Algorithms Sesi 14 Optimization Techniques Mathematical Programming Network Analysis Branch & Bound Simulated Annealing Tabu Search Classes of Search Techniques Calculus Base Techniqes Fibonacci Tabu Search Sort Search Techniqes Guided random search techniqes Hill Climbing Simulated Anealing Genetic Programming DFS Enumerative Techniqes Dynamic Programming Evolutionary Algorithms Genetic Algorithms BFS IF-UTAMA 1 The Metaphor The Metaphor (cont) Based on Darwinian Paradigm Reproduction Competition Optimization problem Environment Nature A set of feasible solutions Nature A population of organisms (species) Survive Selection Intrinsically a robust search and optimization mechanism Feasible solutions Solutions quality (fitness function) Individuals living in that environment Individual s degree of adaptation to its surrounding environment Stochastic operators Iteratively applying a set of stochastic operators on a set of feasible solutions Selection, recombination and mutation in nature s evolutionary process Evolution of populations to suit their environment IF-UTAMA 6 IF-UTAMA 1
Conceptual Algorithm initiate & evaluate The Evolutionary Cycle selection population parents evaluated offspring modification evaluation discard modified offspring deleted members Introduction 1 Inspired by natural evolution Population of individuals Individual is feasible solution to problem Each individual is characterized by a Fitness function Higher fitness is better solution Based on their fitness, parents are selected to reproduce offspring for a new generation Fitter individuals have more chance to reproduce New generation has same size as old generation; old generation dies Offspring has combination of properties of two parents If well designed, population will converge to optimal solution Algorithm BEGIN Generate initial population; Compute fitness of each individual; REPEAT /* New generation /* FOR population_size / 2 DO Select two parents from old generation; /* biased to the fitter ones */ Recombine parents for two offspring; Compute fitness of offspring; Insert offspring in new generation END FOR UNTIL population has converged END Example of convergence Introduction 2 Reproduction mechanisms have no knowledge of the problem to be solved Link between genetic algorithm and problem: Coding Fitness function IF-UTAMA 2
Basic principles 1 Basic principles 2 Coding Coding or Representation String with all parameters Fitness function Parent selection Reproduction Crossover Mutation Convergence When to stop An individual is characterized by a set of parameters: Genes The genes are joined into a string: Chromosome The chromosome forms the genotype The genotype contains all information to construct an organism: the phenotype Reproduction is a dumb process on the chromosome of the genotype Fitness is measured in the real world ( struggle for life ) of the phenotype Parameters of the solution (genes) are concatenated to form a string (chromosome) All kind of alphabets can be used for a chromosome (numbers, characters), but generally a binary alphabet is used Order of genes on chromosome can be important Generally many different codings for the parameters of a solution are possible Good coding is probably the most important factor for the performance of a GA In many cases many possible chromosomes do not code for feasible solutions Representation Possible individual s encoding Bit strings (0101... 1100) Real numbers (43.2-33.1... 0.0 89.2) Permutations of element (E11 E3 E7... E1 E15) Lists of rules (R1 R2 R3... R22 R23) Program elements (genetic programming)... any data structure... Representation (cont) When choosing an encoding method rely on the following key ideas Use a data structure as close as possible to the natural representation Write appropriate genetic operators as needed If possible, ensure that all genotypes correspond to feasible solutions If possible, ensure that genetic operators preserve feasibility Encoding Fitness Evaluation Reproduction Survivor Selection IF-UTAMA 3
Encoding Design alternative individual (chromosome) Single design choice gene Design objectives fitness Problem Example Schedule n jobs on m processors such that the maximum span is minimized. Design alternative: job i ( i=1,2, n) is assigned to processor j (j=1,2,,m) Individual: A n-vector x such that x i = 1,,or m Design objective: minimize the maximal span Fitness: the maximal span for each processor Reproduction Reproduction operators Crossover Mutation Crossover Reproduction Two parents produce two offspring There is a chance that the chromosomes of the two parents are copied unmodified as offspring There is a chance that the chromosomes of the two parents are randomly recombined (crossover) to form offspring Generally the chance of crossover is between 0.6 and 1.0 Mutation There is a chance that a gene of a child is changed randomly Generally the chance of mutation is low (e.g. 0.001) Reproduction Operators Crossover Generating offspring from two selected parents Single point crossover Two point crossover (Multi point crossover) Uniform crossover One-point crossover 1 Randomly one position in the chromosomes is chosen Child 1 is head of chromosome of parent 1 with tail of chromosome of parent 2 Child 2 is head of 2 with tail of 1 Randomly chosen position Parents: 1010001110 0011010010 Offspring: 0101010010 0011001110 IF-UTAMA 4
Two-point crossover Reproduction Operators comparison Uniform crossover Randomly two positions in the chromosomes are chosen Avoids that genes at the head and genes at the tail of a chromosome are always split when recombined Randomly chosen positions Parents: 1010001110 0011010010 Single point crossover Cross point Two point crossover (Multi point crossover) A random mask is generated The mask determines which bits are copied from one parent and which from the other parent Bit density in mask determines how much material is taken from the other parent (takeover parameter) Mask: 0110011000 (Randomly generated) Parents: 1010001110 0011010010 Offspring: 0101010010 0011001110 Offspring: 0011001010 1010010110 Reproduction Operators Uniform crossover Is uniform crossover better than single crossover point? Trade off between Exploration: introduction of new combination of features Exploitation: keep the good features in the existing solution Problems with crossover Depending on coding, simple crossovers can have high chance to produce illegal offspring E.g. in TSP with simple binary or path coding, most offspring will be illegal because not all cities will be in the offspring and some cities will be there more than once Uniform crossover can often be modified to avoid this problem E.g. in TSP with simple path coding: Where mask is 1, copy cities from one parent Where mask is 0, choose the remaining cities in the order of the other parent Reproduction Operators Mutation Generating new offspring from single parent Maintaining the diversity of the individuals Crossover can only explore the combinations of the current gene pool Mutation can generate new genes IF-UTAMA 5
Reproduction Operators Control parameters: population size, crossover/mutation probability Problem specific Increase population size Increase diversity and computation time for each generation Increase crossover probability Increase the opportunity for recombination but also disruption of good combination Increase mutation probability Closer to randomly search Help to introduce new gene or reintroduce the lost gene Varies the population Usually using crossover operators to recombine the genes to generate the new population, then using mutation operators on the new population Example Example: the MAXONE problem Suppose we want to maximize the number of ones in a string of l binary digits Is it a trivial problem? It may seem so because we know the answer in advance However, we can think of it as maximizing the number of correct answers, each encoded by 1, to l yes/no difficult questions` Example (cont) An individual is encoded (naturally) as a string of l binary digits The fitness f of a candidate solution to the MAXONE problem is the number of ones in its genetic code We start with a population of n random strings. Suppose that l = 10 and n = 6 Example (initialization) We toss a fair coin 60 times and get the following initial population: s 1 = 1111010101 f (s 1 ) = 7 s 2 = 0111000101 f (s 2 ) = 5 s 3 = 1110110101 f (s 3 ) = 7 s 4 = 0100010011 f (s 4 ) = 4 s 5 = 1110111101 f (s 5 ) = 8 s 6 = 0100110000 f (s 6 ) = 3 Example (selection1) Next we apply fitness proportionate selection with the roulette wheel method: f ( i) Individual i will have a f ( i) We repeat the extraction as many times as the number of individuals we need to have the same parent population size (6 in our case) probability to be chosen n 1 4 2 3 i Area is Proportio nal to fitness value IF-UTAMA 6
Example (selection2) Suppose that, after performing selection, we get the following population: s 1` = 1111010101 (s 1 ) s 2` = 1110110101 (s 3 ) s 3` = 1110111101 (s 5 ) s 4` = 0111000101 (s 2 ) s 5` = 0100010011 (s 4 ) s 6` = 1110111101 (s 5 ) Example (crossover1) Next we mate strings for crossover. For each couple we decide according to crossover probability (for instance 0.6) whether to actually perform crossover or not Suppose that we decide to actually perform crossover only for couples (s 1`, s 2`) and (s 5`, s 6`). For each couple, we randomly extract a crossover point, for instance 2 for the first and 5 for the second Example (crossover2) Before crossover: s 1` = 1111010101 s 2` = 1110110101 After crossover: s 1`` = 1110110101 s 2`` = 1111010101 s 5` = 0100010011 s 6` = 1110111101 s 5`` = 0100011101 s 6`` = 1110110011 Example (mutation1) The final step is to apply random mutation: for each bit that we are to copy to the new population we allow a small probability of error (for instance 0.1) Before applying mutation: s 1`` = 1110110101 s 2`` = 1111010101 s 3`` = 1110111101 s 4`` = 0111000101 s 5`` = 0100011101 s 6`` = 1110110011 Example (mutation2) After applying mutation: s 1``` = 1110100101 f (s 1``` ) = 6 s 2``` = 1111110100 f (s 2``` ) = 7 s 3``` = 1110101111 f (s 3``` ) = 8 s 4``` = 0111000101 f (s 4``` ) = 5 s 5``` = 0100011101 f (s 5``` ) = 5 s 6``` = 1110110001 f (s 6``` ) = 6 Example (end) In one generation, the total population fitness changed from 34 to 37, thus improved by ~9% At this point, we go through the same process all over again, until a stopping criterion is met IF-UTAMA 7
Another Example: The Traveling Salesman Problem (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, Initialization and Selection) A vector v = (i 1 i 2 i n ) represents a tour (v is a permutation of {1,2,,n}) 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 {1,2,,n} We shall use the fitness proportionate selection TSP (Crossover1) OX 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: p 1 = (1 2 3 4 5 6 7 8 9) and p 2 = (4 5 2 1 8 7 6 9 3) First, the segments between cut points are copied into offspring o 1 = (x x x 4 5 6 7 x x) and o 2 = (x x x 1 8 7 6 x x) 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 3 4 5 2 1 8 7 6 After removal of cities from the first offspring we get 9 3 2 1 8 This sequence is placed in the first offspring o 1 = (2 1 8 4 5 6 7 9 3), and similarly in the second o 2 = (3 4 5 1 8 7 6 9 2) TSP (Inversion) 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 Referensi 1. Jaap Hofstede, Beasly, Bull, Martin.2000. Genetic Algorithms And other approaches for similar applications [online] url : http://web.cecs.pdx.edu/~mperkows/temp/0101.genetic- Algorithm.ppt Tanggal akses: 21 Mei 2011 2. Assaf Zaritsky.-. Introduction to s[online] url : http://www.cs.bgu.ac.il/~sipper/courses/ecal051/assafga.ppt Tanggal Akses:21 Mei 2011 IF-UTAMA 8