Maximum throughput of a rail line

Post all other topics which do not belong to any other category.
mmmPI
Smart Inserter
Smart Inserter
Posts: 3629
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Maximum throughput of a rail line

Post by mmmPI »

quyxkh wrote: Mon Dec 11, 2023 7:44 pm Trying it with one rocket-fueled locomotive I get, assuming I didn't botch either the math or the code above, max throughput at 1-20, that gets about 325 wagons/min vs about 263 for 1-12 and 125 for 1-4.
For the part i understand :

There is the additionnal information of the braking research that is required to compare result, as high braking research increase the maximum throughput due to allowing train shorter braking distance, being closer to each other and thus increasing density even at the same speed which would yield more wagons per minutes.

However, from your "about 325 wagons/min" i suppose you have accounted for braking research as this throughput cannot be reached otherwise. 325 wagons/minutes with 1-20 trains represent 16.25 trains per minutes, which is to my calculation requiring at least braking research 8 ( 1.8 modifier )

https://www.desmos.com/calculator/mrewge9xgq

This throughput can be reached with such braking research and even a little more, but only if the trains are allowed to reach max speed or close, which would only allow 3 of such trains in a square of 100 height and 100 width.

Now 263 wagons per minutes with 1-12 trains represent 21.6 trains per minutes or so for this one braking force research 9 is required and this throughput would require train running at around 238 km/h , which for the same kind of loop would require 4.77 trains, so most likely not possible in game to reach on this amount of track
https://www.desmos.com/calculator/yfxtp8stbh

but a sligthlier larger loop of 96 width and 250 height would get this throughput with 8 trains.

And finally 125 wagons per minutes with 1-4 trains is 31.25 trains per minutes , this one would only require braking force multiplier of 1.4 https://www.desmos.com/calculator/ktrchs6ai2
I suppose this is the test where your prediction is the lowest compared to mine, and i'm afraid i have already posted a save game where a throughput of 37 trains per minute is achieved with 1-4 trains, ( which was done with braking research giving a multiplier of 2) so i have to disagree a little on this one and think something must have slipped in the measure because the other results are closer to the max throughput theorized in perfect flow condition.

My guess is that the train was allowed to go too fast but you had braking research mutiplier 2 https://www.desmos.com/calculator/8zxbpcqj5n
The train reached its max speed or around 250 km/h which correspond to around 32 trains per minutes on a single lane but you would have gotten a higher throughput if trains were going at 160 km/h or so , around 37 train per minutes.
quyxkh wrote: Mon Dec 11, 2023 7:44 pm Measuring actual performance is a little hard because you can't get braking distance directly and there's signal block lengths, but as a way of validating models I thought I'd measure throughput as directly as possible.
I think your method for measuring throughput is correct, but i think your method to estimate the max throughput is not.

I have some data that log the position ID and speed of 12 1-4 trains in a traffic jam on a square loop
train_brake_measure_results loop 1.txt
(2.9 MiB) Downloaded 43 times
Still trying to find a way to import those in Desmos, ideally to graph the speed and position of trains 658 667 694 and so on over the few minutes of recording.

Edit : it appear those data only log something about a train when it is braking and as such it is only the "braking profile" of the trains, the acceleration is not shown.

It would also appear that for train 658, the braking profile repeat itself after 16 occurences of 0 speed. With those it is possible to "math" the speed of propagation of the traffic jam, the average speed of the train during the traffic jam in the stop and go regime, and then compare with the same setup without traffic jam due to signal being spaced closer to each other.

The data correspond to the loop 5 in previous save game
quyxkh
Smart Inserter
Smart Inserter
Posts: 1031
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Maximum throughput of a rail line

Post by quyxkh »

mmmPI wrote: Mon Dec 11, 2023 8:52 pm I think your method for measuring throughput is correct, but i think your method to estimate the max throughput is not.
I think you're right, leaving off the signal spacing made the numbers not good, here's a fixed version that shows how much space each train needs empty to maintain its current speed, you have to tell it the signal spacing, divide the route length by that rdist should give you how many trains you could conceivably fit and still achieve that speed and (close to that) throughput. At the receiving end you'll need an available stop for each arriving train of course, any train's braking point overtakes the reserved signal ahead of it is going to jam the route when it brakes.

Code: Select all

function dist(a,b)
    local x,y =(a.position or a).x, (a.position or a).y
    x = x - (b.position or b).x
    y = y - (b.position or b).y
    return math.sqrt(x*x+y*y)
    end

function gpsl(p) return game.print(serpent.line(p)) end

de=defines.events
trains={}
sdist=30 --[[ distance between signals in meters, 30 is big-electric-pole interval ]]

script.on_event(de.on_tick,function()
    local tname,k,v,cdist
    for k,v in pairs(game.surfaces[1].get_trains()) do if v.has_path then
        tname=v.front_stock.backer_name
        cdist=dist(v.front_rail,v.path_end_rail)
        if not trains[tname] or not trains[tname].path_end_rail.valid then trains[tname]={path_end_rail=v.path_end_rail} end
        do local _=trains[tname]
            if dist(v.path_end_rail,_.path_end_rail) > 0 then
                gpsl(string.format("nwagons=%d, speed=%g, rdist=%g, throughput/min=%g@%gm signal dist (1 train / %g ticks", _.nwagons,
                    _.speed, _.rdist,
                    _.nwagons/(_.rdist/_.speed/3600),sdist, _.rtime))
                end
            _.cdist=cdist
            _.speed=v.speed
            _.nlocos=#v.locomotives.front_movers+#v.locomotives.back_movers
            _.nwagons=#v.cargo_wagons
            _.rdist=dist(v.path_end_rail,v.back_rail)+2
            _.rdist=_.rdist-(_.rdist%sdist)
            _.rdist=_.rdist+2*sdist
            _.rtime=_.rdist/_.speed
            _.path_end_rail=v.path_end_rail
            end
        end end
    end)
