Request: Max number of trains for stations

Post all other topics which do not belong to any other category.
User avatar
ptx0
Smart Inserter
Smart Inserter
Posts: 1507
Joined: Wed Jan 01, 2020 7:16 pm
Contact:

Re: Request: Max number of trains for stations

Post by ptx0 »

foamy wrote: Thu Jun 25, 2020 8:12 pm The benefit specifically is so that, should a stop open up, the train that goes to it comes from, e.g., it's stacker, and not from half-way across the base
why are you setting yourself up for this to even happen at all?

cheeeeeesus crust.

you could use IRON DEPOT WEST, IRON DEPOT EAST. make sure they are all assigned to their specific provider. keep train limit at 1 on both.

problem solved.

don't use generic stackers all over the map and expect the game pathfinder to hold your hand.
foamy
Filter Inserter
Filter Inserter
Posts: 432
Joined: Mon Aug 26, 2019 4:14 am
Contact:

Re: Request: Max number of trains for stations

Post by foamy »

ptx0 wrote: Fri Jun 26, 2020 10:48 pm
foamy wrote: Thu Jun 25, 2020 8:12 pm The benefit specifically is so that, should a stop open up, the train that goes to it comes from, e.g., it's stacker, and not from half-way across the base
why are you setting yourself up for this to even happen at all?

cheeeeeesus crust.

you could use IRON DEPOT WEST, IRON DEPOT EAST. make sure they are all assigned to their specific provider. keep train limit at 1 on both.

problem solved.

don't use generic stackers all over the map and expect the game pathfinder to hold your hand.
Problem *not* solved if there's more than one train. 'Generic stackers all over the map' don't enter into it; the behaviour could occur on a simple point-to-point routing as long as more than one path is available to the destination station -- i.e., a standard stacker.

Besides which, I would point out that the entire reason for this is so that enabling and disabling stations doesn't give you swarm behaviour, and that rather implies you're doing an N-to-N network of some variety since there's very little reason to do so (v. closing signals) if you're just doing point-to-point.
foamy
Filter Inserter
Filter Inserter
Posts: 432
Joined: Mon Aug 26, 2019 4:14 am
Contact:

Re: Request: Max number of trains for stations

Post by foamy »

boskid wrote: Fri Jun 26, 2020 10:34 am Even if this approach would be benefitial, i do not want it.
1/ It still needs some estimate of path cost for all trains that are heading for given station but other train stop. Extra pathfinder that would work in opposite direction.
2/ issue would happen only when a stacker has its own train stop trap (probably with limit set to reduce amount of trains heading to stacker). It would be possible to design loading/unloading in a way that trains heading to load/unload would park in stacker but with a path to the station directly. That way train in stacker would already be assigned to some train stop so would be the first one to arrive, and this would still allow changing train stop when other one would not be full
3/ It would also be possible in other way with CN magic: when an unload/load train stop is not full, by CN force some trains in stacker to repath by reducing limit of trains in stacker.

Corner case for pulling trains to a given train stop would be long rail segment with junction and 2 train stops with same name and equal penalty, both set with limit of 1. When train would repath from train stop A to train stop B, A would become non-full and would want to repath some train to it. This would force train to go to train stop A and now train stop B is non-full. I want to avoid such loops.
Oh. Of course. Pathing terminates as soon as it finds a minimum path, which should generally not be after it's found any longer path. Therefore it would need to rerun the pathfinder every time it hit a blocked minimum station. That *would* be extra work.

For the corner case... why would a train repath from A to B? The only things that can force that are a stop disablement, station rename, or a break in the track; signal-closing doesn't do it, as the train will still attempt to path as close as possible to the target stop. Even in the new case, where there could be, say, a circuit-driven reduction in the number of trains allowed, all of the scenarios where a train changes its choice of station midstream involve that target station being inaccessible in some way. In which case, having pathed away from it... the train won't path *back to it* unless its *new* target becomes disabled.

What happens now if there's a pathfinding tie, anyway?
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 3272
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Request: Max number of trains for stations

Post by boskid »

foamy wrote: Sat Jun 27, 2020 6:30 am Besides which, I would point out that the entire reason for this is so that enabling and disabling stations doesn't give you swarm behaviour,
Right, it is to solve the issue of the swarm. Lets not go into other possible problems it *could* solve with enough CPU power, like choosing closest trains first.

