Page 1 of 2

How to use the train limit with double headed trains/stations

Posted: Tue Oct 05, 2021 8:17 pm
I'm going to play on a ribbon world with double headed trains. The station design is such that I have 2 tracks each at the top and bottom of the map and the train stations go from top to bottom. And bottom to top. Each station has 2 train stops so trains can enter from the top or bottom.

Now this causes a problem with the train stop limit. Each station can only allow one train and chain signals ensure that only one train ever enters a station. I also set each train stop to 1 train only. But one train can target the top stop and another the bottom stop of the same station.

So how do I tell the game that I have 2 stops that make up a train station and for the station all together the train limit is 1?

The solution I'm trying now is to have each stop output the train count (top as C, bottom as D) and enable the other station if D=0 or C=0 respectively. So if a train targets the top station the bottom gets disabled. Seems to work so far. But what if trains target the top and bottom stations in the same tick? Then next tick both stations get disabled. Next tick the trains don't target the stations anymore so both stations get enabled. And then both trains will target both stations again. I'm afraid that the trains will get into a state where both stops of a station will toggle on/off every tick.

I made a little test setup with two trains fighting over the stations:
train-station-fight.png (3.81 MiB) Viewed 1893 times

Place the blueprint, fuel up the trains and then turn on the constant combinator and watch the trains stutter along till one reaches the station. After that the trains will alternate. This would absolutely kill my game.

I can fix this by having the bottom stop turn back on with 1 tick delay. Takes an extra combinator per station and trains still stutter a bit but then settle down:

Any other ideas for making the train limit work for double headed stations with 2 stops?

Re: How to use the train limit with double headed trains/stations

Posted: Tue Oct 05, 2021 8:56 pm
I don’t think that you can have one train count towards the limit of two different train stops. Maybe if you could read the Incoming Train value assigned to a stop and subtract that from the other train stop, but I don’t think that this is possible (not in Vanilla, and I’ve not explored enough rail mods to know if its there).

My suggestion would therefore be a complete redesign, into parallel tracks with terminus stations, rather than having two stops on opposite sides of the same track. If, for some reason, you need a train to switch which track its on (North, or South) then a third line connecting the two rails far enough from the stations that a train could go from the South rail, up the connector to the North rail, and then go into the northern terminus station.

I know, rail World means you are constrained for space. Unfortunately, I think that this is the solution to your problem.

Re: How to use the train limit with double headed trains/stations

Posted: Wed Oct 06, 2021 1:37 am
Leave one station enabled all the time and just disable the other one if the first station has a train count >0. That way even if they both path there on the same tick only one of them will get its path cancelled and the other one will make it, then free the station up again once it leaves.

Re: How to use the train limit with double headed trains/stations

Posted: Wed Oct 06, 2021 2:05 am
torne wrote:
Wed Oct 06, 2021 1:37 am
Leave one station enabled all the time and just disable the other one if the first station has a train count >0. That way even if they both path there on the same tick only one of them will get its path cancelled and the other one will make it, then free the station up again once it leaves.
I would do that too, and if your schedule is not ABAB but ABCABC and you don't want the train to skip a station, you can always have a disconnected train stop with the same name somewhere on the map, so that the train gets a "no path" instead of the skip when the station disable.

Re: How to use the train limit with double headed trains/stations

Posted: Wed Oct 06, 2021 3:39 pm
astroshak wrote:
Tue Oct 05, 2021 8:56 pm
I don’t think that you can have one train count towards the limit of two different train stops. Maybe if you could read the Incoming Train value assigned to a stop and subtract that from the other train stop, but I don’t think that this is possible (not in Vanilla, and I’ve not explored enough rail mods to know if its there).

My suggestion would therefore be a complete redesign, into parallel tracks with terminus stations, rather than having two stops on opposite sides of the same track. If, for some reason, you need a train to switch which track its on (North, or South) then a third line connecting the two rails far enough from the stations that a train could go from the South rail, up the connector to the North rail, and then go into the northern terminus station.

I know, rail World means you are constrained for space. Unfortunately, I think that this is the solution to your problem.
The train stop has an option to output the train count. That's what I use to disable the other station.