(edit: I added the inter-train interval in ticks, I think dispatching with at least that interval and keeping them on parallel tracks until they get up to speed, then merging onto one track, will work, haven't tested that yet. Any variance in signal spacing would mean you'd need extra buffer in front, so give it the usual spacing plus the largest of whatever shorter spacing you might use)
mmmPI
Smart Inserter
Smart Inserter
Posts: 3629
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Maximum throughput of a rail line

Post by mmmPI »

quyxkh wrote: Mon Dec 11, 2023 10:40 pm leaving off the signal spacing made the numbers not good, here's a fixed version that shows how much space each train needs empty to maintain its current speed, you have to tell it the signal spacing, divide the route length by that rdist should give you how many trains you could conceivably fit and still achieve that speed and (close to that) throughput. At the receiving end you'll need an available stop for each arriving train of course, any train's braking point overtakes the reserved signal ahead of it is going to jam the route when it brakes.
How do you stop the thing to print if by not reloading the map ? :lol: that's my lua level, just letting you know before you attempt to explain more things.

Apart from that urgent matter, i think your previous method was calculating properly the "throughput of trains at max speed" but this doesn't yield the highest "number of wagons per minute".

Adding in the calculation the block length will allow to predict a more accurate maximum that is not too much overestimating the throughput achieved , the higher this block length as it factor in the "needlessly" reserved space by a train that is wasted for density / unoccupied nor by train nor any braking distance. This is what farcast model does.

I understand the idea behind route length addition to math the distribution of trains this is related to density. But i am unable to understand how you do for the braking distance, i'm looking for square roots but are you getting it from the game and not mathing it? cuz the only sqrt i see is used for the distance travelled by the train each tick in the early line ? This braking distance math sounds necessary piece of the formula, also i see a modulo operation rdist%sdist which makes me think this is the addition of the block length but i can't understand what is accounted for when train length>2 block length.

I don't understand what is happening when the command is running , and what's with the available stop ? is this the answer to original question or just a joke ? there is no train it's all invisible ! i understand they are simulated using the game formula and i'm getting the result of the actual game code running, which i don't expect to differ much from the models ^^, but there was 10 ticks unexplained when a real train braking occurs, the game seemed to take always 10 extra tick to have the train come to full stop,so maybe it impact the braking distance, or the way the game reserve blocks, or another explanation lying around behind a bit more understanding of lua as of now i'm unable to use the code as intented :|

Edit : i understand i need to have a train running for the command to function , it gave me some result, i understand how to tell it the signal spacing, and that i don't have to tell it the length of the total route, it seem to me that if i don't give it the correct signal spacing used by trains it overestimate the throughput printed ?
quyxkh
Smart Inserter
Smart Inserter
Posts: 1031
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Maximum throughput of a rail line

Post by quyxkh »

mmmPI wrote: Mon Dec 11, 2023 11:43 pm how you do for the braking distance, i'm looking for square roots but are you getting it from the game and not mathing it?
That's right. Each tick I record the distance from the front and back rail of the train to the train's current path_end_rail. Before recording it, I check whether the path end rail has changed since the previous tick. If it has, that's because the braking point passed a scheduled stop. I use waypoints so the trains don't brake, they just go right by, which means the recorded distance is as close as the train got before its braking point passed the stop: that's as close as I know how to get to the actual braking distance. Since the next tick the train would (because it did) pass the stop, it'd have had to brake at the recorded distance anyway if that had been a red signal or whatever.
also i see a modulo operation rdist%sdist which makes me think this is the addition of the block length but i can't understand what is accounted for when train length>2 block length.
The modulus gets me the rewainder, subbing from the distance gets me the lower bound on the length of signal-distance blocks the train can occupy, plus one because the train will certainly at some point not be on an exact edge boundary so it needs an extra block for that, plus one more because its braking point has to enter an empty block.

This is the blueprint I started with, I used it to check the effect of wagon count on braking distance and then started running the code here on the looping trains.
mmmPI
Smart Inserter
Smart Inserter
Posts: 3629
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Maximum throughput of a rail line

Post by mmmPI »

quyxkh wrote: Tue Dec 12, 2023 12:12 am That's right. Each tick I record the distance from the front and back rail of the train to the train's current path_end_rail. Before recording it, I check whether the path end rail has changed since the previous tick. If it has, that's because the braking point passed a scheduled stop. I use waypoints so the trains don't brake, they just go right by, which means the recorded distance is as close as the train got before its braking point passed the stop: that's as close as I know how to get to the actual braking distance. Since the next tick the train would (because it did) pass the stop, it'd have had to brake at the recorded distance anyway if that had been a red signal or whatever.
That's convoluted in the good way :) , if i understand correctly the braking distance is then updated twice per lap if there are 2 train stop acting as waypoint which is the minimum to have the train going continuously, more stop without conditions on the loop would update the data faster but a larger loop would decrease the rate of printing by the command.

The imprecision for the braking distance is then in the order of the train speed in tile per tick, which is no more than 1.38 tile or meter but no need to worry about anything related to block length or signaling.

I'm unsure if i understood correctly how farcast''s brakemeter function because it had to overcome block length imprecision to measure the braking distance ,but i think it does something similar where you could increase the precision of the measure by averaging the (braking distance) result over long period of time ( several braking distance measurements of trains with very close signals), because following the law of large number it would sometimes be very little distance added, sometimes the maximum of those 1.38 ? Those math were necessary i suppose to make the formula saying a locomotive is 36000 Newton of forward force, friction is 1800 newton per rolling stock which is how the braking distance is mathed in both models.