Only part that would be required for trains to work properly with train stop limits is to recalculate path for trains that are going to station A for which every train stop is already full - in that case train would enter "no path" and so when any train stop becomes not full, some trains have to recalculate path because in that state they will not repath spontaniusly. Unless there would be a easy ("non cpu heavy") solution, some heuristic maybe it could be considered to be implemented when train stop limit would, but without that it is not going to happen - in case of a train that already has a path, it will be able to change station only due to spontanius repath and so there would be no guarantee about which train would be heading for train stop - it could be one from the stacker or could be one quite far away. Easier solution is to have a stacker designed in a way that multiple trains sitting here are already having a path to a goal train stop but are not leavins stacker due to chain signals.
foamy wrote: Sat Jun 27, 2020 6:40 am For the corner case... why would a train repath from A to B? The only things that can force that are a stop disablement, station rename, or a break in the track; signal-closing doesn't do it, as the train will still attempt to path as close as possible to the target stop. Even in the new case, where there could be, say, a circuit-driven reduction in the number of trains allowed, all of the scenarios where a train changes its choice of station midstream involve that target station being inaccessible in some way. In which case, having pathed away from it... the train won't path *back to it* unless its *new* target becomes disabled.
For this i had to have some letters to refer to different train stops, even when they would belong to the same station by name. In that sense, they both would be possible target train stop when heading for a station lets say "X".
Pathfinder has its specific expansion order in case of ties, it is required for deterministic results. It could be that train was heading to train stop B while natural goal would be a train stop A due to expansion order. It only requires a train leaving from train stop A to get penalty down to equal and when train would repath for any reason madness would begin. Most likely such case would not be implemented as "forcing train to go to trains top A or B" but rather simply saying to train "hey, you may be interested in repathing" and looking which train stop it chooses on its own without forcing any specific goal since that forcing decision would not be persistent.
foamy
Filter Inserter
Filter Inserter
Posts: 432
Joined: Mon Aug 26, 2019 4:14 am
Contact:

Re: Request: Max number of trains for stations

Post by foamy »

boskid wrote: Sat Jun 27, 2020 6:56 am For this i had to have some letters to refer to different train stops, even when they would belong to the same station by name. In that sense, they both would be possible target train stop when heading for a station lets say "X".
Yes, I'd understood that. But current behaviour is that if you have two stops of the same name, a train that sets out for one or the other will only swap over if its target station becomes completely unavailable: disabled by circuit or removed from the network altogether by rename, track disconnection, or deconstruction. Temporary effects like a closed signal do not trigger it, and I don't believe another station being turned on in the meantime does either. So a train that alters its path from one to the other cannot then alter its path back to the first.
User avatar
Nosferatu
Filter Inserter
Filter Inserter
Posts: 253
Joined: Fri Jan 20, 2017 4:48 pm
Contact:

Re: Request: Max number of trains for stations

Post by Nosferatu »

From: https://wiki.factorio.com/Railway/Train ... ath_events
The train wants to depart from a signal (chain or regular) that it stopped at. The train is forced to recalculate its path
So I think at the moment every time a train stops at a red light it can choose a new station.
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 3272
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Request: Max number of trains for stations

Post by boskid »

foamy wrote: Sat Jun 27, 2020 7:43 am But current behaviour is that if you have two stops of the same name, a train that sets out for one or the other will only swap over if its target station becomes completely unavailable: disabled by circuit or removed from the network altogether by rename, track disconnection, or deconstruction.
Wrong. For example: train is unable to reserve chain signal due to train that entered into block somewhere ahead. When a train repaths, it forgets everything about old path, including train stop it was heading to and computes fresh path with new state of all penalties. In this example, train will choose upper path because lower path has now higher penalty due to train that entered a block.
repath-to-different-train-stop.gif
repath-to-different-train-stop.gif (47.82 KiB) Viewed 4288 times
DerGraue
Fast Inserter
Fast Inserter
Posts: 151
Joined: Mon May 30, 2016 12:12 pm
Contact:

Re: Request: Max number of trains for stations

Post by DerGraue »

@boskid
I wrote this before and I think it is very important, so I write it again:

