A quick Heuristic and a general search algorithm for traveling salesman problem

. This paper puts forward a constructive heuristic algorithm called the method of inserting the minimum neighbor edge from outside to the center (IMNEFOTC) that can be applied to solve large-scale and ultra-large-scale travelling salesman problems. Through it and the randomized greedy heuristic algorithm (RGH) which greedy heuristic algorithm is modified, a general meta-heuristic search algorithm framework is built. The general search algorithm (GSA) is based on a set of initial solutions, and continuous 2-opt operations are performed, so as to search for solutions in better quality. The data from the experiment reveals that the performance of IMNEFOTC is better than the traditional greedy algorithm, and the GSA can obtain a pretty satisfactory solution in a reasonable range of time.


Introduction
The traveling salesman problem (TSP) is to find a minimum Hamiltonian circle which visits all vertices in a given set.It is widely applied to various fields such as transportation, logistics, circuit design, robot control, and so on.TSP is a classic NP difficult problem in the field of combination optimization, on the basis of which other problems, such as colored TSP, multiple TSP, vehicle routing problems and other related problems have emerged and developed rapidly.
Given a complete undirected graph G=(V, E), where V={v1, v2, …, vn} is a set with n vertices, and E is a set with n(n-1)/2 edges.Every vertex's position is denoted by the 2-dimensional coordinate vi(xi, yi), d(i, j) is the Euclidean distance between vertex vi and vertex vj or the cost corresponding to the edge (vi, vj) in E. For any three vertices u, v, w in V, the inequality relation, d (u, w) ≤d (u, v) + d (v, w) should be satisfied.Suppose a tour T=(t1 t2…ti…tn), where ti∈V, if i≠j then ti≠tj, let tn+1=t1, then The mathematical model of TSP is given by: The total distance of a tour is denoted by: The algorithms for TSP are divided into three categories: precision algorithms, heuristic algorithms, modern heuristic intelligent algorithms.The precise algorithms include branch and bound and cutting plane, the common heuristics are greedy, nearest neighbor, 2-opt, 3-opt [1] and Lin Kernighan [2] etc., and the intelligent algorithms usually include tabu search (TS), simulated annealing (SA), genetic algorithms (GA), particle swarm optimization [3], ant colony algorithms, bat algorithms etc.The time complexity of most precision algorithms increases exponentially with the scale of the problem, so large-scale TSP problems cannot be solved.Heuristic algorithm makes the solving process fall into local optimal search, and it is not easy to get satisfactory solution of good quality.Most of the intelligent algorithms simulate the biological features of nature and adopt the behavior evolution mode of the population.In addition, the solution of multi-peak problems converted into multi-target optimization problems [4] can also be tried and applied in TSP.The algorithm with better effect is the hybrid algorithm combining intelligent algorithm with the neighbor search algorithm.
This paper proposed a quick heuristic algorithm which is the method of inserting the minimum neighbor edge from outside to the center (IMNEFOTC) and modified the traditional greedy heuristic algorithm to generate multiple approximate optimal solution, and on this basis a general meta-heuristic search algorithm framework (GSA) was built for TSP.The algorithms of IMNEFOTC and GSA are very suitable for large or super large scale problems, and the GSA algorithm can further improve the quality of the solution.GSA starts at a population comprising of various initial solutions, then every solution is improved quickly by 2-opt operator successively.When distance between two adjacent generations of an individual is close enough, global operators and local operators are alternately executed until the maximum iterations.Finally, the algorithm outputs the best solution during the process of the iterative computing.
The remainder of this paper is organized as follows: In section 2, two quick heuristics and the GSA are described in detail.Experimental results are provided in section 3, and some conclusions are drawn in 4 section of this paper.

