Genetic algorithm is an evolutionary algorithm which is based on Charles Darwin’s theory of evolution and works on the natural phenomenon of evolution according to which only the fittest survive and reproduce, which produces better offspring’s with the best genes from both the parents and as the generation goes on, we obtain an overall fitter population. Genetic algorithm needs a genetic representation of the solution space (usually represented as an array of binary bits) and a fitness function to calculate the fitness of an individual.
First, a population of random individual solutions is generated. The population size depends on the immenseness of the problem. Each individual (possible solution) has certain traits in his genome which are encoded as set of chromosomes, these traits basically define an individual and each individual has his own set of unique traits. These traits are inherited from parent to children. The fitness of an individual is evaluated by a fitness function. The lesser the fitness of an individual, the less likely is he to be selected for reproduction. Only the fittest of the population are selected for reproduction .During reproduction, a recombination of the parent genes occur and their offspring’s inherits the traits of both parents. A mutation in the genes of the offspring might occur as well. The fitness of the offspring is evaluated with the next generation to see if he is fit to be a new parent and this cycle goes on till we achieve the desired result or we reach the maximum number of iterations (generations).
Genetic Algorithm proceeds as follows:
Step 1: Generate random population Pop of N individuals as potential solutions.
Step 2: A fitness function calculates the fitness value of the population.
Step 3: The selection operator removes the unfit population which are discarded and are not allowed to reproduce. If an individual is deemed fit by the fitness function, it remains in population Pop.
Step 4: The population now has M individuals, such that M<=N.
Step 4: The genetic operators (crossover, mutation) are applied and new children population is generated from the parent population.
Step 5: The children population becomes the new parent population and forms a loop from step 2, until th