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

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
User avatar
Impatient
Filter Inserter
Filter Inserter
Posts: 843
Joined: Sun Mar 20, 2016 2:51 am
Contact:

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

Post by Impatient »

mrvn wrote: ↑
Thu Oct 07, 2021 11:55 pm
... As such a train can do a U-turn by going through any of the stations, ... . 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. ...
Ah yes, they can also go past that station and then turn around. Darn. I only thought about up until the target station.

A silly solution attempt would be to have all stops of emtpy stations alternate in sync AND also the station exit signals of all stations alternate in the same sync. So in one cycle trains find only a path westward to top stations and in the next cycle vice versa. But would that even make a difference? Assuming there is a large number of trains on the westward track and a lot of red signals, one more would not do the trick. I have no in depth knowledge about the pathing penalty system. Not to mention that trains, ready to go east, would have to wait for the next cycle. Pro: You would only need one meta alternator for the whole map. ;)

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

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

Post by mrvn »

Impatient wrote: ↑
Fri Oct 08, 2021 12:51 am
mrvn wrote: ↑
Thu Oct 07, 2021 11:55 pm
... As such a train can do a U-turn by going through any of the stations, ... . 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. ...
Ah yes, they can also go past that station and then turn around. Darn. I only thought about up until the target station.

A silly solution attempt would be to have all stops of emtpy stations alternate in sync AND also the station exit signals of all stations alternate in the same sync. So in one cycle trains find only a path westward to top stations and in the next cycle vice versa. But would that even make a difference? Assuming there is a large number of trains on the westward track and a lot of red signals, one more would not do the trick. I have no in depth knowledge about the pathing penalty system. Not to mention that trains, ready to go east, would have to wait for the next cycle. Pro: You would only need one meta alternator for the whole map. ;)
A red signal just has a high cost. Trains still plan to path through them if there is no cheaper way. And once they picked a station they stick to that unless it gets disabled. So no, that wouldn't help. If the only available station needs an U-turn through another station and through red signals then the train will take that path and wait on the signal. If it's blocked by a red signal long enough it tries to find another way but that's it. I don't think it ever changes stations unless it gets into a no-path situation.

But maybe playing with the signals has merit. A train won't move forward even for a single tick if it's waiting on a red signal. So I could turn all signals of occupied stations red. Then set the train limit of empty stations to 1 and check if any double booking occur. If so disable one of the stops for a tick so the train looses interest. Same time drop the train limit of all stations back to 0. Next tick turn signals of occupied stations green so the trains with a target can leave. Blocking in trains with red signals prevents them from stuttering into the traffic lane and gives time to resolve double bookings.

Doing this once a second should be often enough even if it adds half a second to each train ride on average.

mmmPI
Filter Inserter
Filter Inserter
Posts: 660
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

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

Post by mmmPI »

mrvn wrote: ↑
Fri Oct 08, 2021 12:08 am
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.
torne wrote: ↑
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.
I'm pretty sure you have at least 2 ticks when the station opens maybe 3; there is a delay on the train, first tick of new station enabled the train notices it but do not move yet, next tick the pathfinding request is issued, train still doesn't move, 3rd tick the train start to move if the station is still open. I had played with that some time ago :viewtopic.php?t=72635.

If a station is open 2 ticks, then closed 1 tick, then again open 2 tick, then closed 1 tick, a static train heading towards it never has time to start moving.
Not sure how it translate for your case.




Apart from that, 9 wagon trains, 1 per 10 minutes, make sense, that's a scale that intuitively doesn't hurt my brain anymore :),to me it feels the same order of magnitude than 30 minutes compared to like 25 sec which i'm more familiar to and wrongfully assumed you'd be close to.

I'm not familiar with Nullius mod, but feedback loop as i picture it from bob-angel with waste water for example could be handled the same way as regular assembly that have intermediate as output, the ratio of the buildings is not going to change once it's built, same for the number of train. Instead of schematically trains being filled up when going east, and empty when going west, to match previous example it would just be the opposite.

If you build your subfactory between ore patches, and one of them deplete, it's ok because will have room to make a waiting bay in case you need 2 trains to fetch ressources if it's required because the replacement patch is far away. Or if your assembly line are thin, you may just to do, as you say for furnaces, just remove and build somewhere else. It just may break other steps in the chain if it was more interconnected than just the furnaces though.
mrvn wrote: ↑
Thu Oct 07, 2021 11:47 pm
For more advanced products I will use shorter trains while trying to keep it to the same 10 minutes interval.
Makes total sense to have different approach for raw material and intermediates, and refined intermediates, especially the one you mention.

I still can't picture what the train that get its path cancelled should do. Where is it gonna wait ? or do you just expect it to find another train stop somewhere else on the map and reroute it while still filled up ?

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

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

Post by mrvn »

mmmPI wrote: ↑
Fri Oct 08, 2021 11:38 am
I still can't picture what the train that get its path cancelled should do. Where is it gonna wait ? or do you just expect it to find another train stop somewhere else on the map and reroute it while still filled up ?
That's the thing. The train that gets cancelled must remain in its original station. A train must never be cancelled while on route or it has nowhere to go and blocks traffic.

But just because a train is in the original station doesn't mean it is at one of the stops. Haven't checked but at least I think a train with "Destination full" which might have moved a few ticks doesn't still count towards the train limit of the last stop. So more logic there to keep the train limit = 0 as long as a train is within the rail block of the station.

farcast
Inserter
Inserter
Posts: 42
Joined: Fri Jul 06, 2018 8:25 am
Contact:

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