The design is that trains go east at the top and west at the bottom. They drive into a station to load. Then they drive out to the top if the destination is in the east or the bottom if the destination is in the west. With a terminus station the train would always have to leave the direction they came from. And then they would have to find a turn around if that is the wrong way. I want to avoid that.

Re: How to use the train limit with double headed trains/stations

Posted: Wed Oct 06, 2021 11:23 pm
torne wrote:
Wed Oct 06, 2021 1:37 am
Leave one station enabled all the time and just disable the other one if the first station has a train count >0. That way even if they both path there on the same tick only one of them will get its path cancelled and the other one will make it, then free the station up again once it leaves.
Then a train targets the bottom station. Half way there a second train targets the top station. That disables the bottom station leaving the first train standing in the middle of the tracks with "destination full". Instant deadlock.

Re: How to use the train limit with double headed trains/stations

Posted: Wed Oct 06, 2021 11:24 pm
mmmPI wrote:
Wed Oct 06, 2021 2:05 am
torne wrote:
Wed Oct 06, 2021 1:37 am
Leave one station enabled all the time and just disable the other one if the first station has a train count >0. That way even if they both path there on the same tick only one of them will get its path cancelled and the other one will make it, then free the station up again once it leaves.
I would do that too, and if your schedule is not ABAB but ABCABC and you don't want the train to skip a station, you can always have a disconnected train stop with the same name somewhere on the map, so that the train gets a "no path" instead of the skip when the station disable.
Stations with their train limit full aren't skipped so there is no risk of that if one stations remains on.

Re: How to use the train limit with double headed trains/stations

Posted: Thu Oct 07, 2021 9:09 am
mrvn wrote:
Wed Oct 06, 2021 3:39 pm
The design is that trains go east at the top and west at the bottom. They drive into a station to load. Then they drive out to the top if the destination is in the east or the bottom if the destination is in the west.
You can change this to have the train coming from top rotating in the other way than train coming from bottom no ?

What do you think of that ? (apart that it should be mirrored to match your descripition ) :
loops.png (27.39 KiB) Viewed 1771 times
On the left and right side i made the "possible rail" start at different location, it could be helpful to have path to U-turn without ever going through a train stop.
mrvn wrote:
Wed Oct 06, 2021 11:23 pm
Then a train targets the bottom station. Half way there a second train targets the top station. That disables the bottom station leaving the first train standing in the middle of the tracks with "destination full". Instant deadlock.
But when you have your normal operation, it will happen that one train from bottom and one from top are targetting the same station at the same time, the network shape should be made so that the train that has to wait does so in a correct place. To prevent that one can use a train stop as a waypoint, every train would go through one before entering a real station, just so that when the check for next destination that could lead to "destination full" happens, the train is already parked outside the main lane. Just think about where in your case you want the train to wait when 2 of them target the same station, and put a dummy train stop there.

In case it's annoying to use a waypoint as a train stop, you can also turn a signal red to block the second train at correct location when the station is occupied by a train from the other direction.

In this case you don't disable the station. almost the same logic for where the train has to wait, different method to make it do so.

Not sure i'm able to explain correctly, hopefully the picture doesn't make it worse :
file.png (4.14 MiB) Viewed 1771 times
The red path is the train that goes first. In this case the other train shouldn't wait in the pink spot, called "no!", that would be too close and block potential path for the other train, if you don't disable the station, no risk of the train waiting anywhere else. If you wire the signal called "turn red" to turn red when the station is occupied from the other angle, and you add 1 signal where it's written "add 1", then you have an orange block called "yes!" where the 2nd priority train can safely be parked.

mrvn wrote:
Wed Oct 06, 2021 11:24 pm
Stations with their train limit full aren't skipped so there is no risk of that if one stations remains on.
I had not realized both train stop where called the same, and you expect that at all point of time 1 or the other would be open. The concern would only apply if during period time both would be closed at the same time. say 4 ticks due to some delay in opening/disabling station.

Makes me wonder what i have overlooked this time maybe you just neet to remove the 2 pairs of chain signal just next to the train stop, it feels like it would do what i'm describing somewhat.

Re: How to use the train limit with double headed trains/stations

