GORTS: genetic algorithm based on one-by-one revision of two sides for dynamic travelling salesman problems

The dynamic travelling salesman problem (DTSP) is a natural extension of the standard travelling salesman problem, and it has attracted significant interest in recent years due to is practical applications. In this article, we propose an efficient solution for DTSP, based on a genetic algorithm (GA), and on the one-by-one revision of two sides (GORTS). More specifically, GORTS combines the global search ability of GA with the fast convergence feature of the method of one-by-one revision of two sides, in order to find the optimal solution in a short time. An experimental platform was designed to evaluate the performance of GORTS with TSPLIB. The experimental results show that the efficiency of GORTS compares favourably against other popular heuristic algorithms for DTSP. In particular, a prototype logistics system based on GORTS for a supermarket with an online map was designed and implemented. It was shown that this can provide optimised goods distribution routes for delivery staff, while considering real-time traffic information.


Introduction
The Travelling Salesman Problem (TSP), a classical example of NP (non-deterministic polynomial) problem, was first investigated in more detail in the 1950s (Garey and Johnson 1979).The classic TSP aims to determine the shortest path across a set of randomly located cities. (Each city is visited once and only once, except for the starting point.)In other words, TSP is a shortest route planning, whose solution is a minimum Hamiltonian circuit.However, many practical applications exhibit a dynamic behaviour, such as transportation planning (Niendorf and Kabamba 2015;Niendorf et al. 2016), communication design (Boryczka and Strak 2012), workload distribution (Mavrovouniotis and Yang 2013), IoT analysis and optimisation (Bessis et al. 2012;Xu et al. 2013), as well as disaster management (Reina et al. 2014).Hence, such TSP models need to be adaptive, and often real-time, in order to obtain the most appropriate description.The Dynamic Travelling Salesman Problem (DTSP) is an extension of TSP, which has the following supplementary features (Kang et al. 2004;Li et al. 2006): -Real-time The weights of the links between nodes may change probabilistically with time; X. Xu et al.
-Robustness Allows for unexpected situations which require timely response (e.g.nodes may randomly join or quit the system); -Efficiency DSTP requires an optimal or sub-optimum solution in a finite time.
Typical algorithms for solving DTSP mainly include ant colony algorithms (ACA) (Mavrovouniotis and Yang 2013;Melo et al. 2013) and genetic algorithms (GA) (Falcon and Nayak 2010), which generally make appropriate adjustments based on changes in the environment, such as varying travelling cost between cities.However, in this case it is often computationally expensive to identify the optimal solution in a short time, due to the numerous sudden changes in parameter values.
In this article, we propose a new algorithm named GORTS, which is based on the integration of DTSP with a genetic algorithm defined by a one-by-one revision of two sides.Combining the global search ability of the GA and the fast convergence of the method of one-by-one revision of two sides, we show that this method can achieve accurate solutions in shorter time.In particular, the method of one-by-one revision of two sides is adopted to modify the multiple chromosomes initialised by the genetic algorithm, and the elitist strategy is used to select the optimal solution.Subsequently, the crossover and mutation operations identify the optimal solution.
The rest of the article is organised as follows.In Sect.2, we discuss the current state-of-the-art approaches and methods for solving TSP and DTSP.Section 3 presents the details of the mathematical DTSP model.In Sects. 4 and 5, we introduce and discuss the GORTS algorithm, and in Sects.6 and 7, the experimental results and the prototype logistics system for supermarket with GORTS are presented.Finally, Sect.8 concludes the paper by summarising the main contributions of this work and commenting on future directions of investigation.

Related work
Significant research on the classical TSP model and versions with different constraint conditions has been carried out.This includes TSP models with time windows Li et al. (2015) and the minimum ratio TSP Cook (2011), which mainly focus on determining the minimal Hamiltonian circuit for a single travelling salesman.On the other hand, within the DTSP, the parameters related to each node may change dynamically and it can be seen as a combined series of TSPs Li (2013).