At this point there is the question of speed variation there shouldn't be one or the averaging would mean nothing. I think to establish the original formula the braking was measured in lab conditions which allowed for averaging potentially forever to increase precision of the measure.

I understand the command print a "snapshot" result like a driver going on a circular track that would know its braking distance because it has some flexible measurement stick in front of the car whose length vary with speed, and there is some spectator in the public that measure the time it takes for that stick to cross the finish line knowing the speed of the driver. The stick is the distance between the front of the train and the red dot shown as the braking point of the train in debug, so it's not only varying according to speed, but also based on the car's weight and tire friction and air-resistance of the car wether it's raining or not, so the driver and his buddy spectator could potentially study all those by changing 1 factor, then another to extract datas about the car.

I'm not sure how works the combinator contraption from xKnight, improved by farcast that achieved the in game measurement originally, the averaging braking distance from acttual in game measurement, but having a method to measure brake distance "at any time"( wherever one adds a waypoint) allows then all the previous extraction of data, that's like the magic stick, the command you propose using is giving the result under the form of a "snapshot" that if averaged would yield the value used for the models by changing 1 factor at a time like the number of wagons, or loco, or fuel or air-resistance profile of the front rolling stock. The value used for braking distance in the model already comes from the game, so i did not doubt their validity. I'm impressed and happy to see how it can be done using lua command. That's different than what the mod i used to get the data does but it's the same langage, it gives me example i could reuse combined or modify :)
quyxkh wrote: Mon Dec 11, 2023 10:40 pm (edit: I added the inter-train interval in ticks, I think dispatching with at least that interval and keeping them on parallel tracks until they get up to speed, then merging onto one track, will work, haven't tested that yet. Any variance in signal spacing would mean you'd need extra buffer in front, so give it the usual spacing plus the largest of whatever shorter spacing you might use)
Wikpedia refers to this as " The inverse of flow is headway (h), which is the time that elapses between the ith vehicle passing a reference point in space and the (i + 1)th vehicle." And then they add " In congestion, h remains constant. As a traffic jam forms, h approaches infinity. "

You are calculating it, from result you measured, like the braking distance implictly embedding train length in the difference between front and back of train. So you would never read "0" instead the command would just not print anything until a train actually move. It would be impossible to know the throughput if a train is stopped anyway.

The "headway" one can also measure also by measuring how many ticks between 2 times a signal turns red. That's how the train counter from disentius i used in the save game functions. It send pulses when it detect an edge in the signal color red and "somehow" measure how many pulses in a minute. And thus how many trains per minute. Which i transformed into speed because i embedded the length of the loop in the calculation and the number of trains on my loops. 12 trains, 868.xxx meters long loop, if you know how many time between 2 trains, you know the speed at which they go, that's the same "snapshot" result that would need to be graphed overtime to represent how a train behave in a traffic jam, or in a situation of stop and go traffic .

I know this is not really necessary to answer the question of the maximum throughput theorical or practical because that would only occur in suboptimal condition for traffic far from the maximum. But i think it is fascinating how simple rules yield very complex system with nice graph to look at.
quyxkh wrote: Tue Dec 12, 2023 12:12 am The modulus gets me the rewainder, subbing from the distance gets me the lower bound on the length of signal-distance blocks the train can occupy, plus one because the train will certainly at some point not be on an exact edge boundary so it needs an extra block for that, plus one more because its braking point has to enter an empty block.
This particular reasonning is troubing me of some sort, the number of single block to account , 1 or 1+1, 1+rewainder rounded up ? This is because in one way it is true that it is making modeling more accurate because it shows that the theorical maximum is influenced by how close are signals, if further aways it induces more reserved block and thus forces a lower density of cargo.

But then this matters more when spacing is "high" , but then when spacing is "high" there is a increased / induced risk of speed variation of the trains inside a block. There is no more condition to use the rest of the model that assume all trains have the same speed to generate "train / minutes" from 1 measurement, as with your lua commad, or with the models that assume "perfect flow" aka all trains have the same speed.

It leaves me unable to fully agree with anything incuding my own model because given the deterministic nature of factorio, the traffim jams are chaotic but not random, and i know there are some math to describe those emergent phenomenon that's just i'm just unable to pratice but there's plenty documentation exploring many direction that's more than a life time worth of hobbyist things x).

I can't picture mentally what's being calculated if it amounts to 1 or 2 blocks how and when. I read 3 different approach from this page https://en.wikipedia.org/wiki/Traffic_f ... f_analysis some of the documentation regard such case as a matter of periodic boundary conditions https://en.wikipedia.org/wiki/Periodic_ ... conditions, which is tough unknown-to-me math for this case. but would look like it's one way to go to make a good approximation of general train flow from a detailed description of the behavior of 1 trains when changing blocks that is related to the first approach the cellular automaton one.

I think the second approach is what we are currently using, all of us on this thread, density and mean velocity to make up for the precise description of the behavior of a single train overtime like the in the first approach.

Also at this point i have to admit i'm more interested in the endless rabbit hole discussion than in the answer or the solution, the worst math i feel comes from the "certainly" in your sentence x)

Not in 3D not even in 2D but in 1D a train to me is like a particle that has a % of probability of being "accelerating or "decelerating" when there is a repeating speed variation with periodicity oscillating between 2 value of speed ( 0 and max in extreme stop and go traffic around a loop). And this is correlated to its current state, it is more likely to accelerate when slow and vice versa. The better its braking power/acceleration ratio the more it would change the shape of the braking profile toward brake for small time, accelerate for longer to achieve a periodic variation between 0 and max speed as in stop and go traffic. Following that trend of thought it would be possible to estimate the optimal speed a train should go based on its acceleration and braking capacity so that it minimizes the effective distance it occupies when maintaing a certain speed given its length and braking distance relative to its density of cargo. But also to predict where you would see a train and how fast it would go if you were to take pictures at random interval over the same rail boundary. And roughly the badness of the traffic jam and potentially how to measure the flow by measuring how much time a train is staying still in a stop and go traffic.