The two quick algorithms and the general search algorithm framework 2.1 The method of inserting minimum neighbor edge from outside to the center (IMNEFOTC)
IMNEFOTC assumes that all vertices are uniformly distributed in a circle or approximate circular region, and the minimum adjacent edge is inserted from the outer point of the region.This process approaches to the inner center of the circle until n-1 edges have been inserted.The time complexity of the algorithm is Θ(n 2 ).
Step 1: Initialize the set of edges which constructs Hamiltonian cycle, H=Ø, and the degrees of all vertices are equal to 0, degi=0, i=1,2,…n.Assign each vertex a distinct connected component identifier, compi=i.
Step 2: Compute the virtual central with the average coordinate value of all vertices, ( ) Step 3: Calculate the distance from each vertex to the virtual center and store them in the array disTOcenter().
Step 4: Sort the array disTOcenter(1 to n) in ascending order, and store the index numbers of the corresponding vertices to another array Points2(1 to n).
Step 5: Set a pointer, and point to the last element of the array Points2(), let the current vertex ki= Points2(n).
Step 6: If the cardinality of H, |H| <n-1, then do next.Otherwise, turn to step 10.
Step 7: Insert the minimum adjacent edge of ki which is edge (Q→W) into set H without generating any sub-loop and a degree-3 vertex.Vertex Q and W are the two endpoints of the edge.
Step 8: The degrees of vertex Q and W increase 1 respectively.Dispose the connected component identifiers so that the vertices' identifiers of each connected component are identical and different from other connected components'.
Step 9: When the degree of ki is equal to 2, the pointer slides forward to the nearest vertex whose degree is less than 2. Let the current vertex ki be the vertex which the current pointer is pointing to.Turn to Step 6.
Step 10: Connect two vertices with degree of 1, and add the n th edge to H. Output: All edges of H

Randomized greedy heuristic
The idea of randomized greedy heuristic (RGH) is based on classic greedy heuristic, which generates multiple better initial solutions.Its steps are presented as following: Input: a complete graph G＝(V,E) with n vertices, and a random integer β(1≤β<<n).
Step 1: Initialize the set of edges which construct a Hamilton circle, R＝Ф, and the degrees of all vertices are initialized to 0.
Step 4: Take the edge ej' which is the ξ th edge from the neighboring edges after the current edge.The two vertices of the edge ej' are u and w, if the degrees of u and w are less than or equal to 1, and adding ej' to R do not form any sub-circuit, then R←ej' and add 1 to the degrees of u and w, ce= ej', turn to step 3. Otherwise ξ←ξ＋1, and go to step 4 again.
Step 5: Connect the two vertices with degrees less than 2, and a Hamilton circle is constructed.Output: All edges of R.

A general search algorithm (GSA) for TSP
For a TSP with n cities, GSA starts at a population that consists of various initial solutions Ti= (ti1, ti2,…,tin), i=1,2,…,size.These initial solutions are generated by six different quick generation algorithms.The population evolves by alternately executing the operators of local search and global search.The fitness function of Ti is denoted by f(Ti).The best individual and its fitness which the algorithm finds are saved to Pg=(pg1,pg2,…,pgn) and f(Pg).

The algorithm framework of GSA
Step 1: Construct size initial solutions Ti(i=1,2,…, size) by six different quick generation algorithms which are IMNEFOTC, RGH, greedy heuristic, nearest neighbor, modified minimum spanning tree and random generation.size≥6, let λ=0.
Step 2: Calculate f(Ti) for every Ti, and save the best individual to Pg.
Step 3: If λ ≥λmax, putout Pg and f(Pg) , the algorithm is over.Otherwise do next step.
Step 5: Judge the convergence condition, if some individuals meet the convergent criterion then go to step 6, otherwise turn to step 3.
Step 6: Do crossover operator to the individuals Ti λ which have been convergent, generate Ti λ+1 , calculate f(Ti λ+1 ), and update Pg.
Step 7: Do the same as step 6, but replace the crossover operator with the operator of crossover and reverse.

