This paper introduces a novel optimisation algorithm for hybrid railway vehicles, combining a non‐linear programming solver with the highly efficient “Mayfly Algorithm” to address a non‐convex optimisation problem. The primary objective is to generate efficient trajectories that enable effective power distribution, optimal energy consumption, and economical use of multiple onboard power sources. By reducing unnecessary load stress on power sources during peak time, the algorithm contributes to lower maintenance costs, reduced downtime, and extended operational life of these sources. The algorithm's design considers various operational parameters, such as power demand, regenerative braking, velocity and additional power requirements, enabling it to optimise the energy consumption profile throughout the journey. Its adaptability to the unique characteristics of hybrid railway vehicles allows for efficient energy management by leveraging its hybrid powertrain capabilities.