It ressemble what i can picture as necessary to model uneven signal spacing, or speed variation, or traffic jams which to me is the all the same roughly at first, until you consider the positions as signals can't move backward when speed is reduced or none so traffic jams are really the worst to model.

But the models https://www.youtube.com/watch?v=Q78Kb4uLAdA and experiments https://www.youtube.com/watch?v=7wm-pZp_mi0 are quite fun to look at and very explicitly ressemble factorio's traffic jams :D
mmmPI
Smart Inserter
Smart Inserter
Posts: 3629
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Maximum throughput of a rail line

Post by mmmPI »

farcast wrote: Sat Dec 09, 2023 5:20 am New graph with more bells and whistles.

While experimenting with signal spacing i have been able to achieve a higher throughput than the supposed maximum in game with a lower speed than the model predicted with a signal spacing of 35 or 34 or even 33 32... I think it shows there is some (very little) inaccuracies that i can't figure out.

https://www.desmos.com/calculator/jftfqelym7

According to this setting, the max throughput is 25.242 train per minutes achieved with a speed of 233.24 km/h per trains. 1-5 nuclear fuel train, with 2 braking reseach multiplier, and 35 signal spacing. Going down to 34 or 33 or even 32 to make up for the little inaccuracies of my setup related to curve block measuring not an exact number of tile still shows something not corresponding to the following save game :
throughput excess.png
throughput excess.png (441.3 KiB) Viewed 2877 times
The counter counts 25.83 trains and flickers to 25.80 per minutes, the average speed is at 214.94 km/h. However in game a train can be seen changing from around 207 to 221 km, or so 7km/h fluctuation around mean leading the train to sometimes decelerates because of the front train preventing reservation sometimes accelerating which leads to wildly different measure on the lua command but maybe something else too.



I have not been able to explain it so far, despite my attempts at adding an equivalent of the math for block length under several forms to represent the discontinuities as described by SoShootMe or other number of formula to represent the fact that trains occupies an amount of space that is modulo or not the size of block, or that they occupy 1 minimum, but need at least always a second to enter to. This by changing the formula for q(y) in this graph https://www.desmos.com/calculator/cbacif3nds

Currently showing [floor((Length of train + braking distance + speed in tile -1 )/size of block)+2]*block length. So that a train is counted to take at least 2 blocks all the time even in case of small train, but this is not correct for small trains in long blocks which may explain the underestimation of the max throughput. I have tried many things there x).

i had this realization that in the extreme case of a small train and very long block. It is only possible to know how many time a trains occupies 2 block by knowing its speed. But this will have to lead to density variation because most of the time a train will occupy 1 block, but sometimes 2 blocks. With the approach we are following so far it seem to me impossible to make up for this fact precisely. And the other approach used in real life looks quite complex, if anyone has an idea or is able to share some informations that would be appreciated :)
quyxkh
Smart Inserter
Smart Inserter
Posts: 1031
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Maximum throughput of a rail line

Post by quyxkh »

Anything up to about 1-14 rocket-fueled trains can reach the game's speed limit of 1.38m/tick, you're showing 1-5 trains stuck at around 1m/tick. So they're hitting congestion, they're braking. Trains brake faster than they accelerate, and that sort of speed variation makes traffic effectively occupy more space. Much more space. If you want maximum throughput, build trains whose maximum throughput *at their full speed* is highest, and dispatch them so they only have to brake at their destination stop or at another controlled-dispatch station, or send their drivers here to LA where we'll teach them how to avoid and (less intuitively) kill standing-wave traffic jams. Sadly that skill was clearly lost in some pre-game apocalypse, so long trains it is.
mmmPI
Smart Inserter
Smart Inserter
Posts: 3629
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Maximum throughput of a rail line

Post by mmmPI »

quyxkh wrote: Thu Dec 14, 2023 12:30 am Anything up to about 1-14 rocket-fueled trains can reach the game's speed limit of 1.38m/tick, you're showing 1-5 trains stuck at around 1m/tick. So they're hitting congestion, they're braking. Trains brake faster than they accelerate, and that sort of speed variation makes traffic effectively occupy more space. Much more space. If you want maximum throughput, build trains whose maximum throughput *at their full speed* is highest, and dispatch them so they only have to brake at their destination stop or at another controlled-dispatch station, or send their drivers here to LA where we'll teach them how to avoid and (less intuitively) kill standing-wave traffic jams. Sadly that skill was clearly lost in some pre-game apocalypse, so long trains it is.
In order to get the max theorical throughput you would also have to place signal everywhere , which is good to know for certain portions of tracks but you wouldn't want to do that on everysingle track of your network.

My previous post was regarding the influence of signal spacing over throughput, i know 35 tile away signal is not optimal for throughput so is 1-5 trains, or their speed, but i thought it would allow to see wether farcast model could be improved by SoShootMe remark regarding the space in number of block a train is considered to be occupying.

The modulo block length rounded up thing. I tried a situation where there should be a descrepancy between a model that doesn't math block length at all and a model that does, which is the case, farcast model is not suprisingly closer than a model who think block length is 1, but it's still off, surprisingly, it's slightly underestimating the throughput.

Or more visible, there is a 10km/h descrepancy between the supposed optimal speed for those trains, and the speed at which they are running in game to provide a throughput supposed to be "optimal", my trains run 10 to 12 km/h slower than expected, and yet achieve a tiny little fraction of excess throughput.

