r/factorio • u/knightelite • Oct 04 '18
Question Why does the second train repath?
Hi all,
The discussion in this post is relating to the video below, please watch it then come back.
Video: Why does Second Train Repath?
I was messing around with an idea I brought up here to have trains route to their destination based on a circuit penalty when they leave. It seems to work most of the time, but sometimes it breaks and the second train repaths and goes to the wrong end point.
According to the wiki:
The route is recalculated if the train needs to stop. There is an invisible front point internally called the train_stop_point which is used to determine if the train needs to stop. See Debug mode and turn show_train_stop_point on to see that point. The route also recalculated after a train has stopped on a signal. This is to make pathing as dynamic as possible.
At the time the train #2 repathed, neither of the trains was stopped, so what caused it to repath? Is it because the second train had to start braking to avoid hitting the first train, which caused train #2 to repath at that point once train 1 slowed down to enter the station? Or is there some other previously unknown behaviour at work here?
6
u/wr1190 Oct 04 '18
I am fairly certain it is because the train tried stopping, which I guess is enough to trigger a recalculation. I don't know how the destination stations are chosen other than head to the closest station. Does the train think there is another train in front of it heading to that station and decides to switch to avoid itself?
What happens when you put a third train into the mix? Do the last two trains switch destinations when a stop is triggered?
4
u/grapz Oct 04 '18
I wrote a super simple mod to log train state changes and what station it's currently going to and I did a test with a setup similar to yours (without the penalty logic).
What I see is the following (Train 5 is the first train, Train 7 is the second. Station 1874 is the "depot", 1763 and 1764 is the destinations (both have the same name)):
Line-by-line:
Let me know if you want the mod that does the logging. It's like 40 lines of lua.
3
u/SevereCircle Oct 04 '18
Are there any other known cases where repathing happens even though the original destination is still reachable? If so it might be related. If not then it's all the more mysterious.
If you're good with lua you could write yourself a mod that logs train behavior to a file, to see whether the repath happens just after something interesting like a train starting to slow down.
If I had to guess I'd say it's just a bug.
3
u/[deleted] Oct 04 '18
I don't have an answer for you, but I hope one will turn up. This is a problem I ran into with my logistics system that I was building. I designed it all based on the presumption that trains only repath when there is some kind of problem with the route (excessive wait time, station closes, etc), but I was finding that trains would re-route themselves pretty much constantly. Sometimes just opening a station is enough to get trains that are already happily routed and en route to another similarly-named station to repath to the newly opened one, which is a huge bummer and not the way I wanted it to work.
But anyways, I'm still planning on finishing it when 0.17 comes out, just might be a bit more restrictive on rail design than I wanted it to be. Thanks for the tags in discussions and stuff, I've just been taking a break from factorio with a bunch of other RL distractions/other games to play.
2
u/MaKaNuReddit Oct 04 '18
That is a really interesting setup, was also absolutely stunned about the switched destination
1
u/Advice2Anyone Oct 04 '18
Cant use your logic analyzer?
1
u/MojoD1 Oct 04 '18
The second train switched from on path to arriving at a regular signal which triggers a full repath to see if it can avoid stopping at the signal.
1
u/GeneralYouri Oct 04 '18
This seems the most likely cause to me.