Computer Implementation of Genetic Algorithm By Moch Rifan
Computer Implementation of Genetic Algorithm By: Moch. Rif’an Computer Implementation 1
Codings n The principle of meaningful building blocks is simply this: • The user should select a coding so that short, low order schemata are relevant to the underlying problem and reltively unrelated to schemata over fixed position. Computer Implementation 2
n The second coding rule, the principle of minimall alphabets, is simply stated: • The user should select the smallest alphabet that permits a natural expression of the problem Computer Implementation 3
Encoding Methods n Binary Encoding – Most common method of encoding. Chromosomes are strings of 1 s and 0 s and each position in the chromosome represents a particular characteristic of the problem. Chromosome n A B 10110011100101 1111111000011111 Permutation Encoding – Useful in ordering problems such as the Traveling Salesman Problem (TSP). Example. In TSP, every chromosome is a string of numbers, each of which represents a city to be visited. Chromosome A 1 5 3 2 6 4 7 9 8 Chromosome B 8 5 6 7 2 3 1 4 9 Computer Implementation 4
Encoding Methods (contd. ) n Value Encoding – Used in problems where complicated values, such as real numbers, are used and where binary encoding would not suffice. Good for some problems, but often necessary to develop some specific crossover and mutation techniques for these chromosomes. Chromosome A 1. 235 5. 323 0. 454 2. 321 2. 454 Chromosome B (left), (back), (left), (right), (forward) Computer Implementation 5
Encoding Methods (contd. ) n n Tree Encoding – This encoding is used mainly for evolving programs or expressions, i. e. for Genetic programming. Tree Encoding - every chromosome is a tree of some objects, such as values/arithmetic operators or commands in a programming language. (+ x (/ 5 y)) ( do_until step wall ) Citation: http: //ocw. mit. edu/NR/rdonlyres/Aeronautics-and-Astronautics/16 -888 Spring-2004/D 66 C 4396 -90 C 8 -49 BE-BF 4 A-4 EBE 39 CEAE 6 F/0/MSDO_L 11_GA. pdf 6 Computer Implementation
4 individu Computer Implementation Citation: examples taken from: www. genetic-programming. com/c 2003 lecture 1 modified. ppt 7
Mapping Objective function to Fitness Form n n minimization rather than maximization Transform from minimization to maximization problem: • Multiply the cost function by a minus one (insufficient) • Commonly used: Computer Implementation 8
n A problem with negative utility function u(x) value in maximization, transform fitness according to the equation: Computer Implementation 9
Fitness Scaling 1. n Linear scaling To ensure each average population member contribute one expected offspring to the next generation Computer Implementation 10
n n To control the number of offspring given to the population member with maximum raw fitness. c. Mult=the number of expected copies desired for the best population member. For typical small population (n=50 to 100) a c. Mult=1, 2 to 2 has been used successfully Computer Implementation 11
Computer Implementation 12
2. Sigma ( ) truncation: n n n 3. Using population variance information c is choosen as reasonable multiple of population standard deviation (between 1 and 3) Negative result (f’<0) are arbitrarily set to 0 Power Low Scaling Computer Implementation 13
A multiparameter, mapped, fixedpoint coding n Tidak suka n Gunakan n Carefully control the range and precision of the decision variable. The precision: Computer Implementation 14
n Single U 1 parameter • 0000 umin • 1111 umax n Multiparameter Coding (10 parameter): • 0001| 0101|…|1100|1111| • U 1 |…| U 1 | Computer Implementation 15
Discretization Computer Implementation 16
Computer Implementation 17
Constraints n Minimize g(x) Subject to bi(x)≥ 0 i=1, 2, …, n Where x is an m vector n Tranform to the unconstraint form: n n Computer Implementation 18
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 approximate the TSP by GAs Computer Implementation to 19
TSP (Representation, Evaluation, Initialization and Selection) A vector v = (i 1 i 2… in) 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 Computer Implementation 20
Notation (schema) {0, 1, #} is the symbol alphabet, where # is a special wild card symbol A schema is a template consisting of a string composed of these three symbols Example: the schema [01#1#] matches the strings: [01010], [01011], [01110] and [01111] Computer Implementation 21
Notation (order) The order of the schema S (denoted by o(S)) is the number of fixed positions (0 or 1) presented in the schema Example: for S 1 = [01#1#], o(S 1) = 3 for S 2 = [##1#1010], o(S 2) = 5 The order of a schema is useful to calculate survival probability of the schema for mutations There are 2 l-o(S) different strings that match S Computer Implementation 22
Notation (defining length) The defining length of schema S (denoted by (S)) is the distance between the first and last fixed positions in it Example: for S 1 = [01#1#], for S 2 = [##1#1010], (S 1) = 4 – 1 = 3, (S 2) = 8 – 3 = 5 The defining length of a schema is useful to calculate survival probability of the schema for crossovers Computer Implementation 23
Notation (cont) m(S, t) is the number of individuals in the population belonging to a particular schema S at time t (in terms of generations) f. S(t) is the average fitness value of strings belonging to schema S at time t f (t) is the average fitness value over all strings in the population Computer Implementation 24
The effect of Selection Under fitness-proportionate selection the expected number of individuals belonging to schema S at time (t+1) is m (S, t+1) = m (S, t) ( f. S(t)/f (t) ) Assuming that a schema S remains above average by 0 c, (i. e. , f. S(t) = f (t) + c f (t) ), then m (S, t) = m (S, 0) (1 + c) t Significance: “above average” schema receives an exponentially increasing number of strings in the next generation Computer Implementation 25
The effect of Crossover The probability of schema S (|S| = l) to survive crossover is ps(S) 1 – pc( (S)/(l – 1)) The combined effect of selection and crossover yields m (S, t+1) m (S, t) ( f. S(t)/f (t) ) [1 - pc( (S)/(l – 1))] Above-average schemata with short defining lengths would still be sampled at exponentially increasing rates Computer Implementation 26
The effect of Mutation The probability of S to survive mutation is: ps(S) = (1 – pm) o(S) Since pm<< 1, this probability can be approximated by: ps(S) 1 – pm·o(S) The combined effect of selection, crossover and mutation yields m (S, t+1) m (S, t) ( f. S(t)/f (t) ) [1 - pc( (S)/(l – 1)) -pmo(S)] Computer Implementation 27
Schema Theorem Short, low-order, above-average schemata receive exponentially increasing trials in subsequent generations of a genetic algorithm Result: GAs explore the search space by short, low-order schemata which, subsequently, are used for information exchange during crossover Computer Implementation 28
Computer Implementation 29
Computer Implementation 30
Computer Implementation 31
- Slides: 31