This paper considers mathematical optimization for the multistage train formation problem, which at the core is the allocation of classification yard formation tracks to outbound freight trains, subject to realistic constraints on train scheduling, arrival and departure timeliness, and track capacity. The problem formulation allows the temporary storage of freight cars on a dedicated mixed-usage track. This real-world practice increases the capacity of the yard, measured in the number of simultaneous trains that can be successfully handled. Two optimization models are proposed and evaluated for the multistage train formation problem. The first one is a column-based integer programming model, which is solved using branch and price. The secon...