Genetic Algorithms for TSP

A genetic algorithm
genetic algorithm (Genetic Algorithm) is to simulate natural selection and genetic mechanism of Darwinian evolution of computational models of biological evolution, the process is a way to search for the optimal solution by simulating natural evolution. Genetic algorithm is a potential problem may be representative of the population from the solution set of (population) started, and a certain number of population by genetically (gene) encoding individual (individual) components. Each individual is actually the entity with a characteristic chromosome (chromosome). Chromosome as the main carrier of genetic material, i.e., a set of a plurality of genes, the performance of the internal (i.e., genotype) is a combination of a gene, which determines the external shape of the individual's performance such as black hair which is characterized by the control chromosomes It features a combination of a gene determined. Therefore, at the beginning of the work required to implement the mapping that is encoded from phenotype to genotype. Since the gene encoding the modeled work is very complicated, we tend to simplify such as binary encoding, after the first generation population is generated, in accordance with the principle of survival of the fittest and survival of the fittest, from generation to generation (generation) evolution to produce more good approximate solution, in every generation the individual fitness problem domain (Fitness) size selection (selection) individuals by means of genetic operators Nature genetics (genetic operators) combined cross (crossover) and variation (mutation), a representative of a new generation the solution set of the population. This process will lead to the same population as the natural evolution of epigenetic generation of populations to adapt more to the environment than the previous generation, the last best individual in the population decoded (decoding), may as a matter of near optimal solution.

Two for TSP
(1) the definition
given direct access to the distance between a set of n cities and so they both look for a close journey, so that each city exactly once and after the shortest total travel distance.
Also known as the TSP traveling salesman problem, is an old problem. Knight's Tour problem can be traced back in 1759 Euler raised. In 1948, driven by the US Rand Corporation, TSP become typical of modern combinatorial optimization problem areas.
TSP is a combination of a wide range of applications background and important theoretical value of the optimization problem. In recent years, there are a lot more efficient algorithms to solve the problem of constantly being introduced, such as Hopfield neural networks, genetic algorithms and simulated annealing methods.
TSP search space with the increase in the number of cities n increases, the number of combinations of all the tour route is (n-1)! / 2 . Finding the optimal solution in such a large search space for existing conventional methods and computational tools, the computing there are many difficulties. With the ability to search for genetic algorithm to solve the TSP problem is a very natural idea.
(2) Scheme
Here Insert Picture Description
(3) an important step in the algorithm
to generate an initial population of
one completely random, it is suitable solution to the problem without any prior knowledge. Strong randomness, and thus fairer
Second, some a priori knowledge of a set of requirements that must be met to be converted, then the solution satisfying these requirements in a randomly selected sample. Select this initial population genetic algorithm can achieve the optimal solution faster. The population has some goals and representative, but not as good as patients taking a wide range of completely random, and prior knowledge of reliability is an issue
fitness function
based on genetic algorithms in the evolutionary basic search without using external information, only the fitness function use of the fitness value of individuals in each population to search. TSP goal is the total length of the shortest path, the path can be the inverse of that of the total length of the TSP fitness function:
Here Insert Picture Description
select
Generally speaking, the choice should make greater fitness (excellent) individuals have a greater opportunity exists, but the fitness of the smaller (inferior) the continued existence of individual opportunity is small. Simple genetic algorithm roulette wheel selection mechanism, so Σfi represents the sum of the value of the fitness community, fi denotes the i th chromosome fitness value of the population, it's just the ability to produce offspring fitness value of the share fi / Σfi its .
Cross-
encoding method path representation based on the requirements of individual chromosome encoding a not allowed duplicate gene codes, that is to meet any of the city must and can only be accessed once constraints. Crossover genetic algorithm for generating individual generally can not satisfy this constraint.
Cross section matching operation requires two randomly selected crossing point to determine a matched segment, generating two sub individual mapping relationship between the intermediate section of the two parent individuals given two intersections.
Mutation
genetic algorithm to solve TSP problem based on binary value coding mutation can not be applied can not be reversed by a simple variable is implemented
in the TSP in the individual coding sequence is a group of the city, randomly drawn two cities in this sequence then swap their position. This realization of the individual variation of the coding algorithm is as follows:
generates two random real number between 0 and 1;
the two random real number is converted to a random integer between -10 to n (number of cities);
these two random integers refers city exchanged;
(4) code implementation
1.cross.m

Here Insert Picture Description
2.exchange.m
Here Insert Picture Description
3.fit.m

Here Insert Picture Description
4.Mutation.m
Here Insert Picture Description
5.mylength.m
Here Insert Picture Description
6.plot_route.m
Here Insert Picture Description
7.main.m

Here Insert Picture Description
Here Insert Picture Description

Here Insert Picture Description
Here Insert Picture Description

Here Insert Picture Description
Here Insert Picture Description
SUMMARY three experiments
(1) to change the sequence City: randomly generated multiple
1. The first randomly generatedHere Insert Picture Description

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description2. The second random generator
Here Insert Picture Description
Here Insert Picture Description

Here Insert Picture Description
Here Insert Picture Description
3. The third random generator

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
(2)保存随机生成的城市序列
修改代码:

Here Insert Picture Description

将第一次随机生成的城市序列结果导入,达到保存序列的效果。

运行后结果:
Here Insert Picture Description
Here Insert Picture Description

Here Insert Picture Description
Here Insert Picture Description
(3)分析固定城市序列时种群数量大小的影响

1.M=10
Here Insert Picture Description
Here Insert Picture Description
2.M=100
Here Insert Picture Description
! [Insert Picture description here] (https://img-blog.csdnimg.cn/20191119212521368.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,sh
3.M=1000
Here Insert Picture Description
Here Insert Picture Description
当交叉概率和变异概率不变时,种群数量较小时迭代时间短,但容易陷入局部最优,难以找到全局最优解。种群数量较大可以同时处理更多的解,容易找到全局最优解,但迭代时间增长,降低了算法的运行效率。

(4)分析固定城市序列时交叉概率大小的影响
1.Pc=0.01
Here Insert Picture DescriptionHere Insert Picture Description
2.Pc=0.1
Here Insert Picture Description
Here Insert Picture Description
3.Pc=0.5

Here Insert Picture Description
Here Insert Picture Description

4.Pc=0.8
Here Insert Picture Description

! [Insert Picture description here] (https://img-blog.csdnimg.cn/2019111921
5.Pc=1
Here Insert Picture Description
Here Insert Picture Description
当种群数量,变异概率不变时,交叉概率过小,最短路径难以收敛。较大的交叉率又可能导致过早收敛。经查询,交叉概率一般不超过1。

(5)分析变固定城市序列时变异概率大小的影响
1.Pmutation=0.001
Here Insert Picture Description

Here Insert Picture Description
2.Pmutation=0.05
Here Insert Picture Description
Here Insert Picture Description
3.Pmutation=0.2
Here Insert Picture Description
Here Insert Picture Description
4.Pmutation=0.5
Here Insert Picture Description
Here Insert Picture Description
当种群数量,交叉概率不变时,变异概率过小,收敛速度很慢。变异概率较大可能导致过早收敛。变异概率过大时波动较大,很不稳定,难以收敛。经查询,变异概率一般不超过0.1。

四 总结
1.通过实验,发现不同参数的设置对遗传算法的求解有很大的影响。因此我们需要正确选择合适的参数。
2.对于TSP问题,遗传算法并不一定是最优的求解算法,根据不同的情况我们可以选择不同的算法进行尝试。

Released six original articles · won praise 1 · views 567

Guess you like

Origin blog.csdn.net/zencci/article/details/103142954