TSP algorithms
Currently, the algorithms for solving TSP can be divided into accurate and approximate algorithms.The former mainly include the dynamic programming algorithm Mahfoudh et al. (2015), the branch and bound Ghadle and Muley (2014), and integer linear programming algorithm Singh and Mehta (2014).However, these algorithms can only address smallscale TSP, as their complexity increases exponentially with the number of nodes.The latter include heuristic algorithms such as the ant colony optimisation algorithm (ACO) Alves and Lopes (2015), the particle swarm optimisation algorithm (PSO) Avin et al. (2012), the genetic algorithm(GA) Yuan et al. (2013), which have been widely accepted for their suitability at identifying better solutions in a reasonable time.However, their efficiency tends not to match up with the abrupt rates of change present in the DTSP system parameters.Therefore, a variety of fusion algorithms have been proposed.

DTSP algorithms
Following the introduction of the DTSP with a single objective in 1988 (Mavrovouniotis et al. 2016), most of the research has mainly focused on the definition of the problem, algorithm design, performance measurement, or on the test platform construction.Melo et al. Melo et al. (2013) attempted to address the DTSP via the ant colony optimisation algorithm.This type of algorithm tends to quickly converge to obtain the optimal solution based on the pheromone produced by ants, where previous pheromone trajectories can accelerate the optimisation process.However, this scheme is only suitable for DTSP with small environmental changes.
If the number of nodes varies significantly, the optimisation process needs to be recalculated.Cheng and Yang (2009) proposed a genetic algorithm based on the elite immigration strategy.The best population in the previous generation produce individuals through mutation operations, who will replace the least suitable ones in the current generation.Compared with the original GA, it has better adaptability and can optimise the quality of the solution.However, if there are large-scale nodes, the algorithm often needs to iterate several times to converge and cannot meet the realtime requirement.Gharehchopogh et al.Gharehchopogh and Farahmandian (2012) proposed to combine ACO with GA to find the optimal solution, more suitable for severe variations.Nonetheless, its computational overhead is relatively high.Blackwell (2004) proposed a new mutant PSO approach, specifically designed for dynamic environments.This algorithm extends the diversity of particle swarm in a single population and can find a better solution in the case of environmental change.However, the diversity increases the cost of the algorithm and affects the usability in contexts involving real-time processes.

DTSP modelling
The objective of TSP is to find the shortest path across a set of randomly located cities, or in other words, to obtain the minimum Hamiltonian circuit.Regarding their different constraints and limitations, TSP models can be extended to include specific features of practical interest, such as the TSP versions with multiple salesmen, or TSP models with multiple objectives, DTSP, etc.
Let G = G(V , E) be a graph, where V = {v 1 , . . ., v n } represents the set of vertices and denote the set of edges by E = {d i, j : d i, j > 0, d i,i = 0, i, j ∈ N }.In the TSP model, i ∈ N ⊂ {1, . . ., n} represents the city number, and d(v i , v j ) the distance between cities i and j.If TSP is symmetric, then we have The optimal solution of TSP comes in the form of a path V = (v 1 , v 2 , . . ., v n ), minimising the value of the following objective function: (1) The decision variables are defined as where L is the solution sequence.The model of TSP can be formulated as a linear programming in the form given below The objective of Eq. 3 is to minimise the total distance.Equations 4 and 5 ensure that all the salesmen's itineraries must begin and end at the same point.Equation 6ensures that the Hamilton circuit does not have any sub loop.
The main feature of DTSP is the time-varying matrix of road distance, which can be defined as: where t is the period of a dynamic change, d i j (t) is the distance between cities i and j, and n(t) is number of cities at moment t.The difficulty of solving DTSP is proportional to the changes of n(t) and D(t), and inversely proportional to the time interval Δt of environmental change.The more significantly n(t) changes, the weaker the inter-connection between TSPs in each time interval is; the higher performance of algorithm we require, and the greater the difficulty of solving the problem becomes.
A natural question arises.How can we deal with the information changing continuously?This is addressed by defining a suitable sampling.Figure 1 shows a simple network with 3 nodes, as well as the cost of each directed edge.From the graph, we can easily get the initial optimal access order, i.e. 0 − c 1 − c 2 − c 3 − 0, and the initial travel time is 38 min.If a salesman arrives at c 1 and a traffic congestion occurs on the way from c 1 to c 2 , this may increase the travelling time cost by 30 minutes, if the route is not changed.However, if the route gets real-time updates, the travelling time cost can be reduced significantly.
Suppose that: 1) the traffic information between cities can be known in advance, and 2) the scale of the city, the distance between cities, and other parameters are fixed during the sampling period.We define DTSP as a combination of different TSP in different sampling period, where -T S P(t) is used to represent TSP at different times; d i j (t) represents the distance between city i and city j; n(t) is the scale of TSP at time t; -H (i) is the serial number of city; -Δt is the sampling period; -Δd i j is the variation of d i j (t) in Δt, and Δn is the change of city number in Δt; -T is the time period, and -N is the sampling times in each Δt.
The objective value of DTSP is the sum of objective values of all TSP within period T .Therefore, DTSP can be defined as 4 Description of the GORTS algorithm

