Helping with some math

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Post Reply
DepletionMeeple
Burner Inserter
Burner Inserter
Posts: 8
Joined: Fri Feb 16, 2018 4:34 am
Contact:

Helping with some math

Post by DepletionMeeple »

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:
setup.jpg
setup.jpg (203.4 KiB) Viewed 4319 times
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.
advanced setup.jpg
advanced setup.jpg (25.11 KiB) Viewed 4319 times
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?

quyxkh
Smart Inserter
Smart Inserter
Posts: 1027
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Helping with some math

Post by quyxkh »

There was a sign on a ship I was on, The Superior Sailor uses his Superior Experience, Superior Discipline and Superior Judgement to Stay The Hell Out of situations requiring the use of his Superior Skills.

User avatar
impetus maximus
Smart Inserter
Smart Inserter
Posts: 1299
Joined: Sat Aug 20, 2016 10:07 pm
Contact:

Re: Helping with some math

Post by impetus maximus »

try this
blueprint string
should balance the input, and the output.

Engimage
Smart Inserter
Smart Inserter
Posts: 1067
Joined: Wed Jun 29, 2016 10:02 am
Contact:

Re: Helping with some math

Post by Engimage »

To implement balancing between rows I would suggest you using power switch turning on/off power for the respective rows. And you can use the same logic like with inserters within a row to balance rows with each other. Or you can just stop the input belt for the row if you want to avoid power switches like I do.

User avatar
impetus maximus
Smart Inserter
Smart Inserter
Posts: 1299
Joined: Sat Aug 20, 2016 10:07 pm
Contact:

Re: Helping with some math

Post by impetus maximus »

*taps mic
is this thing on?
nevermind :roll:
Last edited by impetus maximus on Wed Feb 21, 2018 2:39 pm, edited 1 time in total.

Caine
Fast Inserter
Fast Inserter
Posts: 213
Joined: Sun Dec 17, 2017 1:46 pm
Contact:

Re: Helping with some math

Post by Caine »

impetus maximus wrote:*taps mic
is this thing on?
It does not matter if it is on or not. Depending on the type of mic you use, tapping it can cause damage/break it.

Don't tap on microphones.

User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2631
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

Re: Helping with some math

Post by steinio »

Caine wrote:
impetus maximus wrote:*taps mic
is this thing on?
It does not matter if it is on or not. Depending on the type of mic you use, tapping it can cause damage/break it.

Don't tap on microphones.
Yes every idiot in tv series does it - so annoying.
Soundcheck: https://www.youtube.com/watch?v=J6P8tdUJ-uc
Image

Transport Belt Repair Man

View unread Posts

User avatar
Deadly-Bagel
Smart Inserter
Smart Inserter
Posts: 1498
Joined: Wed Jul 13, 2016 10:12 am
Contact:

Re: Helping with some math

Post by Deadly-Bagel »

I think you might be looking at this the wrong way.

First of all I think we can assume that stuff isn't going to be added to overfull chests, right? The first Inserter won't pick anything from the belt if its chest is above average. Therefore the only time you should end up with anything over the stack size in one chest while the next is empty, is if both chests previously had items in them and one of them had items removed.

That in mind, this seems a pretty weird use-case. You're obsessing over getting the right numbers in each chest but not about the draw from them? Also, as each chest is next to each other (presumably) you only have one input and one output, so only the last chest in the chain can output anything, and if it's only going to contain one type of item then why not just let ALL items flow down the chain of chests? Connect all chests to the red network, and each Inserter to its entire column of chests in green networks.

Well, you could be using bots or something, idk, I'll give you the benefit of the doubt.

Is there any particular reason you don't just set up each row of Inserters all linked to their destination chest and receiving an average of all chests? If you want it to fill front-to-back, you would probably be able to have the first row of inserters say ([Coal] < 0), then the second row ([Coal] < -10) then ([Coal] < -20) and so on.

With a row of 8 chests and the above logic, each chest in the first row must contain an average of over 10 coal (81 or more total) for the second row to activate, but as long as supply is greater than demand a chest will always contain 10 more items (roughly, accounting for stack size) than the next chest in the chain. However, if one column is drained faster than the others, the high average will be maintained so it'll draw more items from the front.
Money might be the root of all evil, but ignorance is the heart.

DepletionMeeple
Burner Inserter
Burner Inserter
Posts: 8
Joined: Fri Feb 16, 2018 4:34 am
Contact:

Re: Helping with some math

Post by DepletionMeeple »

PacifyerGrey wrote:To implement balancing between rows I would suggest you using power switch turning on/off power for the respective rows. And you can use the same logic like with inserters within a row to balance rows with each other. Or you can just stop the input belt for the row if you want to avoid power switches like I do.
It's not the problem to use a logic that turns a row of inserters on or off - using power switches or using combinators. The core problem is to decide WHEN to turn the inverters on and when to turn them off.
Right now, I'm turning all inserters of the second row on, as soon as all chests in row one reach a certain value. My original question was: How high has this value to be to ensure, that ALL chests of the second row will be filled equally.

