Train balancing between loading and unloading stations

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Post Reply
Tertius
Filter Inserter
Filter Inserter
Posts: 861
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Train balancing between loading and unloading stations

Post by Tertius »

I have an issue with trains always driving to the same almost full unloading station(s) and ignore other unloading stations that are empty. I'm looking for a solution with the least amount of configuration and material. I want to drop my station blueprint wherever I need it and manually configure as less as possible.

It's for ore mines. My setup is like this:
  1. No mods.
  2. All trains are 1 locomotive and 4 wagons
  3. The railway consists of 2 parallel tracks, right hand drive
  4. all stations are on a small branch from the main rail that is as long as one train
  5. all ore mines (loading stations) with the same ore have the same station name ("<ore name> loading")
  6. all unloading stations for the same ore have the same station name ("<ore name> unloading")
  7. all stations have a train limit of 1, so there is no waiting in front of an occupied station
  8. there are as many trains as loading stations
  9. there are more loading stations than unloading stations.
  10. The trains are scheduled to drive to a loading station, wait for full, then drive to an unloading station, wait for empty
With this setup, things run smoothly in general, but one unloading station starves and becomes empty, while other stations are so full the train is waiting to get empty for a long time. The empty unloading station only gets a train if by chance the nearer unloading stations have a train being unloaded and at a loading station a train gets full. It gets better the more mines I have, but I'm still building and don't have that many mines.

If I configure a time limit in the train schedules on a unloading station, the train returns to the loading station after the timeout, is refilled - and returns to the station it just left. The empty station is still ignored.

If I configure a time limit in the train schedules on a loading station, the train drives half empty to the unloading station after the timeout, so the probability the nearer unloading stations are occupied is higher, so more trains drive to the starving station, but this wastes train capacity, and the starving unloading station is only filled half by one train, since trains arrive half empty. This helps a bit, but I'm not satisfied at all.

My current approach is to wire all chests in the unloading stations and count the items in the chests with the circuit network, then set the train limit to 0 or 1 if the chest content is above or below some threshold (currently: 50% full).
This works in general, but if the supply drops below some threshold, for example if some mine becomes exhausted, the issue returns, since my near unloading station falls below 50% sometimes and the trains go there instead of other unloading stations that may have dropped to 0%. It also becomes worse, the faster the items at the oversupplied stations get consumed. I can lower the threshold below 50%, but then there isn't much safety, and full trains are waiting idle at loading stations while there are stations that are 70% empty.

The perfect solution seems a global circuit network that compares the content of all unloading station chests and always activates one or two unloading stations only - the ones that are most empty. However, this needs to connect everything, which is quite tedious, and this makes less trains actually drive than possible, creating a bottleneck, so even more sophisticated circuit network magic has to be invented.

Are there other approaches I didn't see? I don't need the perfect solution, just alternatives.

And another question: I can either set a train limit or activate/deactivate the station. Setting the train limit needs a combinator, activating/deactivating needs none. Is there an advantage to set a train limit instead of directly toggling the station active or inactive? Currently, I don't intend to ever raise a train limit above 1. On the other hand, are there advantages of having a train limit of 2 and a waiting area in front of a station? For my issue of uneven supply of unloading stations, I assume my oversupplied stations will get even one more train and the starving station will still get no train.

I'm certainly not the first one with that challenge. Are there threads with ideas and solutions, not just discussions without conclusion? I did not really find any conclusions, only more or less the same question, but no good answers that go beyond what I already do.

Loewchen
Global Moderator
Global Moderator
Posts: 8894
Joined: Wed Jan 07, 2015 5:53 pm
Contact:

Re: Train balancing between loading and unloading stations

Post by Loewchen »

The simplest solution is to give every unloading station a fixed train limit of e.g. 1, but then you need to adapt it when you expand further out. A more advanced but still not complicated approach is to detect available capacity in each station via circuit signal and automatically set the train limit based on that.

