How-to: Two-way rails

Smart setups of railway stations, intelligent routing, solutions to complex train-routing problems.
Please provide - only if it makes sense of course - a blueprint of your creation.
aaargha
Filter Inserter
Filter Inserter
Posts: 333
Joined: Wed Dec 07, 2016 8:35 am
Contact:

How-to: Two-way rails

Post by aaargha »

Preface
This guide aims to explain how to set up simple and reliable two-way rail systems, how to signal/schedule them to avoid deadlocks and some techniques to address throughput issues.

Hopefully this will cover the most common pitfalls but if I've missed something, or if something is unclear, please let me know and I'll try to include/fix that.
Step 0: But why?
The main motivation for using two-way rails is that they're cheap and super easy to build, especially before bots and blueprints. Compared to one-way dual-track systems you'll save about 50% on the rails an probably at least 75% on signals, not much in the grand scheme of things but noticeable during the initial setup.

The main drawback is, of course, throughput. A pretty basic one-way dual track system will likely support at least 10x the throughput of a two-way system, a well designed one will support even more. That said, a two-way rail system will get you really far, by the time you may start to need to upgrade to a serious dual-lane system you'll probably have a small army of construction bots at your disposal to do the upgrade anyway.
Step 1: Forget rail signals exist
As automatic trains can only pass signals if they're on their right, a two-way stretch of track needs either opposing signals or no signals. The example below shows two different two-way tracks.
Image
If signals are only placed on one side the track becomes one-way. If signals are placed on both sides but not opposite to each other the track becomes a "no-way" track: it can't be used by automatic trains but still traversed manually.

Now that we have two-way track it's time to cover a simple signalling rule* that will remove almost all risk of deadlocks: The only signals you are allowed to place on two-way tracks are chain signals. Or in other words: Rail signals may only be placed on one-way track. The reason for these rules is to avoid deadlocks like this:
Image
We also don't need rail signals at all to build basic systems, chain signals can cover all our needs, which is super amazing as we can skip one assembler. Chain signals even work fine for train stops:
Image
This is actually all we need to make a really basic, but reliable, train system, so let's do that.
Example: The worst reliable system ever
The worst system
TADAAA!

That's basically it, just connect these station pieces to each other with track and you're done, no more signals needed. The only thing you have to be careful of is that you don't have more trains on a route than you have train stops: If you have a route between two train stops you can only have one train on that route. If you try to use two trains they would both be stuck at the stations waiting for the other to move.

The throughput will be absolutely abysmal, only one train can actually travel at a time as everything but the stations is the same block. The example shown can fit 3-car trains.

While this system is not really that useful we can use it as a base to build on.
Step 2: Partitioning
The simplest way to increase the throughput of our system is to use chain signals to partition it into different pieces. As we use chain signals we still avoid the earlier mentioned deadlocks but we can now allow trains that don't use the same pieces of track to run simultaneously.

The effectiveness of this varies heavily depending on how you've organized your train system, usually we're looking at at least 2x over all performance increase. Let's see how this could look in a system.
Example: A more reasonable train system
By applying partitioning to 3- and 4-way intersections and splits/merges we get a system that can look like so:
The more reasonable system
If you have a large knot of rails that you're not really sure how to signal just liberally apply paired chain signals until you feel satisfied. If you apply too many it won't hurt (within reason, if you cover all your rails in signals you might start to get some lag), if you miss some you'll only suffer a bit reduced performance.

The same scheduling restrictions as for the last system still apply, more stations than trains, which is kind of a bummer.

While this system is probably enough to pretty comfortably launch a rocket it does not really allow flexible scheduling, care to guess what we'll look at next? :)
Step 3: More trains and flexibility
To increase the number of trains we can have on each route we need to add additional spaces where trains can park while not at a train stop, aka stackers or waiting bays. While it is possible to implement two-way stackers it requires a more signals, can cause deadlocks if done incorrectly, and has basically no gain. What we'll do instead is to use "regular" one-way stackers, that way we can ensure that there is always a path from -and to- each station.

