**Speaker: Pei-Ni Tsai** Genetic Algorithms

**Outline** • Introduction • Fitness Function • GA Parameters • GA Operators • Example • Shortest Path Routing Problem

**Introduction** • Biological background • Darwin • On the Origin of Species • Natural selection • Reproduction • Recombination (Crossover) • Mutation • The fittest survives • History • John Holland

**Introduction (Cont.)** • Population • A set of solutions • Represented by chromosomes • Solutions from one population are taken and used to form a new population. • New solutions are selected according to their fitness. • This is repeated until some condition (for example number of populations or improvement of the best solution) is satisfied.

**Introduction (Cont.)** Mutation Crossover Selection

**Fitness Function** • Interprets the chromosome in terms of physical representation and evaluates its fitness based on traits of being desired in the solution.

**GA Parameters** • Crossover probability • How often will be crossover performed • If there is no crossover, offspring is exact copy of parents. • If there is a crossover, offspring is made from parts of parents' chromosome . • Mutation probability • How often will be parts of chromosome mutated • Population size

**GA Operators ** • Encoding • Selection • Crossover • Mutation

**Encoding** • The chromosome should in some way contain information about solution which it represents. • Binary Encoding • Permutation Encoding • Value Encoding

**Encoding (Cont.)** • Binary Encoding • In binary encoding every chromosome is a string of bits, 0 or 1.

**Encoding (Cont.)** • Permutation Encoding • In permutation encoding, every chromosome is a string of numbers, which represents number in a sequence. • Permutation encoding is only useful for ordering problems.

**Encoding (Cont.)** • Value Encoding • In value encoding, every chromosome is a string of some values. • Values can be anything connected to problem, form numbers, real numbers or chars to some complicated objects.

**Selection** • According to Darwin's evolution theory the best ones should survive and create new offspring. • Roulette Wheel Selection • Rank Selection • Tournament Selection（競賽挑選） • Elitism（精英挑選）

**Selection (Cont.)** • Roulette Wheel Selection • Parents are selected according to their fitness.

**Selection (Cont.)** • Rank Selection • The previous selection will have problems when the fitnesses differs very much. • Rank selection first ranks the population and then every chromosome receives fitness from this ranking. • The worst will have fitness 1, second worst 2 etc. and the best will have fitness N (number of chromosomes in population). • After this all the chromosomes have a chance to be selected. But this method can lead to slower convergence, because the best chromosomes do not differ so much from other ones.

**Selection (Cont.)** • Rank Selection Situation before ranking (graph of fitnesses) Situation after ranking (graph of order numbers)

**Selection (Cont.)** • Tournament Selection • 在每一代的演化過程中首先隨機地選取兩個或更多的物種(字串），具有最大適應函數值的物種即被選中。 • Elitism • First copies the best chromosome (or a few best chromosomes) to new population.

**Crossover** • Binary Encoding • Single point crossover • Two point crossover • Uniform crossover • Arithmetic crossover • Permutation Encoding • Single point crossover • Value Encoding • All crossovers from binary encoding can be used

**Crossover (Cont.)** • Binary Encoding • Single point crossover

**Crossover (Cont.)** • Binary Encoding (Cont.) • Two point crossover

**Crossover (Cont.)** • Binary Encoding (Cont.) • Uniform crossover • 均一交配又稱為字罩 (mask) 交配，子代的產生係根據事先隨機產生的字罩來決定，字罩是二進位元串其長度等於個體的長度。

**Crossover (Cont.)** • Binary Encoding • Arithmetic crossover • some arithmetic operation is performed to make a new offspring 11001011 + 11011111 = 11001001 (AND)

**Crossover (Cont.)** • Permutation Encoding • Single point crossover • One crossover point is selected, till this point the permutation is copied from the first parent, then the second parent is scanned and if the number is not yet in the offspring it is added. (1 2 3 4 56 7 8 9) + (4 5 3 6 89 7 2 1) = (1 2 3 4 56 8 9 7) • There are more ways how to produce the rest after crossover point

**Crossover (Cont.)** • Value Encoding • All crossovers from binary encoding can be used • Single point crossover • Two point crossover • Uniform crossover • Arithmetic crossover

**Mutation** • Binary Encoding • Bit inversion • Permutation Encoding • Order changing • Value Encoding • Adding a small number (for real value encoding)

**Mutation (Cont.)** • Binary Encoding • Bit inversion • Selected bits are inverted

**Mutation (Cont.)** • Permutation Encoding • Order changing • Two numbers are selected and exchanged (1 23 4 5 6 89 7) => (1 83 4 5 6 29 7)

**Mutation (Cont.)** • Value Encoding • Adding a small number (for real value encoding) • To selected values is added (or subtracted) a small number

**Example** • Shortest Path Routing Problem • Genetic Representation • Population Initialization • Fitness Function • Selection • Crossover • Mutation • Repair Function • Simulation

**Example (Cont.)** • Genetic Representation Fig. 1. Example of routing path and its encoding scheme.

**Example (Cont.)** • Population Initialization • Random initialization • Fitness Function : the fitness value of the th chromosome : the length of the th chromosome : the gene (node) of the thlocus in the thchromosome : the link cost between nodes

**Example (Cont.)** • Selection • Pairwise tournament selection without replacement • Two chromosomes are picked and the one that is fitter is selected. • The same chromosome should not be picked twice as a parent.

**Example (Cont.)** • Crossover Pseudocodeof the crossover.

**Example (Cont.)** • Crossover Example of the crossover procedure.

**Example (Cont.)** • Mutation Pseudocode of the mutation.

**Example (Cont.)** • Mutation Example of the mutation procedure

**Example (Cont.)** • Repair Function Pseudocode of the repair function.

**Example (Cont.)** • Repair Function

**Example (Cont.)** • Repair Function (Cont.)

**Example (Cont.)** • Simulation • Performed with MATLAB 5.3 on Pentium III processor (850-MHz clock) • The mutation probability is set to 0.05 (a typical mutation option) • Each experiment is terminated when all the chromosomes have converged to the same solution

**Example (Cont.)** Simulation Results for a Fixed Network With 20 Nodes Comparison results for the paths found by each algorithm. Result of the Munemoto’s algorithm (total path costs: 187). (b) Result of the Inagaki’s algorithm (total path costs: 234).

**Example (Cont.)** Simulation Results for a Fixed Network With 20 Nodes Comparison results for the paths found by each algorithm. (c) Result of the proposed algorithm (total path costs: 142). (d) Example network with optimal path in bold line (optimal path costs: 142).

**Example (Cont.)** Simulation Results for a Fixed Network With 20 Nodes

**Example (Cont.)** Simulation Results for Random Network Topologies

**Example (Cont.)** Simulation Results for Random Network Topologies

**Example (Cont.)** Simulation Results for Random Network Topologies

**Example (Cont.)** Simulation Results for Random Network Topologies

**Example (Cont.)** Simulation Results for Random Network Topologies

**Reference** • 林豐澤，2005。演化式計算上篇：演化式演算法的三種理論模式。智慧科技與應用統計學報第三卷第一期，1-28。 • 林豐澤，2005。演化式計算下篇：基因演算法以及三種應用實例。智慧科技與應用統計學報第三卷第一期，29-56。 • Introduction to Genetic Algorithms: http://obitko.com/tutorials/genetic-algorithms/ • Chang WookAhn and R.S. Ramakrishna, “A Genetic Algorithm for Shortest Path Routing Problem and the Sizing of Populations,” IEEE Transactions on Evolutionary Computation, Vol. 6, Dec. 2002.

**Q & A**