As I wrote in my example: Although every chest of row one only fills up if it is under the average amount of items, even with 339 items in 16 chests, it is possible that one chest is still empty. So where is the threshold?350? 400? 1K? I don't know how to calculate that. Solving this issue practical is easy by setting this threshold high enough not to worry about. For example: In my 32/12/12 installation, the threshold is simply put on 10K, which is practically sufficient (at least practically). But in this installation (32 chests in a row - inserters with stack size 12 in first row and inserters with stack size 12 in second row, I had situations, where I had 3K items in the first row and still one chest was empty.

Deadly-Bagel wrote:I think you might be looking at this the wrong way.

First of all I think we can assume that stuff isn't going to be added to overfull chests, right? The first Inserter won't pick anything from the belt if its chest is above average. Therefore the only time you should end up with anything over the stack size in one chest while the next is empty, is if both chests previously had items in them and one of them had items removed.
I think this is wrong: This logic only works if there are two chests, not if there are 32 chests. For example (with just 4 chests):
C1: 0
C2: 0
C3: 0
C4: 12
Total (T): 12
Average (A): 3
Now the items on the belt are only coming sporadic so that the inserter would also fill a chest with less than its stacksize. Then we could have:
C1: 0
C2: 4
C3: 4
C4: 12 (as C4 would not add an item because it was above average)
T: 20
A: 5
Next could be:
C1: 0
C2: 4
C3: 16
C4: 12
T: 32
A: 8
Then:
C1: 0
C2: 8
C3: 16
C4: 12
T: 36
A: 9
Then:
C1: 0
C2: 20
C3: 16
C4: 12
T: 48
A: 12
Now (with minimum 49 items) each chest must have at least ONE item when the first inserter has a stack size of 12. And this was not even the most extreme example. But it shows we can easily have two out of four chests having above stack size while one is empty.
As I said above - in a running installation, I have seen about 3K in 32 chests, stack size 12 and one was still empty.
Deadly-Bagel wrote:I think you might be looking at this the wrong way.
With a row of 8 chests and the above logic, each chest in the first row must contain an average of over 10 coal (81 or more total) for the second row to activate, but as long as supply is greater than demand a chest will always contain 10 more items (roughly, accounting for stack size) than the next chest in the chain. However, if one column is drained faster than the others, the high average will be maintained so it'll draw more items from the front.
Same problem: if I have 8 chests, and they have a total of 81 or more, there are several ways, one or more chests could still be empty. So we come back to the original question: What is the threshold for 8 chests stack size 10 for first row inserter and stack size 1 for second row inserter. Written mathematically: What is minimum for F(8,10,1)? It is not 81.

DepletionMeeple
Burner Inserter
Burner Inserter
Posts: 8
Joined: Fri Feb 16, 2018 4:34 am
Contact:

Re: Helping with some math

Post by DepletionMeeple »

impetus maximus wrote:try this
blueprint string
should balance the input, and the output.

Well I tried, but it didn't work.
It neither balanced input nor output?
By the way: How is dividing by zero meant to work? I never tried to do somethink like */0.

User avatar
impetus maximus
Smart Inserter
Smart Inserter
Posts: 1299
Joined: Sat Aug 20, 2016 10:07 pm
Contact:

Re: Helping with some math

Post by impetus maximus »

DepletionMeeple wrote: Well I tried, but it didn't work.
It neither balanced input nor output?
By the way: How is dividing by zero meant to work? I never tried to do somethink like */0.
what? they are set to / -16 (number of rows), then the chests add to the that (to the inserter).
if coal is flowing in and out they will never load/unload from all inserters because it's moving through.
block the exit and you will see it balance. then open it, and block the entrance. it will balance again.

quyxkh
Smart Inserter
Smart Inserter
Posts: 1027
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Helping with some math

Post by quyxkh »

Splitters and a lane balancer will do for storage/compression buffering like this, you don't need circuitry. Wiring lets you work with full stacks in the buffer-chest lanes, everything else just works.
compression+mass-storage.buffer
snap@T79962=2048x1728-38.5+1.25,z2.jpg
snap@T79962=2048x1728-38.5+1.25,z2.jpg (281.33 KiB) Viewed 4155 times
One blue belt is 40/s, 8 buffer lanes is 5/sec, fast inserters can load faster than that easily. Nothing I've thought of to torture it short of actual sabotage has unbalanced the buffer-chest lanes, I've tried all kinds of unbalanced/even/bursty loads for long durations with out-of-spec alarms attached, the output buffer chests never go ≥16 above/below the average, and I've only seen half that rarely.
compression+mass-storage.buffer-w-oos-warnings

