Considering the safety factors in the railway, this paper mainly focuses on the optimal speed of high-speed train or locomotive from the starting station to the ending station. Firstly, some concepts in the railway safety, which include the risk source, hidden danger, accident and safety warning point, are introduced to better understand the railway safety factors. Secondly, the mathematical model including objective function and the corresponding constraints is analyzed to solve the optimal train speed problem. Thirdly, the PSO algorithm is used to provide and design the optimal speed train from the starting station to the ending station. Simulation results show that PSO algorithm can handle with the optimal train speed problem and the obtained optimal speed are provided to ensure the train safety in the constant transportation time.