You're now going to have to remember that rail signals exist as we'll need them to construct our stackers. The idea is to place a single rail signal at the start of each waiting bay, everything else is still chain signal only. As the stackers will be one-way we can use rail signals without worrying, we have to make sure that there is a separate path to and from each station.

Example: Stations with stackers
The stations below each station has room for 3 trains, one at the station, one waiting to leave the station, and one waiting to enter the station. This means that for a path between two stations we can now run 5 trains instead of only one as we have 6 places trains can be instead of two. Also note that we also only use two rail signals per station, one for each extra waiting bay. The small arrows highlight the rail signals while the big arrows indicate direction of travel.
Stacker stations
Building larger stackers for stations is probably not worth it until you move on to dual-lane systems, the throughput available on a two-way line is unlikely to support that kind of configuration. That brings us to our last concern: How do we increase the throughput of our system?
Step 4: More throughput
While there are techniques that can increase the throughput of two-way rails we will not look at them in this guide, they are an excellent source of deadlocks if implemented incorrectly. The more reasonable approach to increasing throughput on our system is to make busy parts of it dual-lane one-way track. Note that only small pieces of the system needs to be made dual-lane to greatly increase throughput.

The main limit on throughput is that only one train can use a particular path at one time, if a train from a far-away outpost wants to travel to the main base it will block all traffic to/from the main base for the entire journey there. The way to get around these kinds of long waits is to add some splits where trains can wait and meet while en-route.
Wait split
Just placing a few of these on busy parts of the system and close to intersections can greatly increase the throughput of the system.

There may still be parts where there is too much traffic to handle, usually close to the main base, those parts will simply have to be made dual-track.
Dual-track connector
When connecting two-way systems to one-way dual-track systems you should make sure that an entire train can fit between the connector and any kind of intersection/crossing on the dual-track system. We do this to ensure that no train gets stuck with its butt in the two-way part and so that it does not block an intersection while getting to the connector.

Further throughput improvements will be on the one-way dual-track system which is outside the scope of this guide, you'll have to look elsewhere for that.
Step "GOD DAMN IT!": Common pitfalls
Part of tracks are accidentally made one-way due to missing/stray signals.
Image
Part of tracks are accidentally made "no-way" due to misaligned signals.
Image
If it's still not working you may want to take a look at this good guide for general train troubleshooting.
Notes
That is pretty much it, if anything is unclear/can be improved please leave a reply and I'll try to explain/improve this guide.

Some good resources on trains
Train automation tutorial. It may look a bit old but it is, in my opinion, one of the best tutorials on trains out there.
All things deadlock is a great resource for in-depth information on different kinds of deadlocks.

Tools used to make this post
Text plates for text and arrows.
Screenshot camera for taking screenshots.
Creative Mode for ease of build.

Thank you for reading and have a great day!

*There are exceptions to this but, if you know how to safely apply them I doubt this guide will cover anything you don't already know.

Trudel
Burner Inserter
Burner Inserter
Posts: 13
Joined: Tue Oct 17, 2017 2:30 pm
Contact:

Re: How-to: Two-way rails

Post by Trudel »

Great guide, thank you! :-)
My wife says I only have to faults: I don't listen and something else.

User avatar
5thHorseman
Smart Inserter
Smart Inserter
Posts: 1193
Joined: Fri Jun 10, 2016 11:21 pm
Contact:

Re: How-to: Two-way rails

Post by 5thHorseman »

First off, this is a nice resource and if I ever try one-way tracks again, I'll surely use it.

However, I still think the best way to use 2-way tracks is for your very first rail line, before building your actual 1-way rail line. And then never, ever use them again. :)

quyxkh
Smart Inserter
Smart Inserter
Posts: 1031
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: How-to: Two-way rails

Post by quyxkh »

Thanks for this, this makes extending the rail network to get that one out-of-the-way patch just _so_ much nicer, I hadn't done the work to figure out how to do this right, let alone make it this clear.

Frightning
Filter Inserter
Filter Inserter
Posts: 810
Joined: Fri Apr 29, 2016 5:27 pm
Contact:

