Train order when waiting for destination space

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
User3141
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon May 06, 2019 11:07 am
Contact:

Train order when waiting for destination space

Post by User3141 »

Hi,

I was trying to solve a train balancing issue, but sadly my solution didn't work and it's got me curious about a confusing train mechanic.

Suppose two trains both have the same destination station, and are waiting for it to have space. When the destination finally gets space, which one should win the race? I think I would expect it to either be the closest as defined at https://wiki.factorio.com/Railway/Train_path_finding, or the one that started waiting first, but I'm seeing counterexamples to both theories. Happy to share more details on my experiments but thought I'd check if people know what should happen first...

An example, with a signal set to red by control signal meaning the right train should be "closer" but the left train seems to win.
trains.png
trains.png (3.51 MiB) Viewed 535 times
robot256
Smart Inserter
Smart Inserter
Posts: 1027
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Train order when waiting for destination space

Post by robot256 »

Trains search for the closest available stops. They don't look at any other trains when they do this, and stops do not "look" for trains in any way. The trains are processed in arbitrary determistic order (probably sorted by Train ID, so the one that was built is processed goes first).
Tertius
Smart Inserter
Smart Inserter
Posts: 1024
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: Train order when waiting for destination space

Post by Tertius »

As far as I understand the wiki information as well as observation of the game, trains are choosing their destination, not stations are choosing their trains.

It is documented, that whenever a train is choosing a destination, all destinations with the same station name are eligible, and the nearest one is chosen.
It is nowhere mentioned something special will happen if a station gets an unused reservation slot. It just becomes available, and that's that.

Instead, as one step in tick processing, the game iterates over the list of all trains with no destination. The pathfinding for each train is started, and if found a destination, the train is assigned this destination. It may happen the slot just freed is then occupied again, if there was a train whose pathfinding found that station. Which train it was depends on the position in the list of trains - essentially, random.

Trains choose the nearest destination.
Stations don't choose the nearest train - they don't choose at all.
User3141
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon May 06, 2019 11:07 am
Contact:

Re: Train order when waiting for destination space

Post by User3141 »

Hmm, interesting. That's a little surprising, but I guess I can work around it. Thank you for the quick responses!
sparr
Smart Inserter
Smart Inserter
Posts: 1463
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Train order when waiting for destination space

Post by sparr »

"Closest" here means as the crow flies, not train pathfinding :(

Or at least it did the last time I saw someone run this experiment, which was years ago.
Post Reply

Return to “Gameplay Help”