Need help with trains deadlocking

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
One33Seven
Burner Inserter
Burner Inserter
Posts: 14
Joined: Sat Jun 27, 2015 9:05 pm
Contact:

Need help with trains deadlocking

Post by One33Seven »

So I have this problem that every one in a while a train will deadlock with itself on a roundabout. The train will try to go around all the way making a 450 degree turn and deadlocking with it's own tail.

I'm not sure if this is a bug or whether I'm doing something wrong, but this is the theory I have.

Every station has a decider which will disable the station when there's a train present, this will cause other trains to reroute. I'm thinking this happens when a train is to forced to reroute while it's on a roundabout.

Any idea's why this is happening and what I can do about it?
Attachments
Design of intersection
Design of intersection
deadlock3.png (202.78 KiB) Viewed 5229 times
Schedule of train
Schedule of train
deadlock2.png (383.18 KiB) Viewed 5229 times
The train in the read square is deadlocked with itseld.
The train in the read square is deadlocked with itseld.
DEADLOCK1.png (246.38 KiB) Viewed 5229 times

BlakeMW
Filter Inserter
Filter Inserter
Posts: 950
Joined: Thu Jan 21, 2016 9:29 am
Contact:

Re: Need help with trains deadlocking

Post by BlakeMW »

This can't be (entirely) avoided when using trains which are longer than the loop. The solution is to not use roundabounts for junctions and to make sure all loops which do exist are longer than the longest train.

mrvn
Smart Inserter
Smart Inserter
Posts: 5696
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Need help with trains deadlocking

Post by mrvn »

The deadlock also happens with short trains since the chain signals will reserve the whole path no matter the length of the train.

I've run into the same problem and only found one solution: remove the chain signals inside the roundabout. The whole thing is then one block and the train won't block itself. Problem though with long trains since it will happily drive into itself.

What I don't get is why the train doesn't reroute after it's blocked by itself for a while (or why it picks that route in the first place). It should pick a different route where it doesn't cross it's own path. Also I watched the trains and sometimes it happily drives around the turnabout, crossing it's own path, and sometimes it deadlocks.

Note: changing the roundabout to a full 4 way crossing solves the problem too since then the train can go any way without crossing itself.

One33Seven
Burner Inserter
Burner Inserter
Posts: 14
Joined: Sat Jun 27, 2015 9:05 pm
Contact:

Re: Need help with trains deadlocking

Post by One33Seven »

Personally I'm leaning towards unwanted behavior, a use-case which hasn't been caught and handled. When rerouting the pathfinder should check whether the train is colliding with itself. I'm gonna file a bugeport, see what the devs have to say.

mrvn
Smart Inserter
Smart Inserter
Posts: 5696
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Need help with trains deadlocking

Post by mrvn »

One33Seven wrote:Personally I'm leaning towards unwanted behavior, a use-case which hasn't been caught and handled. When rerouting the pathfinder should check whether the train is colliding with itself. I'm gonna file a bugeport, see what the devs have to say.
Especially when there are other paths it could take that do not block.

Engimage
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Wed Jun 29, 2016 10:02 am
Contact:

Re: Need help with trains deadlocking

Post by Engimage »

This is not a bug and it is a common problem discussed for decades. Train deadlocks if it is forced to recalculate its path while being inside the loop.
This can not be easily avoided without disrupting throughput of the roundabout. This can also happen within 3-way roundabout intersection.
Best solution so far is using non-roundabout intersections where you can or you have to deal with deadlocks from time to time
Another hint would be using 2-headed trains and avoiding forming any kinds of loops on you rail system other than those inside roundabouts as well as keeping intersections spread out and avoiding putting ones close to each other at all times. This will decrease probability of deadlocks but will not guarantee deadlock free life.

Yes roundabout is easily designed and is a compact solution but deadlocks will be there deal with it.

mrvn
Smart Inserter
Smart Inserter
Posts: 5696
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Need help with trains deadlocking

