Page 1 of 1

[1.1.33] Trains don't route through train stations

Posted: Thu May 13, 2021 4:36 am
by j3robins
When there's a path around a stopped train but it goes through a train station, a train will not pick that path and instead path through the waiting train and wait for the train to move.

See screenshots for example. There is a path around the train that goes past a train station and the train would rather wait for the train in front of it (forever in this case) rather than route around the train.
Screenshot showing path where train refuses to go around blocked train
Screenshot showing path where train refuses to go around blocked train
path_with_station.jpg (597.75 KiB) Viewed 1113 times
Using the screenshot as a reference, two trains are scheduled to the second station. The first train is at the station and the second train is waiting. The third train is scheduled to go the last station and paths straight through the waiting train. Incidentally the schedules are set to wait for passenger so the third train will never arrive at its destination.

If the first station is removed then the train will path correctly and arrive at its station.
Screenshot showing correct pathing
Screenshot showing correct pathing
path_without_station.jpg (610.73 KiB) Viewed 1113 times

Re: [1.1.33] Trains don't route through train stations

Posted: Thu May 13, 2021 4:47 am
by NotRexButCaesar
https://wiki.factorio.com/Railway/Train_path_finding
cost (distance) is calculated using the following weighting rules:
Base cost for a block/segment is the length of the segment (linear grid length along the center of the rail).
When the rail block is occupied by a train -> Add a penalty of 2 * length of the block divided by block distance from the start, so the far away occupied paths don't matter much.
When the rail block is guarded by a rail signal set to red by the circuit network -> Add a penalty of 1000.
When the path includes a train stop that is not the destination -> Add a penalty of 2000.
When the path includes a train stop with a train stopped in it -> Add a penalty of 500.
When the path includes a train stop with a train stopped in it that doesn't have other valid stops in its schedule -> Add a penalty of 1000.
When the path includes a manually controlled stopped train -> Add a penalty of 2000.
When the path includes a manually controlled stopped train without a passenger -> Add a penalty of 7000.
When the path includes a automatic train without a schedule -> Add a penalty of 7000.
When the path includes a train currently arriving to a train stop -> Add a penalty of 100.
When the path includes a train currently arriving to a rail signal -> Add a penalty of 100.
When the path includes a train currently waiting at a rail signal -> Add a penalty of 100 + 0.1 for every tick the train has already waited.
When the path includes a train that doesn't have a path -> Add a penalty of 1000.

Re: [1.1.33] Trains don't route through train stations

Posted: Thu May 13, 2021 4:49 am
by j3robins
Okay, so reading the Path finding penalties, I guess it is expected that the train will wait for 19,000 ticks (a little over 5 minutes) before pathing through the station.

That still seems wrong to me.... Why is the penalty for going through a station so severe?

Re: [1.1.33] Trains don't route through train stations

Posted: Thu May 13, 2021 7:11 am
by j3robins
After playing with this a bit I found a workaround. By adding a train station where the second train is waiting, the correct pathing suddenly click in. My guess is the train station adds 2000 points to the center path so both paths are more "even" now.

This implies that the penalty for "When the path includes a train stop that is not the destination" should be reduced or perhaps the formula for "When the rail block is occupied by a train" needs to be improved / weighted more.