Page 1 of 1

Train Interrupt Condition for "Trains with this stop"

Posted: Wed Oct 23, 2024 4:53 am
by bkrauscs
TLDR
It would be cool if an interrupt condition could be used to control the number of trains with a route on a particular station. This would allow trains to reserve a route for themselves, keeping the number of trains responding to an interrupt to a reasonable amount.
Motivation
I've been diving deep into the new train interrupt system which has been getting the gears in my mind turning. What I'm trying to build is a group of trains that can address any needs in my factory without any being specifically allocated to a particular route. What I have is ~15 (for now) trains in the same group with a schedule that is only go to Depot and wait 30 seconds. Then, for my factories, each consumer station can emit a signal to a circuit network for the type of item it is requesting if it is low. I have interrupts on those signals, which will task a waiting train to get a resource from a producer and supply it to the requesting consumer.

The problem: If there are 15 bored trains waiting in the Depot, and a consumer of Iron Plates sends a signal, then 15 trains will go to the Iron Plate supply and load up, then wait because the consumer has a train limit of 1 and one of the other bunch has gotten there first. This blocks the producer from serving other trains. I also don't need all 15 to go help, just 1 will do.

What I've tried: I have set the train limit on the station to 1, but this causes other trains to wait in the prior station which blocks it. I can set the Depot as an intermediate stop between pickup and dropoff, but this means all routes will include a usually unnecessary pass through the depot, and if any wait there then they're tied up with resources they can't unload. I set the condition on the interrupt to not fire if there is a train at the consumer station, but when the signal is first sent that's not the case and all 15 can acquire the route.

What would be nice: If a condition for interrupts could be added to have a statement of "Trains with this stop" is > X given a stop. This allows me to control how many trains can claim a route, and would let me to service my factory with a very small number of trains using smart circuit signals. I think this seamlessly flows with the current interrupt logic, because once the request has been fulfilled the train no longer has the stop and the count of "Trains with this stop" goes down by 1 and if there is still a consumer need then either that train or another can start the interrupt over.

Re: Train Interrupt Condition for "Trains with this stop"

Posted: Wed Oct 23, 2024 7:11 am
by sarge945
This sounds like a bug/issue with the way train limits work, not something that should necessitate a new condition.

If a stop has a limit of 1, only 1 train should be dispatched to it in the first place.

Re: Train Interrupt Condition for "Trains with this stop"

Posted: Wed Oct 23, 2024 4:34 pm
by sarge945
Okay, I think I may have solved this in some manner using Circuits.

Basically, you need a constant combinator for the train limit (which outputs the preset limit on L), then you need a decider combinator like this:
combinator.png
combinator.png (108.04 KiB) Viewed 1941 times
Where C is the "Read Train Count" variable of the station, L is the limit, and the Station icon is used to enable/disable the station.

Basically the way this works is that, the moment the number of trains with the station as their current destination (C) is greater than or equal to the train limit (L), it disables the station, so whenever a train wants to go there it should automatically prevent any future trains going there.

While I was there I also decided to limit the station to only being enabled when it actually has a worthwhile amount of resources to pick up as well, but this is optional.

This is at the SOURCE station (the pickup), not the destination station, although it would probably work for both

Here's a quick and dirty blueprint for it:



My train network is still relatively small, I had to start a new run for 2.0, but I haven't run into any problems so far using a generic station name like "Item Pickup" for every resource, and interrupts for dropping everything off.

Despite all this, I still feel like train limit should also affect incoming trains as well, so no more trains than the maximum train limit should be able to have the station as a stop at the same time.

For reference, here's my interrupt as well
10-24-2024, 02-37-18.png
10-24-2024, 02-37-18.png (42.16 KiB) Viewed 1940 times

Re: Train Interrupt Condition for "Trains with this stop"

Posted: Thu Oct 24, 2024 12:58 am
by bkrauscs
I'm shooting for a slightly different setup, the merits of which are debatable. I'd like trains to only be in motion if a factory is requesting goods. My interrupt setup (example below) has the conditions that a request for iron ore is on the circuit network, along with the station identifier (0). The other two conditions are guards against showing up somewhere with the wrong stuff. Then, the targets include where to get the items and where to drop it off.
10-23-2024, 17-38-44.png
10-23-2024, 17-38-44.png (546.34 KiB) Viewed 1886 times
Since the measure of "Read train count" is how many trains are going to the station it doesn't do well to block the interrupt on that count since any trains that pick up the interrupt schedule are going to the source first which won't show up in that number. If I block trains to go to the source from the "Read train count" of the source or destination, then I'm limiting the provider (in this example an iron mine) from serving other destinations.

This picture better describes the situation:
10-23-2024, 17-52-53.png
10-23-2024, 17-52-53.png (181.68 KiB) Viewed 1886 times
There is a train limit of 1, which is adhered to, but the Trains with this stop is at 2 and that's what I'm trying to control. The 2nd train is sitting in the iron pickup waiting for this station to be clear, stopping other trains from using the pickup station. I'd rather not have a 2nd train to begin with.

Re: Train Interrupt Condition for "Trains with this stop"

Posted: Thu Oct 24, 2024 4:00 am
by bkrauscs
Actually, thinking about this for an evening I might have it sorted out. It's pretty much what Sarge suggested combined with the FFF posts about the train interrupts using generic filters. The basic method is that consumers emit a 1 signal for the type they need (when stock is low) and producer stops of that type are disabled unless the total number of requests on the network for their produced type is > # trains going to that particular stop (with the separate train limit set to, say, 2).

Say I have a factory that produces iron plates with 2 stops that can load them into trains. If a request comes in for 1 train of iron, then all stops at the producer become enabled. When the first idle train sets a path to the load stop, then all other stops are disabled since all stops at the factory are wired together and share train counts. If another request comes in while the first train is loading, then 2 requests > 1 at the factory, and the 2nd stop becomes enabled again, and so on. When the first train leaves the station after loading, the consumer will subtract the number of trains going to it's stop from the number of requests being emitted, causing the request to be satisfied (unless after offloading there's still low stock).

My interrupt schedule now looks like:
10-23-2024, 20-57-19.png
10-23-2024, 20-57-19.png (275.13 KiB) Viewed 1858 times

Re: Train Interrupt Condition for "Trains with this stop"

Posted: Tue Oct 29, 2024 2:56 pm
by falconfused
I too want this feature. How do we elevate this?
Although I think it would be faster/easier to implement just being able to have train stops output that value on the circuit network. Like it works now with "Trains with this stop - C"

Re: Train Interrupt Condition for "Trains with this stop"

Posted: Mon Nov 18, 2024 10:00 pm
by Tomeamis
I also think this feature would enable much better train management. Unfortunately, because if there are more trains which can both process that interrupt, they will both process it in the same tick, solutions with circuit network won't work, as they always take at least one tick to update the outputs.