Page 1 of 3

Train Roundabouts

Posted: Thu Apr 13, 2017 9:57 am
by apoptosis
Hello All!

I've been using trains in Factorio for some time now and have had not problems yet. In a new game I designed the network with double-headed trains with 4 wagons. In the past I have either used a 1-2 or 1-4 design. For a higher throughput for my bot-base I now use six wagons.

In previous games I have been using roundabouts extensively. They worked quite well for me and I have not had a single problem in the past. In this game I have no seen a strange occurence:

A train is coming from the right (blue arrow) into the roundabout and is supposed to leave the roundabout at the bottom exit (red arrow). Instead the train stays in the roundabout and gets stuck because it's too long to fit completely. The bottom track is straight for some time with normal signals spaced evenly. So I do not think that a problem lies there. There are 4 rail chain signals: top, bottom, left and right. The one to the top is hidden by the train.

99.99% of the times the design works, just once every few hours a train gets stuck. Does anybody know why or has a solution? Preferably without changing the design too much if possible.

Thanks!

Re: Train Roundabouts

Posted: Thu Apr 13, 2017 11:04 am
by SyncViews
Sometimes a train will change its path (e.g. to take a different route, or because a player changed its order) while already on the roundabout causing it to try and go all the way round, at which point if its long enough it can jam any roundabout.

Personally I just avoid roundabouts, normally in favor of a simple merge intersection (normally all trains will be heading in some common direction, e.g. to or from the main base), or a t-junction or such if there are multiple routes at play. Because a complete loop on such a junction is not possible, your situation cant happen, worse case it will pick some other path so it can turn around safely, but its fairly rare and you can make sure long track stretches have a safe u-turn point.

Re: Train Roundabouts

Posted: Thu Apr 13, 2017 12:00 pm
by Aeternus
Most likely cause: The path from the blue arrow to the train's ultimate destination is occupied while the train entered the roundabout. It wants to go around, probably by exiting to the left.

