Tutorial:Quality upcycling math

From Official Factorio Wiki
Revision as of 11:54, 24 November 2024 by Untitled7 (talk | contribs) (→‎Number of crafting machines)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

How do we get the most amount of legendary items out of an upcycling plant?

The answer is not quite as straight forward as we'd like it to be, because it depends on a number of factors, luckily there is a finite number of possibilities of what the modules can be, and for the sake of simplicity this tutorial will ignore the productivity gain from infinite technologies. But first, a presentation of the results.

Best ratios

The table below shows the best ratio for quality to productivity modules in the crafting machines, while the recyclers always take only quality modules. The values are not given in whole numbers because often it is not just a single crafting machine per tier that will be used, then the ratios can change between different crafting machines in the same tier. e.g. "3.67 quality / 1.33 productivity" could have 4 machines where 3 have a ratio 4 to 1, and one a ratio 3 to 2.

The columns "Modules for X items" denote which modules need to go into the machines that are set to produce items of X quality.

Crafting machine Modules for common items Modules for uncommon items Modules for rare items Modules for epic Modules for legendary Percentage yield Items recycled*
Chemical plant 3 quality
0 productivity
3 quality
0 productivity
3 quality
0 productivity
3 quality
0 productivity
0 quality
3 productivity
0.034014% 2940
Assembling machine 3 4 quality
0 productivity
4 quality
0 productivity
4 quality
0 productivity
4 quality
0 productivity
0 quality
4 productivity
0.046275% 2161
Foundry 4 quality
0 productivity
4 quality
0 productivity
4 quality
0 productivity
4 quality
0 productivity
0 quality
4 productivity
0.133814% 747
Electromagnetic plant 5 quality
0 productivity
5 quality
0 productivity
5 quality
0 productivity
5 quality
0 productivity
0 quality
5 productivity
0.176712% 566
Cryogenic plant 6 quality
2 productivity
6 quality
2 productivity
6 quality
2 productivity
6.5 quality
1.5 productivity
0 quality
8 productivity
0.119134% 840
* "items recycled" quantifies how many items need to be crafted and put into the entire upcycler to yield a single legendary item, it doesn't account for those which get recycled multiple times.

The columns "Modules for X items" denote which modules need to go into the machines that are set to produce items of X quality.

Crafting machine Modules for common items Modules for uncommon items Modules for rare items Modules for epic Modules for legendary Percentage yield Items recycled*
Chemical plant 3 quality
0 productivity
3 quality
0 productivity
3 quality
0 productivity
3 quality
0 productivity
0 quality
3 productivity
0.059498% 1681
Assembling machine 3 3.75 quality
0.25 productivity
3.75 quality
0.25 productivity
3.8 quality
0.2 productivity
3.9 quality
0.1 productivity
0 quality
4 productivity
0.082296% 1216
Foundry 4 quality
0 productivity
4 quality
0 productivity
4 quality
0 productivity
4 quality
0 productivity
0 quality
4 productivity
0.243699% 410
Electromagnetic plant 4.7 quality
0.3 productivity
4.67 quality
0.33 productivity
4.75 quality
0.25 productivity
4.9 quality
0.1 productivity
0 quality
5 productivity
0.324189% 309
Cryogenic plant 4.6 quality
3.4 productivity
4.6 quality
3.4 productivity
4.67 quality
3.33 productivity
5 quality
3 productivity
0 quality
8 productivity
0.257621% 389
* "items recycled" quantifies how many items need to be crafted and put into the entire upcycler to yield a single legendary item, it doesn't account for those which get recycled multiple times.

The columns "Modules for X items" denote which modules need to go into the machines that are set to produce items of X quality.