this system will only work if the trains that are assigned to a "limited" station can remember that specific station (call it "station ID") regardless of the name and will only go to that specific station once it has been set as a target. The target station is calculated only once, it is based on the "max train value" and it does not recalculate the target station if the value for that station changes.

This prevents random target switching of assigned trains and addresses many of previously mentioned issues, for example deadlocks, endless loops or trains going to one stacker and then pathing to a station that does not belong to that specific stacker.
The only case when the target station is deleted for the train, is if: the station is deconstructed, the train is set to manual/deconstructed or if the station is closed with a combinator signal.


This requires some changes in the code but if it is not done you will always be stuck with edge cases (like you mentioned in your posts) that will make this idea invalid and you are stuck explaining basic pathfinding.
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 3272
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Request: Max number of trains for stations

Post by boskid »

DerGraue wrote: Sat Jun 27, 2020 10:56 pmthis system will only work if the trains that are assigned to a "limited" station can remember that specific station (call it "station ID") regardless of the name and will only go to that specific station once it has been set as a target. The target station is calculated only once, it is based on the "max train value" and it does not recalculate the target station if the value for that station changes.
Such approach would require complete rewrite of trains logic since trains do not remember which train stop they were heading to. In such case i am not going to implement that at all.

Prototype i did long time ago (was it january?) it did work quite nice with counting amount of trains heading for each train stop. When train stop was full and train heading to it was repathing, it first cleared path making train stop not full and this allowed train to find a path again to the same train stop it was heading already, but with an option of finding a path to another non full train stop - and thus allowing for train stop switching. No need for rewriting trains logic.

Btw, i am trying to stick to precise terminology based on internals: train stop is an entity, one particular place on map with assigned station. Station is just a name and may be assigned to multiple train stops. Train has a station in its schedule and is allowed to choose any train stop from a given station.

-- edit:
There is one inconsistency between some of posts here. Since there is request for repathing a train that is closer to loading/unloading train stop, that means request is to force train already in stacker that was heading to a trap train stop, to now repath to another train stop (same station). When a train stop pinning would be implemented, such stacker would immediately get stuck since trains which would enter it would never be able to leave it. If train would be in a stacker behind a chain signal with a path to a destination train stop, there would be no issue to start with since train would already have reserved a slot in train stop and would not need any repath.
DerGraue
Fast Inserter
Fast Inserter
Posts: 151
Joined: Mon May 30, 2016 12:12 pm
Contact:

Re: Request: Max number of trains for stations

Post by DerGraue »

boskid wrote: Sat Jun 27, 2020 11:09 pm There is one inconsistency between some of posts here. Since there is request for repathing a train that is closer to loading/unloading train stop, that means request is to force train already in stacker that was heading to a trap train stop, to now repath to another train stop (same station). When a train stop pinning would be implemented, such stacker would immediately get stuck since trains which would enter it would never be able to leave it. If train would be in a stacker behind a chain signal with a path to a destination train stop, there would be no issue to start with since train would already have reserved a slot in train stop and would not need any repath.
Of course there are inconsistencies between our posts, we are all different people with different expectations and ideas.
Btw, this is a very nice example where your own prototype can get stuck. Because you allow, after the pinning is done, to change the pathing to a different train stop (same station) in case of a change of the max train value.

Such approach would require complete rewrite of trains logic since trains do not remember which train stop they were heading to. In such case i am not going to implement that at all.
That's kinda what I feared and understandable, although I am wondering why it is such a huge "rewrite"? All you need to do is add a variable "pinned train stop ID" to each train.

Normally this is set to nil or 0 ( -> no change to the train behavior), but if the train is being used for a pinned train stop it is set to the train stop ID. The only change to the train logic is that if there is a "pinned train stop ID" it needs to go to that specific train stop with that ID, instead of the station. And the "pinned train stop ID" needs to be deleted after the train leaves the station, or the the station gets deleted or disabled.

I am just wondering why this is such a huge change, after all you already changed the pathfinding algorithm from Dijkstra to A*, which must have been on a completely different level, at least compared to this feature.
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 3272
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Request: Max number of trains for stations

Post by boskid »

