[2.0.16] Recycler quality enrichment setup resulted in non-balanced output

Bugs that are actually features.
User avatar
Hares
Filter Inserter
Filter Inserter
Posts: 334
Joined: Sat Oct 22, 2022 8:05 pm
Contact:

[2.0.16] Recycler quality enrichment setup resulted in non-balanced output

Post by Hares »

I made a recycling loop for quality enrichment on modules, and it looks like items with percent-based chance are of-ratio:

T3 speed module disassembly:
  • 100% 1x T2 module
  • 100% 1x red circuit, with 25% 1x extra red circuit
  • 100% 1x blue circuit, with 25% 1x extra blue circuit
  • 100% 0x tungsten carbide, with 25% 1x extra tungsten carbide
In other words, there's 100% chance to get one of each red circuit, blue circuit, and T2 module, and 25% chance to get one red circuit, one blue circuit, or one tungsten carbide. Assuming law of large numbers should take place, I made a closed recycling setup and left it work for a while making sure no disassembly results never leave the build (after manual maintenance, if any, any "stragglers" are returned to the setup).
Images

After some time, I noticed significant disbalance in the output of recyclers. I added wiring to count exactly how many are present inside the build and watched it slowly start to clock up:
Belt content + assembler content
Belt content + assembler content
11-09-2024, 17-04-55.png (99.58 KiB) Viewed 840 times
The ratio between T2Q2 speed modules and Q2 tungsten carbide is not 4:1.
Ratios!
Ratios!
11-09-2024, 17-03-12.png (104.05 KiB) Viewed 840 times
Note: Even though quality enrichment of drills is present on the diagram, the actual enrichment never started, and the recyclers stopped after 42 drills -- I hadn't finished that build when noticed the disbalance on speed modules.

Everything worked fine on 2.0.15, it looks something broke on 2.0.16.
I will report later with more testing.
User avatar
Hares
Filter Inserter
Filter Inserter
Posts: 334
Joined: Sat Oct 22, 2022 8:05 pm
Contact:

Re: [2.0.16] Recycler quality enrichment setup resulted in non-balanced output

Post by Hares »

I made a test world setup and it is indeed unbalanced (I let it work for > 10h of factorio-time).
Attaching both setup blueprint (requires editor extensions; text plates; nixie tubes) and the save file.

Test conditions - same as on the "prod" version but scaled up:
  • T3Q1 & T3Q2 speed modules as input (with a customly-selected ratio of 3:1)
  • T3Q3 quality modules in recyclers (+16% quality)
  • Q4 & Q5 are not unlocked
11-09-2024, 18-21-13.png
11-09-2024, 18-21-13.png (583.72 KiB) Viewed 818 times

11-09-2024, 18-26-04.png
11-09-2024, 18-26-04.png (381.69 KiB) Viewed 818 times
These "expected from actual" numbers are based on the number of T2Q2 speed modules produced by the build.
Attachments
120584 - Recycler unbalanced output.zip
(3.41 MiB) Downloaded 8 times
User avatar
Hares
Filter Inserter
Filter Inserter
Posts: 334
Joined: Sat Oct 22, 2022 8:05 pm
Contact:

Re: [2.0.16] Recycler quality enrichment setup resulted in non-balanced output

Post by Hares »

2nd update. I let it cook for another 250+ hours of Factorio (5h in real time) and distribution got more or less to the expected.
11-10-2024, 00-03-34.png
11-10-2024, 00-03-34.png (409.24 KiB) Viewed 786 times
Note that "Expected from input" numbers are not accurate as one of the recyclers worked at +13% quality instead of +16%

Edit: Re-calculated "Expected from input" taking the previous fact in mind:
11-10-2024, 00-20-18.png
11-10-2024, 00-20-18.png (42.56 KiB) Viewed 776 times
Attachments
120584 - Recycler unbalanced output - 250h later.zip
(5.06 MiB) Downloaded 7 times
J_nas
Burner Inserter
Burner Inserter
Posts: 6
Joined: Fri Apr 05, 2024 4:30 pm
Contact:

Re: [2.0.16] Recycler quality enrichment setup resulted in non-balanced output

Post by J_nas »

you can see this very well when doing recycling loops for 2 input recipes that on normal quality it overproduces one ingredient, on rare the other and so onImageImage
User avatar
Hares
Filter Inserter
Filter Inserter
Posts: 334
Joined: Sat Oct 22, 2022 8:05 pm
Contact:

Re: [2.0.16] Recycler quality enrichment setup resulted in non-balanced output

Post by Hares »

I partially solved the problem by adding steel chests as a buffer after sorting (one chest for each ingredient for each quality).
Rseding91
Factorio Staff
Factorio Staff
Posts: 14244
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [2.0.16] Recycler quality enrichment setup resulted in non-balanced output

Post by Rseding91 »