Re: How-to: Two-way rails

Post by Frightning »

I've actually taken to using a mix of 1-way and 2-way rail in my systems, though I stick to 1-way trains because they perform better (1-1-0 trains have full speed, you would need 6-1-6 to achieve the same with 2-way trains; note even 1-2-0 trains have full forward speed, in fact the mathematically perfect ratio is 6-13-0). The result is that I have some pretty funky rail setups sometimes, but I've never really had issues signalling them correctly. As long as you understand how signals create blocks and under what conditions trains are allowed past a signal, it's pretty easy to figure out on the fly.

Koub
Global Moderator
Global Moderator
Posts: 7614
Joined: Fri May 30, 2014 8:54 am
Contact:

Re: How-to: Two-way rails

Post by Koub »

I guessed who wrote this post without even looking at its author :)
[Koub] Topic stickied, because excellent how-to ressource.
Koub - Please consider English is not my native language.

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

Re: How-to: Two-way rails

Post by aaargha »

5thHorseman wrote:First off, this is a nice resource and if I ever try one-way tracks again, I'll surely use it.

However, I still think the best way to use 2-way tracks is for your very first rail line, before building your actual 1-way rail line. And then never, ever use them again. :)
Hehe, that is pretty much how I usually use them, for my current world though I'm actually trying to run mostly two-way rails and it's kind of liberating to just snake the rails around trees/water/whatever without having to worry about fitting the second rail. I'll likely regret the mess later, but for now it's nice :)
Frightning wrote:I've actually taken to using a mix of 1-way and 2-way rail in my systems, though I stick to 1-way trains because they perform better (1-1-0 trains have full speed, you would need 6-1-6 to achieve the same with 2-way trains; note even 1-2-0 trains have full forward speed, in fact the mathematically perfect ratio is 6-13-0). The result is that I have some pretty funky rail setups sometimes, but I've never really had issues signalling them correctly. As long as you understand how signals create blocks and under what conditions trains are allowed past a signal, it's pretty easy to figure out on the fly.
I'm also partial to one-way trains, while they can be a bit troublesome at times, I really don't like lugging around the extra locomotives, then there is also the fact that RoRo stations can handle more trains that terminus.
Koub wrote:I guessed who wrote this post without even looking at its author :)
[Koub] Topic stickied, because excellent how-to ressource.
Flattery will get you nowhere..... who am I kidding? Thank you :D

dinodod
Long Handed Inserter
Long Handed Inserter
Posts: 84
Joined: Tue Mar 10, 2015 10:42 pm
Contact:

Re: How-to: Two-way rails

Post by dinodod »

You want to show me an example on how you use these rails cause I have a lot of issues with your claim.

1) Which is super amazing as we can skip one assembler. 1 assembler and you're amazed?
2) Saves on signals??? At the very least you still need 2 signals. If adding multilanes, you now have to use 2x as many signals since every rail must be DUAL signaled.
3) Liberally apply paired chain signals until you feel satisfied <-- CHAIN Signals eh? Clearly you haven't tested this idea at all
4) In order for trains to pass each other, you need either a stacker system or multilane solution. Well, a stacker system would need to be used in a lot of places to avoid long queue times when a train has to wait for another to clear the path. And if you use multilanes, then where are you saving anything at all???

In the most simplistic usage, trains would have to wait a VERY long time to deliver resources on a 1 rail solution as the rail would only support 1 train at a time. This is just not a feasible solution at all. I could drive a car faster than wait on trains.

I would love to see how your solution works as I can not even begin to understand it.

ratchetfreak
Filter Inserter
Filter Inserter
Posts: 952
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: How-to: Two-way rails

Post by ratchetfreak »

dinodod wrote:You want to show me an example on how you use these rails cause I have a lot of issues with your claim.