Posted: Thu Oct 07, 2021 12:22 pm
mrvn wrote:
Wed Oct 06, 2021 11:23 pm
torne wrote:
Wed Oct 06, 2021 1:37 am
Leave one station enabled all the time and just disable the other one if the first station has a train count >0. That way even if they both path there on the same tick only one of them will get its path cancelled and the other one will make it, then free the station up again once it leaves.
Then a train targets the bottom station. Half way there a second train targets the top station. That disables the bottom station leaving the first train standing in the middle of the tracks with "destination full". Instant deadlock.
Ah right. You need to have the logic the OP described for the normal case (each station disabled if the other station has a train on the way) but apply the logic I said only if *both* stations have a train on the way to catch the case that they both pathed there at the exact same time.

So, station A should be enabled if station B has train count=0, and station B should be enabled if station A has train count=0 *or* if station B has train count>0.

That way it there's already a train on the way to one of them the other will be disabled and the issue you mention can't arise, but if two trains pick the two stations simultaneously one of them will have its route cancelled on the following tick, before it has a chance to actually leave its current station and potentially get in the way.

Re: How to use the train limit with double headed trains/stations

Posted: Thu Oct 07, 2021 5:21 pm
torne wrote:
Thu Oct 07, 2021 12:22 pm
mrvn wrote:
Wed Oct 06, 2021 11:23 pm
torne wrote:
Wed Oct 06, 2021 1:37 am
Leave one station enabled all the time and just disable the other one if the first station has a train count >0. That way even if they both path there on the same tick only one of them will get its path cancelled and the other one will make it, then free the station up again once it leaves.
Then a train targets the bottom station. Half way there a second train targets the top station. That disables the bottom station leaving the first train standing in the middle of the tracks with "destination full". Instant deadlock.
Ah right. You need to have the logic the OP described for the normal case (each station disabled if the other station has a train on the way) but apply the logic I said only if *both* stations have a train on the way to catch the case that they both pathed there at the exact same time.

So, station A should be enabled if station B has train count=0, and station B should be enabled if station A has train count=0 *or* if station B has train count>0.

That way it there's already a train on the way to one of them the other will be disabled and the issue you mention can't arise, but if two trains pick the two stations simultaneously one of them will have its route cancelled on the following tick, before it has a chance to actually leave its current station and potentially get in the way.
Yes, but I can't see any way to implement that without adding a combinator, which adds a delay making trains stutter. Each time the train moves 1 tick forward. If it keeps happening to the same train over and over, e.g. it's the only one that targets the bottom station, eventually the train will stutter out of it's resting station and block the main traffic lane.

Note: unlike other entities it seems the train stop sees the signals it outputs itself. The even see the red and green wire signal they output separately. So a train stop with train count C=1 with 2 wires sees C=2. So I can have: C=0 no train, C=1 other stop, C=2 this stop, C=3 both stops. But then I need one station to enable on C != 1 and the other on C=0 or C=2.

As for the other suggestions:

A turn around inside the station takes space I don't want to waste on the limited 128 tiles height of the map. It would require reducing the the train length. But maybe that is a wash because then trains can be single headed. The saved length of the backwards locomotives becomes the turnaround.

A waystation? Same problem there as with the original. I would need a top and bottom waystation.
mmmPI wrote:
Thu Oct 07, 2021 9:09 am
You can change this to have the train coming from top rotating in the other way than train coming from bottom no ?

What do you think of that ? (apart that it should be mirrored to match your descripition ) :
loops.png
That would turn a 4 tile wide vertical station into a 140 tiles horizontal station. That would waste so much space on the map. And I need one for loading and one for unloading. If I place them top and bottom then trains might have to wait on the main track to let the another pass into the station. I'm trying to avoid that. Putting them side to side would be 280 tiles horizontal. Double the wasted space. Some sub factories have 8 or 10 stations if the recipe is complex enough or I combine multiple steps of something.
mmmPI wrote:
Thu Oct 07, 2021 9:09 am
mrvn wrote:
Wed Oct 06, 2021 11:24 pm
Stations with their train limit full aren't skipped so there is no risk of that if one stations remains on.
I had not realized both train stop where called the same, and you expect that at all point of time 1 or the other would be open. The concern would only apply if during period time both would be closed at the same time. say 4 ticks due to some delay in opening/disabling station.