Thanks for the report however random is random. It's entirely possible that you get zero of one result and all of another with an ever increasingly small chance.
If you want to get ahold of me I'm almost always on Discord.
User avatar
Hares
Filter Inserter
Filter Inserter
Posts: 334
Joined: Sat Oct 22, 2022 8:05 pm
Contact:

Re: [2.0.16] Recycler quality enrichment setup resulted in non-balanced output

Post by Hares »

Rseding91 wrote: Sun Nov 10, 2024 7:23 pm Thanks for the report however random is random. It's entirely possible that you get zero of one result and all of another with an ever increasingly small chance.
I made some math. The odds of my 1st test outcome happening (according to the CLT) are about 0.23%. Can you tell me, is the same RNG algorithm used across all Factorio, including one exposed to the Lua API, or are they different? If 1st, I can make more advanced tests.
Flouid
Burner Inserter
Burner Inserter
Posts: 17
Joined: Sun Nov 26, 2017 3:52 pm
Contact:

Re: [2.0.16] Recycler quality enrichment setup resulted in non-balanced output

Post by Flouid »

I just want to add onto this that I've spent a considerable amount of time working on a blue circuit recycling plant and I've created half a dozen design iterations. It's not at 300% productivity yet so an input of normal circuits is toggled only when the belts inside the build start running low... I've had to manually clear the system of uncommon green circuits about a dozen times, and they keep backing up and clogging everything. It's never reds that fill in excess, but green circuits do appear to be returned more than the ratio would imply. Are you sure there is not a rounding issue? When I added logic to remove some uncommon green circuits when the belts were near backing up and no reds were present, the problem fixed itself. Only now it spits out some extra uncommon green circuits from time to time with no apparent reason. I think something is up.

Edit: A few hours later, this build has produced 6000 excess uncommon green circuits, and the problem is beginning to manifest at rare quality level... Something is wrong.
User avatar
Hares
Filter Inserter
Filter Inserter
Posts: 334
Joined: Sat Oct 22, 2022 8:05 pm
Contact:

Re: [2.0.16] Recycler quality enrichment setup resulted in non-balanced output

Post by Hares »

Flouid wrote: Wed Nov 13, 2024 2:37 am I just want to add onto this that I've spent a considerable amount of time working on a blue circuit recycling plant and I've created half a dozen design iterations. It's not at 300% productivity yet so an input of normal circuits is toggled only when the belts inside the build start running low... I've had to manually clear the system of uncommon green circuits about a dozen times, and they keep backing up and clogging everything. It's never reds that fill in excess, but green circuits do appear to be returned more than the ratio would imply. Are you sure there is not a rounding issue? When I added logic to remove some uncommon green circuits when the belts were near backing up and no reds were present, the problem fixed itself. Only now it spits out some extra uncommon green circuits from time to time with no apparent reason. I think something is up.

Edit: A few hours later, this build has produced 6000 excess uncommon green circuits, and the problem is beginning to manifest at rare quality level... Something is wrong.
Please, share your design. I want to recreate the setup on a larger time scale, so the numbers can be confirmed.

A side note: I started just adding steel chests after filters block on my enrichment setups just to prevent clocking. Or, to be exact, requiring a full chest of extra items to clock.
Flouid
Burner Inserter
Burner Inserter
Posts: 17
Joined: Sun Nov 26, 2017 3:52 pm
Contact:

Re: [2.0.16] Recycler quality enrichment setup resulted in non-balanced output

Post by Flouid »

Sure, this is the string. I will note that shortly after I posted, red circuits began to become more prevalent in the build... Now I'm not sure what to think anymore.

https://factoriobin.com/post/11xzbt
kelth
Manual Inserter
Manual Inserter
Posts: 1
Joined: Wed Nov 13, 2024 9:19 pm
Contact:

Re: [2.0.16] Recycler quality enrichment setup resulted in non-balanced output

Post by kelth »

I'm having the same issue with my legendary processing unit farm, it always clogs up with green chips after a time, every time I clear it, it slowly builds up an excess again. Never reds

I looked up my all time production stats :
green | red | ratio
3392661 | 338558 | 10,0209151755386 | uncommon
3344712 | 333671 | 10,0239817065313 | rare
3307360 | 330361 | 10,0113512188182 | epic
i can't post legendary since I produce legendary red chips on top of the setup

same thing happens on a my test world with an even larger sample size
I don't think we are all being unlucky here

When recycling a blue chip you always get 5 green chips back, it doesn't use RNG, but red chips do. Adding the RNG of quality on top might also play a part in it but I have not tested the recycling loop without it
Flouid
Burner Inserter
Burner Inserter
Posts: 17
Joined: Sun Nov 26, 2017 3:52 pm
Contact:

Re: [2.0.16] Recycler quality enrichment setup resulted in non-balanced output

Post by Flouid »