1) Which is super amazing as we can skip one assembler. 1 assembler and you're amazed?
2) Saves on signals??? At the very least you still need 2 signals. If adding multilanes, you now have to use 2x as many signals since every rail must be DUAL signaled.
3) Liberally apply paired chain signals until you feel satisfied <-- CHAIN Signals eh? Clearly you haven't tested this idea at all
4) In order for trains to pass each other, you need either a stacker system or multilane solution. Well, a stacker system would need to be used in a lot of places to avoid long queue times when a train has to wait for another to clear the path. And if you use multilanes, then where are you saving anything at all???

In the most simplistic usage, trains would have to wait a VERY long time to deliver resources on a 1 rail solution as the rail would only support 1 train at a time. This is just not a feasible solution at all. I could drive a car faster than wait on trains.

I would love to see how your solution works as I can not even begin to understand it.
2) when adding a new lane each should be made one-way. Much higher throughput.

3) You need all chain on 2-way track otherwise there will be deadlock, only put normal signals on one-way portions and never going into a 2-way track. Yes this does mean that a train will reserve the entire path up until the next siding or to the destination but that's the way factorio functions at the moment. If there was a "reserved but enterable if block can be cleared" signal this would be less bad. The current solution means a siding/waiting area before each crossing.

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

Re: How-to: Two-way rails

Post by mrvn »

dinodod wrote:You want to show me an example on how you use these rails cause I have a lot of issues with your claim.

1) Which is super amazing as we can skip one assembler. 1 assembler and you're amazed?
2) Saves on signals??? At the very least you still need 2 signals. If adding multilanes, you now have to use 2x as many signals since every rail must be DUAL signaled.
3) Liberally apply paired chain signals until you feel satisfied <-- CHAIN Signals eh? Clearly you haven't tested this idea at all
4) In order for trains to pass each other, you need either a stacker system or multilane solution. Well, a stacker system would need to be used in a lot of places to avoid long queue times when a train has to wait for another to clear the path. And if you use multilanes, then where are you saving anything at all???

In the most simplistic usage, trains would have to wait a VERY long time to deliver resources on a 1 rail solution as the rail would only support 1 train at a time. This is just not a feasible solution at all. I could drive a car faster than wait on trains.

I would love to see how your solution works as I can not even begin to understand it.
You need 2 signals at every train stop. But only at the train stops. No need for signals on crossings or on longs paths. The drawback of using only the minimum of signals though is that only one train can move at a time.

So you add some more chain signals so trains with paths that don't overlap can move at the same time. It's still always reserving the whole path from train stop to train stop though. Or from train stop to wait split. Note the full signals on the wait split. You also need full signals or dummy train stops for a stacker.

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

Re: How-to: Two-way rails

Post by mrvn »

Note: don't confuse the two-way rails with unidirectional mono rails.

At the start I find building a simple single unidirectional rail loop works well. Just a single large loop around your base and then you place terminus or roro stations as spikes on that loop. Uses less signals than dual tracks and performs better than two-way rails.

dinodod
Long Handed Inserter
Long Handed Inserter
Posts: 84
Joined: Tue Mar 10, 2015 10:42 pm
Contact:

Re: How-to: Two-way rails

Post by dinodod »

In the early beginnings of your rail network, you will probably start with single rail system. But that will only last for so long, You should be BPing at least a dual rail system as you plan your rail system to ensure you can support it when you expand. single rail system is a very short term starter rail system only, normally to get more iron. I can't see it as being feasible otherwise.

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

Re: How-to: Two-way rails

Post by aaargha »

dinodod wrote:You want to show me an example on how you use these rails cause I have a lot of issues with your claim.

1) Which is super amazing as we can skip one assembler. 1 assembler and you're amazed?
2) Saves on signals??? At the very least you still need 2 signals. If adding multilanes, you now have to use 2x as many signals since every rail must be DUAL signaled.
3) Liberally apply paired chain signals until you feel satisfied <-- CHAIN Signals eh? Clearly you haven't tested this idea at all
4) In order for trains to pass each other, you need either a stacker system or multilane solution. Well, a stacker system would need to be used in a lot of places to avoid long queue times when a train has to wait for another to clear the path. And if you use multilanes, then where are you saving anything at all???

