Planning tools that work only on data stage (e.g. YAFC) need a way to replicate the weight calculation, but the little information given is not enough to explain what is going on.
Example that might involve some rounding
electronic-circuit
1x iron plate (1000)
3x copper cable (250 each)
ingredient_to_weight_coefficient 0.28
---
1750 * 0.28 = 490
but in-game weight is 500
Example that might involve the fact that the item can be placed as entity
wooden-chest
2x wood (2000 each)
ingredient_to_weight_coefficient 0.5
---
4000 * 0.5 = 2000
but in-game weight is 20000 (yes, that's off by an order of magnitude)
I have really no idea what is going on, but need it for cross-surface transportation optimization. Please add detailed information to the auxiliary section.
Add weight calculation documentation
-
- Long Handed Inserter
- Posts: 82
- Joined: Wed Apr 29, 2020 9:53 pm
- Contact:
Re: Add weight calculation documentation
Bumping this: I thought I understood how weight calculation works, but when multiple recipes produce the same item (e.g. limestone in Py's mods) Factorio decides to calculate the weight based on the "extract-limestone-01" recipe instead of the "mining-limestone" recipe. I can find no obvious reason for it to make that choice. (Neither recipe name matches the item name, neither recipe consumes limestone, and both recipes produce only limestone.)
Re: Add weight calculation documentation
I had a look at this, and the algo to determine item weight is quite ... involved. Basically impossible to figure out from the outside. So I added an auxiliary page that describes it and includes an example for the next release, which'll hopefully clear up any questions.
Re: Add weight calculation documentation
Thank you for the additional information, but I'm still not getting the right answers in at least two cases.
The recipe consumes 5 iron plate and 5 copper plate, so the intermediate result is (5*1000 + 5*1000)/1*.5 = 5000.
The recipe doesn't support productivity, and the stack size is 5, so the simple result is 1000000/5 = 200000.
The simple result is larger, so the weight of a pistol is 200000.
However, Factorio says the weight is 100 instead.
I'm guessing the pistol recipe was excluded from consideration because hidden = true?
Neither match the item name, neither use limestone as a catalyst, and both have allow_as_intermediate set true by default. mining-limestone's category is "ground-borer", which comes before extract-limestone-01's category "soil-extraction". I should therefore use mining-limestone to calculate the weight, but if I switch the logic to use extract-limestone-01 instead, I get the same result as Factorio.
I suspect I don't understand what it means for a recipe to fulfill its category. I've attached data-raw-dump.json (as 7z, since the zip refused to upload) and a save for syncing mods, if you need to look at what I'm seeing.
Case 1
There is a vanilla item named "pistol" which is produced by a vanilla recipe named "pistol". Since the names match, that recipe is used for calculating the item weight.The recipe consumes 5 iron plate and 5 copper plate, so the intermediate result is (5*1000 + 5*1000)/1*.5 = 5000.
The recipe doesn't support productivity, and the stack size is 5, so the simple result is 1000000/5 = 200000.
The simple result is larger, so the weight of a pistol is 200000.
However, Factorio says the weight is 100 instead.
I'm guessing the pistol recipe was excluded from consideration because hidden = true?
Case 2
Back to Pyanodon, there are two recipes that produce only limestone: extract-limestone-01 and mining-limestone.Neither match the item name, neither use limestone as a catalyst, and both have allow_as_intermediate set true by default. mining-limestone's category is "ground-borer", which comes before extract-limestone-01's category "soil-extraction". I should therefore use mining-limestone to calculate the weight, but if I switch the logic to use extract-limestone-01 instead, I get the same result as Factorio.
I suspect I don't understand what it means for a recipe to fulfill its category. I've attached data-raw-dump.json (as 7z, since the zip refused to upload) and a save for syncing mods, if you need to look at what I'm seeing.
- Attachments
-
- data-raw-dump.7z
- (1.14 MiB) Downloaded 20 times
-
- Pyanodon save.zip
- (988.89 KiB) Downloaded 15 times
Re: Add weight calculation documentation
Thanks for the feedback! You are right about case 1, hidden recipes aren't even considered when finding the relevant recipe. This logic was done elsewhere so I missed it when documenting. Will add a clarification for it, thanks. The recipe also needs to allow decomposition, turns out.
As for your second case, I did a quick implementation of the sorting in Lua, and it sorts the extract-limestone-01 recipe as the first one. I didn't investigate yet quite why, but maybe you can compare your implementation with mine to see where the difference might come from?
This is the order I get from the attached test mod.
As for your second case, I did a quick implementation of the sorting in Lua, and it sorts the extract-limestone-01 recipe as the first one. I didn't investigate yet quite why, but maybe you can compare your implementation with mine to see where the difference might come from?
This is the order I get from the attached test mod.
Code: Select all
Recipe order:
1: extract-limestone-01
2: soil-separation-2
3: rejects-separation
4: mining-limestone
5: calcinate-separation
6: lithium-hydroxide
7: auog-paddock-mk02-with-dirt
8: py-sodium-hydroxide
9: limestone-void
- Attachments
-
- testmod.zip
- (5.13 KiB) Downloaded 19 times
Re: Add weight calculation documentation
I see at least two problems now. First, I was excluding too many recipes, which is entirely on me.
The second is that when you said "The recipe's category, subgroup, then order," I thought you meant these values:
But you're comparing based on these values instead:
I'm confined to the data stage, and within that restriction I think I've found your subgroup and order values, but not the category. For lithium-hydroxide, for example, I need to convert "chemistry" to "u". There is a recipe category named chemistry (line 965731), but it doesn't have an order. There are 8 places where «"order": "u"» appears, but none of them jump out at me as being related to chemistry or lithium.
The second is that when you said "The recipe's category, subgroup, then order," I thought you meant these values:
Code: Select all
1: lithium-hydroxide: chemistry, ,
2: py-sodium-hydroxide: chemistry, py-rawores-recipes, a8
3: auog-paddock-mk02-with-dirt: crafting, ,
4: mining-limestone: ground-borer, py-drilling, c
5: extract-limestone-01: soil-extraction, ,
6: calcinate-separation: solid-separator, py-fusion-recipes, l
7: rejects-separation: solid-separator, py-items-class, e
8: soil-separation-2: solid-separator, py-items-class, e
9: limestone-void: secondary-crusher, ,
Code: Select all
1: extract-limestone-01: t, c-0, limestone
2: limestone-void: t, c-0, soil
3: rejects-separation: t, c-2, e
4: soil-separation-2: t, c-2, e
5: mining-limestone: t, h, c
6: calcinate-separation: u, b, l
7: lithium-hydroxide: u, bc, ab
8: auog-paddock-mk02-with-dirt: v, a-b-b, c[animal]-b[auog-paddock]
9: py-sodium-hydroxide: v, xb, a8