Common stacker for multiple stations that never jams

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.
mm.lion
Inserter
Inserter
Posts: 25
Joined: Mon Dec 31, 2018 11:39 am
Contact:

Common stacker for multiple stations that never jams

Post by mm.lion »

I heard many times that multiple stations with common stacker cannot have dynamic limits: it just does not work, it jams. Well... I think there is an interesting and simple solution. So the problem:

Design a common stacker for multiple train stations that never jams and allows to park as much trains as possible.

Suppose there are 3 stations A , B, C, and a stacker for 3 trains.

Image

Video: https://www.veed.io/view/c6096e7f-65cb- ... 7f8fc2af34

There is a boring non-optimal solution: put static train limit 2 on each station (1 train in a station and 1 train in a stacker slot). There will be no jamming. But if, for any reason, there are no trains going to stations A and B, then 2 stacker slots will always be empty. This is not optimal as these 2 slots could be in theory occupied by trains going to station C

I think there is an almost optimal solution via dynamic change of trains limits. My wife has found it, she is a mathematician. So she said: "basically, train limit is an invitation. If you put limit = 3 that means you invite 3 trains to come to the station", and suggested the following simple solution.
  • Any station knows the number of trains that are going to the station: C = [train count]
  • Any station knows if there is a train stopped at the station: T = [train id] if present.
So

Code: Select all

[number of occupied slots in the stacker] = [number of trains going to all station] - [number of trains stopped on stations]
Indeed, we should always avoid jams, so if a train is going to a station then we should always assume that it will occupy a slot in the stacker (worst case scenario) and

Code: Select all

[number of available slots] = [stacker size] - [number of occupied slots]
Now choose train limits. Obviously, if some trains are already going to station X, they should be included in the limit of station X as they have already been invited. Further, we can invite new trains to occupy all available slots on the stacker. So for any station X, put

Code: Select all

L = [number of available slots] + C
For example, if there is only 1 available slot in the stacker, then each station will invite 1 new train = 3 new trains in total. This looks very strange, but works surprisingly well! If a train decides to accept an invitation an go to station X, the number of available slots immediately goes down to 0 and no new trains will be invited.

This solution also works if you have an other logic to set train limits (e.g. Nilaus load or unload stations): you just compute minimum of those two limits.


There remains one edge case: if two stations increase their train limit simultaneously at the same tick. In this case it may happen that number of invited trains would become bigger than the staker size, which would create a jam. This case is solved easily: we do not need to invite trains to a station at any tick, we invite trains to station A at tick 10, to station B at tick 20 and to station C at tick 30 of 60 ticks in a second.

Here is a bp with an example

Last edited by mm.lion on Sun Feb 25, 2024 2:45 pm, edited 3 times in total.
Tertius
Filter Inserter
Filter Inserter
Posts: 950
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: Common stacker for multiple stations that never jams

Post by Tertius »

The problem with dynamically adjusting train limits according to free space in the stacker is that trains with one item (for example iron ore) can completely occupy the stacker while stations that require a different item (for example copper ore) will starve, because all lanes in the stacker are occupied with iron ore trains. If there is currently no demand of iron ore, a stacker lane will never become free.
You need guaranteed space in the stacker for every item, and enough guaranteed space, so the corresponding station(s) cannot run empty.

In the end, a static setup with fixed limits is all you need, because they guarantee space in the stacker for every train type in a very simple way that's completely sufficient for reliable operation. You may need more stacker lanes perhaps, but if you reserve space in your base in advance, there should be no issue with that.

Look at this slightly different setup:
Screenshot 2024-02-18 024640.png
Screenshot 2024-02-18 024640.png (2.15 MiB) Viewed 2768 times
Every station on the right has a fixed train limit of 4. This means, it will attract 4 trains, of which one will enter the station and 3 will wait in the stacker lanes.
Since there can be up to 3 trains per station in the stacker and we have 6 stations, we need 3 * 6 = 18 stacker lanes.
This setup will never jam, and it's so simple due to being completely static, so there is no unexpected behavior to expect as it is often with sophisticated combinator setups and their edge cases.