Crafting machine Modules for common items Modules for uncommon items Modules for rare items Modules for epic Modules for legendary Percentage yield Items recycled*
Chemical plant 2.8 quality
0.2 productivity
2.8 quality
0.2 productivity
2.9 quality
0.1 productivity
2.9 quality
0.1 productivity
0 quality
3 productivity
0.100660% 994
Assembling machine 3 3 quality
1 productivity
3.1 quality
0.9 productivity
3.2 quality
0.8 productivity
3.33 quality
0.67 productivity
0 quality
4 productivity
0.145220% 689
Foundry 3.5 quality
0.5 productivity
3.5 quality
0.5 productivity
3.6 quality
0.4 productivity
3.9 quality
0.1 productivity
0 quality
4 productivity
0.424039% 236
Electromagnetic plant 3.6 quality
1.4 productivity
3.6 quality
1.4 productivity
3.6 quality
1.4 productivity
3.9 quality
1.1 productivity
0 quality
5 productivity
0.588510% 170
Cryogenic plant 3.6 quality
4.4 productivity
3.6 quality
4.4 productivity
3.6 quality
4.4 productivity
3.9 quality
4.1 productivity
0 quality
8 productivity
0.565030% 177
* "items recycled" quantifies how many items need to be crafted and put into the entire upcycler to yield a single legendary item, it doesn't account for those which get recycled multiple times.

The columns "Modules for X items" denote which modules need to go into the machines that are set to produce items of X quality.

Crafting machine Modules for common items Modules for uncommon items Modules for rare items Modules for epic Modules for legendary Percentage yield Items recycled*
Chemical plant 2.33 quality
0.67 productivity
2.4 quality
0.6 productivity
2.4 quality
0.6 productivity
2.4 quality
0.6 productivity
0 quality
3 productivity
0.152486% 656
Assembling machine 3 2.5 quality
1.5 productivity
2.5 quality
1.5 productivity
2.6 quality
1.4 productivity
2.8 quality
1.2 productivity
0 quality
4 productivity
0.232966% 430
Foundry 2.7 quality
1.3 productivity
2.7 quality
1.3 productivity
2.75 quality
1.25 productivity
3 quality
1 productivity
0 quality
4 productivity
0.664130% 151
Electromagnetic plant 2.6 quality
2.4 productivity
2.6 quality
2.4 productivity
2.67 quality
2.33 productivity
2.9 quality
2.1 productivity
0 quality
5 productivity
0.974700% 103
Cryogenic plant 2.6 quality
5.4 productivity
2.6 quality
5.4 productivity
2.6 quality
4.4 productivity
2.8 quality
4.2 productivity
0 quality
8 productivity
1.122444% 90
* "items recycled" quantifies how many items need to be crafted and put into the entire upcycler to yield a single legendary item, it doesn't account for those which get recycled multiple times.

The columns "Modules for X items" denote which modules need to go into the machines that are set to produce items of X quality.

Crafting machine Modules for common items Modules for uncommon items Modules for rare items Modules for epic Modules for legendary Percentage yield Items recycled*
Chemical plant 1.67 quality
1.33 productivity
1.67 quality
1.33 productivity
1.67 quality
1.333 productivity
1.8 quality
1.2 productivity
0 quality
3 productivity
0.344061% 291
Assembling machine 3 1.67 quality
2.33 productivity
1.67 quality
2.33 productivity
1.67 quality
2.33 productivity
1.8 quality
2.2 productivity
0 quality
4 productivity
0.586191% 171
Foundry 1.4 quality
2.6 productivity
1.4 quality
2.6 productivity
1.4 quality
2.6 productivity
1.5 quality
2.5 productivity
0 quality
4 productivity
1.624266% 62
Electromagnetic plant 1 quality
4 productivity
1 quality
4 productivity
1 quality
4 productivity
1 quality
4 productivity
0 quality
5 productivity
2.722332% 37
Cryogenic plant 0 quality
8 productivity
0 quality
8 productivity
0 quality
8 productivity
0 quality
8 productivity
0 quality
8 productivity
4.835199% 21
* "items recycled" quantifies how many items need to be crafted and put into the entire upcycler to yield a single legendary item, it doesn't account for those which get recycled multiple times.

Number of crafting machines

If we assume a constant input stream of uncommon items, which will always fill back up, we can additionally figure out what ratio of items will be inside the system at once, and with that we can figure out how many crafting machines we need per tier of quality. This is done by setting after each iteration and further adjusting for the crafting machines change in speed dependant on the modules (assuming the machines which only house productivity modules are not additionally boosted by speed moduled beacons). See the calculations further below for a full explanation of the calculations.

