This is really interesting. Found: https://www.researchgate.net/publication/225576076_Shunting_...
I wonder what real railway yards do.
train shunting problems seem like a variation of tower of hanoi https://en.wikipedia.org/wiki/Tower_of_Hanoi
https://en.wikipedia.org/wiki/Train_shunting_puzzle