DepletionMeeple
Burner Inserter
Burner Inserter
Posts: 8
Joined: Fri Feb 16, 2018 4:34 am
Contact:

Re: Helping with some math

Post by DepletionMeeple »

impetus maximus wrote: what? they are set to / -16 (number of rows), then the chests add to the that (to the inserter).
if coal is flowing in and out they will never load/unload from all inserters because it's moving through.
block the exit and you will see it balance. then open it, and block the entrance. it will balance again.
Maybe you should post your combinator settings. I once again build the blueprint, had again a zero as divisor and even if I change it to -16 it had no effect. No balancing.
combinatorsetting.jpg
combinatorsetting.jpg (116.42 KiB) Viewed 4149 times

DepletionMeeple
Burner Inserter
Burner Inserter
Posts: 8
Joined: Fri Feb 16, 2018 4:34 am
Contact:

Re: Helping with some math

Post by DepletionMeeple »

quyxkh wrote: One blue belt is 40/s, 8 buffer lanes is 5/sec, fast inserters can load faster than that easily. Nothing I've thought of to torture it short of actual sabotage has unbalanced the buffer-chest lanes, I've tried all kinds of unbalanced/even/bursty loads for long durations with out-of-spec alarms attached, the output buffer chests never go ≥16 above/below the average, and I've only seen half that rarely.
You are right - splitters and belts are absolute sufficient for distributing incoming items properly. And for a <100 chest installation this is a neat and sufficient setup, thanks for taht. But for larger installations (please no discussion why someone wants to have large storages) you miss some kind of auto correction feature.

Imagine setups like 128 chests in a row and 100 rows. And imagine several things that should not but nevertheless may occur:
- You accidentally remove one chest by clicking right or - even worse - you accidentally remove a lot of chests by dragging your deconstruction planner carelessly
- You get short of power and therefore some inserters are running faster than others for a while
- If you blueprint some bigger storage, you miss one substsation, because a robot has to fetch it from a far away storage chest and for some minutes, an area of 20 chests/inserters isn't working and you don't notice
- You are running through your storage and accidentally hit R at the wrong spot and one belt shows in the wrong direction causing parts of the buffer not be loaded
...
An unbalanced storage with >10K boxes and round about 50M items can't be corrected easily neither by blueprint nor manually.

And besides that: It is a mathematical question, I really want to be answered and it drives me nuts, that I don't get a formula for that.
Last edited by DepletionMeeple on Thu Feb 22, 2018 8:31 am, edited 1 time in total.

User avatar
impetus maximus
Smart Inserter
Smart Inserter
Posts: 1299
Joined: Sat Aug 20, 2016 10:07 pm
Contact:

Re: Helping with some math

Post by impetus maximus »

are you playing 0.15, or 0.16? those blueprint strings are from 0.16.25

DepletionMeeple
Burner Inserter
Burner Inserter
Posts: 8
Joined: Fri Feb 16, 2018 4:34 am
Contact:

Re: Helping with some math

Post by DepletionMeeple »

impetus maximus wrote:are you playing 0.15, or 0.16? those blueprint strings are from 0.16.25
Playing 0.15 - but besides that very first and last inserter/loader/whatelse - does it contain any .16 technology?

User avatar
impetus maximus
Smart Inserter
Smart Inserter
Posts: 1299
Joined: Sat Aug 20, 2016 10:07 pm
Contact:

Re: Helping with some math

Post by impetus maximus »

i guess the combinator settings got lost for some reason. that one had infinity chests just to supply the coal, and to void it.

here is a 0.15.37 string that has the correct settings.
0.15 blueprint string

quyxkh
Smart Inserter
Smart Inserter
Posts: 1027
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Helping with some math

Post by quyxkh »

DepletionMeeple wrote: And besides that: It is a mathematical question, I really want to be answered and it drives me nuts, that I don't get a formula for that.
I should have seen that, my apologies. I still think there's a simple solution to the Factorio part of the puzzle, see below, but yeah, tackling it head-on leads to nerd-sniping-level math and that's its own kind of fun.
- You accidentally remove one chest by clicking right or - even worse[…]
haha, I have never done anything like that. You believe me, don't you?

Kidding aside, yah, there's no disaster recovery, small or large, built in to that design, and it'd need addressing.
An unbalanced storage with >10K boxes and round about 50M items can't be corrected easily neither by blueprint nor manually.


but it can, with just one combinator, and it's easy enough to construct that you can do it on the fly with two ad hoc and disposable prints. To avoid brownout trouble I use a canary accumulator wired to belt shutoffs. Damage-induced-unbalance recovery is as simple as
find the tip row of the backup, the closest to the loaders that has non-empty chests. Wire that row to an averager, carry the average and the chest counts back to the loading inserters to selectively control loading as usual, you'll need to add lane balancers to the inputs but there's room for that even in this little design without much trouble
.

Post Reply

Return to “Gameplay Help”