Genetic Algorithm: A Simple Example
Introduction
Genetic Algorithm (GA) can sometimes be a bit difficult to understand !! :(
In this article, I’ll help you understand GA with a simple example. So don’t worry. Hang tight. All will be clear soon !! :)
Below are the steps to be followed to solve any optimization problem with the help of GA.
- Step 1- Choose an encoding technique, a selection operator, and a crossover operator
- Step 2- Choose a population size
- Step 3- Randomly choose the initial population
- Step 4- Select parental chromosomes
- Step 5- Perform Crossover (random crossover points)
- Step 6- Evaluation of offsprings
- Step 7- Repeat the process
Now we’ll see an example of a simple optimization problem and try to solve it with the help of the steps mentioned above.
Question
Answer
Step 1-
- Encoding technique- Binary encoding
- Selection operator- Roulette Wheel Selection
- Crossover operator- Single point crossover
Step 2-
Population size (n) = 4
Step 3-
Initial population (x value) = 13, 24, 8, 19
Step 4-
We see that if the Roulette wheel is spun four times, we’ll get 24 twice and 13 and 19 once. So possible parental combinations are (24,13) and (24,19).
Step 5-
Step 6-
We can see that the maximum f(x) value has increased from 576 to 729.
Step 7-
Now we’ll take these four offsprings as parents and repeat the process until our termination condition is not satisfied.
That will be it for this article.
Don’t forget to 👏 if you liked the article.
If you want to learn more about GA, check out my series of articles:
If you have any questions or would like something clarified, you can find me on LinkedIn.
~happy learning.