Application of Ant Colony Algorithm in Selecting Shortest Engineering Path

In engineering surveying, topographic maps can be used to find the shortest path. Traditional methods identify the smallest radius based on the design slope before finding the shortest path. This paper, by using the ant colony algorithm and MATLAB software, manages to select the shortest path in engineering practice, and compares the result with that obtained using the genetic algorithm. The results show that the ant colony algorithm can be applied in selecting the shortest path in engineering projects and it can deliver a stable and optimal result after 240 times of iteration. However, the genetic algorithm cannot achieve that even after 400 times of iteration. Therefore, the ant colony algorithm is superior to the genetic algorithm in the aspect of the calculation speed, the stability of achieving the optimal solution, and selection of the shortest path.


Introduction
For the path planning and design in engineering projects such as roads, railways, pipelines, and communications, it is often necessary to plan an optimal path connecting the starting point with the target point [1]. This paper, based on the ant colony algorithm and MATLAB software, manages to select the shortest path in engineering, and compares the result with that obtained using the genetic algorithm [2].
The results show that the ant colony algorithm can be applied in selecting the shortest path in engineering projects and it can deliver a stable and optimal result after 240 times of iteration. However, the genetic algorithm cannot achieve that even after 400 times of iteration.

Ant colony algorithm
The ant colony algorithm is derived from the study of ant foraging. It is found that ants release a pheromone on their way of food searching, and its concentration is positively correlated with the length of the path. Other ants will choose the path with higher pheromone concentration and also leave more pheromone on their way, which can update the pheromone and help to select a shortest path [3][4][5].

Basic principles
The algorithm flow based on MATLAB design is shown in Figure 1.

Three-dimensional modeling of planning area
The primary condition for implementing the path planning algorithm is the conversion of the topographic map of the planning area into a 3D model [4]. Here are the specific steps: (1) Set the inflection point in the lower left corner of the topographic map as the origin point o, and take the north-south direction as the X-axis, the east-west direction as Y-axis, and the zenith direction as the Z-axis. The maximum lengths in the X, Y, and Z directions are OA, OB, and OC, respectively, as shown in Figure 2.
(2) Discretize the space after establishing the three-dimensional coordinate system. First, equally divide the 3D space along the OA direction into s n+1 planes (i=1, 2,…, n+1), and then equally divide each plane along the OB and OC directions by m and l. The more the divided spaces, the higher the similarity between the sets after discretion and the original one, as shown in Figure 3.
(3) Through spatial discretization, the points in the planning area also correspond to the coordinates in the three-dimensional model,

Pheromone update
The key of the ant colony algorithm is the pheromone update of each discrete point i a after the pass of ants. The pheromone concentration affects the probability of subsequent ants passing the point [6]. The pheromone update can be divided into local update and global update. The function of local update is to increase the probability of an ant passing a point that has never been passed through before. When an ant passes a point i a , its pheromone value decreases according to the following equation: In Equation (1) Global update refers to the path evaluation and shortest path selection after the path is completed. The pheromone values of the nodes are increased to enhance the probability of subsequent passing. The equation for global update is: In Equations (2) and (3),  is the coefficient for pheromone update; length (m) is the length of the route through which the m th ant passes; K is a constant number.

Heuristic function
When the ant moves in the three-dimensional model, we can set the current point as a, the next point as b, and the target point as c. In this way, a heuristic function for calculating the probability of the ant moving to each point can be set as: (4), S is a safe value, and is taken as 0 or 1 to ensure that the selected path meets the design requirements; w1 and w2 are weight coefficients, representing the importance of in the heuristic function.
is the distance between the current point and the next one, which urges the ant to select the shortest path.
is the distance from the next point to the target point, which urges the ant to select a point closer to the target.

Searching method
Set the x-axis direction as the main direction in which the ant advances, which is to regard the movement of the ant in the planning area as moving from the plane where the current point In Equation (7), (4) The specific position of the next point is obtained based on the calculated probability. Repeat the above steps until the final point is reached.

