## 4 Design of the Algorithm
### Improved Ant Colony Algorithm  
For merchant self-operated takeaway delivery, each rider is assigned a service area defined as a cluster calculated by the K-means algorithm. As each rider has multiple destinations to traverse in their service area, it is essential to optimize the delivery routes to reduce the total distance it takes to visit all destinations. The ant colony algorithm, which  
Figure 1: The flow chart for K-means algorithm. has significant application in solving the capacitated vehicle routing problem (CVRP), is used to optimize the routes for the rider. The idea of the ant colony algorithm is inspired by the fact that ants can always find the shortest path when looking for food [33; 34]. Ants will leave a kind of pheromone on their walking route, which can transmit information. Ants determine the route to continue moving forward by checking the pheromone intensity on the road. The pheromone intensity will increase as more ants are walking on the route. The pheromone will evaporate over time. The probability of ant '\(r\)', which is located at node \(i\), will choose node \(j\) as the next node, as shown in Equation (8). \[P_{i,j}^{r}=\frac{[\tau_{i,j}]^{\alpha}[\eta_{i,j}]^{\beta}}{\sum\limits_{q \in\Gamma_{j}^{r}}[\tau_{i,q}]^{\alpha}[\eta_{i,q}]^{\beta}},\quad\text{if} \quad j\in N_{j}^{r} \tag{8}\]  
where \(\tau_{i,j}\) is the pheromone intensity between node \(i\) and \(j\); \(\eta_{i,j}\) is the visibility of node \(j\) from node \(i\), which is the reciprocal of the distance between node \(i\) and \(j\); \(\alpha\) is the parameter weighting the value of pheromone trail; \(\beta\) is the parameter that evaluates the value of visibility; \(N_{j}^{r}\) is the nodes that ant '\(r\)' has not visited; and \(q\) represents each possible next node for the ant within the set \(N_{j}^{r}\). The algorithm tends to fall into the local optimum if the next node always chooses the node with the highest probability. The roulette strategy shown in Figure 2 is introduced to solve this problem, in which the next node selection is not entirely based on the probability value. A random number between 0 and 1 is generated by the roulette strategy, which was compared with the number calculated by Equation (8), and the number with a higher value was chosen as the probability for the following calculation. Some pheromones will be deposited on the road when the ant walks through it, and some pheromones on the road will also be evaporated over this time. When the ants  
Figure 2: The flow chart for the roulette strategy. have traversed all nodes, the pheromone intensity on the road will be updated upon its evaporation and deposition process, as shown in Equations (9) and (10). \[\tau_{i,j}=(1-\rho)\tau_{i,j}+\sum_{r=1}^{m}\Delta\tau_{i,j}^{r} \tag{9}\]  
\[\Delta\tau_{i,j}^{r}=Q/L_{r} \tag{10}\]  
where \(\rho\) is the coefficient to evaluate the pheromone evaporation rate, which can prevent the pheromone from unlimited accumulation; \(m\) is the number of ants; \(\Delta\tau^{r}_{i,j}\) is the ant '\(r\)' deposited pheromone when it moves from node \(i\) to node \(j\); \(Q\) is the total pheromone deposited by each ant; and \(L_{r}\) is the length of ant '\(r\)' traversed routes. A higher pheromone is obtained when the route is shorter. The flow chart of the improved ant colony algorithm is illustrated in Figure 3. The utilization of the improved ant colony algorithm to solve the route optimization problem in takeaway delivery is as follows:  
Step 1: Parameter setting. The setting of parameters can directly influence the convergence and efficiency of the algorithm. The parameters in the ant colony algorithm are set  
Figure 3: The flow chart of the improved ant colony algorithm. as shown in Table 1. Considering that the number of nodes in this research is small, the number of ants was set equal to the number of nodes to simplify the computation process.