Basic idea
The dynamics of DTSP is defined by the scale of the problem and the time variation of the cost matrix change.This dynamical aspect affects the performance and effectiveness of the algorithm and determines how to choose the appropriate algorithm.If the system exhibits a stable behaviour, a local optimisation algorithm is used to obtain an acceptable approximate solution.Otherwise, a global optimisation algorithm is necessary.The application of a GA often requires to iterate several times to converge to get the satisfactory solution for TSP.However, in DTSP it is generally required that the algorithm can converge to reach the optimal solution with fewer iterations.The method of one-by-one revision of two sides Yuan et al. (2013) aims to continuously optimise the solution via several iterations.Its process of calculation is fast.However, the algorithm is greatly affected by the initial solution and may fall easily into a local optimum.
In this article, we combine the method of one-by-one revision of two sides with GA to introduce the new GORTS algorithm.This algorithm inherits the global search ability of GA and uses the method of one-by-one revision of two sides to correct chromosomes, which speeds up the process of convergence to meet the real-time requirements.

The method of one-by-one revision of two sides
The method of one-by-one revision of two sides is an approximate algorithm for obtaining the optimal Hamiltonian circuit, suitable for the case with a large number of vertices.
Suppose that G = (V , E) is a connected undirected graph.The cycle, which joins each vertex of G exactly once, is called a Hamiltonian circuit of G. Suppose that W (v i , v j ) is the weight of the link between the vertices v i and v j , then The optimum H circuit is the cycle on G with the smallest total weight.The workflow of finding the optimum H circuit is as follows: Step 1 Draw the initial Hamiltonian circuit randomly, as shown in Fig. 2, Step 2 For all i, j, delete edges (v i , v j+1 ) and (v j , v j+1 ) in C 0 , and add edge as shown in Fig. 2. Step 3 Repeat the above steps until the best H circuit is achieved.Consider the complete graph as is shown in Fig. 2. Suppose that the weight of the initial circle C 0 = v 1 , v 2 , . . ., v 6 , v 1 is 237, and w(1, 4) + w(2, 5) < w(1, 2) + w(4, 5), edges (v 1 , v 2 ) and (v 4 , v 5 ) need to be deleted to obtain a better H circuit C, that is,

Genetic algorithm improvement
The genetic algorithm (GA) is known for its good global search ability, high efficiency, and good scalability in solving TSP (Fig. 3).However, GA needs many iterations to obtain the optimal solution in high-dynamic systems.The integration of the GA with the method of one-by-one revision of two sides can accelerate the speed of finding the ideal solution, based on the following workflow: Step 1 Generate the initial population; Step 2 Optimise each chromosome by the method of one-byone revision of two sides, and use the optimised individual to replace the original one; Step 3 Execute operations of selection, crossover, and mutation on individuals in the population; Step 4 Select the best individual in each generation.
Unsuitable implementations and various operations of encoding, crossover, or mutation may lead to different precision values, as well as the failure of the iterative process.Therefore, it is necessary to redesign the above operations.

