The implementation of genetic algorithm mainly contains the following 7 important questions:
1. Chromosome encoding
2. Group initialization
3. Evaluation of Fitness value
4. Select a population
5. Mating of the population
6. Population variation
7. Algorithm Flow
The following is a brief introduction
1. Chromosome encoding
The solution to solve the problem is the encoding of chromosomes, the choice of encoding method will have a significant impact on the subsequent operation, often a relatively simple coding method
There are binary encoding methods (binary representation) and floating-point encoding methods (float points representation)
2. Group initialization
Using the method of random number initialization, the initialization of each dimension variable of chromosome is assigned.
3. Evaluation of Fitness value
The evaluation function is used to evaluate the adaptive values of each chromosome, thus differentiating the pros and cons, and the evaluation function is often determined based on the optimization objective.
4. Select operator
The traditional selection operator of genetic algorithm chooses the best individual from the population according to the value of the adaptive value function, including roulette choice and tournament selection .
5. Mating operator
Mating operators are an important means of acquiring new and excellent individuals, and two of parents exchange their excellent genes for better individuals through mating operations.
Mating operators are: partially matched mating, sequential mating (ox mating), cyclic mating, and side recombination.
6. Mutation operator
Mutation operation occurs on a certain gene of a chromosome, it introduces the variability into the population, enhances the diversity of the population, and provides a partial optimal
A means of jumping out of a. The mutation method is also a random, blind mutation, so a relatively small mutation probability (PM) is needed to control it to avoid creating
The destruction of the population. Frequently used mutation operators have "location-based mutation" and "sequence-based mutation".
7. Algorithm Flow
Step1: Initializes a population of size n, where the value of each gene of the chromosome is generated by a random number. Current Evolutionary algebra g=0
Step2: The evaluation function was used to evaluate the population of all chromosomes, to calculate the adaptive value of each chromosome, and to preserve the best of the chromosome with the highest adaptive value.
Step3: Using the appropriate selection algorithm to select the chromosome of the population to produce the same size of the population.
Step4: Mating is selected from the population by a given mating probability, and no mating chromosomes are copied directly into the new population.
STEP5: Mutation operation of the genes of the new population According to the given mutation probability, the mutated chromosome replaces the original chromosome into the new group, not mutated
Chromosomes directly into the new population.
STEP6: After the mutation of the new population to replace the original population, re-calculate the adaptive value of chromosomes, if the maximum adaptive value of the population is higher than the best adaptive value, then the group's largest
The chromosome corresponding to the adaptive value is the best.
STEP7: Current Evolutionary algebra g plus 1, if G reaches the specified maximum evolutionary algebra or best meets the specified error requirements, the algorithm ends, otherwise returns STEP3
In the back of the blog will write the application of genetic algorithm, the initial decision is to solve the equation and tsp problem.
Genetic algorithm for primary knowledge