Makes me wonder what i have overlooked this time maybe you just neet to remove the 2 pairs of chain signal just next to the train stop, it feels like it would do what i'm describing somewhat.
Not only are the two stops of a station called the same. There are likely to be many stations of the same name on the map. That's the reason I need the train limit. E.g. there may be 20 stations called "Iron Ore - Load", 40 stops with the same name. Several smelters that have an ore in and plate out stations. Many stops with "Iron Plate - Unload". With the trains being the full height of the map minus the west-east tracks I don't have space for a waiting bay or anything other. I really want to deliver trains count perfect. I looks so nice if the train network is like a sideways ladder.

I now realize the problem might be much more frequent then I first thought. Once I have more ore mines and produce more than I consume I will have full trains waiting for a destination all over the map. I want to overproduce everything otherwise far off stations would starve. But then when a station needs e.g. Iron Plates and enables the station lots of trains will path to it in the same tick. Having trains target the top and bottom station in the same tick should be the norm, not the exception.
I'm just not there yet because I just started and am input starved.

Re: How to use the train limit with double headed trains/stations

Posted: Thu Oct 07, 2021 5:24 pm
As far as I understand it, the stuttering is a result of a feedback loop which is caused by the stations being input and output at the same time.

What if you use two stations in each direction, all the same name (top1, top2 and bottom1, bottom2 instead of top and bottom). top1 and bottom1 are enabled initially and can be targeted. If they are targeted the logic decides if top2 or bottom2 should be activated and the other 3 are deactivated after that. This way there should be no feedback loop as only the x1 stations are input and only the x2 stations are output.

Needs a lot more combinators though.

After a 2nd thought, that can also be achieved with only one top and bottom station, but with a lot of combinators. essential would be amemory cell, that says if the station is in "compare" mode or in "wait for incoming train to leave again" mode.

Re: How to use the train limit with double headed trains/stations

Posted: Thu Oct 07, 2021 6:22 pm
Impatient wrote:
Thu Oct 07, 2021 5:24 pm
As far as I understand it, the stuttering is a result of a feedback loop which is caused by the stations being input and output at the same time.

What if you use two stations in each direction, all the same name (top1, top2 and bottom1, bottom2 instead of top and bottom). top1 and bottom1 are enabled initially and can be targeted. If they are targeted the logic decides if top2 or bottom2 should be activated and the other 3 are deactivated after that. This way there should be no feedback loop as only the x1 stations are input and only the x2 stations are output.

Needs a lot more combinators though.

After a 2nd thought, that can also be achieved with only one top and bottom station, but with a lot of combinators. essential would be amemory cell, that says if the station is in "compare" mode or in "wait for incoming train to leave again" mode.
The stuttering is because for one tick the train targets the stations and starts moving. Then the station is disabled and the train can't find another station and switches to "destination full". In the simple setup both stations get disabled and that causes a feedback loop. Because next tick both stations are disabled, don't output a train count signal and both get enabled again and the loop closes.

In the enhanced setup with an extra combinator one station activates after 1 tick, the other after 2 ticks. That way the first station has a train targeted at it before the second station enables and thus the second station remains disabled. No loop there but still a single stutter.

In your case you still have 2 trains targeting the top1 and bottom1 stations respectively. So both trains will start moving. Then next tick (or even later) you disable 3 stations. One train will switch to top2 or bottom2 and the other will stop wherever it is. So the loosing train still stutters driving one tick forward every time this situation happens. Eventually it will drift into the main traffic lane.

And you don't control which train will win. The train targeting top1 might win when you enable bottom2. It then has to drive through another station somewhere to turn around and approach the destination from the wrong side. Kind of makes the double headed idea pointless.

I don't think there is a solution to this problem. I can't see any solution that works in 0 ticks. Any combinator logic adds at least 1 tick delay and that causes trains to move for 1 tick before you can shut them down again. Or you have trains trying to turn around because the station for the right way wasn't opened.

It would be nice to have a single train stop that's double sided. Then one could set that as a waypoint with a train limit between the two actual stations.