Crafting machine Recyclers Machines producing common items Machines producing uncommon items Machines producing rare items Machines producing epic items Machines producing legendary items
Chemical plant 1 4.418130519 0.037216657 1.294369664 0.009779 0.431955
Assembling machine 3 1 4.733868899 0.052316655 1.527502978 0.015336 0.52576
Foundry 1 4.314446 0.082198 1.683088 0.03016 0.58448
Electromagnetic plant 1 4.494435 0.116985 1.93479 0.049665 0.60795
Cryogenic plant 1 5.23556 0.21384 2.53374 0.1034 0.594

Crafting machine Recyclers Machines producing common items Machines producing uncommon items Machines producing rare items Machines producing epic items Machines producing legendary items
Chemical plant 90.1223 331.8198 38.5325 11.2893 2.9653 1
Assembling machine 3 52.8432 208.4632 30.3992 9.8094 2.8783 1
Foundry 24.7668 89.0483 19.9206 7.7712 2.8592 1
Electromagnetic plant 16.5379 61.9418 17.4010 7.4908 3.1822 1
Cryogenic plant 10.8718 47.4350 18.2124 8.8138 4.2654 1

Crafting machine Recyclers Machines producing common items Machines producing uncommon items Machines producing rare items Machines producing epic items Machines producing legendary items
Chemical plant 53 198 23 7 2 1
Assembling machine 3 31 123 18 6 2 1
Foundry 14 53 12 5 2 1
Electromagnetic plant 14 56 16 7 3 1
Cryogenic plant 9 41 16 8 4 1

The crafting machines

Crafting machine Module slots Base productivity bonus
Chemical plant 3 +0%
Assembling machine 3 4 +0%
Foundry 4 +50%
Electromagnetic plant 5 +50%
Cryogenic plant 8 +0%


Quality probability

When an item gets produced and the initial roll decides that the quality of the item will increase, there is a 90% chance it will rise one tier, a 9% chance it will rise two, a 0.9% chance it will rise three, and a 0.1% chance it will rise four. This is of course capped if the item already started out at a higher tier.

Mathematical model

The mathematical model is time discrete. As opposed to dealing with derivatives in respect to time, the next state is a direct function of the previous state.

  • ... Number of materials of tier (whereas 1 is common, 2 is uncommon, 3 is rare, 4 is epic, and 5 is legendary) after the -th iteration before being crafted. (this doesn't mean that an item only needs one type of ingredient, but that "1 materials" can be crafted into 1 item from them)
  • ... Number of items of tier after the -th iteration, after being crafted together.
  • ... the crafting machines inherent productivity bonus
  • ... number of modules the crafting machine can hold
  • ... quality probability of the recyclers with 4 quality module 3's (6.2% is the chance of a legendary tier quality module 3)
  • ... productivity due to legendary productivity module 3's in the crafting machine which takes -tier materials (25% is the productivity boost of a legendary tier productivity module 3)
  • ... quality probability due to legendary quality module 3's in the crafting machine which takes -tier materials

Recycled materials

When a quarter of all items being recycled and the quality probability rules, we can write the equations for the amount of materials received after recycling. This calculation is rather simple, as uncommon items can only come forth from uncommon material failing to raise in quality. The second tier are 90% of tier 1 items that did increase, and all those tier 2 items that didn't. This continues for all tiers as follows, but legendary items will not be recycled

which can also be written as a vector-matrix-multiplication

As we assume there is nothing to be done about recyclers to make them more effective but fill them with all quality modules, the value of is a constant, and therefore the matrix is also a constant. For legendary quality module 3's, it looks like:

Recrafted items

Once more we first check how many items are produced, which is, again, the sum of all possible ways to get to a tier, this time adding productivity , and bringing along all those items which are already legendary

This can once more be written as a vector-matrix-multiplication

Combined model

As such we gain an equation for the amount of items for every tier after any amount of iterations

A realistic starting point for is only items in tier 1, and if we do not care for any other tiers, we simply choose sufficiently large , and, through numeric means, try to maximize a single value. , which falls in the fifth row, first column, of the Matrix raised to the 100th power.

The choice of optimization method (simplex, branch and bound, etc.) itself is irrelevant, although most software will want the problem to be stated in a way so it can find a minimum, and may require the proper guard rails as to not pick values below 0 or higher than the maximum number of allowed modules.