In the most simplistic usage, trains would have to wait a VERY long time to deliver resources on a 1 rail solution as the rail would only support 1 train at a time. This is just not a feasible solution at all. I could drive a car faster than wait on trains.

I would love to see how your solution works as I can not even begin to understand it.
I think most of the issues you present come from trying to use the system for far longer than is reasonable, or in places where the throughput requirements are simply too high. As I try to emphasize in the guide its strengths are ease of build and low cost, not throughput. This system is meant more as a quick starter system/something that new players might use to build off of, not to build X KSPM bases (it might be possible to use it for that but you'd have to plan your base REALLY well). If you're doing a large build this could likely be useful for most bootstrap bases, depending on scale and design. It is basically made to be grown out of once you're at a point where doing so is easy: production of base building things is stable and you've got a nice power armour and bots to handle the transition. If you try to look at it like that things hopefully make more sense.

Anyway, on to your questions:
  1. Overemphasis for comedic effect which seems to have been, at best, partially successful :)
  2. As the only places we need signals are stations, two at each, we can save a bunch on signals. Even if we're using the more reasonable partitioning techniques we only add signals at crossings, splits and mergers. The main place we save on signals is the long stretches of uninterrupted track that don't need any signals when using a two-way track. As for multi-lane two-way systems, my recommendation is simply: don't, unless you're trying it for the gimmick. Designing a multi-lane two-way system that increases throughput by a useful amount, while not turning into deadlock city, would need a lot of work. I might attempt it some time, just for fun, but I really don't see that being useful. If you need multiple lanes use one-way track.
  3. Yes, chain signals. Using rail signals in some places can work if you really know what you're doing, however they're a great way to get the kinds of deadlocks mentioned in step 1.
  4. I think this should be covered by the other answers and step 4, hopefully at least. If not, don't hesitate to ask.
As for an example: below is the map of my current world, it is basically what I used as a base for the rules and designs. It's about 50-60 SPM on expensive recipes with a 4x science cost multiplier. I'm currently trying to finish off most of the useful techs before I start preparing to build something bigger. Had the goal only been to launch a rocket, I'm pretty confident that that would have been comfortably possible on a base of similar scale on normal cost settings.
I might soon, depending on how/where I expand my production, be approaching the point where I actually need to expand the one-way dual-lane part around the main base to include some kind of proper intersection, this would have been much more of a pain than it is now that I have bots and power armour.
Example world map
Again, the reason to use a system like this is mostly to quickly, and easily, reach the point where building/redesigning a serious high-performance rail network is no longer a chore. Or, basically finish the game if you're satisfied with a rocket launch.

If things are still unclear please keep asking and I'll do my best to try and answer.

dinodod
Long Handed Inserter
Long Handed Inserter
Posts: 84
Joined: Tue Mar 10, 2015 10:42 pm
Contact:

Re: How-to: Two-way rails

Post by dinodod »

Well I'll give yoU credit for taking the K.I.S.S. (Keep It Simple Simon) statement to the max on this one, however, in a game where you need more resources faster, I feel that most new players will quickly see this as a problem as it literally slows down your trains to a crawl. If you honestly don't care about having only 1 train active at a time, then fine, have fun waiting. But as most players go, I think they would be pulling out their hair waiting for the resources. I honestly that while this does technically work, the lack of throughput and the long queues will do more harm than good. You might as well be using 20+ wagon trains.

As someone mentioned, a 1 way roundabout around your base would be a better design if used with regular signals so at least the trains could all be active. As it is a 1 way track, there would never be any deadlocks. You can then expand that with more circles if you want or branches as you see fit..

To respond to your comments,
1) Sarcasm. What's that?
2) Using chain signals only at train stations, then yes you would save on them. Since you are literally going for a 1 train at a time solution, then this would work and you would save.
3) Again, 1 train at a time solution. Then it can work
4) Since you only allow 1 train at a time, this is not needed.

I'd like to see a vote on this to see how many people would use this.

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

Re: How-to: Two-way rails

Post by aaargha »

