[2.0.32] When trains are trying to leave a stop, trains at stops with higher priority are not dispatched first

Bugs that are actually features.
terrenna
Burner Inserter
Burner Inserter
Posts: 6
Joined: Wed Feb 12, 2025 6:17 am
Contact:

[2.0.32] When trains are trying to leave a stop, trains at stops with higher priority are not dispatched first

Post by terrenna »

Description
When trains are trying to leave a stop, trains at stops with higher priority are not dispatched first.
This behavior conflicts with the intention stated in FFF 395, see https://factorio.com/blog/post/fff-395

Previously reported (but retracted) here: 126216
Steps to reproduce
Create a setup as shown in the following picture. Name left train stops "src", right stop "dst". Set all train stops to train limit 1 and priority 50. Create the left train first. Activate and deactivate constant combinator in quick succession. Watch left train go first, as expected. Wait for trains to reach their respective stations again. Increase priority of src station of right train. Toggle constant combinator again. Expected result would be for the right train to leave first. Actual result is that the left goes first again.
trains.png
trains.png (785.96 KiB) Viewed 994 times
Muche
Smart Inserter
Smart Inserter
Posts: 1006
Joined: Fri Jun 02, 2017 6:20 pm
Contact:

Re: [2.0.32] When trains are trying to leave a stop, trains at stops with higher priority are not dispatched first

Post by Muche »

I think this is related to/duplicate of 118818 Not closest train arrives at the station.

I believe the priority works as you'd expect it only when the trains are in Destination stop full state. In your setup they are waiting at stop for the wait condition to be true.

To see the priority in action try this in your setup:
1. Set train limit of dst station to zero, priorities of src to 50, enable the departure combinator. Increase dst limit to 1. The right train will depart first, because the station is closer.
2. Set priority of the left src stop to 51, enable the combinator. Increase dst's limit. Now the left train will depart first, because of higher priority.
terrenna
Burner Inserter
Burner Inserter
Posts: 6
Joined: Wed Feb 12, 2025 6:17 am
Contact:

Re: [2.0.32] When trains are trying to leave a stop, trains at stops with higher priority are not dispatched first

Post by terrenna »

Muche wrote: Wed Feb 12, 2025 12:52 pm I think this is related to/duplicate of 118818 Not closest train arrives at the station.

I believe the priority works as you'd expect it only when the trains are in Destination stop full state. In your setup they are waiting at stop for the wait condition to be true.

To see the priority in action try this in your setup:
1. Set train limit of dst station to zero, priorities of src to 50, enable the departure combinator. Increase dst limit to 1. The right train will depart first, because the station is closer.
2. Set priority of the left src stop to 51, enable the combinator. Increase dst's limit. Now the left train will depart first, because of higher priority.
Thanks for your reply. In your scenario, source priority works as expected. It appears to only work under the same conditions that the "closest train" logic works, so the post you linked is definitely related. The explanation by boskid in the other thread shines some light on the issue. The destination is not yet full by the time the circuit condition becomes true because none of the trains have claimed it, in which case the train with the lower id gets to go first. At that point, train two is "in destination full" state, but there is no more priority to figure out, since the first train is already on the way. I have added a third train to show the difference in the blueprint below (and fixed my shoddy track placement). The train with the lowest ID goes first, then, as both of the other trains are in "destination full" state, priority (and path length) logic is applied to the two of them.

Reading "When trains are trying to leave a stop, trains at stops with higher priority are dispatched first.", I expected priority to apply at the level of train updating already, not only when the destination becomes available while in a "destination full" state. Then again, I would also expect "closest train" logic to apply earlier than it apparently does, which has been considered "not a bug", so I'm guessing the same will be true for the priority as well.


Loewchen wrote: Wed Feb 12, 2025 1:46 pm I don't see anything suggesting a bug here.
Apparently it is not. The behavior differs from what I expected after reading the FFF, but if the current logic is working as intended, I guess it's not technically a bug.
Last edited by terrenna on Wed Feb 12, 2025 2:49 pm, edited 1 time in total.
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 4028
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [2.0.32] When trains are trying to leave a stop, trains at stops with higher priority are not dispatched first

Post by boskid »

I am not seeing any good reasons to make trains update to become 2 passes update: first to check schedule conditions if train wants to depart so all trains become ready in the same tick and then run the trains priority logic to select which train should acquire the train stop. Quite contrary, i see a lot of reasons for not doing it, which is making sure that schedule conditions like "station X not full" work correctly because if there would be 2 trains that depart a train stop at the same time because station X was not full, when there was only 1 empty slot, one train would claim the train stop while the other would go into "destination full" state effectively making "station X not full" condition broken because train was dispatched but failed to acquire the train stop. Current solution is reasonable one where in order for train priority logic to take place, it must see trains that already fulfilled their departure condition and are only waiting for the destination to become not full. This behavior is literally that the trains are evaluated in order, first train checks its departure condition, it is true, it claims the train stop because there are no other trains going there, then second train checks its departure condition and regardless of it having a higher priority, it lets existing train to complete its travel as it was dispatched before. It does not matter it was dispatched earlier in the same tick, it was dispatched earlier when there was no other train competing for that train stop. Not a bug.
Niedzwiedzislaw
Burner Inserter
Burner Inserter
Posts: 18
Joined: Thu Oct 31, 2024 7:52 pm
Contact:

Re: [2.0.32] When trains are trying to leave a stop, trains at stops with higher priority are not dispatched first

Post by Niedzwiedzislaw »

boskid wrote: Wed Feb 12, 2025 2:21 pm Quite contrary, i see a lot of reasons for not doing it, which is making sure that schedule conditions like "station X not full" work correctly because if there would be 2 trains that depart a train stop at the same time because station X was not full, when there was only 1 empty slot, one train would claim the train stop while the other would go into "destination full" state effectively making "station X not full" condition broken because train was dispatched but failed to acquire the train stop.
What is keeping you from using priority to sort trains? If trains were sorted by priority you could use the first found train and dispatch it.
Post Reply

Return to “Not a bug”