Imo you should never deactivate stations, especially now that train limits exist. It was never a well implemented feature that can create several issues and is now completely replaceable with train limits.

Xeorm
Fast Inserter
Fast Inserter
Posts: 206
Joined: Wed May 28, 2014 7:11 pm
Contact:

Re: Train balancing between loading and unloading stations

Post by Xeorm »

My understanding of the process is that it works something like this:
1. Train finishes loading, and selects a destination, choosing closest unfilled station.
2. Train travels to station.
3. If it's waiting before a filled station, it may reroute to an unfilled station.

Note when that third bit happens. If you have the train waiting at a section that it can't reroute to an unfilled station, it never will. This is why I've seen it pretty common to build a waiting area before a large number of stations, or a waiting area -> back onto the main railway so that trains can reroute.

Not sure what you have for areas for the trains to wait before pulling into the stations. Might also be a signalling issue there where things aren't working quite as you think they should. As always, pictures >>> words because you might be getting something wrong with your description without realizing it.

astroshak
Filter Inserter
Filter Inserter
Posts: 631
Joined: Thu May 10, 2018 9:59 am
Contact:

Re: Train balancing between loading and unloading stations

Post by astroshak »

No mods, that means each wagon holds 2000 ore and each train 8000 ore. How many chests is each cargo wagon unloading to?

Set a Constant Combinator with an output of the negative maximum quantity of ore that the unloading station can hold. 2400 per Steel Chest, times 4 wagons times 6 chests per wagon results in 57600 maximum capacity, so set the CC to -57600 ore. Wire this CC to each unloading chest at the station. Wire up an Arithmetic Combinator to divide the ore signal by -8000 (the amount that one train can hold). Send that result to the Train Stop as the Train Limit.

If the station drops 8000 ore below the maximum, then the limit will go from 0 to 1 (or whatever, based on just how low it gets) and it will take a train. However, once a train present offloads enough to bring it to less than 8000 ore from full, the limit will drop to zero and other trains will have to go elsewhere.

You will have to use two Decider Combinators between the Arithmetic Combinator and the Train Stop if you want to limit the Train Limit to something less than 7 (7 being the highest that the train stop limit can get to with this setup, if the chests are all empty). One to output the limit if it is less than the desired maximum, the other to output the desired maximum if it is higher than the desired maximum. IE - L <= 1 output L value; L > 1 output L=1.

Tertius
Filter Inserter
Filter Inserter
Posts: 861
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: Train balancing between loading and unloading stations

Post by Tertius »

@Loewchen This is exactly what I do now. Detect available capacity at station and set train limit to 0 or 1. Works, but not perfectly.

@Xeorm I don't understand how these waiting areas can work to re-route a train to some completely different area of my factory, where the "starving" station is. A waiting area in front of 2 stations to feed these 2 stations, ok. But if some train is waiting, it's stuck in front of a signal in the waiting area, and that signal will not magically get green if the train was re-routed to some other station far away. A train can re-route if it's waiting at a chain signal, but it will probably choose the station it's currently waiting, because that is just at the next block. And even if it's re-routed to that far away station, how will the signal get green the train is waiting behind?

Screenshot, well this is from my sandbox:
screenshot-tick-57502109.png
screenshot-tick-57502109.png (801.39 KiB) Viewed 3354 times
The ore mines are on the top row. Locate the 2 iron factories in the middle, as well as the steel factory bottom left. The 2 iron factories in the middle are supplied perfectly with iron ore, but the steel factory at the bottom left is neglected, and for this I look for an idea that goes beyond what I already did.

Laie
Long Handed Inserter
Long Handed Inserter
Posts: 65
Joined: Fri Dec 25, 2020 6:18 pm
Contact:

Re: Train balancing between loading and unloading stations

Post by Laie »

Tertius wrote:
Wed Jun 30, 2021 4:05 pm

It's for ore mines. My setup is like this:
[...]

What you describe sounds as if you had a general shortage of ore. There's simply not enough coming in, so the factories farther from the mines are starving. (reads OP again) Yeah, you even say as much yourself. The obvious solution is to build more mines.

