How do locomotives know where they're going

How do locomotives know where they're going? Lots of training