Helping with some math
Posted: Tue Feb 20, 2018 9:03 pm
Hello,
usually I try to fix problems like this on my own - but I got stuck here. The problem I have is a more abstract math problem, but it triggered me when trying to calculate the perfect threshold value for a factorio storage logic.
Setup: There is a belt and alongside a couple of inserters that put items from the belt into a chest. The belt only has one kind of item - no mixed belts. Usually these are 32 chests in a row, but sometimes only 8 etc. And usually the inserters have a stack size of 12, but sometimes only 3 or even 1.
To avoid one chest being full and another one being empty (because the belt arrives at one box earlier) I implemented the following logic:
This example is made with one blue belt for coal, 16 chests, and stack inserters with stack size 12.
The combinator counts all coal in all chests and divides the number by 16 - so output A gives me the average amount of coal per chest.
All inserters are connected by a second red wire to the combinator to get the average amount of coal as input A. Additionally each inserter is connected by a green wire to the box behind, which gives them the amount of coal in its chest. Any inserter is only activated if its chest contains less coal than the average amount of coal.
In general this system works but it gets a bit complicated when I extend this setup with more chests. For example if I have a second and third row of 16 chests - always connected by inserters.
The logics are here: Only if the first row of chests has more than x coal in total, activate the inserters for the second row.
Additionally I want to assure, that each chest of the second row has the same amount of coal. In generally this works, but the problem is the value for x.
For example: Let's say the inserters for the second row activate, if the first row has more than 100 coal in total. Then it might be the case that nine chests each contain 12 coal and another seven chests are empty. In this case the inserters for the second row will be activated and seven chests of the second row stay empty.
To avoid this, one could simply increase the number, that would activate the inserters for the second row. But how high is high enough? I'd like to have a formula, that uses 1.) number of chests, 2.) stack size of inserter for first row, 3.) stack size of inserter for second row. The result should be the minimum number of overall coal in the chests of the first row to ensure that every chest has at least enough coal for a full inserter stack 3.) in its chest.
For example (16 chests, stack size first row 12, stack size second row 1)
Chest 1: 0 coal
Chest 2-9: 12 coal
Chest 10-16: 9 coal
Chest 1, 10-16 would be active (as the average is 10). Chest 1 stays empty and Chest 10 to 16 fill up with 12 more coal. So we have:
Chest 1: 0 coal
Chest 2-9: 12 coal
Chest 10-17 21 coal
The new average is 15 and chests 2-9 could load another 12 coal:
Chest 1: 0 coal
Chest 2-9 = 24 coal
Chest 10-17 21 coal
Now only chest 1 could fill up as all other chests were above average. But we already have 339 coal inside those 15 chests. So I'd like to know, what is the minimum number of coal over all chests in the first row to ensure, that each chest has at least x coal inside. If the solution to this would be indeed 339 (I doubt it), the formula should give me 339 as the result with the inputs 16 chest, stack size of first row 12 and stack size of second row is 1. Like F(16,12,1) = 339
Right now, I need those number for a 32/12/12 installation. Any help?
usually I try to fix problems like this on my own - but I got stuck here. The problem I have is a more abstract math problem, but it triggered me when trying to calculate the perfect threshold value for a factorio storage logic.
Setup: There is a belt and alongside a couple of inserters that put items from the belt into a chest. The belt only has one kind of item - no mixed belts. Usually these are 32 chests in a row, but sometimes only 8 etc. And usually the inserters have a stack size of 12, but sometimes only 3 or even 1.
To avoid one chest being full and another one being empty (because the belt arrives at one box earlier) I implemented the following logic:
This example is made with one blue belt for coal, 16 chests, and stack inserters with stack size 12.
The combinator counts all coal in all chests and divides the number by 16 - so output A gives me the average amount of coal per chest.
All inserters are connected by a second red wire to the combinator to get the average amount of coal as input A. Additionally each inserter is connected by a green wire to the box behind, which gives them the amount of coal in its chest. Any inserter is only activated if its chest contains less coal than the average amount of coal.
In general this system works but it gets a bit complicated when I extend this setup with more chests. For example if I have a second and third row of 16 chests - always connected by inserters.
The logics are here: Only if the first row of chests has more than x coal in total, activate the inserters for the second row.
Additionally I want to assure, that each chest of the second row has the same amount of coal. In generally this works, but the problem is the value for x.
For example: Let's say the inserters for the second row activate, if the first row has more than 100 coal in total. Then it might be the case that nine chests each contain 12 coal and another seven chests are empty. In this case the inserters for the second row will be activated and seven chests of the second row stay empty.
To avoid this, one could simply increase the number, that would activate the inserters for the second row. But how high is high enough? I'd like to have a formula, that uses 1.) number of chests, 2.) stack size of inserter for first row, 3.) stack size of inserter for second row. The result should be the minimum number of overall coal in the chests of the first row to ensure that every chest has at least enough coal for a full inserter stack 3.) in its chest.
For example (16 chests, stack size first row 12, stack size second row 1)
Chest 1: 0 coal
Chest 2-9: 12 coal
Chest 10-16: 9 coal
Chest 1, 10-16 would be active (as the average is 10). Chest 1 stays empty and Chest 10 to 16 fill up with 12 more coal. So we have:
Chest 1: 0 coal
Chest 2-9: 12 coal
Chest 10-17 21 coal
The new average is 15 and chests 2-9 could load another 12 coal:
Chest 1: 0 coal
Chest 2-9 = 24 coal
Chest 10-17 21 coal
Now only chest 1 could fill up as all other chests were above average. But we already have 339 coal inside those 15 chests. So I'd like to know, what is the minimum number of coal over all chests in the first row to ensure, that each chest has at least x coal inside. If the solution to this would be indeed 339 (I doubt it), the formula should give me 339 as the result with the inputs 16 chest, stack size of first row 12 and stack size of second row is 1. Like F(16,12,1) = 339
Right now, I need those number for a 32/12/12 installation. Any help?