## 3 Mathematical Model and Solution Algorithm
### Model Solving Algorithm Design
#### 3.3.2 Algorithm Steps  
(1) Parameter initialization  
Initially, we set the relevant parameters. The input data include five main categories: (1) passenger flow OD data with a granularity of 1 min during the study period; (2) line parameters such as the number of stations, configuration of turnaround stations, depot settings, and the quantity of available rolling stock; (3) technical parameters for trains, including capacity, dwell time at stations, running times, maximum and minimum departure intervals, as well as maximum and minimum turnaround times; (4) genetic algorithm parameters: population size \(pop\_size\), crossover probability \(p_{c}\), mutation probability \(p_{m}\), Iteration number \(max\_gen\); (5) simulated annealing algorithm parameters: the initial temperature \(t_{max}\), cooling coefficient \(\varepsilon\), termination temperature \(t_{min}\). (2) Chromosomal coding  
The chromosome coding consists of two components: One part is the sequence for up train solutions, comprising three segments. The first segment utilizes binary coding to indicate train departures, the second segment employs natural number coding to denote the train's route type and destination at the terminal station, while the third segment utilizes real number encoding to signify the departure time from the originating station. The other part is the sequence for down trains the same as the up trains. When a train departs from its originating station at a specific time, the departure operator corresponding to that time is assigned a value of 1; otherwise, it is 0, with the departure time code representing the respective time. If a full-length route train proceeds to the terminal and opts to enter the depot, the value is 0; if it chooses to reverse, it is 1. For short-turn route trains required to reverse, the value is 2. Concatenating these two parts forms the chromosome code for this algorithm, illustrated in Figure 2.  
Initialize the population  
We randomly generate running trains and route types, ensuring that the departure time from the first station is a feasible solution, and assign departure times for the last train at each station. First, we randomly generate the departure time for the first train at the first station in the range of \([0,h_{max}]\). Subsequently, we generate an integer \(h_{1}\in[h_{min},h_{max}]\). The departure interval between two consecutive trains at the first station is \(h_{1}\) (for non-coupling sending) or 0 (for coupling sending), allowing for the computation of departure times for all trains at the first station. Fitness function construction  
Building upon the initial feasible solution, the passenger flow distribution is simulated using train operation simulation, shown in Figure 3.  
The specific steps are outlined below. Step 1: Initial data input involves entering model parameter values, such as time-varying passenger flow demand, turnaround stations, dwell time at each station, running time, train capacity, unit waiting cost, average train acquisition cost per unit time, unit travel kilometer cost, etc. We utilize a dictionary within the data structure to store attributes related to passengers and trains. Train attributes primarily encompass train route type and return plan, current train location, train arrival time, and passenger capacity; while passenger attributes include passenger OD, arrival time for each passenger, passenger's train selection behavior, and waiting time. Step 2: Simulation initialization begins by initializing each parameter value and setting the station where the train is located, along with the number of people getting off the train, to zero. Then, the simulation process commences. As the simulation clock progresses, updates are made to passengers' boarding and alighting statuses, on-board status, and waiting status. Concurrently, the number of passengers waiting at each station and the relevant train attributes are updated until the system reaches a stable state and halts. Step 3: Simulation process design.