Post by mrvn »

PacifyerGrey wrote:This is not a bug and it is a common problem discussed for decades. Train deadlocks if it is forced to recalculate its path while being inside the loop.
This can not be easily avoided without disrupting throughput of the roundabout. This can also happen within 3-way roundabout intersection.
Best solution so far is using non-roundabout intersections where you can or you have to deal with deadlocks from time to time
Another hint would be using 2-headed trains and avoiding forming any kinds of loops on you rail system other than those inside roundabouts as well as keeping intersections spread out and avoiding putting ones close to each other at all times. This will decrease probability of deadlocks but will not guarantee deadlock free life.

Yes roundabout is easily designed and is a compact solution but deadlocks will be there deal with it.
How is it not a bug when there are alternate paths with no red signal?
How is it not a bug if it only happens when recomputing the path while the train is inside the roundabout?

Engimage
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Wed Jun 29, 2016 10:02 am
Contact:

Re: Need help with trains deadlocking

Post by Engimage »

mrvn wrote:
PacifyerGrey wrote:This is not a bug and it is a common problem discussed for decades. Train deadlocks if it is forced to recalculate its path while being inside the loop.
This can not be easily avoided without disrupting throughput of the roundabout. This can also happen within 3-way roundabout intersection.
Best solution so far is using non-roundabout intersections where you can or you have to deal with deadlocks from time to time
Another hint would be using 2-headed trains and avoiding forming any kinds of loops on you rail system other than those inside roundabouts as well as keeping intersections spread out and avoiding putting ones close to each other at all times. This will decrease probability of deadlocks but will not guarantee deadlock free life.

Yes roundabout is easily designed and is a compact solution but deadlocks will be there deal with it.
How is it not a bug when there are alternate paths with no red signal?
How is it not a bug if it only happens when recomputing the path while the train is inside the roundabout?
Simple. Red signal does not prevent pathfinder from taking the route. If it would be so then most of trains would stand still with no path at all. Red signal only adds some penalty for a given path making it slightly less desirable
Path recalculation are much rarer since 0.15 but they still happen if you add or remove tracks within blocks that train is patching through. Also repath happens if you mess with stations and if a train is standing for long time on a chain signal. The later can happen if you have dense traffic around your roundabout
I have to admit this behavior bugs me as well so I am not protecting it.

mrvn
Smart Inserter
Smart Inserter
Posts: 5696
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Need help with trains deadlocking

Post by mrvn »

Imho the more important question is: With short trains why does it normally successfully drive a 270° turn, crossing it's own path, around the roundabout but when a repath happens why does it suddenly notice it blocks itself? And how does the same not lead long trains into crashing into them self?

Engimage
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Wed Jun 29, 2016 10:02 am
Contact:

Re: Need help with trains deadlocking

Post by Engimage »

mrvn wrote:Imho the more important question is: With short trains why does it normally successfully drive a 270° turn, crossing it's own path, around the roundabout but when a repath happens why does it suddenly notice it blocks itself? And how does the same not lead long trains into crashing into them self?
This depends on whether there are chain signals inside the roundabout or not and how many.
If there are no chain signals inside no deadlock will happen and all trains shorter than the loop will be able to make 270 turn no problem. Longer train WILL crash into itself.
In case if chain signals are inside they will prevent trains from crashing into themselves and will cause deadlocks as most of trains won't be able to make 270 turn

One33Seven
Burner Inserter
Burner Inserter
Posts: 14
Joined: Sat Jun 27, 2015 9:05 pm
Contact:

Re: Need help with trains deadlocking

Post by One33Seven »

/edit:

Sorry, have another topic running on a similar but very different issue and got confused, wrong topic... :(
Last edited by One33Seven on Tue Jun 27, 2017 4:13 pm, edited 1 time in total.

mrvn
Smart Inserter
Smart Inserter
Posts: 5696
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Need help with trains deadlocking

Post by mrvn »

One33Seven wrote:Anyway back onto the subject.

I did some testing, leaving the game running and trying to judge the throughput.

I split the exits in two, 8 stations going north and 7 stations going south. As I suspected this shifted the stress onto the two roundabouts north and south from the stations. This finally confirms my original thoughts that this is systemic and I need to design something else. Next weekend I'm going to put some time and thought into designing some kind of bufferzone.
You need a way to turn the 270° turn into a direct 90° turn.

mrvn
Smart Inserter
Smart Inserter
Posts: 5696
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Need help with trains deadlocking

Post by mrvn »

PacifyerGrey wrote:
mrvn wrote:Imho the more important question is: With short trains why does it normally successfully drive a 270° turn, crossing it's own path, around the roundabout but when a repath happens why does it suddenly notice it blocks itself? And how does the same not lead long trains into crashing into them self?
This depends on whether there are chain signals inside the roundabout or not and how many.
If there are no chain signals inside no deadlock will happen and all trains shorter than the loop will be able to make 270 turn no problem. Longer train WILL crash into itself.
In case if chain signals are inside they will prevent trains from crashing into themselves and will cause deadlocks as most of trains won't be able to make 270 turn
I tried it with the chain signals as in the original screenshot and with more chain signals in a slightly more complex roundbout. As soon as there are chain signals inside the roundabout deadlocks can happen.

Obviously if there are no chain signals then the train reserves the whole roundabout and can always drive out of it (or into itself). But I fail to see how the behaviour comes along with chain signals. Writing about it maybe the bug is not when it repaths but when it doesn't.

Here is how I figure it:

1) The train picks a path that does a 270° turn and all signals are green. It start driving.
2) It approaches the roundabout and the break distance hits the first chain signal.
3) All the chain signals along the path up to the next signal are reserved (yellow).

Here is where I think there is a problem: When the first chain signals gets reserved the one before that in the roundabout should become red. So when the train tries to reserve that signal for its exit path it should fail, it's already red. The train should never be able to enter the roundabout for a 270° turn.

Then one of two things happens:
4) the train enters the roundabout, does a 270 turn and leaves. (exit here)

or

4) the train enters the roundabout but half way through a repath happens
5) the train picks the same path
6) the 270° chain signal is now red because the train is on the block crossing that one
7) the train stops at the next chain signal and deadlocks

One33Seven
Burner Inserter
Burner Inserter
Posts: 14
Joined: Sat Jun 27, 2015 9:05 pm
Contact:

Re: Need help with trains deadlocking

Post by One33Seven »

mrvn wrote:
One33Seven wrote:You need a way to turn the 270° turn into a direct 90° turn.
Sorry mate, was looking at the wrong topic. Have another topic running on a similar issue but it's about throughput.

aaargha
Filter Inserter
Filter Inserter
Posts: 330
Joined: Wed Dec 07, 2016 8:35 am
Contact:

Re: Need help with trains deadlocking

Post by aaargha »

This problem has been around for a while and is a known issue, though I'm not sure if a fix is being worked on.

I think what makes the train stop when changing path (even if it ends up being the same) is that it needs to re-reserve its blocks. You can see this in that its possible to stop any train, regardless of speed and length as far as I can tell, instantly by turning turning a sufficiently long chain of rail signals red via the circuit network.

The only reliably way around this problem is by using another intersection. Any intersection with a C or better rating should not have this kind of issues.

mrvn
Smart Inserter
Smart Inserter
Posts: 5696
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Need help with trains deadlocking

Post by mrvn »

aaargha wrote:This problem has been around for a while and is a known issue, though I'm not sure if a fix is being worked on.

I think what makes the train stop when changing path (even if it ends up being the same) is that it needs to re-reserve its blocks. You can see this in that its possible to stop any train, regardless of speed and length as far as I can tell, instantly by turning turning a sufficiently long chain of rail signals red via the circuit network.

