There's a bug in the train's parking

Bugs that are actually features.
gaucho_tche
Inserter
Inserter
Posts: 26
Joined: Fri Mar 08, 2019 2:13 am
Contact:

There's a bug in the train's parking

Post by gaucho_tche »

I've observed that the trains in a waiting station with 6, 8, 10 lanes, are not following the order they arrive in the "block". So sometimes a train with rocket fuel gets there first, but keeps waiting for hours all the other trains join and leave, not respecting the order they arrived there. This should certainly be fixed cause it compromises the reception of materials since a necessary one can keep eternally in the waiting while the others come and go...

tehfreek
Filter Inserter
Filter Inserter
Posts: 391
Joined: Thu Mar 17, 2016 7:34 am
Contact:

Re: There's a bug in the train's parking

Post by tehfreek »

Are all these trains going to the same single station?

Selvek
Fast Inserter
Fast Inserter
Posts: 238
Joined: Fri May 06, 2016 4:04 am
Contact:

Re: There's a bug in the train's parking

Post by Selvek »

Sounds a whole lot like not a bug. If you want the trains to "respect the order they arrived", you'll have to do it using circuit network.

gaucho_tche
Inserter
Inserter
Posts: 26
Joined: Fri Mar 08, 2019 2:13 am
Contact:

Re: There's a bug in the train's parking

Post by gaucho_tche »

Selvek wrote:
Mon Mar 18, 2019 7:17 pm
Sounds a whole lot like not a bug. If you want the trains to "respect the order they arrived", you'll have to do it using circuit network.
Of course it should respect the order they arrive. What else would it respect?

User avatar
TruePikachu
Filter Inserter
Filter Inserter
Posts: 978
Joined: Sat Apr 09, 2016 8:39 pm
Contact:

Re: There's a bug in the train's parking

Post by TruePikachu »

Probably NaB, but just out of curiousity, what are the train ID numbers? I'd expect the one with the lowest number to get priority in this sort of situation.

gaucho_tche
Inserter
Inserter
Posts: 26
Joined: Fri Mar 08, 2019 2:13 am
Contact:

Re: There's a bug in the train's parking

Post by gaucho_tche »

TruePikachu wrote:
Mon Mar 18, 2019 7:32 pm
Probably NaB, but just out of curiousity, what are the train ID numbers? I'd expect the one with the lowest number to get priority in this sort of situation.
well, the train ID number is certain not a good choice for prioritizing it. The arriving order is what it should take in account, so to me IT IS a bug that it is not working that way.

golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Re: There's a bug in the train's parking

Post by golfmiketango »

I have spent many hours -- probably many 24-hour days -- working on circuit logic to solve this problem in general. I still don't have anything I'm happy with.

Admittedly, I've piled several additional design objectives on top of this so that I end up wanting an infinitely tile-able FIFO capable of holding arbitrary circuit-network data in each memory cell, with an addressable delete operation across the full array. Oh, and I seem to want it to accept a new input and a new delete every tick.

I'm 100% sure such a thing can be made. And 99% sure it doesn't need to be completely ridiculous unplayable monstrosity. But it's a pretty hard problem. Even once I have such a thing, there are still open questions pertaining to situations where the data flows in faster than one-datum-per-tick (but I think they are solvable by chaining such FIFO's together and implementing a FIFO-merging apparatus, something I also have working prototypes for, so long as the average rate does not exceed one datum per tick).

Point being, if this is not a bug, "you can just solve it with the circuit network" is a pretty extreme form of hand-waving. Sure, if we have two or four stations or something, there are some kludges that will do the trick. But once we start wanting an infinitely tile-able solution that works efficiently, this can get scary-hard.

dewiniaid
Long Handed Inserter
Long Handed Inserter
Posts: 96
Joined: Tue Mar 07, 2017 8:50 pm
Contact:

Re: There's a bug in the train's parking

Post by dewiniaid »

It isn't so much "Trains are prioritized by ID number" as much "There is no natural prioritization of trains and all trains are evaluated in a deterministic order."

Presumably, Factorio does not track when a train arrives in a station or maintain any sort of queue. This is not a bug, though it's not a terrible idea for a feature.

Assuming that this is a "waiting" station/stacker before an actual station:

It's not hard to implement your own prioritization with the circuit network. The general idea is to have a pair of counters -- one increments when a train arrives and determines which signal is allowed to be green for entering the stacker, the other does the same for trains leaving on the exiting side.

gaucho_tche
Inserter
Inserter
Posts: 26
Joined: Fri Mar 08, 2019 2:13 am
Contact:

Re: There's a bug in the train's parking

Post by gaucho_tche »

golfmiketango wrote:
Mon Mar 18, 2019 7:59 pm
I have spent many hours -- probably many 24-hour days -- working on circuit logic to solve this problem in general. I still don't have anything I'm happy with.

Admittedly, I've piled several additional design objectives on top of this so that I end up wanting an infinitely tile-able FIFO capable of holding arbitrary circuit-network data in each memory cell, with an addressable delete operation across the full array. Oh, and I seem to want it to accept a new input and a new delete every tick.

I'm 100% sure such a thing can be made. And 99% sure it doesn't need to be completely ridiculous unplayable monstrosity. But it's a pretty hard problem. Even once I have such a thing, there are still open questions pertaining to situations where the data flows in faster than one-datum-per-tick (but I think they are solvable by chaining such FIFO's together and implementing a FIFO-merging apparatus, something I also have working prototypes for, so long as the average rate does not exceed one datum per tick).

Point being, if this is not a bug, "you can just solve it with the circuit network" is a pretty extreme form of hand-waving. Sure, if we have two or four stations or something, there are some kludges that will do the trick. But once we start wanting an infinitely tile-able solution that works efficiently, this can get scary-hard.
I certainly agree with you that it must be hell to make such a circuit. So I will say again, to me this is a bug, since it affects the general play-ability of the game.

golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Re: There's a bug in the train's parking

Post by golfmiketango »

Around here there's a convention that such things are not considered bugs. So even though in casual speech we might say "it's a bug," the only thing that properly belongs in the "Bug Reports" forum would be situations where the developers intended for things to work a certain way, and they don't. Otherwise it's a "proposal" or, in cases like this where we aren't proposing a specific solution, but rather observing something about factorio that we find inconvenient or difficult, perhaps we would call it a balancing problem or an open question.

Posting it here will often result in a response along the lines of "not a bug, topic closed," even if your idea/point was a good one.

Also, you don't need anything nearly so complicated as what I described above to fix this in most cases. My solution described above is sort of a general solution for regulating the flow rate of items between a large stacker and a small train station, which isn't really the problem you're describing (although such a thing could be repurposed to solve that too).

Selvek
Fast Inserter
Fast Inserter
Posts: 238
Joined: Fri May 06, 2016 4:04 am
Contact:

Re: There's a bug in the train's parking

Post by Selvek »

gaucho_tche wrote:
Mon Mar 18, 2019 7:24 pm
Selvek wrote:
Mon Mar 18, 2019 7:17 pm
Sounds a whole lot like not a bug. If you want the trains to "respect the order they arrived", you'll have to do it using circuit network.
Of course it should respect the order they arrive. What else would it respect?
I would say the most natural choice would be whichever train is closest. But it could also be, say, the train with the lowest train ID. The point is, parking bays aren't a special case from the standpoint of train routing logic, and the trains don't know what you're attempting to accomplish. For example, the goal of getting as many trains as possible through the intersection would require different logic than the goal of getting trains through the intersection in the order they arrived.

Selvek
Fast Inserter
Fast Inserter
Posts: 238
Joined: Fri May 06, 2016 4:04 am
Contact:

Re: There's a bug in the train's parking

Post by Selvek »

Instead of a parking bay, consider an intersection where two tracks combine into one. Imagine a never-ending stream of trains is coming in on each track.

If priority is given to whichever train has been waiting the longest, the two input tracks will alternate, meaning the streams of trains will both have to stop every couple seconds. It will be "fair", but the throughput will be very low.

If the goal is to get as many trains through the intersection as possible, one track will block indefinitely while the other runs trains at full speed. The trains on one track will never have to stop, so far more trains will make it through.

Without a high level understanding of what the player wants to accomplish, the game has no way of knowing which of these is "better".


Fortunately, even without the circuit network, the game gives you plenty of tools to solve this problem. In the case of your parking bay, if you want a FIFO queue, wouldn't the easiest solution just be to use a long serial track as your parking instead of parallel ones? Or to build separate parallel parking bays to different kinds of trains so no single kind ever gets blocked?

dewiniaid
Long Handed Inserter
Long Handed Inserter
Posts: 96
Joined: Tue Mar 07, 2017 8:50 pm
Contact:

Re: There's a bug in the train's parking

Post by dewiniaid »

Selvek wrote:
Mon Mar 18, 2019 9:00 pm
In the case of your parking bay, if you want a FIFO queue, wouldn't the easiest solution just be to use a long serial track as your parking instead of parallel ones?
This has the drawback of extending travel time for a train that it wouldn't otherwise need when the queue is empty, and takes more space.

