Personally, I'm not to fond of the idea of using relays to control the train. The sudden start and stops you get are not very realistic and are hard on the equipment. They also increase the possibility of derailments and unwanted uncouplings. I also agree that something like an Arduino would probably be a better option than a Raspberry pi; although, depending on exactly what you are wanting to accomplish I can think of reasons for going with the pi as well(for example, if you want access to video and a keyboard).
You may already know this, but the Arduino has what are called "shields" that plug right into the Arduino. A "motor shield" can directly power a model train(actually two, because it has two outputs). With a motor shield, you don't just get on and off, but you can vary the output, allowing you to realistically ramp the train speed up and down.
I've actually done this sort of thing. At Christmas, I have an N scale loop of track that that I mount in the tree and an HO scale loop I put under the tree. I use an Arduino with a motor shield, PIR motion sensor and infrared receiver to run the trains. I can control the trains through the infrared receiver using a universal remote, or I can set it to "automatic" mode. In automatic mode, if it detects someone in front of the tree(using the PIR sensor), it will run the trains on it's own. It ramps one up to speed, then the other, waits a set period of time, then slows each one to a stop.