Spread out trains among stops with shared names by adding a routing penalty per train already heading to a given stop

Post your ideas and suggestions how to improve the game.

Moderator: ickputzdirwech

Post Reply
Super Mikal
Burner Inserter
Burner Inserter
Posts: 9
Joined: Thu May 30, 2019 11:16 am
Contact:

Spread out trains among stops with shared names by adding a routing penalty per train already heading to a given stop

Post by Super Mikal »

(To mods: I butter-fingered the submit button while typing this on my phone. There was no way to open the old post and edit it, and I don't have access to private messages. I hope you understand, and delete the other incomplete post.)
TL;DR
A better built-in mechanism to spread out trains between stops with the same name, without mods or circuitry or configuration.
What ?
Essentially, when a train is selecting which station to go to, add a fixed route penalty for each train already heading for or stopped at a stop. Or possibly even simpler, select the stop with the fewest number of trains heading for or stopped at it.

I would also support and accept a simple round robin selection of stops, which there are also other suggestion posts for already, but the route penalty solution has one advantage in that it won't cause a buildup of trains at the stops with lowest supply.
Why ?
I'm working on a tileable nuclear reactor in sandbox, which is using a fluid-wagon-train-fed water supply. I'll share the save if anyone's interested, but it's still WIP. The trains have a very low margin for unloading time in order to keep the boilers filled with water (which is hardly the only challenge I'm facing...). But the trains tend to favor the nearest station, and end up neglecting the furthest ones, causing the boilers on that side to run dry. This is not a problem that I can solve by simply throwing more trains at it, because that means the rails will just back up a lot more and eventually block the branch-out junction, causing even worse delays.

My current workaround is to have dedicated tracks for each entry point. I'll be honest, I suspect this is required for an additional reason as well, namely capacity. The fluid wagons don't carry that much water. But I like my idea enough to write this post for it, and to see how far I could push it with just one track.

There are already many other ideas and suggestions posted for trains and stops that are similar to mine. But most of them suffer from having large or complex scopes, often involving circuit networks or mod support or lots of customisability.

I'm trying to keep the scope razor-sharp by deliberately avoiding that. I'm not offering a perfect solution to everything, just something that is a clear improvement for everyone and that shouldn't break any existing maps or be an obstacle for future, more advanced features, and that is (what I would consider to be) a fairly small effort to implement.

I looked into accomplishing this with modding, but I couldn't find a way to send a train to a stop by id, only by name. It would be possible to create a naming convention so the mod could understand stops with distinct names as a group and hot-swap a train's schedule when it's about to depart, but I figured I could throw out this idea first.

slippycheeze
Filter Inserter
Filter Inserter
Posts: 587
Joined: Sun Jun 09, 2019 10:40 pm
Contact:

Re: Spread out trains among stops with shared names by adding a routing penalty per train already heading to a given sto

Post by slippycheeze »

Super Mikal wrote:
Fri Aug 30, 2019 6:13 pm
Why ?
I'm working on a tileable nuclear reactor in sandbox, which is using a fluid-wagon-train-fed water supply. I'll share the save if anyone's interested, but it's still WIP. The trains have a very low margin for unloading time in order to keep the boilers filled with water (which is hardly the only challenge I'm facing...). But the trains tend to favor the nearest station, and end up neglecting the furthest ones, causing the boilers on that side to run dry. This is not a problem that I can solve by simply throwing more trains at it, because that means the rails will just back up a lot more and eventually block the branch-out junction, causing even worse delays.
I'd describe this as a "doctor, it hurts when I do this" sort of situation, as in, if it hurts, don't do that. Instead, do one of:
  1. Build in higher tolerances, so that tiny delays while a train repaths from a busy station don't break everything, or
  2. Don't build a system where it is possible for trains to block forever, rather than repath to another station, if the target is busy, or
  3. Build a system that doesn't suffer from multiple trains competing to fill a single target, probably using a transshipping system.
Incidentally, other than the absolute capacity of the track, you *should* be able to solve this with more trains. The fact you can't strongly suggests to me a design error where trains don't hit a repathing condition before they get "stuck" waiting for a stop to clear -- and blocking progress for other trains.

You *should* be hitting the repathing trigger "The train is braking for a signal (chain or regular) it cant reserve and the train is not inside a chain signal block. The train is forced to recalculate its path", "The train has waited at a chain signal for a multiple of 5 seconds", or "The train enters a new rail block and can't reserve the next needed signal (chain or regular). The train is forced to recalculate its path".

Since that'd force a recalculation, you *should* see the train then decide it would rather visit another open station (cost approximately equal to the number of rails) rather than wait here for the station to clear (cost 500, for "station with train in", plus 2 x block length / distance from signal, for a train being there.)

Since this should be happening fairly close to the destination station, you would need to have a pretty long run to the next station before the train *should* choose to stay blocked until the current station frees up.

So ... clearly that isn't happening for you, and I believe you when you say it. I'm much more inclined to ascribe this to a human design error than a bug, though, and neither requires a change to the pathfinder or train schedules to continue to work correctly. Fix that design and you should find the problem goes away™.
Super Mikal wrote:
Fri Aug 30, 2019 6:13 pm
I looked into accomplishing this with modding, but I couldn't find a way to send a train to a stop by id, only by name. It would be possible to create a naming convention so the mod could understand stops with distinct names as a group and hot-swap a train's schedule when it's about to depart, but I figured I could throw out this idea first.
You would have to rename stations, which would incidentally cause all trains heading to that station to repath, in order to achieve this. Train schedules don't support ID based stations, and unless I missed some very indirect work around, trains can't be routed other than to slots in their schedule. You might be able to do something using a temporary station with a custom name, and routing to that, without perturbing the original schedule.

User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12888
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: Spread out trains among stops with shared names by adding a routing penalty per train already heading to a given sto

Post by ssilk »

I would go with the OP.
There is already a (clever) mechanism to spread the trains over the same train stop names. But currently it seems not to be correctly balanced.
I helped me out by adding as many signals as possible in the “waiting zones” of the trains. When a train stands there it seems to add just enough penalty so that another station more far away is preferred.

This points also to the repeated wish, that there are signal-like things, that can add penalty by allowing more or less speed. Makes many sense into many directions.
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...

User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 2420
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: Spread out trains among stops with shared names by adding a routing penalty per train already heading to a given sto

Post by BlueTemplar »

Heh, not even being aware at the time of the various penalties involved, I went with the nuclear option of just disabling the station that was the most filled one.
But this of course involved combinators, and looks like it would scale poorly combinator-complexity-wise with the number of stations involved... unless I missed some trick ?
BobDiggity (mod-scenario-pack)

Super Mikal
Burner Inserter
Burner Inserter
Posts: 9
Joined: Thu May 30, 2019 11:16 am
Contact:

Re: Spread out trains among stops with shared names by adding a routing penalty per train already heading to a given sto

Post by Super Mikal »

slippycheeze wrote:
Fri Aug 30, 2019 7:04 pm
Incidentally, other than the absolute capacity of the track, you *should* be able to solve this with more trains.
...
I'm much more inclined to ascribe this to a human design error than a bug, though, and neither requires a change to the pathfinder or train schedules to continue to work correctly. Fix that design and you should find the problem goes away™.
Probably! :lol: But I think I'm at my mental limit on my current build. I've tried to exploit those rules, but never got the trains to behave. I think I read somewhere that there's a difference between what will make trains try to repath to their current destination versus choosing a different destination. I'll post a screenshot and the save file to show what I have, just need to dig up the correct older save.
slippycheeze wrote:
Fri Aug 30, 2019 7:04 pm
Super Mikal wrote:
Fri Aug 30, 2019 6:13 pm
I looked into accomplishing this with modding, but I couldn't find a way to send a train to a stop by id, only by name. It would be possible to create a naming convention so the mod could understand stops with distinct names as a group and hot-swap a train's schedule when it's about to depart, but I figured I could throw out this idea first.
You would have to rename stations, which would incidentally cause all trains heading to that station to repath, in order to achieve this. Train schedules don't support ID based stations, and unless I missed some very indirect work around, trains can't be routed other than to slots in their schedule. You might be able to do something using a temporary station with a custom name, and routing to that, without perturbing the original schedule.
No, the idea was to work around this limitation by having unique but similar stop names and actually rewriting the train's schedule. Suppose the stops are named "Water Unload [1]", "Water Unload [2]", "Water Unload [3]" and so on. The game considers them distinct stops, and when you set up a new train's schedule, you add any single one of the stops to it. When a train departs or wants to reroute (which I think have signals mods can listen for), and its next stop is one of these stops, for example "Water Unload [2]", the mod can check every stop that follows the naming pattern, and rewrite the train's schedule to swap out that stop with the one with the least trains heading for it (which the mod can simply track internally itself), for example "Water Unload [1]".


User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 2420
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: Spread out trains among stops with shared names by adding a routing penalty per train already heading to a given sto

Post by BlueTemplar »

Super Mikal wrote:
Sat Aug 31, 2019 10:27 am
I think I read somewhere that there's a difference between what will make trains try to repath to their current destination versus choosing a different destination.
Yes, the wiki seems to make a distinction between revalidation and recalculation ?
https://wiki.factorio.com/Railway/Train_path_finding
BobDiggity (mod-scenario-pack)

Post Reply

Return to “Ideas and Suggestions”