## 4 Methods
### Design of Particle Swarm Algorithm  
The particle swarm algorithm is a global stochastic search algorithm based on group collaboration developed by simulating the foraging behavior of a flock of birds. The basic idea of this algorithm is to find the optimal solution through cooperation and information sharing among individuals in the group. The particle swarm optimization algorithm has the advantages of a simpler principle, fewer parameters, and easier implementation. For example, compared with genetic algorithm, particle swarm algorithm does not need coding, and there are no \"crossover\" and \"mutation\" operations in this algorithm. It is also faster than the simulated-annealing algorithm. The basic idea of both particle swarm algorithm and ant colony algorithm is to simulate the behavior of biological groups in nature to construct stochastic optimization algorithms. Since the individual in the ant colony algorithm can only perceive the local information and cannot directly use the global information, the basic ant colony algorithm generally needs a long search time and is prone to stagnation [37]. Therefore, the two-decision variable stochastic nonlinear-programming mathematical model for the joint optimization of ticket price and allocation established in this paper is more suitable for being solved by a particle swarm optimization algorithm [38]. Figure 2 shows the basic procedure of the algorithm. The steps for solving the model using this algorithm are shown below. Step 1: Set algorithm parameters, including maximum number of iterations (maxgen), number of populations (sizepop), velocity maximum (\(V_{\text{max}}\)), velocity minimum (\(V_{\text{min}}\)), search space dimension (\(n_{\text{var}}\)), search range maximum (pop\({}_{\text{max}}\)), search range minimum (pop\({}_{\text{min}}\)), learning factor (\(c_{\text{max}}\)), and own velocity inertia (\(\bar{\varpi}\)). Step 2: Initialize particle position and velocity. Stochastically generate the initial positions of n particles in the search space range, where the value of n is equal to the population size. The position of each particle consists of n\({}_{\text{var}}\) dimensional coordinates, and the value of n\({}_{\text{var}}\) is equal to the number of decision variables in the objective function. For the model in this study, the n\({}_{\text{var}}\) dimensional coordinates of each particle correspond to the ticket price and ticket allocation in each OD section in each period during the pre-sale period, which is a set of solutions of the model. At the same time, stochastically generate the initial velocity of each particle in the velocity range. Step 3: Set the fitness function. The maximum model of the optimization problem generally takes the objective function (Equation (8)) as the fitness function. In addition, set the current iteration generation \(t=0\). Step 4: Calculate each particle current fitness value, i.e., the objective function value. Step 5: Based on the fitness value, update and replace individual optimum of each particle. If the current position of the particle has a higher fitness value, it will be updated. Otherwise, the original position remains unchanged. In addition, traverse all particles. The velocity and position update rule can be expressed as Equation (19). \[\mathrm{V}_{i}^{t+1}=\varpi\mathrm{V}_{i}^{t}+c_{1}\cdot\mathrm{rand}(0,1) \cdot\left(\mathrm{P}_{\mathrm{best}}^{t}-\mathrm{X}_{i}^{t}\right)+c_{2}\cdot \mathrm{rand}(0,1)\cdot\left(\mathrm{G}_{\mathrm{best}}^{t}-\mathrm{X}_{i}^{t}\right)\]  
\[\mathrm{X}_{i}^{t+1}=\mathrm{X}_{i}^{t}+\mathrm{V}_{i}^{t+1} \tag{19}\]  
In the Equation (19), \(\mathrm{V}_{i}^{t+1}\) represents the search speed of the \(i^{th}\) particle in the (t+1)\({}^{th}\) generation, and \(\mathrm{X}_{i}^{t+1}\) represents the position of the \(i\)th particle in the (t+1)\({}^{th}\) generation.