Tutorial:Quality upcycling math

From Official Factorio Wiki
Revision as of 19:11, 23 November 2024 by Untitled7 (talk | contribs)
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.

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 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
  • ... productivity due to legendary productivity module 3's in the crafting machine which takes -tier materials
  • ... 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 we the lowest tier can only come forth from it's own tier 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.

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.

Best ratios

This table 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.

Crafting machine Modules in Tier 1 Modules in Tier 2 Modules in Tier 3 Modules in Tier 4 Modules in Tier 5 Percentage yield of legendary items
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.344%
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.586%
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.624%
Electromagnetic plant 1 quality / 4 productivity 1 quality / 4 productivity 1 quality / 4 productivity 1 quality / 4 productivity 0 quality / 5 productivity 2.722%
Cryogenic plant 0 quality / 8 productivity 0 quality / 8 productivity 0 quality / 8 productivity 0 quality / 8 productivity 0 quality / 8 productivity 4.835%

Number of crafting machines

If we assume a constant input stream of tier 1 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. This is done by setting after each iteration.

Crafting machine Recyclers Machines producing Tier 1 items Machines producing Tier 2 items Machines producing Tier 3 items Machines producing Tier 4 items Machines producing Tier 5 items
Chemical plant 1 3.4427 0.0290 1.0086 0.0077 0.2979
Assembling machine 3 1 3.3027 0.0365 1.0657 0.0108 0.3286
Foundry 1 2.9551 0.0563 1.1528 0.0208 0.3653
Electromagnetic plant 1 2.7239 0.0709 1.1726 0.0301 0.3474
Cryogenic plant 1 2.3798 0.0972 1.1517 0.0470 0.2700

Crafting machine Recyclers Machines producing Tier 1 items Machines producing Tier 2 items Machines producing Tier 3 items Machines producing Tier 4 items Machines producing Tier 5 items
Chemical plant 108.8978 374.9134 43.5367 12.7555 3.3856 1
Assembling machine 3 70.4576 232.7032 33.9340 10.9500 3.2432 1
Foundry 33.0224 97.5872 21.8308 8.5164 3.1550 1
Electromagnetic plant 24.1178 65.6959 18.4556 7.9448 3.3747 1
Cryogenic plant 19.9316 47.4350 18.2124 8.8138 4.2654 1

Crafting machine Recyclers Machines producing Tier 1 items Machines producing Tier 2 items Machines producing Tier 3 items Machines producing Tier 4 items Machines producing Tier 5 items
Chemical plant 92 318 37 11 3 1
Assembling machine 3 62 205 30 10 3 1
Foundry 30 89 20 8 3 1
Electromagnetic plant 20 56 16 7 3 1
Cryogenic plant 17 41 16 8 4 1