Simple solution: Eliminate the chain signals inside the roundabout loop, and ensure a train is no larger then 9 units total (so it can't complete the circle and rearend itself)
Drawback: Trains cannot cross in opposite direction to eachother anymore, the entire roundabout is blocked if any one train is on it, so throughput is limited.

Less simple solution:
Image
This intersection was proposed by Impetus Maximus. You can add loops at the edges of the "cross" to allow trains to reverse direction.

Re: Train Roundabouts

Posted: Thu Apr 13, 2017 1:09 pm
by apoptosis
Thanks for the replys.

Maybe it is the recalculation of the path while they are in the loop. The exit itself should not become blocked while the train is in the roundabout as no other train can enter the exit.

Unfortunately eliminating the chain signals is not an option as the main advantage of the design is that more than one train can enter the roundabout as long as their paths do not cross. I will probably try to enlarge the roundabout by a bit so that a 2-6 train can circle.

Re: Train Roundabouts

Posted: Thu Apr 13, 2017 1:15 pm
by Engimage
This is a well known problem with roundabouts.
As already said this one occurs if a train is forced to recalculate path while being inside the roundabout.
Currently this happens because trains do recalculate a path when you do any operation with rails even if it is in other part of the map and in unrelated rail network. This behaviour will be changed in 0.15 so this will happen much less often. However the problem will still persist unless devs will change train pathfinding algorithm which would prevent a path through blocks that are currently occupied by the same train or something more complex and smart.

Re: Train Roundabouts

Posted: Thu Apr 13, 2017 1:28 pm
by Miravlix
A roundabout is a type of circular intersection or junction in which road traffic flows almost continuously in one direction around a central island.

So-called "modern" roundabouts require entering traffic to give way to traffic already in the circle and


You didn't make a roundabout, you made a small circle intersection design that is very flawed.

It's too small so train blocks on it's own tail.

It blocks other traffic from merging into the circle, because it is too small and because of how it's signaled.

It needs to be 10 times the size and it needs some magic, I'm not sure can be done in circuitry, for the concept of a roundabout to be theoretically achievable.


To make the small circle 4 way intersection somewhat work, you need trains smaller than signal blocks and need at least 3 signals in the circle, so the train can't block on it's own tail and have it surrounded by chain signals so only one train can enter at once.


BTW: It uses 4 exists, but that only work in the real world, avoid at all cost intersection in factorio with more than 3 exits.

Re: Train Roundabouts

Posted: Thu Apr 13, 2017 5:16 pm
by aaargha
As others have said, the pathfinder causes issues with some intersections, roundabouts in particular. If you are planning to replace intersections in spots where the pathfinder is causing issues I'd recommend not using another intersection that suffers from similar problems.
lock.png
lock.png (1.1 MiB) Viewed 32755 times
Granted, it does not get quite as bad as the roundabout with deadlocks. The trains can still change paths to straight ahead once/if that path clears up.
A better alternative would be something like:
compact 4-way.png
compact 4-way.png (1.36 MiB) Viewed 32755 times
It uses a bit more signals than strictly necessary (need that .1% additional throughput) but it does not suffer from pathfinder induced deadlocks.
Miravlix wrote:To make the small circle 4 way intersection somewhat work, you need trains smaller than signal blocks and need at least 3 signals in the circle, so the train can't block on it's own tail and have it surrounded by chain signals so only one train can enter at once.
I'm not sure what you mean by "somewhat work" but that does not sound deadlock safe to me at least, so if that's what you mean I'll gladly test it if you provide me with a picture or a blueprint string of this setup.
Miravlix wrote:BTW: It uses 4 exists, but that only work in the real world, avoid at all cost intersection in factorio with more than 3 exits.
I don't know what sources/test you base this on, but that sure sounds like superstition/misinformation.

Re: Train Roundabouts

Posted: Fri Apr 14, 2017 11:47 am
by aober93
This happens on my early game inline train station that are in the form of a stretched 0. When i overuse it and send more trains at it, it will deadlock. Because its a tiny circle it cannot handle long trains or 2 shorter trains or whatever. Then its time to extend my build to use stacker stations and longer deceleration rails. Bypass rails as well as inevitable crossings. If this all comes together i dont get deadlocks.

Factorio doesnt have space limitations, so theres no problem going big.

Re: Train Roundabouts

Posted: Fri Apr 14, 2017 12:10 pm
by steinio
I keep it like UPS at crossings: never turn left.
My trains can only turn right and 3 times right is one time left.

But you probably need a city block like layout.

Greetings steinio

Re: Train Roundabouts

Posted: Wed Apr 19, 2017 1:40 pm
by Deadly-Bagel
There is massive discussion on intersections and it's pretty clear there's no right answer. If reliability is your priority then you cannot go wrong with a 3 way intersection, I would recommend them for nearly every game as regardless of signals they're almost impossible to jam (a very short U turn on one of the exits and trains to fill it is the only way). The downside is in heavy rail networks they can increase load on small sections of rails which can cause minor delays but if you're going for that sort of game then you need to know exactly what you're doing.

Re: Train Roundabouts

Posted: Wed Apr 19, 2017 11:50 pm
by Aeternus
A threeway roundabout could still jam like above... if a train wanted to go straight but changes path to the close exit as it has already passed it, would force the train to loop around and jam itself. For this to happen though, you'd need a mesh type network, where the same station (or stations with the same name) can be reached by different exits of an intersection. If you use a star-type network (each station only reachable via 1 path from any other station in the network) then this problem would never occur - but that kind of pathing tends to create traffic jams near the center of the star.

For reliability, block the entire intersection when a train is on it, until the train exits it. This means no signals on the inside of the loop, or a direct cross type intersection as posted by aaargha earlier.

Re: Train Roundabouts

Posted: Thu Apr 20, 2017 6:29 am
by impetus maximus
aaargha wrote:As others have said, the pathfinder causes issues with some intersections, roundabouts in particular. If you are planning to replace intersections in spots where the pathfinder is causing issues I'd recommend not using another intersection that suffers from similar problems.
lock.png
Granted, it does not get quite as bad as the roundabout with deadlocks. The trains can still change paths to straight ahead once/if that path clears up.
can you post a save showing my intersection causing a dead lock?

Re: Train Roundabouts

Posted: Thu Apr 20, 2017 8:37 am
by Deadly-Bagel
Aeternus wrote:A threeway roundabout could still jam like above...
I mean just a regular T junction, not a roundabout.

Re: Train Roundabouts

Posted: Thu Apr 20, 2017 8:39 am
by aaargha
impetus maximus wrote:can you post a save showing my intersection causing a dead lock?
Unfortunately that save contains way too many leftovers from "commission"/collaboration work I've done that are simply not mine to share. I'm also not really sure what more it would provide that is not already visible in the picture already posted.

However, if anything is unclear or there is something you'd like to know about my test setup, feel free to ask.

Re: Train Roundabouts

Posted: Thu Apr 20, 2017 8:54 am
by aaargha
Deadly-Bagel wrote:I mean just a regular T junction, not a roundabout.
As long as they're properly spaced you're fine, otherwise you may end up with stuff like:
2x_3-way_lock.png
2x_3-way_lock.png (797.11 KiB) Viewed 32514 times

Re: Train Roundabouts

Posted: Thu Apr 20, 2017 8:59 am
by Deadly-Bagel
Okay make that two ways to deadlock it but it's still circumstantial. Signalled correctly this will not happen.

Re: Train Roundabouts

Posted: Thu Apr 20, 2017 9:16 am
by aaargha
Deadly-Bagel wrote:Signalled correctly this will not happen.
True, just be aware that the only signalling, at least as far a I know, that will avoid this deadlock is the "entire intersection is one block" style which kills throughput. Proper spacing is a much better alternative, assuming there is room for it.

Re: Train Roundabouts

Posted: Thu Apr 20, 2017 9:42 am
by Deadly-Bagel
The use of chain signals technically does not make the whole intersection one block but I assume that's what you mean to do. Braking distances for large trains are very long, the throughput you would lose is inconsequential. Trains can't really follow each other that closely, I think it's reasonable to say a distance between trains equal to the length of the train is acceptable. If you need more than half your rails filled with trains going top speed (seriously, going for one rocket per second or something?) then it's time to consider more rails, either more routes or four lanes.

Re: Train Roundabouts

Posted: Thu Apr 20, 2017 10:36 am
by SyncViews
aaargha wrote:
Deadly-Bagel wrote:Signalled correctly this will not happen.
True, just be aware that the only signalling, at least as far a I know, that will avoid this deadlock is the "entire intersection is one block" style which kills throughput. Proper spacing is a much better alternative, assuming there is room for it.
A lot of it comes down to planning for the busy routes. Correct signals fix jams but still have terrible throughput if its the wrong layout, and just "adding lines" can result in a mess with still lots of delays.

e.g. if the 2 trains you show stuck are busy routes, the crossing right turns and block each other and also block the opposite left turn so will cause heavy traffic. More spacing wont really help because you still merge in between. Worse because of slow stopping/acceleration, once you have trains start stopping frequently a junction slows to a crawl, (and the path finder doesn't like immediately switching to a free route when already stopped on a red chain signal causing occasional problems for multiple line solutions).

But simply swapping the north/south lines solves that scenario it because those busy routes wont cross.

Re: Train Roundabouts

Posted: Thu Apr 20, 2017 11:56 am
by aaargha
Here is how the intersection is signalled in the deadlock shown above:
locked_signalling.png
locked_signalling.png (1.05 MiB) Viewed 32484 times
Here is the "safe" way to signal it:
safe_signalling.png
safe_signalling.png (1.04 MiB) Viewed 32484 times
Note that trains may still get stuck in the intersection but as long as the output block eventually clears the train will be able to move on. The entire intersection will likely be blocked in the meanwhile though, but by itself it should not deadlock.

As for the throughput reduction: Tests using 24 2-4 trains going in various directions and patterns puts the unsafe signalling at about 24 trains/min over a 15 min run. The safe signalling manages 15 trains/min over 15 min. So about a 37.5% reduction?