special thaks to Daniel Shiffman and his work Nature of code.
In computer science and operations research, a genetic algorithm (GA) is a metaheuristic inspired by the process of natural selection that belongs to the larger class of evolutionary algorithms (EA). Genetic algorithms are commonly used to generate high-quality solutions to optimization and search problems by relying on biologically inspired operators such as mutation, crossover and selection.
process involved in genetic algorithm:-
-
SETUP:
- Initialize. Create a population of N elements, each with randomly generated DNA. LOOP:
- Selection. Evaluate the fitness of each element of the population and build a matingpool.
- Reproduction. Repeat N times:
- Pick two parents with probability according to relative fitness.
- Crossover—create a “child” by combining the DNA of these two parents.
- Mutation—mutate the child’s DNA based on a given probability.
- Add the new child to a new population.
- Replace the old population with the new population and return to Step 2.