Adding the limitations that makes the curves look like discontinuous to math the block length when thinking about it more makes it to me obvious that is not going to yield proper result without math like integral and probabilities which are not used at all atm. Because if the trains slows down and accelerate a little, one need to know how much distance was travelled during one or the other phase, and when it started, the distance travelled is integral math, and the "when it started" i'm not sure.

I am not sure what should be achieved with trains achieving their max throughput at their max speed ? If they "never" have to break, then they will always reach that speed no matter the signal placement and there should be no descrepancies expected. I need to try with more than 1 train on the loop right ? otherwise it doesn't matter if there is some wasted space for density there is no impact if there is no need for braking. How many of those trains should i put on the loop ? 1 ? signal placement no impact, 2 ? they may start to brake, or if they don't no impact ?

I'm testing with 1-32 trains atm

Edit : i can confirm if trains don't need to brake, there is no need to math block length, the result of throughput is the same as with block length 1, but then if trains need to brake the proposed way of modelizing the interaction of block length and throughput are not properly modelizing what is happening in game, although one can get very close

Taking the case of 2x 1-32 trains on a 188 rail long loop signaled very 35 signal and 1 block for the U turn since it's around 35 tile, this time farcast model overestimate the throughput in trains per minutes https://www.desmos.com/calculator/79v5xlzmbm , at 11 instead of the measured 9.91 in game, that my model that doesn't account for signal spacing correctly predict for 2 trains : https://www.desmos.com/calculator/sbkbs30tix , the purple curve at 2 trains says 9.946
9.91.png
9.91.png (242.25 KiB) Viewed 2843 times
mrvn
Smart Inserter
Smart Inserter
Posts: 5860
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Maximum throughput of a rail line

Post by mrvn »

quyxkh wrote: Thu Dec 14, 2023 12:30 am Anything up to about 1-14 rocket-fueled trains can reach the game's speed limit of 1.38m/tick, you're showing 1-5 trains stuck at around 1m/tick. So they're hitting congestion, they're braking. Trains brake faster than they accelerate, and that sort of speed variation makes traffic effectively occupy more space. Much more space. If you want maximum throughput, build trains whose maximum throughput *at their full speed* is highest, and dispatch them so they only have to brake at their destination stop or at another controlled-dispatch station, or send their drivers here to LA where we'll teach them how to avoid and (less intuitively) kill standing-wave traffic jams. Sadly that skill was clearly lost in some pre-game apocalypse, so long trains it is.
Those long trains are really slow to accelerate and take forever to get up to speed. Total killer when they hit a junction and have to wait.
mmmPI
Smart Inserter
Smart Inserter
Posts: 3629
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Maximum throughput of a rail line

Post by mmmPI »

mrvn wrote: Thu Dec 14, 2023 11:58 am Those long trains are really slow to accelerate and take forever to get up to speed. Total killer when they hit a junction and have to wait.
I made this one => https://www.desmos.com/calculator/mmalpgpa8o

It should model how the train accelerate in game, for what i've tested it shows the correct speed of accelerating train over time and the max speed it will reach.

It uses geometric series math, but i'm not sure how it's called in english, one can change the 0.0075 in the air resist upper fraction to 0.01 to represent a forward facing wagon, otherwise it's just forward facing loco and number of wagons fuel.
quyxkh
Smart Inserter
Smart Inserter
Posts: 1031
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Maximum throughput of a rail line

Post by quyxkh »

mrvn wrote: Thu Dec 14, 2023 11:58 am Those long trains are really slow to accelerate and take forever to get up to speed. Total killer when they hit a junction and have to wait.
Yes, but you gave the parameters: train length, acceleration and braking, and signal spacing, in the first post. Congestion and route length are pretty obviously important, so I took their exclusion as intentional. Kinda feeling jerked around here.
mmmPI
Smart Inserter
Smart Inserter
Posts: 3629
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Maximum throughput of a rail line

Post by mmmPI »

quyxkh wrote: Fri Dec 15, 2023 7:17 pm Yes, but you gave the parameters: train length, acceleration and braking, and signal spacing, in the first post. Congestion and route length are pretty obviously important, so I took their exclusion as intentional. Kinda feeling jerked around here.
The maximum throughput is indeed achieved with long trains you are correct ! to me it seem to be always achieved when you use the maximum number of wagon before the train isn't able to move them at the max speed. If you use 2 nuclear fueled loco, this means the optimal number of wagon is 77 per train for around 500 wagon per minutes throughput (predicted) but those trains would take more than 10 minutes to reach their max speed.

If you use trains with 20 locos and 77 wagons, the max throughput in theory is only 477 wagons per minutes. But the trains reach their max speed in less than 6 second.

Instead with 20 locos the optimal number of wagon seem to be 960 which would yield a thoughput of 650 wagons per minutes. Which at this point you may realize a minute is too short for the train to move all its wagon accross a certain point.

Surprisingly it is possible to achieve better throughput with only 16 locos and 760 wagons, for 677 wagons per minutes but that's only in theory because those would need around an hour to reach their top speed.

If you use 250 locos and 8000 wagons, the trains would reach top speed in around 10 seconds for a max throughput of 686 wagon per minutes. But only 200 locos and you get a better theoric throughput.

I was wrong when i said removing locos always gives better throughput, that is the case for given number of wagon, if you remove locos and can still move the trains to the optimal speed, the best throughput will be achieved when there is no "needless" locos which are just wasted density of cargo when the train is already at max speed.

So there is a tradeoff, the longer it takes to accelerate the wagons, ""the better"" for theoric throughput, because that means one is using just the right amount of locos and not too many to achieve the best density when max speed is finally reached ( even if takes hours ).