Re: How to use the train limit with double headed trains/stations

Posted: Thu Oct 07, 2021 8:07 pm
Ok, I am down to 6 combinators and 4 ticks delay.

- I changed fuel for nuclear fuel.
- I changed the chain signals at the waiting stations to normal signals to see if the losing train can move beyond that signal in 4 ticks with nuclear. It can't.

Have a look and tell if it meets your needs.

I understand that the track example you posted was just to showcase the stuttering. The solution I post solves the stuttering. But maybe it does not meet the needs of the ribbon world track layout as you mention potential routing problems. In that case please post another, more versatile example. I would be interested to see it.

Edit:
mrvn wrote:
Thu Oct 07, 2021 6:22 pm
In your case you still have 2 trains targeting the top1 and bottom1 stations respectively. So both trains will start moving. Then next tick (or even later) you disable 3 stations. One train will switch to top2 or bottom2 and the other will stop wherever it is. So the loosing train still stutters driving one tick forward every time this situation happens. Eventually it will drift into the main traffic lane.
Maybe I should read the comments more in detail. Reading this paragraph again, I realise now, that also the slightest movement forward of a losing train is too much. At some point, when it lost often enough, a train will pass the next track signal and block the track section after it.

So stuttering or no stuttering, I conclude my solution will not do.

Re: How to use the train limit with double headed trains/stations

Posted: Thu Oct 07, 2021 9:27 pm
Impatient wrote:
Thu Oct 07, 2021 8:07 pm
The solution I post solves the stuttering. But maybe it does not meet the needs of the ribbon world track layout as you mention potential routing problems. In that case please post another, more versatile example. I would be interested to see it.
I would be curious to see it too, i didn't thought about solving the stuterring, instead i looked for the routing/schedule/layout approach.
mrvn wrote:
Thu Oct 07, 2021 5:21 pm
Not only are the two stops of a station called the same. There are likely to be many stations of the same name on the map. That's the reason I need the train limit. E.g. there may be 20 stations called "Iron Ore - Load", 40 stops with the same name. Several smelters that have an ore in and plate out stations. Many stops with "Iron Plate - Unload". With the trains being the full height of the map minus the west-east tracks I don't have space for a waiting bay or anything other. I really want to deliver trains count perfect. I looks so nice if the train network is like a sideways ladder.

I now realize the problem might be much more frequent then I first thought. Once I have more ore mines and produce more than I consume I will have full trains waiting for a destination all over the map. I want to overproduce everything otherwise far off stations would starve. But then when a station needs e.g. Iron Plates and enables the station lots of trains will path to it in the same tick. Having trains target the top and bottom station in the same tick should be the norm, not the exception.
This really helped me picture what you are trying to achieve.

I think the scale of which you build really matters to know if it's doable or not. By that i mean the ressources will be further and further away from the furnaces overtime. I made a picture of a single factory ( or subfactory ) .
distance.png (14.41 KiB) Viewed 1701 times
On the left side you have patches of ressources further and further away. The different subfactory (or sub-subfactory) are labeled with letter. The idea is to have a tech progression, A and B requiring raw materials, like furnaces and refinery, THEN you have the other part of the factory, other leters on the right side of the red cutting line.

The ressources becoming further and further away as time goes, you need to have room in your train station to handle more and more train if things were to stop: stackers. because at first 1 or 2 100 tiles trains would be enough, but if the ressources are 10 times the distance, you'd need 10 times the amount of train running permanently to maintain the same flow of ressources. Which in case of sudden stop would require a proportionnate amount of waiting bay. [ i'm voluntarily ignoring rerouting them to their departure point or anywhere else still filled up]

Even using the train limit this seem true; it would be the situation where the limit has to be 10 trains due to them coming from very far away. And when all 10 are incoming already, suddenly, consumption stops. The case where only 1 train has nowhere to go due to the station being occupied by a train coming from the other direction is just the beginning of the trouble, as you seem to note.

This is not true if we're talking moving copper and iron plate to green circuit assembly or anything that uses intermediate product as input. Once the furnaces and the assemblies are built , the amount of trains carrying ressources will stay the same. For those "more evolved tech", then the sideway ladder seems like it can do the job.

