Genetic algorithms structure
In this section, let's understand the structure of a genetic algorithm that finds the optimum solution for a problem where the search space is so huge that brute force cannot solve it. The core algorithm was proposed by John Holland in 1975. In general, Genetic Algorithm provides an ability to provide a good enough solution fast enough to be reasonable. The generic flow of a Genetic Algorithm is depicted in the diagram:
Let's try to illustrate Genetic Algorithm with a simple example. Consider that you have to find out a number (integer) in millions of values (the solution space). We can follow the steps in the algorithm and reach the target solution much quicker than application of a brute force method. Here is the implementation of the algorithm in Java:
- Define the
GA
class with a simple constructor to initialize the population:
public GA(int solutionSpace, int populationSize,int targetValue, int maxGenerations, int mutationPercent) { this.solutionSpace...