TG:Logic/Work order logic/Disperse

To "disperse" some wagons means "find a place for them":
 * if there is space free in the wagon idling tracks of the named yard, they will be stored there.
 * Otherwise, if there is a sorting track available at the named yard, they will be stored there (this is undesirable because sorting tracks will be used automatically by the shunters as they create and break trains).
 * The final alternative is they will remain exactly where they are (which is very undesirable, as they will block access to the track when the work order that brought them is due again next month).

The automatic yard management algorithm should keep a close eye on the last two possibilities, and issue a "shunt to other track" order to shunters assigned to the named yard when space on an idling track or a sorting track becomes available, preferring the dedicated idling tracks.

When dispersing to a sorting track, preference should be given to those that have wagons on them that haven't moved in a long time (the longer, the better) and have less than 50% of the track occupied (if most of it is occupied we don't want to clutter it up even more). However, if all tracks have wagons that have moved in the last month, and more than 50% of the yard's sorting tracks are empty, prefer an empty track. If necessary, repeat the algorithm above for 75% and "all but one", respectively, as the key numbers (always leave one sorting track empty, otherwise your yard is useless for sorting). If you reach this point without a place to put the dispersed wagons, fail the algorithm.

Incidentally, this algorithm suggests at least part of the logic of yard design.