This is what symbolize the red line separating the different modules. it doesn't have to be this way on the map ofc you can have furnaces in different areas. The whole A->F could be just a subfactory, if it takes raw material as input you need to keep room for additionnal waiting bay later and not put them too close to each other. It was only to illustrate the logic. A and B, no ladder, C to F, sideway ladder, why not, if you ok with combinators to stop the stutter ?

If you manage to implement a no stutter version, with countperfect trains, i still can't picture how you deal with the other problems to make the whole factory like a sideway ladder. Maybe i'm just not representing the correct scale in my mind. 128 tiles is very long for a train to me, even if you remove bits north and south, 100+ tile trains are a huuuge pain in ribbons maps i would say, where you inevitably have loads of crossings.

I have fiddle a bit on a 128 tile ribbon world to see, my last played map was a 200 tile wide vertical map. I think i would do train that are a little half of the full height. At least for the raw material, for which the distance/number of trains will increase over time
similadder.png (7.27 KiB) Viewed 1701 times
In green there is room for assemblies or furnaces. the orange area are 2 waiting bays. This station have 4 total, 2 from each direction ,and they are vertical, so it doesn't take too much space to add more when ressources are further and further away and you need to increase the limit. Also train coming from both direction unload to the same station, but it's easy to put down 2 parralel unloading stations utilizing the same waiting bay if you have different input you can even put 3 or 4 horizontal unloading. All the different trains would wait vertically on their half side of the map, you can even plop down train stop on the vertical portion to guide the trains better with a limit of 1 per bay instead of like 2 3 4 on the main stop as time goes to ease the repartition of train over several stops named the same.

Another dimension i didn't mention on which you can play is the difference between the amount of time it requires to unload the material, and the amount of time required to consume it. If you have a 12 wagon train of iron ore unloaded onto only 1 yellow belt, you need a train every 30 minutes or so. That's a way to partially neglect what i've just said

Re: How to use the train limit with double headed trains/stations

Posted: Thu Oct 07, 2021 9:36 pm
mrvn wrote:
Thu Oct 07, 2021 5:21 pm
Yes, but I can see any way to implement that without adding a combinator, which adds a delay making trains stutter. Each time the train moves 1 tick forward. If it keeps happening to the same train over and over, e.g. it's the only one that targets the bottom station, eventually the train will stutter out of it's resting station and block the main traffic lane.

Note: unlike other entities it seems the train stop sees the signals it outputs itself. The even see the red and green wire signal they output separately. So a train stop with train count C=1 with 2 wires sees C=2. So I can have: C=0 no train, C=1 other stop, C=2 this stop, C=3 both stops. But then I need one station to enable on C != 1 and the other on C=0 or C=2.
I haven't tried this ingame but I think you can do this without any arithmetic/decider combinators due to the property you note of them seeing their own signals.

Set one station to output train count as A, and the other to output it as B. Connect them to each other and add a constant combinator set to B=1. Set station A to be enabled if B=1. Set station B to be enabled if B > A.

If there's a train enroute to A then A and B will both be 1 and B will be disabled. If there's a train enroute to B then B will be 2 and A will be disabled. If they both get a train enroute on the same tick then A will be 1 and B will be 2; A will be disabled but B will stay enabled.

This approach of comparing two signals to each other but biasing it in one direction with a constant combinator to break ties is one that I've used before in other contexts, but didn't remember until now

Re: How to use the train limit with double headed trains/stations

Posted: Thu Oct 07, 2021 10:48 pm
mrvn wrote:
Thu Oct 07, 2021 6:22 pm
I don't think there is a solution to this problem.
Wait, wait, wait, wait wait, ... .

In my first solution I was focused on the example given by you. Two trains and not a problem if one of them moves slightly, before it actually can go to the target station.

With the bigger picture of an arbitrary number of waiting trains in mind, I have another concept for a solution.

The problem is, that both stops of a station are enabled at the same time. Two trains can target the two stops of the station, start moving slightly, before one stop gets disabled and the associated train will stop again. Losing often enough, a train will pass the next track signal and cause a jam.