That said, I've been effectively nerdsniped and will make a simple combinator-implemented FIFO in a bit.

gaucho_tche
Inserter
Inserter
Posts: 26
Joined: Fri Mar 08, 2019 2:13 am
Contact:

Re: There's a bug in the train's parking

Post by gaucho_tche »

dewiniaid wrote:
Mon Mar 18, 2019 9:13 pm
Selvek wrote:
Mon Mar 18, 2019 9:00 pm
In the case of your parking bay, if you want a FIFO queue, wouldn't the easiest solution just be to use a long serial track as your parking instead of parallel ones?
This has the drawback of extending travel time for a train that it wouldn't otherwise need when the queue is empty, and takes more space.

That said, I've been effectively nerdsniped and will make a simple combinator-implemented FIFO in a bit.
Where will you post it? I just want that the first train to arrive in the parking lot is the first to leave. EDIT: well, I believe that's exactly what FIFO means :?

robot256
Filter Inserter
Filter Inserter
Posts: 594
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: There's a bug in the train's parking

Post by robot256 »

dewiniaid wrote:
Mon Mar 18, 2019 9:13 pm
This has the drawback of extending travel time for a train that it wouldn't otherwise need when the queue is empty, and takes more space.
You might be able to make one long track with multiple "bypass" points that open up if there are not many trains in it. Similar to how airport security takes down some of the cordons when the lines are short.

dewiniaid
Long Handed Inserter
Long Handed Inserter
Posts: 96
Joined: Tue Mar 07, 2017 8:50 pm
Contact:

Re: There's a bug in the train's parking

Post by dewiniaid »

After trying a bunch, I came up with something that sort of works but not entirely. So I'll post my write-up here and maybe it can serve as a foundation for someone else.



Alright, here's a FIFO stacker. It took a bit longer than planned to complete since I had to resolve some issues where a train would reserve a path to a signal just before the signal was able to close.

Image
Blueprint String
EDIT: After doing all the above, I realized the bottommost signal should probably be a chain signal otherwise things may fail when a new train arrives and all lanes are full.

Explanation:

The top signal in the loop is the stacker's exit. The bottom is the stacker's entrance.

While those signals are green (or yellow), they output "O" (for Out) or "I" (for In). These signals connect to a pair of combinators (top and middle) which form a rising edge detector -- in short, it sends a 1-tick-long pulse whenever one of those signals increases. This pulse is then suitable for feeding into a counter (bottom combinator) -- here implemented as "Each < 5" combinator. 5 corresponds to the number of lanes in the stacker.

This counter is then connected to the entrance/exit signals for each lane. Each lane has a number (between 0 and 4, "L") and signals are closed if the value of I/O is not equal to the lane number.

The line of arithmetic combinators is used so that new lanes can be created just by copying and overlapping that part of the blueprint so everything connects -- and then the only adjustment needed is to the counter to signal the correct number of lanes.

The net effect of this is:

The first train to arrive enters bay 1. The second train to arrive enters bay 2. Even if the first train has since left, the third train will enter bay 3.

Each time a train leaves, the next bay is permitted to leave. This preserves the arrival order and thus allows FIFO-like behavior.

Note that there are some issues: since there's a small delay before signal changes occur, a train may start routing to a lane just before the signal changes and get stuck there. The station after the entrance signal is intended to be a countermeasure for this to force the train to reroute, but simply ensuring the entrance signal is far enough away from any junctions may prevent this from occuring as well.

This should work with multiple entrances and exits, as long as all entrances and exits are connected and configured correctly.

The exit must be the ONLY way in to the next rail block. If it is not, the signal may change as a result of other traffic which will prematurely advance which bay is allowed to leave and this may deadlock the system. The fix here is easy: have another signal immediately after the exit signal.

golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Re: There's a bug in the train's parking

Post by golfmiketango »

dewiniaid wrote:
Mon Mar 18, 2019 9:13 pm
That said, I've been effectively nerdsniped and will make a simple combinator-implemented FIFO in a bit.
Heh, see you in a couple of months :)

Never saw that xkcd before, holy crap, that guy really has me pegged -- undoubtedly a lot of us factorians are similarly prone.

golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Re: There's a bug in the train's parking

Post by golfmiketango »

dewiniaid wrote:
Mon Mar 18, 2019 8:09 pm
It isn't so much "Trains are prioritized by ID number" as much "There is no natural prioritization of trains and all trains are evaluated in a deterministic order."
That sounds pretty plausible... I'm inclined to believe something like this is the case, but can't resist asking: what is known of the precise game mechanics leading to OP's complaint? Can we make it more precise? To wit, my uneducated guess would be: s/a deterministic /build-/, so that, all things being equal, either the oldest or the newest trains tend to win these battles (which probably means that ordering trains by increasing ID does indeed order them from most-favored to least-favored?)