Post by farcast »

You could periodically switch which stop gets the train limit signal, and use train count to pause the clock. Maybe also include a gap where neither station gets it to give time for the train count signal to update. No disabling stops, so no stutter, and there won't be a situation where both stations are receiving a train.
Efficient inefficient design.

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

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

Post by mrvn »

farcast wrote: ↑
Fri Oct 08, 2021 8:20 pm
You could periodically switch which stop gets the train limit signal, and use train count to pause the clock. Maybe also include a gap where neither station gets it to give time for the train count signal to update. No disabling stops, so no stutter, and there won't be a situation where both stations are receiving a train.
That just leads to U-turns because when only the sub-optimal station is activated the train will path through another station to make an U-turn and arrive at the stop from the other direction.

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

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

Post by mrvn »

I've made a better test world to play with this (savegame attached):
train-station-fight.png
train-station-fight.png (4.63 MiB) Viewed 68 times
There are three test stations for unloading on the concrete all with the same name. Left and right of the concrete are the loading stations that would be e.g. ore mines.

For all stations a green LED means the station is ready for a train to arrive. Meaning loading stations have coal and unloading stations need coal. A yellow light means a train is on the way to the station. For the unloading stations there is also a red light that shows when 2 trains are targeting the same station. That's the first error that is to be fixed. Last there are blue lights next to train stops to show if the stop is enabled (where there is logic to disable the stop). Left and right on the outside are rails for a U-turn so trains will not try to go through a blocked station and deadlock. Any train taking a U-turn will be held for a while to simulate this being a bad idea. U-turns, red lights, trains stuttering or trains parking on the traffic lane with "Destination full" are to be avoided.

From right to left the 3 unloading stations are:

right most: no control logic at all
middle: disable stop if other stop has a train, MAJOR stuttering for trains
left most: The idea to prefer the top station with T>B logic and constant combinator to offset the T.
torne wrote: ↑
Thu Oct 07, 2021 9:36 pm
Idea for left most station


That is as far as I've come implementing ideas from the past days when I noticed the following:

The left most station becomes ready, needs a train. So two trains will path to the 2 stops of the station. One chooses the red path reaching the train limit for the stop. So the other train chooses the green path using an U-turn. I really want the red path in this case, not the green. But the control logic prefers the top stop. If I reverse that and prefer the bottom stop then the same happens with 2 trains from the right.
bad-u-turn.png
bad-u-turn.png (5.24 MiB) Viewed 68 times
I haven't implemented the idea with jailing trains using circuit controlled signals till a double booking of a station is resolved. Because that wouldn't help in this case. Can't see from the signals the train stop emits if a train is going to U-turn. So I can't disable the station with an U-turn and keep the other train.

So what is left that I could try? Mess with the trains schedule? Have the train leave when "cargo full" AND "circuit condition: G=1" and "cargo empty" AND "circuit condition: G=1". And then when a station needs a train somehow figure out which train to send the G=1 signal?

Maybe encode trains ready to leave as bitfield. The first iron ore sets iron ore=1, second iron ore sets iron ore=2, the third sets iron ore=4, ... That gives me 32 bit for 32 iron ore fields. After that I would need multiple wires. Then each turn the station with highest ID picks a train from the bitfield, enables the right stop and subtrackts the bit from the wire (turning it off). The iron ore field station can detect that and set G=1 to send the train.

Better ideas? Send a blueprint.
Attachments
train-station-fight.zip
Test world
(4.41 MiB) Downloaded 138 times

farcast
Inserter
Inserter
Posts: 42
Joined: Fri Jul 06, 2018 8:25 am
Contact:

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

Post by farcast »

mrvn wrote: ↑
Fri Oct 08, 2021 11:33 pm
farcast wrote: ↑
Fri Oct 08, 2021 8:20 pm
You could periodically switch which stop gets the train limit signal, and use train count to pause the clock. Maybe also include a gap where neither station gets it to give time for the train count signal to update. No disabling stops, so no stutter, and there won't be a situation where both stations are receiving a train.
That just leads to U-turns because when only the sub-optimal station is activated the train will path through another station to make an U-turn and arrive at the stop from the other direction.
Since both stops need to stay enabled, then the only way to avoid stuttering that I can think of is to clock the release of trains to one at a time (per station name, if clock speed is a concern.

Note: a train should only be released if a station is available & the clock says it's its turn.
Efficient inefficient design.

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

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

Post by mrvn »

farcast wrote: ↑
Sat Oct 09, 2021 12:28 am
mrvn wrote: ↑
Fri Oct 08, 2021 11:33 pm
farcast wrote: ↑
Fri Oct 08, 2021 8:20 pm
You could periodically switch which stop gets the train limit signal, and use train count to pause the clock. Maybe also include a gap where neither station gets it to give time for the train count signal to update. No disabling stops, so no stutter, and there won't be a situation where both stations are receiving a train.
That just leads to U-turns because when only the sub-optimal station is activated the train will path through another station to make an U-turn and arrive at the stop from the other direction.
Since both stops need to stay enabled, then the only way to avoid stuttering that I can think of is to clock the release of trains to one at a time (per station name, if clock speed is a concern.

Note: a train should only be released if a station is available & the clock says it's its turn.
With 1000 trains that would be > 5 minutes to go through all the trains. Assuming consecutive train IDs. See my last post. Trains with different destinations can be done in parallel and we can be smart finding the train to release.

But oh what a combinator mess this would be ....

Post Reply

Return to β€œGameplay Help”