Optimal Sorting of Rolling Stock