Implementation details of the GSA (1) Generation of initial solutions
The steps of the algorithms of IMNEFOTC and RGH have been described in detail in section 2.1 and section 2.2.The other four generations of initial solutions are summarized as follows.
The randomized generation algorithm produces a random permutation from 1 to n. Greedy heuristic starts at the shortest edge, and repeatedly inserting the shortest remaining available edge which does not create a degree-3 vertex or a cycle of length less than n, until the (n-1) th edge are added.Greedy heuristic can be implemented in time Θ(n 2 logn) [1].Generation by modified minimum spanning tree first build the minimum spanning tree by Prime algorithm.Then a vertices' sequence can be got by visiting the tree in preorder walk, which is also an approximate TSP tour.The time complexity of Prime algorithm can be improved to Θ(|E|+nlogn).Nearest neighbor starts from a vertex, and always go next to the nearest as-yet-unvisited location until all vertices are visited.The running time of nearest neighbor is Θ(n 2 ). (

2) Local search operator
The local search operator of GSA continuously executes 2-opt operations ɧn times, n is the scale of TSP, ɧ is the coefficient.The times of the consecutive execution depend on the scale of the problem.The large the scale of TSP is, the more times the operator is executed consecutively.
The 2-opt operator removes two existing edges of a tour, and then adds two other edges, so that it can generate a different effective tour.Replace edges of (i, j+1) and (j, i+1) with other E3S Web of Conferences 360, 01097 (2022) https://doi.org/10.1051/e3sconf/202236001097VESEP2022 edges of (i, i+1) and (j, j+1).The distance of a tour is shortened after the exchange, which satisfies the condition d(i, i+1)+d( j, j+1)< d(i, j+1)+d( j, i+1), and the feasible solutions are improved, as figure 1 shown.(3) Global search operators The process of global search includes two operators which are crossover operator, the operator of crossover and reverse in this paper.
1) Crossover operator Because of the particularity of TSP, any component of the solution (or any gene of the individual) must be unique.In the global search process, two different parts of an individual are exchanged as shown in figure 2. As indicated in the figure, one part starts at i th component with the components of length l, and another part starts at j th component with components of the same length l, crossover operator is to exchange the two parts.Here, i, j and l are random integers and satisfy formula (3), n is the number of cities or the scale of TSP.
2) Crossover and reverse operator On the basis of the crossover operator, crossover and reverse operator further arrange the components of the parts that have been exchanged in reverse order, which is shown as in figure 3.  where CT is a given small positive number, j=1,2,…,size.

Experiments and analysis
In experiments part, IMNEFOTC, RGA and GSA algorithms have been tested for some instances of TSPLIB.From table 1, we find a better path than the optimal path known in instance Eil51, which was found by GSA.The deviations of other instances of GSA do not exceed 4%.The time complexity of the GSA algorithm is polynomial function, and it can get a better trade-off between search time and search precision.From the results of the 10 instances which are randomly selected from TSPLIB, we know that IMNEFOTC performs better than greedy heuristic except instance Rd100.IMNEFOTC is more suitable for solving large scale and super large problems.

( 4 )
Convergent criterionIf an individual has already converged, local search could not make much sense to it again, which means that it has fallen into local optimum.Global search operator should be adopted to enable it to escape from the precociousness.Simple convergence criterion is that if the absolute value of the difference between the fitness values of the two successive generations Conferences 360,01097 (2022)   https://doi.org/10.1051/e3sconf/202236001097VESEP2022 of the same individual is less than a given threshold value as formula (4), the individual is considered to be convergent.|f(Tj λ+1 )-f(Tj λ ) | <CT(4)

Table 1 .
All tests of this paper have been run on Lenovo ThinkPad, CPU: 2.5GHz, memory: 4G.For different scale instances, we need to adjust relevant parameters such as size, ɧ, and λmax, etc. sometimes.The test data is recorded in table1, where O.P. presents the real distance of the optimal path known, O.V. denotes the optimal value known.The distance of the best satisfactory solution which was got by GSA is denoted by B.F., B.F. deviates from O.P. is denoted by D (%).ID is the distance of the approximate solution computed by IMNEFOTC, and IDD (%) is its deviation from O.P.. GD is thedistance of the tour got by traditional greedy heuristic, and GDD (%) is the deviation from O.P.. Data of testing by GSA and IMNEFOTC for some TSPLIB instances.