DerGraue wrote: Sun Jun 28, 2020 12:25 am Btw, this is a very nice example where your own prototype can get stuck. Because you allow, after the pinning is done, to change the pathing to a different train stop (same station) in case of a change of the max train value.
My prototype does not use pinning because it was not required at all. It was relying on a pathfinder to choose lowest cost path with deterministic behavior around ties and not forcing train into going to any specific train stop. Trains were able to choose train stops (from same station) freely as long train stop is not full. And it was working flawlessly since train before recalculating path was first releasing a train stop it was heading to so even if train stop was full, when a train heading to it was repathing, it was seeing a train stop with one last empty slot.
DerGraue wrote: Sun Jun 28, 2020 12:25 am although I am wondering why it is such a huge "rewrite"? All you need to do is add a variable "pinned train stop ID" to each train.
It is never "just add a variable". There would be a lot extra tests, new cases to handle (when should the train stop pinning be applied? what if pinned train stop is disabled, should train unpin and choose different train stop from same station? what if path to a pinned train stop would be unreachable due to rails removed, should train enter no-path? how would player be told train is pinned? what would be a value added of train stop pinning?, would there be some exceptions where train would be allowed to repath to a different train stop even when there is pinned train stop?). I see no point in train stop pinning. Even if it would be suggested that pinning should happen only for train stops with limits, then stacker train stop trap would not be allowed to use trains limit since trains would be pinned to trap train stop and would be unable to leave such stacker. If trains limit would not be used in a trap train stop, then there would be a horde of trains heading to a stacker which this feature was supposed to prevent. Repath loop would be only an issue in case of forcing train to find a path to a choosen train stop since it would switch from "low energy state" (path with lowest cost where due to repath, it would still choose the same path) into "high energy state" (when under repath, train will choose different path up to a different goal train stop).
DerGraue wrote: Sun Jun 28, 2020 12:25 am I am just wondering why this is such a huge change, after all you already changed the pathfinding algorithm from Dijkstra to A*, which must have been on a completely different level, at least compared to this feature.
It was not that huge change, merely adding heurstic to estimate cost to goal (<50 LOC) and making its value used in priority queue. I like simple changes with huge value added
foamy
Filter Inserter
Filter Inserter
Posts: 432
Joined: Mon Aug 26, 2019 4:14 am
Contact:

Re: Request: Max number of trains for stations

Post by foamy »

boskid wrote: Sat Jun 27, 2020 7:24 pm
foamy wrote: Sat Jun 27, 2020 7:43 am But current behaviour is that if you have two stops of the same name, a train that sets out for one or the other will only swap over if its target station becomes completely unavailable: disabled by circuit or removed from the network altogether by rename, track disconnection, or deconstruction.
Wrong. For example: train is unable to reserve chain signal due to train that entered into block somewhere ahead. When a train repaths, it forgets everything about old path, including train stop it was heading to and computes fresh path with new state of all penalties. In this example, train will choose upper path because lower path has now higher penalty due to train that entered a block.
repath-to-different-train-stop.gif
That's interesting, because I've closed off every possible route to a station via circuit and trains just slam right on in even if another station is pathable. Only way to make 'em go elsewhere was to turn the station off entirely.
Zavian
Smart Inserter
Smart Inserter
Posts: 1650
Joined: Thu Mar 02, 2017 2:57 am
Contact:

Re: Request: Max number of trains for stations

Post by Zavian »

foamy wrote: Sun Jun 28, 2020 12:10 pm That's interesting, because I've closed off every possible route to a station via circuit and trains just slam right on in even if another station is pathable. Only way to make 'em go elsewhere was to turn the station off entirely.
Using circuits to set signals to red does not prevent a train from pathing though that signal, it justs adds a penalty of 1000 to that path. https://wiki.factorio.com/Railway/Train_path_finding
User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12889
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: Request: Max number of trains for stations

Post by ssilk »

Train stop pinning: LTN uses temporary stops to pin a train to a stop. That temporary stop is just a millimeter before the target stop. Makes a lot of sense and enables duplicate station names.

If someone likes to pin “nearest trains” when a stop awakes, he/she can write a mod to do it similarly. Waiting for an awakening station and then go to through all trains, make a virtual copy of that train, set the temporary stop to that station and ask the pathfinder for the cost of that path. And then you can path the train with the lowest cost.

(IMHO this feature makes really no sense, reasons have been said.)
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
Post Reply

Return to “General discussion”