I think those trains are not made to be used in junctions though, it would take a while for a 250-8000 trains to clear a junction with 680 wagons per minute only. That's 1.3M ore per minutes, for a total of 16 M ore in the train. The train would be around 115k rails long which is more than i use in many games to make a full network lol.
quyxkh
Smart Inserter
Smart Inserter
Posts: 1031
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Maximum throughput of a rail line

Post by quyxkh »

Max throughput on a single line over a given distance seems like the figure of merit to me, I don't see any reason to include congestion because whatever the shortest inter-congestion distance is will have at most the congestion-free throughput for that distance, so that will be the best possible throughput for the entire route. With rocket fuel a 1-4 train takes almost a full km to hit top speed but hey, the farther out you go for ore the less often you have to redo your outposts, so… sure, a 1km multilane acceleration buffer feeding 9km of single lane 1-4s at about 125 wagons/min, 2-8s would at least double that, if you smelt at the outpost end you should "easily" pump over a million plates per minute over a single line.
mmmPI
Smart Inserter
Smart Inserter
Posts: 3629
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Maximum throughput of a rail line

Post by mmmPI »

quyxkh wrote: Fri Dec 15, 2023 8:56 pm Max throughput on a single line over a given distance seems like the figure of merit to me, I don't see any reason to include congestion because whatever the shortest inter-congestion distance is will have at most the congestion-free throughput for that distance, so that will be the best possible throughput for the entire route.
That's a way to see, i agree that the throughput of a lane is limited by the segment that has the lowest throughput. it makes it easier or even possible at all to average the flow of a traffic jam when it's happening on a loop. In a game you can also have some grid-like network and wish to math the max throughput of a block egde, whose signaling is going to be always the same. Or a tree-like one , where knowing the throughput of the trunk signaled more heavily compared to the branches could help.

Bridges are supposed to get rid of any congestion anyway :D

Also in real life "free flow" is used to describe the state when cars don't have to slow down due the car in front of them and can reach easily max speed, it is usually the prefered configuration, because in real life "synchronized flow" is more a self-regulating mechanism than an objective, it happens when density of car increase, then they have to slow down a little and if it's not critical density , it improves the flow because the braking distance increase with the square of the velocity so the overall multiplication density*speed= flow increase as density increase more than speed decrease due to density including a part of velocity squared so that it returns to "free flow" "hopefully".

The trains all have the same behavior regarding reaction time, so it's a little bit better than human drivers and they can really achieve wonders during synchronized flow but when density increases a tad more it breaks into traffic jam, which is bad, though the best throughput is achieved just before, which makes it very prone to disruptions. The critical density of rolling stock/rails is one that doesn't work well because the effective density in game depends on factor like speed and block length.

quyxkh wrote: Fri Dec 15, 2023 8:56 pm With rocket fuel a 1-4 train takes almost a full km to hit top speed but hey, the farther out you go for ore the less often you have to redo your outposts, so… sure, a 1km multilane acceleration buffer feeding 9km of single lane 1-4s at about 125 wagons/min, 2-8s would at least double that, if you smelt at the outpost end you should "easily" pump over a million plates per minute over a single line.
Well to me, wether you use rocket fuel wood or nuclear fuel doesn't matter because 1-4 trains are the best for throughput going at around 158km/h when you have 2 as braking research multiplier because i suppose that's when their braking distance is the closer to 35 tiles which is the length of the train. You can achieve at least 145 wagons per minutes !

Max from model is expected at 151.518 wagons/minutes, but that would require a very precise loop length so that it fits better the number of trains than 7 trains on a 106 rails long loop. ( should be 7.034 trains ).To double that you'd need at least a 2-15, a 1-15 would not do with rocket fuel but with nuclear fuel it could reach the speed required. A 2-8 could only get you as far as 214 wagons per minutes, but 250 wagons per minutes would be required for at least a million plate per minute which is in theory possible with only 2 rails lanes using 1-4 trains, but as you see in practice it wouldn't quite fit with the loop design.
145.png
145.png (231.52 KiB) Viewed 2614 times
2 decimals digits for all three counters



I have not been able to make the integrals for acceleration to compute the speed from the physical /second units due to not knowing how to model the drag that's not in equations i could find online that's why i instead tried to model how it behave in game tick per tick but maybe i will have more chance making the integrals of the speed computed this way to find the distance travelled during the acceleration to 158 km/h depending on which fuel is used, so that one can build curvy loops to buffer speed at first and remove/straigthen tracks later when changing for better fuel in game ? :D At this point the math are complex and precise enough that i feel it requires being used for something more fancy than just maximizing throughput. Things like flying trains or signaless networks :)
quyxkh
Smart Inserter
Smart Inserter
Posts: 1031
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Maximum throughput of a rail line

Post by quyxkh »

I might be in the minority here but for me, before first launch rail line throughput just isn't a factor at all. I do the first few launches with 1-3 ore trains feeding what gets built up to a ~25k/min smelter complex, for a rail line that's *nothing*.
mmmPI
Smart Inserter
Smart Inserter
Posts: 3629
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Maximum throughput of a rail line

Post by mmmPI »

I'm pretty sure anyone reading this discussion is already in a very tiny minority, i won't blame you for that :) I had tried on several occasion to bring water to nuclear plant with trains, or bring steam to turbines, or other silly things like that, which require a lot of throughput and had issues / tried to optimize.

I usually do my smelting on site and not on centralized smelters to avoid carrying ore by train and such kind of considerations so i hardly even experience throughput issues in real game.

Most of the time it comes from junctions too close to each other leading to long chain of chain signals but the math for those are much harder than the math for throughput which are not easy already ... maybe eventually who knows as i said i'm more interested in the discussion tha in the actual "solution" for best throughput, having a tool that can help mathing things out precisely can be helpful when building contraptions with signals networks too, knowing how many tick a train would need to clear a block of very small length can be used to act as trigger or measure.

