Train shunting puzzle

Train shunting puzzles, also often called railway shunting puzzles  or railroad switching puzzles, are a type of puzzle.

Shunting puzzles usually consist of a specific track layout, a set of initial conditions (typically the starting place of each item of rolling stock), a defined goal (the finishing place of each rolling stock item), and rules which must be obeyed while performing the shunting operations.

There are often constraints such as making the minimum number of couplings and uncouplings, or making the minimum number of junction direction changes, or completing the puzzle within a specified time limit.

Other important factors may include the lengths of tracks limiting the number of rolling stock vehicles which can be placed along them. Some shunting puzzles allow certain types of rolling stock to navigate a particular section of track but not other types of rolling stock, for example a locomotive might not be allowed to pass below a low bridge whereas wagons are allowed, or a particularly heavy wagon might not be allowed across a weak bridge, or a particularly tall wagon might not be allowed to pass through a tunnel.

Some train shunting puzzles have been developed as add-ons for railway simulator computer programs such as Auran's Trainz and Microsoft Train Simulator.

Categories
Shunting puzzles tend to fall into the following categories, but this list is not intended to be exhaustive:
 * Build up a train (known as a "consist" in Australian and North American railway terminology) in a specified order, picking up rolling stock from various locations such as sidings.
 * Decompose a train, placing rolling stock items in specified locations.
 * Devise the optimum sequence of rolling stock items in a train, so that it can be efficiently assembled at its starting point and decomposed at its destination(s).
 * Devise a means by which two long trains can pass each other on a single track, for example the double saw-by manoeuvre at a passing loop, used when both of the trains are too long to fit into the loop. It may or may not be required to maintain the original sequence of rolling stock in each train.
 * Run a locomotive around its passenger carriages at a terminus ready for the return journey.
 * Reverse the direction of a train, for example at a wye where the train is too long to fit into any of the individual sections of track.

Examples
Two of the best known model railway train shunting puzzles are:
 * Alan Wright's "Inglenook Sidings"
 * John Allen's "Timesaver".