So, having both stops enabled at the same time is a no go for any solution. But how can both stops be made usefull then, I asked myself.

My simple answer is, just enable them alternatingly. For a period of time/an ammount of ticks to be determined. If the train count after that period is still 0, disable it and enable the other stop. Repeat. If the train count becomes 1 within that period, keep that stop enabled, the other one disabled and wait until the train has left the station. Repeat.

That way only a single train should ever target a double headed station. Because there is only one stop ever enabled in a double headed station.

Re: How to use the train limit with double headed trains/stations

Posted: Thu Oct 07, 2021 11:47 pm
mmmPI wrote:
Thu Oct 07, 2021 9:27 pm
This really helped me picture what you are trying to achieve.

I think the scale of which you build really matters to know if it's doable or not. By that i mean the ressources will be further and further away from the furnaces overtime. I made a picture of a single factory ( or subfactory ) .distance.png

On the left side you have patches of ressources further and further away. The different subfactory (or sub-subfactory) are labeled with letter. The idea is to have a tech progression, A and B requiring raw materials, like furnaces and refinery, THEN you have the other part of the factory, other leters on the right side of the red cutting line.

The ressources becoming further and further away as time goes, you need to have room in your train station to handle more and more train if things were to stop: stackers. because at first 1 or 2 100 tiles trains would be enough, but if the ressources are 10 times the distance, you'd need 10 times the amount of train running permanently to maintain the same flow of ressources. Which in case of sudden stop would require a proportionnate amount of waiting bay. [ i'm voluntarily ignoring rerouting them to their departure point or anywhere else still filled up]

Even using the train limit this seem true; it would be the situation where the limit has to be 10 trains due to them coming from very far away. And when all 10 are incoming already, suddenly, consumption stops. The case where only 1 train has nowhere to go due to the station being occupied by a train coming from the other direction is just the beginning of the trouble, as you seem to note.
That's picture is nearly right. Except ore patches aren't just on one side. They are spread all along the ribbon. So I build the sub factories between ore patches. As I'm playing with mods including RSO I also have more types of ores and some only appear further away from the start and are only needed for more advanced techs. And lots of fluids and intermediates. Also lots of loops where waste products of later stages need to be fed back into earlier stages. So I will have tons of trains going back and forth. It's not a straight shot from ore to rocket.

My trains are LLCCCCCCCCC>L>L so they carry quite a load. My subfactories are designed to be rather thin and slow. Meaning only a few furnaces or assembler per wagon. I'm not going to max out throughput with blue belts and such. Each subfactory shouldn't need a train more than every 10 minutes per station. I rather build 10 small smelters than one that needs tons of trains. Next time I need a new furnace I will probably build it bigger but give it 2 or 4 ore unloading stations. That way the 10 minutes per station remains but with 4 stations it's 4 times the throughput. A train can go a long way in 10 minutes so I'm not too worried that my ore patches are going to be too far away from a smelter to keep it running. If it eventually happens I can always destroy the old smelter and create a new one nearer to the new ore fields.

For more advanced products I will use shorter trains while trying to keep it to the same 10 minutes interval.
mmmPI wrote:
Thu Oct 07, 2021 9:27 pm
Another dimension i didn't mention on which you can play is the difference between the amount of time it requires to unload the material, and the amount of time required to consume it. If you have a 12 wagon train of iron ore unloaded onto only 1 yellow belt, you need a train every 30 minutes or so. That's a way to partially neglect what i've just said
I have 9 wagon trains, 2 locomotives each end. The basic setup I start with is 18 assembler/chemical plants/ore crusher or 27 furnaces (furnaces are smaller), so 2 or 3 per wagon. That gives a single vertical line of assemblers or furnaces. Input comes from the left, output goes to the right. Refineries are bigger fitting just 9 per train.

If something gets too slow I can scale that up by using more buildings per wagon or condensing the output into smaller trains. If I need more throughput than the 10 minutes per train then it's time to build a second sub factory. The one station I've build that needs refineries so far I made with 3 rows of 9 refineries. It's splits air into nitrogen and carbon dioxie (Nullius mod). I already know I need a lot of CO2 and the recipe was rather slow.

Re: How to use the train limit with double headed trains/stations

