How often do trains poll for destinations and interrupts?

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
pfooti
Burner Inserter
Burner Inserter
Posts: 5
Joined: Wed Dec 13, 2017 11:39 pm
Contact:

How often do trains poll for destinations and interrupts?

Post by pfooti »

I'm trying to figure out train timing:

Three trains are at a station in automatic mode, each trying to navigate to another station, but that station currently has limit 0. On tick t_0 the station goes to limit 2. How do the three trains prioritize which two select the new station? How often do the trains poll for station availability, and does the train allocation all start on the same tick? By which tick will the C signal on the target station read 2?

Similarly: a train is at station A (and therefore the C_a signal is 1) and departs for station B. At some point C_b will go to 1 (as the station reads inbound train count). For how many ticks is C_a + C_b not 1? Is there a gap when C_a is zero (assuming we're also reading the parked train count) because the train is "leaving" but C_b hasn't become 1 yet? If I am transmitting C_b on the radar circuit, there'll be at least two ticks in my current design (combinator delay) but are those few ticks enough time for another train waiting for station A to get allocated to it? Will that always happen, or only if that (say) three tick window coincides with the (per the wiki) every-5 seconds polling of the engine?

I'm trying to set up some global demand / satisfaction mapping that puts supply stations in limit 0 mode when there is no global demand. When there is global demand, the stations turn on, ideally with a limit equal to min(global demand, possible station satisfaction) (so if there's demand for 2 trains worth of ore, we send 2 trains to that station). The problem here is that if I set a limit on the number of inbound trains, when the train arrives at the supply station and fills up, it will then depart for the drop station. While it is inbound to the drop station, the train is not counting towards global satisfaction or to local, inbound-to-that-station count (C by default).

What I want to avoid is a stuck train situation, where the first two trains arrive at the supply station and depart to the drop station, and then a third train arrives at supply and gets filled up. At that point it has nowhere to go (the drop station is satisfied and will not accept more trains), so it goes back to the parking lot and waits for a drop station to open up. At some point, all the cargo trains end up in this state in the degenerate case.

I have a couple of solutions to this (frustratingly one of them would be time-sharing on the radar network, but i don't want to put memory cells at each station ... yet), but a lot of them involve delays.
  • When there's a global demand change (and supply stations would activate), delay a little while so that any stuck trains with supply on them route to the demand station instead, so we can unstick the system. This seems to work naturally, even with the very small number of ticks of delay already inbuilt between demand going onto the radar circuit and the supply stations activating.
  • When a supply station calculates its inbound train count, don't reduce the station limit for a little while so that the second or third inbound train will be correctly routed to that supply station.
I can instead just put supply stations at limit 1, which is likely a steady state situation when the base is under load anyway (since I'm either going to overprovision the supply and have excess supply, but demand will only turn on one at a time anyway, or I'll underprovision and only have 1 train of supply at a time). Once there is a lot of horizontal scaling, this does not work (when I have multiple copper plate drops, and they all turn on at the same time). It is also unsatisfying.

So that's what I'm sort of thinking about- I'd like to not recalculate demand / supply levels until I'm pretty sure that all the trains have had a chance to poll. This presupposes an excess of cargo trains- that there's always more trains than active demand, but trains are cheap, and parking lot train stations are plentiful. I guess an even better calculation would be stable - the supply station limits would only change once the supply trains depart.

All of this has gotten me thinking that maybe I need additional circuit network colors to tell the supply stations how many trains are inbound to the drop stations (radar at least would be helpful with blue / purple wires just for segmentation, or like i said, timesharing on the radar) or just run physical wires on my power bus alongside the radar network, but that's fiddly.

I *think* if I can understand the tick timing I can probably work around that.
User avatar
PssX
Inserter
Inserter
Posts: 24
Joined: Tue Mar 01, 2016 9:00 am
Contact:

Re: How often do trains poll for destinations and interrupts?

Post by PssX »

I didn't test it with trains, but you can use Map Editor to be able to set game on pause and to make it advance by a single tick.

Backup your save.
Switch to editor mode: console command "/editor", disables achievements!
Before changing station train limit, pause the game.
Change limit on pause.
Advance to the next game tick.
Still on pause, check GUI of all trains you are interested in.

I think scheduling will be done on the next tick already, but maybe not. Please, write your results if you actually try this.
pfooti
Burner Inserter
Burner Inserter
Posts: 5
Joined: Wed Dec 13, 2017 11:39 pm
Contact:

Re: How often do trains poll for destinations and interrupts?

Post by pfooti »

Good idea, I didn't realize I could just experiment with the editor like that.

There is definitely some strange behavior when a train program has no stops at all (and all the behaviors are interrupt-driven), it doesn't seem to notice interrupt state changes.

But, as long as the train in question is doing something on an automatic drive (including just loitering at a station), it seems that as soon as the destination has room, the next tick the trains (a) have a route and (b) the destination station's C value is updated. This next-tick behavior happens whether the train is programmed to go to the destination on its regular destination list or if the "station has room" interrupt condition became true causing an interrupt stop.

The origin station's C value takes longer to update (it seems like it does not decrease until the departing train has physically moved far enough to make room for the next train to park.
mrvn
Smart Inserter
Smart Inserter
Posts: 5968
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: How often do trains poll for destinations and interrupts?

Post by mrvn »

Afaik all changes happen every tick on the tick. Has been so far at least.

As for interrupts I believe they only ever trigger when the conditions at a station are met:
interrupt.png
interrupt.png (286.74 KiB) Viewed 173 times
So no station, no interrupts. Unless you already are in an interrupt and allow other interrupts to override. Then you could keep the train always on an interrupt and pray it never finishes.
Post Reply

Return to “Gameplay Help”