The station limit is big enough for very long distance between source (here: ore mines) and these stations, as long as there are enough trains deployed so every loading station is occupied while the train is being filled and waits there if it is full, so any full train can start driving immediately as soon as some slot in one of the unloading stations becomes free.

No circuits necessary for train limits. A very good working static train limit setup for my base (with 8 wagon trains) is 4 at the unloading stations and 3 at the loading stations. The static limit of 3 for the loading stations (not shown here) means there must be a small stacker with 2 lanes in front of every loading station. Shouldn't be a problem, since ore mines usually have plenty of space around.

However, I don't know the numbers for shorter trains. May be you need higher numbers, because trains carry less, so more trains need to be employed.

About numbers. The amount of trains must be the sum of all the train limits of the loading stations. If there are not enough trains to support all your unloading stations, you need to deploy more loading stations and 3 more trains (3=train limit) per loading station until full trains start to accumulate in the stacker in front of the unloading stations. You cannot create too many loading stations, however you must not deploy more trains than the sum of all the train limits of the loading stations (and you should not deploy less).

mm.lion
Inserter
Inserter
Posts: 25
Joined: Mon Dec 31, 2018 11:39 am
Contact:

Re: Common stacker for multiple stations that never jams

Post by mm.lion »

Very nice! Yes I've also always used this design (before yesterday). You're right: it is simple and it never jams. I like it. But I was wondering if the dynamic limit jamming problem could be solved. And it could be.

The design upwards does not jam even if station A tries to invite 100 trains and station B tries to invite just 1. This is because station A invites trains only at tick say 10, and station B at say tick 40. Suppose a slot in the stacker becomes free at tick X. If 10<X<=40, then a new train will be invited by station B; and if X<=10 or X>40, then a new train will be invited by station A. So A and B have equal chances to invite a new train. Try my test BP, it is highly saturated by exceeding trains, but all stations have some incoming trains.

Moreover, these ticks should be used as privileges. If station A invites new trains at say tick 0, and station B at tick 40 (out of 60), it means that station B will be able to invite a new train first with probability 40/60, and station A -- with probability 20/60. So station B will invite two times more trains than station A on the average if the stacker is fully occupied (and if the stacker is not fully occupied, both station will invite all the trains they want)
mm.lion
Inserter
Inserter
Posts: 25
Joined: Mon Dec 31, 2018 11:39 am
Contact:

Re: Common stacker for multiple stations that never jams

Post by mm.lion »

Here is a video of the stacker working

https://www.veed.io/view/c6096e7f-65cb- ... 7f8fc2af34
Last edited by mm.lion on Sun Feb 25, 2024 2:46 pm, edited 1 time in total.
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2768
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Common stacker for multiple stations that never jams

Post by FuryoftheStars »

Another thing you can potentially do for a dynamic train limit is setup a max limit for each station that respects the size stacker you have. You could also use intermediary stations in the stacker (depending on the setup).

That said, I think your thread title and opening line may need a bit of rewording.
mm.lion wrote: Sat Feb 17, 2024 9:38 pm I heard many times that multiple stations cannot have common stacker: it just does not work, it jams.
When I first read the thread title and then came in and read that opening line, it seriously made me wonder what I am doing differently from these other people experiencing this issue as I've never had a common stacker to multiple stations jam. It wasn't until reading the followup posts that I realized you were referring specifically to small, space saving stackers where the stations are using high limit (if at all) train limits.

Yeah, as Tertius kind of mentioned, you typically need enough space in your stacker to account for when all of your stations are requesting max limit.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
mm.lion
Inserter
Inserter
Posts: 25
Joined: Mon Dec 31, 2018 11:39 am
Contact:

Re: Common stacker for multiple stations that never jams

Post by mm.lion »

FuryoftheStars wrote: Sun Feb 18, 2024 4:12 pm Another thing you can potentially do for a dynamic train limit is setup a max limit for each station that respects the size stacker you have.

That said, I think your thread title and opening line may need a bit of rewording.
Probably, you're right, thanks. Let me try to change the opening line. I hope now it is better.
Post Reply

Return to “Railway Setups”