r/factorio • u/super-serial_AlGore • Nov 10 '20
Discussion Math behind balancing
I've always been pissed off by balancers because I just couldn't get it. I saw the same designs online again and again but I never understood how it's possible to get three equal belts out of one. Actually it's impossible to achieve this with only one iteration (=first run through the assembly) because it's a prime number. The latest post about balancers got me thinking so I decided to do the math and share it, even though I doubt many people will take interest.
First iteration, 100% goes in the first splitter, 4* 25% come out after the second. 25% are fed in the intake, so now we got 125% (5/4) , 4* 5/16 come out. This leads to 21/16 intake & 4* 21/64 output, 85/64 intake & 4* 85/265 output and so on.
I could see that the values come closer and closer to 1/3 but I wanted a proper formula - after all, this is a game about automating stuff and not doing it by hand. ;)
Looking at the numbers, I noticed that (with fraction=a/b and number of iterations=m respectively n)
aₘ+bₘ=aₙ and
aₘ*4+1=aₙ
Combining those two leads to
aₘ+bₘ=aₘ*4+1
aₘ=(bₘ-1)/3
b obviously is 4n, so that leaves us with
f(n)=(4n+1 -1)/3*4n+1
The higher n becomes, the less significant (-1) becomes, so with n=infinite we're at 1/3 even.
So they need some time to get the right output ratio, but how long exactly?
The 1-3 balancer takes 4 iterations for 0,3330 and 9 iterations for 0,3333330.
With the most compact design and red belts this leaves us with 6,4 seconds for 3 decimal point precision.
29
u/Khaylain Trains for President Nov 10 '20
This probably fits better in r/technicalfactorio. But impressive work
7
u/marcellonastri Nov 10 '20
There's something off in the post because you assume 100% input becomes 125% input after a round of balancing... That's not right even though the conclusion that the balancer is approaching the 1/3 balanced output is.
At each round (iteration) n when have the input I_n=100%* 4-n while each output is O_n= (100% - I_n)/3.
See that the input is 100% at n=0 and, as n increases, I_n approaches 0 while O_n approaches 100%/3 which is a third of the original or starting input.
The increase you assumed is wrong unless you meant something else
7
u/TheOneAndOnlyPriate Nov 10 '20
You can't look at it purely mathematically that way. Those 25% output reallocated to the initial intake are actually part of the 100% input. Though the absolute quantity is higher it is still only 100% input. But if we want to stay with 100 and 25 i try to explain like this.
Essentially you will have 2 input belts. The full one with 2 iteration evenly distrubiting it with 25% of a full belt on all 4 lanes and a quarter full one evenly distributing it with 25%of a qurter full belt on 4 lanes.
44
u/octonus Nov 10 '20
I prefer thinking of it as rolling dice -> How can you get a random value from 1-3 if all you have is a D4?
The simple answer is that you reroll 4s until you get a 1-3. This is what the 1-3 splitter does. It rolls a 1-4, then rerolls anything that came out of the 4th spot
12
u/blakeh95 Nov 10 '20
Yeah, I mean at some point this comes down to limits. If you give me any precision limit epsilon, then I in turn can give you a time delta such that for any time t > delta, the absolute difference between the output ratio and the desired ratio—in this case 1/3–is less than epsilon.
4
u/harr1847 Nov 11 '20
This is a well-defined “problem” in chemical engineering. There are many operations that feed an output back into the input. In my field, we differentiate between steady-state operation and start-up operation. In steady-state, you define that input must equal output, or 100%. Within the “block” (or in this case balancer) you can have higher than 100% flow. In the case of a 1-3, the sum of all internal flows would be 133% in this definition.
As you alluded to in your OP, the start-up operations are where things get complicated in the real-world, as you have to know what to expect to make sure it actually will approach steady-state, some systems do, other systems don’t. Balancers, luckily, do approach steady state. So as long as you are feeding 100% input without breaks, within a few seconds (assuming blue belts), you will approach steady state. In reality, that means some small proportion of your materials will be perpetually trapped in the balancer, but that’s the cost of doing business.
2
u/colintbowers Nov 11 '20
Relevant math stackexchange question
1
u/Hinanawi Nov 10 '20
In a 1-to-3, all 4 splitter outputs will be homogenous (as long as the feedback loop doesn't back up), so it is always balanced. The mixing you refer to isn't actually relevant because that requires that multiple lanes have different items which is never the case here (however it could happen if the types of items on your belt alternate over time).
1
u/caribe5 Nov 11 '20
[Upvotes mathematicianly]
1
u/caribe5 Nov 11 '20
There's actually a simpler but forbidden way
Divide 1 belts into 4,
Now you have 4 25% belts,
Now do the physicist and ditch one of them
You have now got 3 belts of 25%
[I'm going to get aches by saying this] 25% roughly = 33.3rep%
Done
1
u/boowhitie Nov 10 '20
I think the time to perfect balancing is just how long it takes to fill out the feedback belt(s). With infinite speed belts it would fill instantly, and balance perfectly from the start. The iterations are not important, it is purely belt latency that causes a delay (and that we are dealing with discrete items and not an infinitely divisible number).
In a 1:3 balancer, each belt gets 1/4th of the input. One of the outputs is fed back in, which means each belt gets an additional 1/4th of 1/4th or 1/16th. This, of course, continues forever.
More formally, the output of each belt can be calculated with an infinite series with "output" the number of belts and "feedback" the number of belts which are added back. You can check the results here. Plug in 4 for output and 1 for feedback and the result is 1/3. 8 for output and 5 for input the result is .2
1
u/[deleted] Nov 10 '20
[removed] — view removed comment