Download presentation
Presentation is loading. Please wait.
Published byEugenia Simon Modified over 9 years ago
1
ECE 103 Engineering Programming Chapter 52 Generic Algorithm Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material developed by Professor Phillip Wong @ PSU ECE
2
Syllabus Generic Algorithm C c
3
3 Genetic Algorithms A genetic algorithm (GA) can solve certain classes of optimization problems in which: The details of the problem are not well known. The search space is large. Genetic algorithms are based on the biological principles of evolution and selection.
4
4 General Plan: An initial randomized population of candidate solutions is constructed. For each subsequent generation: The current generation is evaluated to determine its “fitness”. The most fit candidates are selected for “reproduction”. A new generation of offspring is created. This continues until a suitable solution is found or a fixed number of generations is reached.
5
5 Solutions are encoded as “bit strings”, e.g., a sequence of 1’s and 0’s stored in an array. Fitness is determined by how well a candidate solution meets a pre-defined criterion. Roulette wheel selection: An individual’s probability of being selected is directly proportional to its fitness. Only selected individuals are allowed to reproduce.
6
6 Typical reproduction methods: Crossover - potentially copies good (or bad) traits: Mutation (helps introduce genetic variety): Parent 1 1011010010100110 Parent 2 0011010110110101 Child 1 1011010110110101 Child 2 0011010010100110 Before 1101101001101110 After 1101100001101110
7
7 Expressed in terms of arrays: Create initial population P current from N randomized bit strings (arrays) Create blank population P next to hold N bit strings (arrays) FOR up to G generations Evaluate population P current for fitness Initialize roulette wheel using fitness results Select parents from P current using roulette wheel probabilities Create population P next by generating N offspring using genetic operators Copy P next to P current END FOR
8
8 Depending on N, L, and # of generations to run, the array copy operation can be expensive. Why not use pointers to arrays instead? P current N bit-strings of length L (N L array) Evaluate fitness Initialize roulette wheel Roulette wheel selects parents Generate offspring P next N bit-strings of length L (N L array) Copy the contents of array P next to array P current one element at a time. In other words, the next generation becomes the current generation.
9
9 Expressed in terms of pointers: Create initial population P A from N randomized bit strings (arrays) Create blank population P B to hold N bit strings (arrays) Assign pointer P current → P A and pointer P next → P B FOR up to G generations Evaluate population P current for fitness Initialize roulette wheel using fitness results Select parents from P current using roulette wheel probabilities Create population P next by generating N offspring using genetic operators Swap pointers P current and P next END FOR
10
10 Gen k P current P A N bit-strings of length L (N L array) Evaluate fitness Initialize roulette wheel Roulette wheel selects parents Generate offspring P B N bit-strings of length L (N L array) P next Swap the pointers P current and P next. Gen k+1 P current P B N bit-strings of length L (N L array) Evaluate fitness Initialize roulette wheel Roulette wheel selects parents Generate offspring P A N bit-strings of length L (N L array) P next Swap the pointers P current and P next.
11
11 Example: Find the minimum of the following equation: f (x, y) = 4x 2 – 2.1x 4 + (1/3)x 6 + xy – 4y 2 + 4y 4 over the range –5 x, y 5 Using Mathcad, the global minimum value for f (x, y) on the defined interval is –1.0316285. This occurs at: (x 0, y 0 ) = (– 0.089842, +0.7126564) (x 1, y 1 ) = ( +0.089842, –0.7126564)
12
12 Run a genetic algorithm simulation using these reproduction methods: (GA-1) M 1 = 1-point crossover and M 2 = complement randomly chosen bit position. Probabilities are p 1 = 0.97 and p 2 = 0.03. The GA is not elitist. (GA-2) Identical to GA-1 except that M 1 = 2-point crossover. (GA-3) M 1 = 1-point crossover with p 1 = 1.0. No M 2 is defined. Each bit in each member of the offspring population is complemented with a probability of 10 -5. The GA is not elitist. (GA-4) Identical to GA-3 except that the GA is elitist.
13
13 Simulation results: %Relative Error in Minimum Value & (x, y) for Best and Worst Runs @ 200 th Generation (N=50, L=28, Runs=25) Best Run Worst Run RelErr%xy xy GA-10.000-0.0906430.7126296.864-0.0869800.612525 GA-20.000-0.0894220.7132397.773-0.002747-0.625954 GA-30.013-0.0869800.70896713.659-0.098578-0.713239 GA-40.075-0.0894220.70286315.357-0.000916-0.823109 Comparison to Mathcad locations for minimum: (x 0, y 0 ) = (– 0.089842, +0.7126564) (x 1, y 1 ) = ( +0.089842, –0.7126564)
14
14 0
15
15 Example: NASA experiment to design an X-band antenna (8 to 12 GHz range for satellite communications): Result: improved performance and efficiency
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.