I play many modded games where i don't do many launches but just try new systems, so throughput is not as much as concern as the precise math :)
farcast
Long Handed Inserter
Long Handed Inserter
Posts: 87
Joined: Fri Jul 06, 2018 8:25 am
Contact:

Re: Maximum throughput of a rail line

Post by farcast »

New graph 2, Electric Boogaloo

New graph, new model, this time including acceleration.

Velocity formula comes from something I did a while ago, I messed around with regressions to find a good formula for train velocity until I got something that was suspiciously perfect. I later looked up formulas for linear drag models and what I found was actually the right formula to use, and the proof was one of those black magic proofs that separates dy/dx. I can't find which page I found it on now. It's similar enough to what mmmPI shared. What I'm trying to say is don't ask me how the formula works 'cause I don't know.

Initial conditions are as follows:
-Train speed is at its minimum (x)
-Stop point is at a signal
-The block in front has just opened up
-Identical trains are packed as close as can be for the minimum speed

The graph calculates the time it takes for the train to speed up until it hits the next signal, then slow down until it reaches the minimum speed. At that time the next block should open up and the cycle repeats. From this time the average speed is calculated, and then throughput comes from the time it takes to travel to the starting position of the train in front (train length + minimum braking distance + signal block length).

Whether or not block length evenly divides train length + braking distance, I don't think it matters. It should just affect whether train acceleration cycles are in phase or out of phase... did that make sense? I hope it did.

The new model gives significantly different results for low starting speeds, but the difference between the new and old models disappears as signal block length approaches zero. I think that's a good sign. Another good sign is this matches mmmPI's 1-5 train test result.

I had to use newton's method to find the travel time, and I can't think of a way to directly calculate max throughput from this, so you just have to get by without it.

Lower starting speeds might need a different S_0 for newton's method to get an accurate result.

Edit: fixed the graph so it doesn't completely break when a train can't reach the game's max speed.
Efficient inefficient design.
mmmPI
Smart Inserter
Smart Inserter
Posts: 3629
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Maximum throughput of a rail line

Post by mmmPI »

farcast wrote: Sat Dec 16, 2023 1:56 am New graph 2, Electric Boogaloo

New graph, new model, this time including acceleration.

Velocity formula comes from something I did a while ago, I messed around with regressions to find a good formula for train velocity until I got something that was suspiciously perfect. I later looked up formulas for linear drag models and what I found was actually the right formula to use, and the proof was one of those black magic proofs that separates dy/dx. I can't find which page I found it on now. It's similar enough to what mmmPI shared. What I'm trying to say is don't ask me how the formula works 'cause I don't know.
As far as i'm concerned this look more complicated than what i did, and also than what i attempted . I will look at the "linear drag model" online because that's what i couldn't do. I can try to explain what i did because I figure i would probably not be able to understand the graph i made in a few month, and i don't know how long are Desmos graph available , i think i know why the formula worked, and hopefully there is enough similarities that it could be helpful to understand your graph but i'm not seeing them yet :D

1) How to make a model for the train speed over time in tick (easier method :D with working example ) https://www.desmos.com/calculator/sd5of8hkgr :
Long
2) What i attempted to do before but it didnt work and i think that's what farcast did properly x) :
shorter
farcast wrote: Sat Dec 16, 2023 1:56 am The graph calculates the time it takes for the train to speed up until it hits the next signal, then slow down until it reaches the minimum speed. At that time the next block should open up and the cycle repeats. From this time the average speed is calculated, and then throughput comes from the time it takes to travel to the starting position of the train in front (train length + minimum braking distance + signal block length).

Whether or not block length evenly divides train length + braking distance, I don't think it matters. It should just affect whether train acceleration cycles are in phase or out of phase... did that make sense? I hope it did.
The description of what the graph does seems clear, but i'm not sure i understand why you made it do that, and i'm no way near capable of telling if it actually does /checking for mistakes in the math .It will take quite some time to think if it's covering properly what happens in game from thought experiment and testing in game loops :p. And even longer to try and understand the math used to represent what you describe that is supposed to be what is happening in the game.

I'm not sure why the "at this time the next block should open up and the cycle repeats". I still think it may matter the block length dividing or not evenly the train length+braking distance in such case, maybe as a "worse" division would means a longer time for the train to wait before being able to re-accelerate.

To my intuition the block length modulo or not the train length +braking distance, may/might act somewhat similarly as difference in reaction time of drivers as if some trains re-accelerate when the train front of them has just started , or sometimes leaving a long time = distance gap . Not sure the analogy is correct there.

I think there is a set of equations that can predict the flow on a loop on which occurs a certain traffic jam because it will be periodic, i think it will have to do with modeling the behavior of 1 train and the density of that one train over time considering its velocity impact its braking distance and also its position impact the amount of block it occupy.

I was watching the loop of train for a long time thinking, if that one train is stuck at 0 velocity in between 2 blocks, it's not the same as if the same train is stuck at 0 velocity inside 1 single block in both case the braking distance is temporarily 0, but the effective amount of space occupied by the train goes from simple to double, in case of block sized like the train. Now if you look at the loop for hours, ( and log the train velocity ) it occurs that the same pattern repeated after 16 occurences of velocity 0. Which makes me think that this is where the modulo block length modulo loop length lies.