Verification
This paper takes the 1:500 digital topographic maps (CGCS2000 coordinate system) of Anhui Agricultural University High-tech Agricultural Park as an example, and uses the ant colony algorithm and the MATLAB programming to automatically search for the shortest path from the starting point to the end point. In order to facilitate calculation, this paper takes the lowest point elevation in the planning area as 0, and determines the other points by the height difference from the lowest point; the X and Y coordinates on the topographic map correspond to the serial number coordinates in the model.

MATLAB programming
The steps to write a program in MATLAB are as follows: (1) Input the coordinates of the elevation points into the x, y, z matrix, and form a three-dimensional image. To make calculation easier, this paper first divides the planning area into 20*20 grids, and forms a 21*21 elevation matrix based on the elevation of each grid point (rounded to one decimal place), and then obtains an initial three-dimensional model after converting the measured coordinates of each point into the coordinate in the algorithm.
(2) In order to make the algorithm faster and more accurate, this paper set the initial parameters as follows. The size of ant colony is set as 20; the pheromone update coefficient  , 0.2; the number of algorithm iteration, 400 times; the starting point, (1, 10, 4.2); the ending point, (21, 4, 5.4). The safety value S is determined based on the height difference and the horizontal movement.
(3) Calculate the heuristic value of the ant moving from the current point to the next one based on the above formulas. Then, search all 3D paths from the starting point to the end based on the pheromone and the heuristic value, and calculate the fitness value of each path. Finally, seek the optimal solution using the ant colony algorithm iteration.
(4) Output the final optimal path and the graph of fitness change of the optimal individual, and evaluate the ant colony algorithm.

Program operation and graph drawing
After importing elevation points into a computer 3D model, initialize the relevant parameters and update the pheromone at the starting point before the algorithm starts, and then judge the safety value of the next point using the if function. In this way, all possible next points can be obtained.
After updating the pheromone at the starting point and judging the security value of the heuristic function, we can start to iteratively search for the shortest path, which is the core part of the algorithm. When each ant advances from the starting point to the next point according to the probability , record the current shortest path of each iteration, update the pheromone of the nodes, and calculate optimal individual fitness value corresponding to the number of times of the current iteration. Through multiple fitting, the optimal path can be obtained.
Finally, simulate and output the shortest path through a 2D model diagram ( Figure 4) and a 3D model diagram ( Figure 5) so as to facilitate engineering planning and application.

Comparison of ant colony algorithm and genetic algorithm
The ratio of the algorithm fitness value to the number of iterations is the reflection of the convergence speed. When the fitness value tends to be stable, the possibility of the algorithm optimization reduces,  Figure 6(a), it can be seen that as the number of iterations increases, the optimal individual fitness value of the ant colony algorithm decreases continuously, and the declining is the fastest during the 0 to 50 th iteration. When iterations is over more than 240 times, the fitness value no longer decreases, indicating that the algorithm results tend to be stable and the shortest path is obtained [9].
This paper refers to the genetic algorithm for comparison [10][11][12]. 400 times of iteration using the genetic algorithm and the same data delivers the variation tendency of the optimal individual fitness value, as shown in Figure 6(b). From Fig. 6(a) and (b), it can be clearly seen that the declining speed of the variation trend of the fitness value obtained using genetic algorithm is slower than that obtained using the ant colony algorithm. Besides, after 400 times of iteration, the fitness value obtained using the genetic algorithm still keeps decreasing, suggesting that the optimal solution is still not obtained. Therefore, the ant colony algorithm is superior to genetic algorithm in terms of calculation speed and stability.
(a). the ant colony algorithm (b). the genetic algorithm Figure 6. Variation of adaption degree using the ant colony algorithm and the genetic algorithm

Conclusion and prospects
This paper, based on MATLAB program, complete the iterative optimization of the path with good efficiency and stability, using ant colony algorithm, following the steps of heuristic function calculation and pheromone update. The result is shown in the form of image, thus improving its practical value. However, the algorithm may still have a deceptive problem. Subsequent research can further optimize the selection of fitness functions and other bionic algorithms. In conclusion, ant colony algorithm provides a new idea for finding the shortest path in engineering measurement.