Initial chromosome encoding
Suppose X = (x 1 , x 2 , . . ., x i , . . ., x n ), 1 ≤ x i ≤ x n i where n i is the maximum of gene i.This requires genes to be encoded with different values at different bits.The length of chromosome is determined by the scale of the DTSP.The initialisation of chromosome is automatically generated with some heuristic algorithm, and the encoding method is to directly arrange nodes randomly.

Fitness function
The fitness function is used to differentiate the individuals in a group.High value of the fitness evaluation implies that an individual has a high probability of being chosen.The selection operation based on the fitness value is important to GA, which means that the fitness function determines the performance of GA.The fitness function is defined as where x represents an individual of a population, and D(x) is the evaluation value of x.Here, D(x) is defined as the distance travelled by individual.In this article, we use the reciprocal of D(x) as the fitness function.

Crossover operation
Two parent chromosomes, parent 1 and parent 2 are selected according to the crossover probability p c , which generates two intersection points.The segments Δp 1 and Δp 2 are subsequently selected according to the two intersection points.
Child 1 assigns Δp 1 as the initial gene, while the same parts of parent 2's chromosome are ignored.Finally, the remaining component is added to child 1.Likewise, child 2 is similarly generated.In this way, even if the two parents are identical, the new offspring can be generated iteratively to overcome the disadvantages of local optimisation and premature convergence.
As shown in Fig. 4, assuming there are 8 cities, the integers {0, 1, 2, 3, 4, 5, 6, 7} are randomly selected to represent the two parents chromosomes.The randomly selected gene segment (e.g. 4, 6, 2, 3) of parent 1 is adopted as the initial gene of child 1, and the identical parts of parent 2's chromosome are ignored.Finally, the remaining parts are added to child 1. Child 2 is generated in a similar manner.

Mutation operation
The mutation operation plays an important role in improving local search ability, maintaining variability of the population, and preventing the premature convergence of GA.The swapping mutation operation is based on the mutation probability.This will identify a mutated chromosome, and subsequently, two crossing points are randomly selected and swapped As shown in Fig. 5, assuming again there are 8 cities, the sequence of integers corresponding to cities (1, 5, 4, 6, 2, 3, 0, 7) may represent a route scheme.Two selected swapping gene points are node pairs (3, 6), and (3, 5), which are exchanged to generate the offspring.

Selection strategy
A new selection strategy is adopted, and after crossover and mutation, the new individuals are put together with the original population.Subsequently, all the chromosomes are arranged from good to bad according to fitness values.The chromosomes, whose number is equal to the population size, are selected to the next iteration.GORTS is designed as a global optimisation algorithm, suitable for dynamical environments with global changes, such as the change of distance between cities and the change of number of cities.In this article, DTSP is abstracted into a series of TSPs.This requires that GORTS has the strong convergence ability to get the better solution during the sampling period.The workflow of GORTS is shown in Fig. 6.

Performance criteria
According to Eq. 19, assume that the distance matrix of DTSP is a function of time.Therefore, a test case of the dynamical properties of DTSP can be generated by modifying the value of distance between two nodes where t i j represents the change on the edge between v i and v j .
where r is a random variable uniformly distributed in [F L , F U ], q is a random variable uniformly distributed in  2009) is generally used as an important criteria in solving dynamic optimisation problems where I is the total number of iterations, E is the number of independent executions, and P * i j is the best-so-far solution.