The only reliably way around this problem is by using another intersection. Any intersection with a C or better rating should not have this kind of issues.
But it also needs to reserve the blocks when driving through without stop. There must be something in the way it reserves block that checks if the path intersects itself, if the train is short enough to not hit itself and then allows it. But when repathing the same check does not work. I guess that since the train is already past the point where it intersects it does not notice it intersects itself and assumes the block is taken by some other train. Or the block is now red instead of yellow and the self crossing check fails. Then it waits for the block to clear, which never happens.

Maybe I can make a test world tonight triggering the different behaviours on command and the devs can weigh in and explain what the code actually does.

aaargha
Filter Inserter
Filter Inserter
Posts: 330
Joined: Wed Dec 07, 2016 8:35 am
Contact:

Re: Need help with trains deadlocking

Post by aaargha »

mrvn wrote:But it also needs to reserve the blocks when driving through without stop. There must be something in the way it reserves block that checks if the path intersects itself, if the train is short enough to not hit itself and then allows it. But when repathing the same check does not work. I guess that since the train is already past the point where it intersects it does not notice it intersects itself and assumes the block is taken by some other train. Or the block is now red instead of yellow and the self crossing check fails. Then it waits for the block to clear, which never happens.
Do long trains actually not crash into themselves on a chain signalled loop if they've reserved the whole path beforehand? I've not tested it but I wouldn't be surprised if they did.
mrvn wrote:Maybe I can make a test world tonight triggering the different behaviours on command and the devs can weigh in and explain what the code actually does.
If you don't want to build the path changing part you can take a look at the "Deadlockomatic" from my test save (see signature), it's what I've used to create the path changing deadlock examples in the testing thread.

mrvn
Smart Inserter
Smart Inserter
Posts: 5696
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Need help with trains deadlocking

Post by mrvn »

aaargha wrote:Do long trains actually not crash into themselves on a chain signalled loop if they've reserved the whole path beforehand? I've not tested it but I wouldn't be surprised if they did.
I assumed so because the original poster used long trains. But something to include in the tests.

aaargha
Filter Inserter
Filter Inserter
Posts: 330
Joined: Wed Dec 07, 2016 8:35 am
Contact:

Re: Need help with trains deadlocking

Post by aaargha »

Man, this game does not like rail loops. At least it usually, but not not always, avoids those kinds of paths.
regular.png
regular.png (219.96 KiB) Viewed 5060 times

mrvn
Smart Inserter
Smart Inserter
Posts: 5696
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Need help with trains deadlocking

Post by mrvn »

Actually I just tried having a short loop with chain signals and a longer loop and even with a long train it would still choose the short loop and crash into itself. The path finder sees the short loop as shorter (well it is) so it picks it. Now the bad thing is that it sticks to that choice even when the short path has a deadlock. You can see this in the traincrash2 savegame. Everything works fine till you remove the locomotive without fuel. Then the train crashes.

In traincrash I've build a simpler test case though for crashing and repathing in a loop. Load the save game and set the train to automatic. It will crash into itself. Then remove the last car and set it to automatic and it will go to station A. Next it will go to station B. But B will get disabled while the train is inside the loop and then it deadlocks.

I imagine that when planing a path and reserving the chain signals the code checks all chain signals on the path till it hits a signal. If the chain signals are all blue or green and the signal is green too then it reserves all the blocks. It does not notice that a block gets reserved twice. An since all blocks are then reserved to the train it will happily cross its own path. When repath happens inside the loop some chain signals are red due to the train standing on some blocks it needs to cross. So it can't reserve the path again.

Fixing this might not be trivial. If you simply prevent blocks from getting reserved twice then no loop with chain signals will ever work, even for short trains. On the other hand no deadlocks. A proper fix should include the length of the train though and allow blocks from getting reserved twice IF the train is short enough to clear the first block before entering the second.
Attachments
traincrash2.zip
(3.71 MiB) Downloaded 64 times
traincrash.zip
(3.53 MiB) Downloaded 63 times

Post Reply

Return to “Gameplay Help”