The optimal trajectory planning for trains under constraints and fixed maximal arrival time is considered. The variable line resistance (including variable grade profile, tunnels, and curves) and arbitrary speed restrictions are included in this approach. The objective function is a trade-off between the energy consumption and the riding comfort. First, the nonlinear train model is approximated by a piece-wise affine model. Next, the optimal control problem is formulated as a mixed integer linear programming (MILP) problem, which can be solved efficiently by existing solvers. The good performance of this approach is demonstrated via a case study.