So I've ran this for quite a few hours now and I'm starting to conclude that in the long run, it is balanced. I've had to add what are pretty much "overflow valves" for green circuits at every quality, and even ones for red circuits at common and uncommon. I think random variance over very large numbers of crafts can swing pretty far in favor of green circuits if you get unlucky with reds for long enough, and then letting some out inevitably means that when variance catches up you'll have slightly too many reds. A ring of belts like in my build is not large enough to buffer these swings, so it looks like it's imbalanced. My bot builds with chests for supercapacitors do not suffer from this problem. I think Rseding was right after all.
User avatar
Hares
Filter Inserter
Filter Inserter
Posts: 334
Joined: Sat Oct 22, 2022 8:05 pm
Contact:

Re: [2.0.16] Recycler quality enrichment setup resulted in non-balanced output

Post by Hares »

Flouid wrote: Sun Nov 17, 2024 3:56 pm So I've ran this for quite a few hours now and I'm starting to conclude that in the long run, it is balanced. I've had to add what are pretty much "overflow valves" for green circuits at every quality, and even ones for red circuits at common and uncommon. I think random variance over very large numbers of crafts can swing pretty far in favor of green circuits if you get unlucky with reds for long enough, and then letting some out inevitably means that when variance catches up you'll have slightly too many reds. A ring of belts like in my build is not large enough to buffer these swings, so it looks like it's imbalanced. My bot builds with chests for supercapacitors do not suffer from this problem. I think Rseding was right after all.
It looks for me that it is balanced on the very long run -- more than 50 hours, and is unbalanced on runs ~10h. Maybe the RNG method has linear distribution when speaking strictly on the infinite time but on the finite time it's not. In other words, the cumulative distribution function itself is a function of time rather than straight line (which should be for a random value from 0 to 1).

I can't make a strict proof of that... yet -- I'm still considering options/methods to do so.
User avatar
Hares
Filter Inserter
Filter Inserter
Posts: 334
Joined: Sat Oct 22, 2022 8:05 pm
Contact:

Re: [2.0.16] Recycler quality enrichment setup resulted in non-balanced output

Post by Hares »

Okay, it seems I gathered the required math/statistics so I will be doing more tests on the recylclers. I am sure there's that's more complicated than "it's just random".

And yes, I will be referring to Ig Nobel winning paper.
User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 411
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: [2.0.16] Recycler quality enrichment setup resulted in non-balanced output

Post by Stringweasel »

Just a note: for these tests make sure to count actual items. The production statistics still has a few oddities as mentioned in 120132
Alt-F4 Author | Factorio Modder
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Official Contributor to Space Exploration
User avatar
Hares
Filter Inserter
Filter Inserter
Posts: 334
Joined: Sat Oct 22, 2022 8:05 pm
Contact:

Re: [2.0.16] Recycler quality enrichment setup resulted in non-balanced output

Post by Hares »

Stringweasel wrote: Mon Nov 18, 2024 10:42 am Just a note: for these tests make sure to count actual items. The production statistics still has a few oddities as mentioned in 120132
Exactly. And if you look at my testing design above, it only counts real items.
User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 3020
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: [2.0.16] Recycler quality enrichment setup resulted in non-balanced output

Post by BlueTemplar »

Hares wrote: Mon Nov 18, 2024 12:59 am
Flouid wrote: Sun Nov 17, 2024 3:56 pm So I've ran this for quite a few hours now and I'm starting to conclude that in the long run, it is balanced. I've had to add what are pretty much "overflow valves" for green circuits at every quality, and even ones for red circuits at common and uncommon. I think random variance over very large numbers of crafts can swing pretty far in favor of green circuits if you get unlucky with reds for long enough, and then letting some out inevitably means that when variance catches up you'll have slightly too many reds. A ring of belts like in my build is not large enough to buffer these swings, so it looks like it's imbalanced. My bot builds with chests for supercapacitors do not suffer from this problem. I think Rseding was right after all.
It looks for me that it is balanced on the very long run -- more than 50 hours, and is unbalanced on runs ~10h. Maybe the RNG method has linear distribution when speaking strictly on the infinite time but on the finite time it's not. In other words, the cumulative distribution function itself is a function of time rather than straight line (which should be for a random value from 0 to 1).

I can't make a strict proof of that... yet -- I'm still considering options/methods to do so.
https://en.wikipedia.org/wiki/Random_walk
To answer the question of how many times will a random walk cross a boundary line if permitted to continue walking forever, a simple random walk on Z will cross every point an infinite number of times.
So eventually, it balances again, but :
In one dimension, the trajectory is simply all points between the minimum height and the maximum height the walk achieved (both are, on average, on the order of √n.
The buffer you need to be X% sure to not stall grows with the number of crafts you do (but slower than the number of crafts you do).
(Which IIRC is a counter-intuitive property of the random walk ?)

(Not sure if being only on N rather than Z — not being able to go below 0 like here— radically changes the math ? I doubt it, since it doesn't seem to change it for more dimensions...)
BobDiggity (mod-scenario-pack)
Locked

Return to “Not a bug”