By the way, the game already has a wonderful mechanism to cope with shortages: most everything is made and consumed in conjunction with anything else. If you have an excess of something (or not enough of something else, same problem) the excess will pile up, until you simply cannot make any more. Eventually, resources will become available for whatever is in short supply. Of course, with trains and stations and chests involved, it may take a looong time to fill all buffers... but in principle you can simply wait for the situation to resolve itself. (You may also want to have a look at how many chests you have and reconsider their limits.)

If you are impatient and want to manage the shortage yourself, I do not think you should do that on a train level. If the production of item A consumes too many resources and starves the remainder of your factory, then, by all means, reduce the production of item A -- which can probably be done by snipping the transport belt halfway through the assembly line. Easy, and just as easily undone when you finally have enough mines to run everything at full capacity.
Last edited by Laie on Wed Jun 30, 2021 6:44 pm, edited 2 times in total.

Tertius
Filter Inserter
Filter Inserter
Posts: 861
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: Train balancing between loading and unloading stations

Post by Tertius »

@astroshak Thanks for the explanation of how to compute the train limit. It's actually computing "how many full train loads will fit in my chests". Will keep this in mind, should I ever introduce waiting areas. Currently, I use a simple variant of that. I use the "1" output of a decider combinator directly to set the train limit to 1 if more than 1 train load fits in the chest (which automatically outputs 0 if it doesn't fit).

@Laie I assume you hit the nail on the head: general shortage of ore. I'm no veteran player and built no big bases yet, so I never exceeded perhaps 10 ore mines of one ore type. More than half of my play time I was in sandbox mode to explore game mechanics and to develop factory concepts and blueprints. In the real game, this is quite tedious if you start with nothing. And I don't want to copy blueprints from anywhere. I intend to do develop my own version of everything.
And in my sandbox, I just created only one loading station more than unloading stations, because I didn't want to create what wasn't supposed to be consumed. That's lab against reality.

So I will probably stick with the circuit network approach and prioritize the work to increase ore mines more than I initially wanted.

Laie
Long Handed Inserter
Long Handed Inserter
Posts: 65
Joined: Fri Dec 25, 2020 6:18 pm
Contact:

Re: Train balancing between loading and unloading stations

Post by Laie »

Tertius wrote:
Wed Jun 30, 2021 5:57 pm
@Laie I assume you hit the nail on the head: general shortage of ore.
Thank you very much, you're welcome :)
Please note that I have essentially rewritten my post in the mean time.

Xeorm
Fast Inserter
Fast Inserter
Posts: 206
Joined: Wed May 28, 2014 7:11 pm
Contact:

Re: Train balancing between loading and unloading stations

Post by Xeorm »

Image

This is what I was meaning in terms of a waiting area. Something off the side of the grid where trains can stay, to ensure a steady flow of ore. This isn't the necessarily best way to build it, but it's one I have a picture of, so there you go.

As far as ore trains go, I did find that as I built more that I couldn't rely on any set number of trains. Ore patches drying up would be top on my list of for reasons why, but also that I was annoyed at the latency of trains. You should absolutely expect that eventually you'll have more trains than destinations, or making sure to take care when things go a little haywire.

Tertius
Filter Inserter
Filter Inserter
Posts: 861
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: Train balancing between loading and unloading stations

Post by Tertius »

I assume there is no best way to do a railway setup, given the many different valid approaches. I chose 1+4 trains, so every station is a bit bigger and waiting areas need more space, but at the same time my unloading stations need only half the trains, so there is less traffic on the tracks. I think, I need to expand my base well beyond the size that just enables you to launch a satellite once in a while, so I will do that to explore railways on a larger scale. And I need to do that in an actual game and not in a sandbox (what I did for a major part until now), because only there mines run out and things didn't just get reset by one mouse click but run for a long time.
Tinkering with all this is really fun.

Post Reply

Return to “Gameplay Help”