## 5 Solution Algorithms
### The Procedure of the Algorithm  
The two-layer optimization model is designed according to the two optimization objectives, which can better take into account the factors of cost and full load rate. As a bi-level model, the lower level's decision variables are the parameters for the upper-level model. \(f1,f2,\,a,\,b\) are decision variables of the upper model, and they are also the variables that make up the objective function of the lower model. Firstly, the genetic algorithm is used to obtain the optimal solution of the upper model. Then, the optimal frequencies and locations of the turn-back station from the upper model are substituted into the lower model to solve its optimal solution. The procedure of the algorithm is provided below. Step1: The upper model is converted into a single-objective optimization problem by normalization. The weights of each objective function are determined based on the objective function values of the single-routing operation plan. \[\min\mathcal{W}=\alpha_{1}\cdot W_{1}+\alpha_{2}\cdot W_{2} \tag{48}\]  
\(T_{W0}\) is the waiting time for passengers of the single train operation scheme, \(L_{50}\) is the train running distance under the single routing mode. \(\alpha_{1}\) and \(\alpha_{2}\) are the weights of the two objective functions, which can be calculated as follows:  
\[\alpha_{1}\cdot T_{W0}=\alpha_{2}\cdot L_{50}, \tag{49}\]  
\[\alpha_{1}+\alpha_{2}=1. \tag{50}\]  
Step2: The upper model can be solved using a genetic algorithm. First, we need to determine the parameters required by the upper model, including crossover probability, mutation probability, and initial number of marshalled vehicles. The initial population has 100 individuals. The evolution is 50 generations. The initial number of marshalled vehicles is \(n1\) and \(n2\), both of which are 4. The key steps are shown below. (1) Individual coding: One-dimensional binary coding is adopted. The upper model established in this paper has 4 decision variables, so each chromosome consists of 4 gene segments. Among them, the number of genes corresponding to the departure frequency of the full-length train and short-turn train is 4, the number of genes corresponding to the starting station and terminal station of the short-turn route is 5. In summary, the total number of genes per chromosome is 18. As shown in Figure 3,\(f1\) is \(12,f2\) is \(3,a\) is 9, and \(b\) is 13. (2) Selection strategy: The tournament algorithm is used to select individuals. The reciprocal of the objective function is taken as the fitness function. Penalty function is used to screen infeasible solutions. Before calculating the objective function, decode the chromosome first, and then check whether this chromosome meets the constraint. The objective function corresponding to the chromosome that does not meet the constraint is a larger value. As shown in Figure 4, \(f1\) is \(16,f2\) is \(6\), \(a\) is \(13\), and \(b\) is \(9\). This chromosome does not meet the restrictions of Formula (17) and Formula (19), so this chromosome has a larger objective function value. (3) Single-point crossover: Two adjacent chromosomes are grouped together for crossover. If the chromosomes are odd, the last chromosome does not cross. Randomly select a gene bit and generate a random number. If the random number is less than the crossover probability, crossover is performed to generate a new chromosome. Single-point crossover is shown in Figure 5.  
(4) Basic bit mutation: Randomly select a gene bit and generate a random number, if the random number is less than the mutation probability, the gene bit will change. As shown in Figure 6, the mutation principle is that \(0\) becomes \(1\), and \(1\) becomes \(0\). Parent chromosome  
\begin{tabular}{|c|c|c|c|c  
(5) Termination criterion: Repeat (2) to (4) 50 times, compare the optimal chromosomes in 50 generations, and take the chromosome with the maximum value of fitness function as the output result. Step3: The optimal solution of the upper model is input into the lower model as a known parameter.