Posted: Thu Oct 07, 2021 11:55 pm
Impatient wrote:
Thu Oct 07, 2021 10:48 pm
mrvn wrote:
Thu Oct 07, 2021 6:22 pm
I don't think there is a solution to this problem.
Wait, wait, wait, wait wait, ... .

In my first solution I was focused on the example given by you. Two trains and not a problem if one of them moves slightly, before it actually can go to the target station.

With the bigger picture of an arbitrary number of waiting trains in mind, I have another concept for a solution.

The problem is, that both stops of a station are enabled at the same time. Two trains can target the two stops of the station, start moving slightly, before one stop gets disabled and the associated train will stop again. Losing often enough, a train will pass the next track signal and cause a jam.

So, having both stops enabled at the same time is a no go for any solution. But how can both stops be made usefull then, I asked myself.

My simple answer is, just enable them alternatingly. For a period of time/an ammount of ticks to be determined. If the train count after that period is still 0, disable it and enable the other stop. Repeat. If the train count becomes 1 within that period, keep that stop enabled, the other one disabled and wait until the train has left the station. Repeat.

That way only a single train should ever target a double headed station. Because there is only one stop ever enabled in a double headed station.
I thought of that too. But every station connects the top and bottom tracks. As such a train can do a U-turn by going through any of the stations, it's just costly so trains try to avoid it (1000 points for going through a train stop). If a train is west of the destination then it wants to go to the bottom stop. But if you only enable the top stop then it will move past the station, make a U-turn and go to the top stop. Trains would go to the wrong station and that would increase the congestion on the rails. If I wanted to do U-turns I could just use single headed stations.

Re: How to use the train limit with double headed trains/stations

Posted: Fri Oct 08, 2021 12:08 am
torne wrote:
Thu Oct 07, 2021 9:36 pm
mrvn wrote:
Thu Oct 07, 2021 5:21 pm
Yes, but I can see any way to implement that without adding a combinator, which adds a delay making trains stutter. Each time the train moves 1 tick forward. If it keeps happening to the same train over and over, e.g. it's the only one that targets the bottom station, eventually the train will stutter out of it's resting station and block the main traffic lane.

Note: unlike other entities it seems the train stop sees the signals it outputs itself. The even see the red and green wire signal they output separately. So a train stop with train count C=1 with 2 wires sees C=2. So I can have: C=0 no train, C=1 other stop, C=2 this stop, C=3 both stops. But then I need one station to enable on C != 1 and the other on C=0 or C=2.
I haven't tried this ingame but I think you can do this without any arithmetic/decider combinators due to the property you note of them seeing their own signals.

Set one station to output train count as A, and the other to output it as B. Connect them to each other and add a constant combinator set to B=1. Set station A to be enabled if B=1. Set station B to be enabled if B > A.

If there's a train enroute to A then A and B will both be 1 and B will be disabled. If there's a train enroute to B then B will be 2 and A will be disabled. If they both get a train enroute on the same tick then A will be 1 and B will be 2; A will be disabled but B will stay enabled.

This approach of comparing two signals to each other but biasing it in one direction with a constant combinator to break ties is one that I've used before in other contexts, but didn't remember until now
It's too late tonight to try but that sounds possible.

It might still not be enough. I don't know how fast stations disable and stop trains. If it's in the same tick then OK. But if it only stops the train the next tick then that doesn't solve the problem. It would make sense that the station gets a train and changes its output but only on the next tick it gets disabled. Avoids problems with the status of a station changing multiple times per tick. From my stuttering example I know there is a delay either in the station or the trains.

So your solution might make it so stop B will always win when 2 trains path the station but the loosing train would still move 1 tick forward. Loose often enough and it drifts into traffic.

I will build a more elaborate testing setup over the weekend. This needs more trains, stations and items to transferre to be realistic. Need to disable the station while it has enough items buffered too.

Re: How to use the train limit with double headed trains/stations

Posted: Fri Oct 08, 2021 12:10 am
Yes, it might still take one tick for the disabling to take effect if that's how the engine works and if so then there's no way to entirely prevent that just by disabling the stations on demand like this, but this setup if it works should be the shortest possible delay.