Experiments
We selected four representative datasets from TSPLIB Gerhard (2013) with different scales of cities, ranging from 52 to 318.The value of m is defined within [0, 0.25], [0, 0.5] or [0, 1], to create different dynamic changes of the environment.Subsequently, GORTS is compared with typical heuristic algorithms, including the MAX-MIN ant system (MMAS) Stutzle and Hoos (1997), the population based on ACO (PACO) Guntsch and Middendorf (2002), the elitismbased immigrants ACO (EIACO) Mavrovouniotis and Yang (2013), and EIGA-GAPX Tinos et al. (2014).The experimental parameter values are set as follows: As shown in Table 1, In Table 2 only MMAS has slightly better performance than GORTS with changes of distance between cities.
In the rest of the section, the performance of GORTS compared with algorithms with changes in the number of cities will be discussed.We selected four representative datasets from TSPLIB, including Eil51, Eil101, St70, Eil76, and defined DTSP (t) as follows: We tested GORTS in different sample periods.Specific parameters are set as the following two groups: 1.If Δt = 1s, G = 5, P size = 10, p c = 0.80, and p m = 0.05.As shown in Fig. 7, there is no cross in any routes, which indicates that the solution quality of GORTS is good.With the increase in the number of iterations, we can find that the quality of the solution is improved, as shown in Fig. 8.However, with respect to DTSP, it is necessary to find the optimal solution in a short time, which means reducing the number of iterations.
Furthermore, we compared the length of route planned with GORTS, the adaptive ACO algorithm (AACO) Liu et al. (2012), and the nearest neighbour method (NN) Wang (2014).As shown in Fig. 9, the length of route planned with GORTS is shorter than the length of route planned with NN (c) Route 5 Fig. 13 The process of route adjusting but slightly longer than the length of route planned with AACO.
The dynamic properties of DTSP require the algorithm to quickly obtain the optimal solution.GORTS can reach this after 10 iterations in 2s, while the length of route planned by AACO with 10 iterations is much longer.
As shown in Fig. 10, it can be seen that GORTS only needs 5 or 6 iterations to converge to satisfying results, while AACO needs to iterate 150 times to converge to satisfying results.The computation time increases with the increasing number of iterations.

Prototype implementation and testing
We applied GORTS to the logistics distribution planning system for large supermarket chains with distribution centre.Low efficiency in the logistics distribution planning system is likely to cause a waste of transport capacity and the high distribution costs.We implemented the logistics distribution planning system with the Baidu Map SDK based on the Android 4.2 platform.We selected ten supermarket stores at the Gulou District.The detailed locations of these ten stores are shown in Fig. 11 and below the Table .The distribution centre of the supermarket at the Hehui road (Sm-HH) is the starting point of distribution.Note that 0 represents the distribution centre.The initial logistics distribution route is: 0 → 2 → 3 → 4 → 5 → 7 → 8 → 9 → 10 → 6 → 1 → 0, as shown in Fig. 12a.The delivery of the goods depends on specific initial arrangement and the delivery route will be adjusted according to the real-time traffic.As shown in Fig. 12c, there is a traffic congestion along the route to Sm-YL (Fig. 13).Therefore, the rest route is recalculated, which is 3 → 5 → 4 → 7 → 8 → 9 → 10 → 1.Finally, on the way to Sm-XH, the route is adjusted as: 8 → 10 → 9 → 6 → 1, as shown in Fig. 14a.Compared with the initial route, the route planned with GORTS can be adaptive to to condition of traffic and save the cost of time.

Conclusion
TSP is an NP combinatorial optimisation problem, with important theoretical value and many applications.DTSP is an adaptation with usability in a realistic dynamic environment.GA is an intelligent search algorithm for simulating biological evolution, which is widely used in solving TSP.In this article, based on the analysis of DTSP theory and mathematical model, a genetic algorithm based on the method of one-by-one revision of two sides (GORTS) is introduced.
This method integrates the better global search ability of genetic algorithm, while improving the convergence speed of the algorithm by adding the method of one-by-one revision of two sides to correct the chromosome.Finally, GORTS was compared with other algorithms and the experimental results showed it can provide accurate solutions, while the reduced computational time ensures the algorithm is suitable for use for models involving dynamic environments.

Fig. 2 a
Fig. 2 a Initial H circuit b New H circuit

Fig. 3 aFig. 4
Fig. 3 a Complete graph b Updated initial circle c Better H circuit

Fig. 9
Fig. 9 Length of route planned with different algorithms

Fig. 12
Fig.12The process of route adjusting

X
.Xu et al.

Fig. 14
Fig.14The process of route adjusting