If the loop is a certain size, it means the traffic jam will propagate at a certain speed reverse to the flow and as such trains will periodicly come to a velocity 0 at the exact same position relative to the loop. Sometimes the traffic jam will do a lap of loop, and immobilize train slightly in a different position due to the speed at which it propagate not being a modulo necessarily with the speed at which the trains run so this leads to different kind of traffic jam/loop relation, in the case i observed it was requiring 16 times for the train to stop so that it would have the same exact pattern of deceleration. I suppose that value "16" could be mathed out related to the speed of the traffic jam propagation and the length of the loop. The speed of the traffic jam propagation sounds like the "delay" between 2 trains following the same braking/acceleration pattern due to stop and go traffic but this number used to divide the difference between the position of the 2 trains when it occurs. If you have 100 trains 1 meter apart that start accelerating 1 second apart from each other, it will look like 1sec of time happens and 1m further something happens, so that's 1m/s wave propagation.

And then you get the question of position of train relative to the block it occupies and block length, because in factorio train are not points 1 meter apart, so their length increase the speed of propagation of the wave, also if there is lots of empty room behind a train in a single block, but if the train is slow to accelerate and clear its own length, it takes more time for the following train to start moving , which lower the speed of propagation of the traffic jam. As such i think longer block length would impact the cycle of braking acceleration, them being out of phase is one thing, them looking different / different time accelerating braking or starting at different speed, would be more problematic to calculate density from the behavior of a single train.

At this point the model you are making that is on a straight line, is not going to yield the same results as one that tries to math out the resonance between the loop length and the traffic jam.
farcast wrote: Sat Dec 16, 2023 1:56 am I had to use newton's method to find the travel time, and I can't think of a way to directly calculate max throughput from this, so you just have to get by without it.
I don't understand this, isn't your graph showing the max throughput ? I don't see what i do have to get by without. It seemed to me you detailed earlier how you did calculate max throughput. Was it only "some predicted throughput" considering the interaction with block length ? And there is still a way missing to know what is the optimal parameter for block length to maximize the new way you calculated "some predicted throughput" ? to me it seem like clicking on the graph shows the maximum throughput that's enough to make tests :)

Although i'm not sure what it means to calculate the maximum flow of a "traffic jam", the minimum throughput makes sense to me. It would represent a traffic jam so bad only 1 train can move at a time and the flow would be the acceleration inversely proportionnal to the number of train factored by their length. I suppose the "maximum" would be something like only 1 vehicule being impacted by the traffic jam otherwise there would be no traffic jam at all and considering this is the segment of a network where there would be the lowest throughput, on a loop , there couldn't be an average higher than the throughput occuring due to that specific interaction at that specific location but then there's a whole range of possible intermediate throughput when there is 2 or 3 or 5 or 12 trains that are experiencing the "stop" phase of the "stop and go" at the same time. This is also part of why i said earlier than the models may give different results.

On a straight line, it may be possible to calculate how much time a traffic jam caused by 1 train running out of fuel for 10 second before manual refuel would need to disappear, or IF it will disappear, given a number of train per minutes piling up behind it. that would be pretty cool math. Going into looking at junctions, considering 1 train is blocking the path of another for x second is similar situation.

Having speed overtime and block length and train lengh allow to know when the last driver in the formula race starting grid will start moving by modelizing the increasing distance between the first and second car, and then second and third, and delaying the acceleration of the second car when the first one has clear "block length" no ?

Then it is also possible to know if that amount of time is more or less than the time the lane was stopped due to junction, and thus the number of trains that piled up behind the first one, and thus the rank of the last driver ? which keeps increasing as long as there is at least 1 standing vehicule.

There is plenty of experimental data on junction throughput waiting for someone to corellate throughput and some value to help people designing them :D


Edit: actually i may have spotted something, i think there is a "k" factor missing in the vmax or the V0(max), as it doesn't show properly the correct speed cap when set in km/h i think it is stuck at showing 82.8 when it should be multiplied by 3.6 to show in km/h
mrvn
Smart Inserter
Smart Inserter
Posts: 5860
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Maximum throughput of a rail line

Post by mrvn »

quyxkh wrote: Fri Dec 15, 2023 8:56 pm Max throughput on a single line over a given distance seems like the figure of merit to me, I don't see any reason to include congestion because whatever the shortest inter-congestion distance is will have at most the congestion-free throughput for that distance, so that will be the best possible throughput for the entire route. With rocket fuel a 1-4 train takes almost a full km to hit top speed but hey, the farther out you go for ore the less often you have to redo your outposts, so… sure, a 1km multilane acceleration buffer feeding 9km of single lane 1-4s at about 125 wagons/min, 2-8s would at least double that, if you smelt at the outpost end you should "easily" pump over a million plates per minute over a single line.
But why would you want full speed? Staying below full speed gives you a higher throughput (in many cases).

This also isn't about just plates. Ore and plates actually are the most boring part, just use bigger trains. They have so much throughput that it's worth it.

But consider all the other items you transport, especially with heavily modded games. And those items frequently become expensive and slow to produce. The more complex an item the more the amount condenses from the huge ore train down to even 1-1 trains. And soon you will have to transport that stuff to the spaceport to ship to another planet. :)
quyxkh
Smart Inserter
Smart Inserter
Posts: 1031
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Maximum throughput of a rail line

Post by quyxkh »

mrvn wrote: Sun Dec 17, 2023 6:19 pm But why would you want full speed? Staying below full speed gives you a higher throughput (in many cases).
Because no matter what, whatever lower-than-full speed you like, you get not just a little better but massively better throughput with trains long enough that that *is* full speed.
consider all the other items you transport, especially with heavily modded games. And those items frequently become expensive and slow to produce. The more complex an item the more the amount condenses from the huge ore train down to even 1-1 trains. And soon you will have to transport that stuff to the spaceport to ship to another planet. :)
Seems to me if you're not shipping huge quantities you don't want rail at all, you want belts or bots. A sushi train… hunh. Is it insane to even wonder if there's a sane design using one?
Post Reply

Return to “General discussion”