*4.2. Genetic Algorithm*

A genetic algorithm is used to divide the MTSP into 2M-1 independent TSPs for SSIS region constraint by designing an appropriate encoding so that the MTSP can be decomposed into 2M-1 TSPs appropriately.

(1) Encoding

The gene sequence of GA is divided into 2M-1 corresponding segments to the 2M-1 different accessible regions in the SSIS region, as shown in Figure 10 so that the MTSP can be decomposed the MTSP into 2M-1 TSPs. The gene indicates which arm the fruit should be allocated to. The DNA fragment corresponds to the picking region Sk in Figure 5 one by one.


**Figure 10.** Diagram of DNA sequence proposed in this paper.

Each ripe fruit in the reachable region corresponds to each element in the corresponding DNA segment. DNAk(j) indicates the picking arm allocated to the j-th fruit in the k-th area. Therefore, in order to be consistent with the harvesting arm allowed to enter each accessible region of Equation (3), the assignment rule of DNAk(j) in the initialization of the corresponding population is as follows:

$$DNA\_k(j) = \begin{cases} random(1,k) \\ \hline random(k-M+1,M), \; k \in \{M, M+1, \ldots, 2M-1\} \end{cases} \tag{18}$$

where random (1,*k*) represents any integer in the randomly assigned closed interval 1 to *k*.

(2) Selection operator

Roulette is adopted as the selection operator to improve the optimization ability of the algorithm. In this method, two individuals are selected at a time, and then the individual with the better fitness of the two individuals is selected by the probability of survival.

(3) Crossover operator

To increase the global search ability, a multipoint crossover is used to randomly select multiple segments in the gene sequence for crossover.

(4) Mutation operator

Different mutation rules are required for each DNA segment, and it can merely mutate into the code for the harvesting arm accessible to the corresponding reachable area of the segment.

All of the mature mushrooms in the current cycle were divided into M groups based on the DNA sequences of the best individuals in the population.

#### *4.3. Improved Ant Colony Algorithm*

In order to solve the problems of sequence harvesting of cluster fruits and collision avoidance when M harvesting arms work together, the respective trajectory planning of each harvesting arm should be carried out in parallel, so that it can be judged in real-time whether there the clustered fruits are harvested in the specified order and whether will be collisions between the arms.

The ant colony algorithm has good parallelism and late convergence of the algorithm, so this paper adopts the ant colony algorithm to solve the trajectory planning problem of each of the M harvesting arms and combines the auction mechanism to deal with the sequence harvesting of cluster fruits when the M harvesting arms work together.

In actual harvesting, in addition to harvesting efficiency, the harvesting success rate is also a very important indicator. According to actual harvesting requirements and experiments, the trajectory planning algorithm designed in this paper needs to ensure that the harvesting success rate is more than 95%. Therefore, the following approach is designed so that in the early stage of the evolution of the algorithm, the success rate is the main guide, while after the success rate meets the requirements, the pheromone concentration of the current fruit to be harvested should be temporarily increased to increase the probability of its selection.

The specific calculation process for the success rate is shown in Figure 11.

**Figure 11.** Flow chart for judging whether fruit in the cluster be harvested in specific order.

The following are the detailed steps:

Step 1 Initialize.

Initialize the pheromone matrix, the path taboo table, the set containing the nominal harvesting order of clustered fruits (for calculating the success rate), the set of coordinates of the fruit to be harvested for each arm, and the matrix containing the information corresponding to the time axis and displacement of the X-axis.

Step 2 Build trajectory.

Ants construct m-picking arms in parallel. First, the path taboo table is used to remove the picked fruits and generate a preliminary candidate fruit set. Additionally, then, the auction mechanism is used to determine the current candidate fruit set for each ant and choose the fruit to be picked next from the set according to the pheromone concentration until all ants have completed the trajectory construction.

Step 3 Evaluation.

The objective function E, which can be calculated by Equation (4), is used for evaluation. To make the success rate of harvesting meet the requirement of more than 95%, the K1 and K2 coefficients in Equation (4) are dynamically adjusted. When the success rate is less than 95%, set K1 = 0.4, K2 = 0.6; after the success rate is greater than or equal to 95%, set K1 = 0.6, K2 = 0.4.

Step 4 Update the pheromone matrix.

The trajectory with maximum E in Equation (3) is selected to update the pheromone matrix. Step 5 Determine the number of iterations.

If the maximum number of iterations is reached, turn to End, otherwise go to step 1. Step 6 End.

Output the final optimal trajectory.