Both step 2 & 4 involve increasing the number of active trains, "one train at a time" is only true for the "Example: The worst reliable system ever". Apparently the guide is still not kissed enough ;)

The one-way loop is a valid alternative to a two-way system. I'd think that they would become obsolete at about the same time, though for different reasons: by the time you would want to replace most of the two-way system due to throughput concerns the one way loop is too much of a hassle to expand to new outposts. Also note that a one-way loop track is not deadlock safe in the general case, if it's only the loop and a few stations you'll most likely be fine, but once you connect larger branches you risk saturation deadlocks.

ratchetfreak
Filter Inserter
Filter Inserter
Posts: 952
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: How-to: Two-way rails

Post by ratchetfreak »

aaargha wrote:Both step 2 & 4 involve increasing the number of active trains, "one train at a time" is only true for the "Example: The worst reliable system ever". Apparently the guide is still not kissed enough ;)

The one-way loop is a valid alternative to a two-way system. I'd think that they would become obsolete at about the same time, though for different reasons: by the time you would want to replace most of the two-way system due to throughput concerns the one way loop is too much of a hassle to expand to new outposts. Also note that a one-way loop track is not deadlock safe in the general case, if it's only the loop and a few stations you'll most likely be fine, but once you connect larger branches you risk saturation deadlocks.
The one-way ring road is deadlock safe as long as all trains can pull out of the main line if they need to wait and trains exit a station further down the road than they enter it.

Extending a ring road to outposts is a bad idea and instead spurs should used to connect them. Single 2-way track for single/low throughput outpost and 2 lane one-way tracks for stuff that needs higher throughput.

mozair
Burner Inserter
Burner Inserter
Posts: 14
Joined: Sun Apr 02, 2017 9:15 pm
Contact:

Re: How-to: Two-way rails

Post by mozair »

great read

i've just done a lot of single track train setups in 0.16 since i was playing in a world with ridiculous amounts of water and cliffs (and forcing myself to not build _any_ cliff explosives nor landfill... so pretty much impossible to have multiple lines)

just sad i didn't read some of the info you have here before : ).


i think i actually started liking single track trains more than the usual 2 or 4 lane setups, it adds so much complexity

drmatt
Manual Inserter
Manual Inserter
Posts: 1
Joined: Mon Mar 26, 2018 6:25 am
Contact:

Re: How-to: Two-way rails

Post by drmatt »

I created an account so that I could post the below.

Thank you!

This is exactly what I needed to finally do something useful with two way rail.

It's easy to just run loops everywhere but Factorio is about pushing yourself to make it feel smart. This got me feeling smart.

EDIT: I should add that my application is very low-throughput, but it needs to cover a lot of territory and be flexible. The approach given here provides flexibility since sections can easily be converted to one way, N-track as needed. It actually helps show where your bottlenecks are. Even veterans might be surprised :P
Last edited by drmatt on Wed Mar 28, 2018 2:55 am, edited 1 time in total.

dood
Filter Inserter
Filter Inserter
Posts: 360
Joined: Wed Mar 21, 2018 8:36 am
Contact:

Re: How-to: Two-way rails

Post by dood »

Why is this pinned?
This is a really bad practice.

A 2 lane rail system is no effort to set up and the signal advantage presented is a non-issue.
It's probably not good if this is the first thing a new player looking how to use rails sees.

User avatar
impetus maximus
Smart Inserter
Smart Inserter
Posts: 1299
Joined: Sat Aug 20, 2016 10:07 pm
Contact:

Re: How-to: Two-way rails

Post by impetus maximus »

dood wrote:Why is this pinned?
This is a really bad practice.

A 2 lane rail system is no effort to set up and the signal advantage presented is a non-issue.
It's probably not good if this is the first thing a new player looking how to use rails sees.
there are instances of this being really handy. especially early on when resources are scarce, or you are really reaching out for ore etc.
is a 2 rail 2 way system better for throughput? sure. but it can be a lot of fun getting single line systems up and running well.

Post Reply

Return to “Railway Setups”