Optimization of energy consumption in a railway traction system