1 experimental environment
Lab Environment: CPU [email protected], memory 6g,windows7 64-bit operating system
Implementation language: Java (JDK1.8)
Experimental data: TSPLIB,TSP the ATT48 data source in the sampling instance library
Data address: http://comopt.ifi.uni-heidelberg.de/software/TSPLIB95/tsp/att48.tsp.gz
Tsplib is a sample library of TSP and its related problems from various sources and various types, the ATT48 data source in the TSP sampling instance Library is selected, and the optimal value is 10628. The data source has 48 location coordinates, the experimental process is based on these 48 coordinates to solve TSP problem.
2 tsp problem review
The problem of traveling salesman, that is, TSP (travelling salesman problem), is one of the famous problems in the field of mathematics. Suppose there is a travel merchant to visit N cities, he must choose the path to go, the limit of the path is that each city can only visit once, and finally return to the original city of departure. The path selection target is the minimum required path distance for all paths.
3 common solution of TSP problem
Algorithm |
Advantages |
Disadvantages |
The law of poor lifting (violence) |
Simple to implement |
The complexity of time and space is too large to solve the problem of too many cities. |
Greedy algorithm |
Simple to implement and fast to calculate |
It is easy to derive local optimal solution rather than global optimal solution. |
Dynamic planning |
With the increase of the number of cities, the computational amount is greatly reduced, and the shortest path of the intermediate points to the end point is obtained. |
Also unsuitable for dealing with too many cities. |
The above three kinds of common algorithms are their own problems, the poor lifting method and the rules can not solve the city number of the situation, and greedy law in the city when the number of less can not get the global optimal solution, then whether there are more than the number of cities to solve the situation and can get the best? Genetic algorithm.
4 Genetic algorithms
Genetic algorithm (genetic algorithm) is a computational model of evolutionary process that simulates the natural selection and genetic mechanism of Darwinian evolution, and is a method of searching the optimal solution by simulating the natural evolutionary process.
5 Algorithm Implementation steps
5.1 Initialization phase
Initialized objects: Population size, number of cities, operational algebra, crossover probability, mutation probability
Initialize data: Read into data source, convert coordinates to distance matrix (standardized Euclidean distance)
Initialize the population: randomly generate n path sequences, n indicates the population size.
5.2. Calculation of population Fitness
This indicates that each path is summed.
5.3 Calculating the cumulative probability
Calculating the cumulative probabilities of individual individuals in the initialized population
5.4 Iterations
Select operator: Bet wheel selection strategy to pick the next generation of individuals.
Cross operation: K operators and k+1 operators have a certain probability crossover transformation, k=0, 2, 4 、...、 2n
Mutation operation: Each operator has a certain probability gene multiple swap, probability of execution and mutation probability
The new population adaptability and individual accumulative probability were calculated, and the optimal solution was updated.
Replicate the new population newgroup to the old population oldgroup and prepare for next generation evolution (iteration)
5.5 Output
Shortest path length, shortest path occurrence algebra, and shortest path during output iteration
6 Key Algorithm 6.1 Betting wheel selection algorithm
Also known as the proportional selection method. The basic idea is that the probability of each individual being chosen is proportional to the size of its fitness.
Here's how:
(1) to calculate the fitness F (i=1,2,...,m) for each individual in the group, and M for the population size;
(2) Calculate the probability of each individual being inherited into the next generation group;
(3) Calculating the cumulative probability of each individual;
(Q[i] is called chromosome x[i] (i=1, 2, ..., n) accumulation probability)
(4) Generating a uniformly distributed pseudo-random number in the [0,1] interval R
(5) If r<q[1], then select individual 1, otherwise, select the individual K, make: q[k-1]<r≤q[k] established;
(6) Repeat (4), (5) A total of M-times
6.2 Crossover algorithm
K (k=0, 2, 4 、...、 2n) operators and k+1 operators have a certain probability crossover transformation, this probability is the crossover probability.
6.3 Mutation algorithm
Each operator has a certain probability (mutation probability) gene for multiple swaps.
For an operator, randomly generates a random integer of two unequal ranges between [1, city number]. The operator in the two random integer corresponding to the location of the city number of the swap, for the above n-times, N is also a [1, city number] a random integer between.
7 Program Results Analysis
main Parameters: population size, number of cities, maximum operational algebra, crossover probability, mutation probability
Effect of 7.1 population size on the results
Invariant parameters
Maximum operating algebra |
Number of cities |
Crossover probability |
Mutation probability |
1000 |
10 |
0.9 |
0.09 |
10 cities with a minimum length of 6178, path: 3->9->4->5->6->8->7->0->2->1->3
Variable Parameters: Population size
The running results of 10, 20, 30, 40, 50 and 100 of the population were excel-sheet1
Conclusion: In these cases, when the population size is greater than or equal to 30, the algorithm can get the correct solution, reach 40 algorithm can 100% get the shortest path, but the best path appears algebra is not stable, when the population scale reaches 1000 stable in 50 generation to get the correct result.
7.2 Effect of maximum operating algebra on results
Invariant parameters
Population size |
Number of cities |
Crossover probability |
Mutation probability |
30 |
10 |
0.9 |
0.09 |
10 cities with a minimum length of 6178, path: 3->9->4->5->6->8->7->0->2->1->3
Variable parameter: Maximum operating algebra
Operation results of maximum operating algebra at 50, 100, 200, 300, 500, 1000, 10000, respectively, see Excel-sheet2
Conclusion:
In these cases, when the maximum operating algebra reaches 1000, the result of the algorithm tends to be stable (the shortest path is stable), then the efficiency of the algorithm is higher.
When 10000 is 100% correct, but the best path appears algebraic stability within 2000 generations, so it is unnecessary to calculate after 2000 generations, the maximum operational algebraic optimal parameter of the algorithm is 2000.
7.3 Impact of the number of cities on the results
Invariant parameters
Population size |
Maximum operating algebra |
Crossover probability |
Mutation probability |
30 |
1000 |
0.9 |
0.09 |
Variation: Number of cities
The number of cities is 5, 8, 10, 12, 15, 48 o'clock running results see Excel-sheet2
Conclusion: In the above case, when the number of cities <=8, the algorithm 100% to the correct solution. When the number of cities reaches 12, the parameters cannot be solved optimally and some parameters must be adjusted. The following conditions are adjusted:
(1) Other parameters are unchanged, the population size is gradually adjusted to 120, the algorithm results are stable.
(2) Other parameters are unchanged, the maximum operating algebra is gradually adjusted to 10000, the algorithm results are stable.
(3) Other parameters do not change, cross-probability regardless of the adjustment, the algorithm can not get the optimal solution. However, when the population size is adjusted to 40 and the crossover probability is 0.1, the result of the algorithm tends to stabilize.
Synthesis (1) (2) (3) It seems that there is a problem with the crossover probability at first, and the crossover probability of the algorithm should be lowered. When the crossover probability is higher, both the population size and the maximum operating algebra are too expensive.
When the number of cities is 48 o'clock (optimal solution 10628)
(1)
Population size |
Maximum operating algebra |
Crossover probability |
Mutation probability |
1000 |
10000 |
0.1 |
0.09 |
The algorithm run time is 6s, the algorithm result (10937) is better than the greedy result (12842), very close, but not optimal.
Thank Not to be continued ...
Solving tsp problem by genetic algorithm