It's worth mentioning that there are more straightforward factors which can lead to the sort of situation described by OP: placement of signals and track merges, for example. If we have a train on a curved track behind a signal trying to merge onto a heavily-loaded segment of straight track with no signals for example, heck yeah, the signalled train might be there for a good long while waiting for his chance to merge, maybe forever. That is not a bug in any sense, I don't think. Also, if you have two trains, one behind a chain signal and one behind a regular signal, the game will tend to favor trains coming from one side over the other... but I forget which is which (my guess would be: the guy with the chain signal probably wins since the guy with the regular signal has to treat the other guy as already "virtually" occupying the contested segment of track).

Anyhow, whether or not OP is encountering those problems I think it's worth-while to consider "all things being equal" situations, i.e., trains A and B are held behind circuit-controlled signals and asked to merge in a completely symmetric manner onto the same track, and then they both get the green light from the circuit network at the same time: now, who wins a race?

gaucho_tche
Inserter
Inserter
Posts: 26
Joined: Fri Mar 08, 2019 2:13 am
Contact:

Re: There's a bug in the train's parking

Post by gaucho_tche »

dewiniaid wrote:
Tue Mar 19, 2019 1:09 am
After trying a bunch, I came up with something that sort of works but not entirely. So I'll post my write-up here and maybe it can serve as a foundation for someone else.



Alright, here's a FIFO stacker. It took a bit longer than planned to complete since I had to resolve some issues where a train would reserve a path to a signal just before the signal was able to close.

Image
Blueprint String
EDIT: After doing all the above, I realized the bottommost signal should probably be a chain signal otherwise things may fail when a new train arrives and all lanes are full.

Explanation:

The top signal in the loop is the stacker's exit. The bottom is the stacker's entrance.

While those signals are green (or yellow), they output "O" (for Out) or "I" (for In). These signals connect to a pair of combinators (top and middle) which form a rising edge detector -- in short, it sends a 1-tick-long pulse whenever one of those signals increases. This pulse is then suitable for feeding into a counter (bottom combinator) -- here implemented as "Each < 5" combinator. 5 corresponds to the number of lanes in the stacker.

This counter is then connected to the entrance/exit signals for each lane. Each lane has a number (between 0 and 4, "L") and signals are closed if the value of I/O is not equal to the lane number.

The line of arithmetic combinators is used so that new lanes can be created just by copying and overlapping that part of the blueprint so everything connects -- and then the only adjustment needed is to the counter to signal the correct number of lanes.

The net effect of this is:

The first train to arrive enters bay 1. The second train to arrive enters bay 2. Even if the first train has since left, the third train will enter bay 3.

Each time a train leaves, the next bay is permitted to leave. This preserves the arrival order and thus allows FIFO-like behavior.

Note that there are some issues: since there's a small delay before signal changes occur, a train may start routing to a lane just before the signal changes and get stuck there. The station after the entrance signal is intended to be a countermeasure for this to force the train to reroute, but simply ensuring the entrance signal is far enough away from any junctions may prevent this from occuring as well.

This should work with multiple entrances and exits, as long as all entrances and exits are connected and configured correctly.

The exit must be the ONLY way in to the next rail block. If it is not, the signal may change as a result of other traffic which will prematurely advance which bay is allowed to leave and this may deadlock the system. The fix here is easy: have another signal immediately after the exit signal.
This is what my parking station looks like. 8 Lanes for waiting and 3 to unload. Could your circuit be adapted to my design?
Attachments
factorio.jpg
factorio.jpg (421.55 KiB) Viewed 4998 times

Rseding91
Factorio Staff
Factorio Staff
Posts: 13177
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: There's a bug in the train's parking

Post by Rseding91 »

gaucho_tche wrote:
Mon Mar 18, 2019 6:28 pm
I've observed that the trains in a waiting station with 6, 8, 10 lanes, are not following the order they arrive in the "block". So sometimes a train with rocket fuel gets there first, but keeps waiting for hours all the other trains join and leave, not respecting the order they arrived there. This should certainly be fixed cause it compromises the reception of materials since a necessary one can keep eternally in the waiting while the others come and go...
Thanks for the report however this is working as intended: trains do not follow "first in, first out" logic when waiting at rail signals. They simply operate in what ever order the train(s) are updated where that order is deterministic.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Not a bug”