[0.13.3] [Rseding91] Smelting progress and rounding errors
[0.13.3] [Rseding91] Smelting progress and rounding errors
These bugs may be splitted into separate reports, but I will post them here because they are related to each other.
Initial question: how many iron plates can be produced using 6 coal and a steel furnace?
Using math:
Energy from coal: 8 Mj (according to the game info) * 6 = 48 Mj
Iron smelting time: 3.5 sec (according to the game info)
Iron smelting time in steel furnace: 3.5 sec / 2 crafting speed = 1.75 sec
Energy consumption: 180 kW (according to the game info)
Putting it all together: 48 000 kJ / (1.75 sec * 180 kW) = 152.38 iron plate.
Using game: exactly 151 iron plate. What? Where is 152-nd plate?
Ok, Factorio, I don't know why, but you produces 151 iron plates for 6 coal.
But how many iron plates will you produce for 24 coal? 151*4=604?
Result = 603.99
Factorio, go home, you are drunk, you've eaten a small piece of my coal.
Actually, I know that 1/3 + 1/3 + 1/3 could be 0.99999, but this case is 1.000001 + 1.000001 + 1.000001 = 2.999999 - and it looks weird.
Initial question: how many iron plates can be produced using 6 coal and a steel furnace?
Using math:
Energy from coal: 8 Mj (according to the game info) * 6 = 48 Mj
Iron smelting time: 3.5 sec (according to the game info)
Iron smelting time in steel furnace: 3.5 sec / 2 crafting speed = 1.75 sec
Energy consumption: 180 kW (according to the game info)
Putting it all together: 48 000 kJ / (1.75 sec * 180 kW) = 152.38 iron plate.
Using game: exactly 151 iron plate. What? Where is 152-nd plate?
Ok, Factorio, I don't know why, but you produces 151 iron plates for 6 coal.
But how many iron plates will you produce for 24 coal? 151*4=604?
Result = 603.99
Factorio, go home, you are drunk, you've eaten a small piece of my coal.
Actually, I know that 1/3 + 1/3 + 1/3 could be 0.99999, but this case is 1.000001 + 1.000001 + 1.000001 = 2.999999 - and it looks weird.
Re: [0.13.3] Smelting progress and rounding errors
That's the nature of floating point numbers when you store them with some fixed amount of space If you can solve floating point rounding issues in computers I'm sure a large amount of people would love to know.
Until then, that's just how it is in Factorio.
Until then, that's just how it is in Factorio.
If you want to get ahold of me I'm almost always on Discord.
Re: [0.13.3] Smelting progress and rounding errors
(152.38-151)/152.38 = 0.9% this is an extermely huge rounding error.Rseding91 wrote:That's the nature of floating point numbers when you store them with some fixed amount of space If you can solve floating point rounding issues in computers I'm sure a large amount of people would love to know.
Until then, that's just how it is in Factorio.
I would believe that you are using 106 ticks unstead of 105 ticks (1.75 sec) for smelting, because this will give 48018 kJ energy, pretty close.
About the second part:
Assume, that 6 coals give enough energy for 151 iron plates and a small epsilon due to rounding errors, and this epsilon is definitely positive.
My question is how 4 positive epsilons may be negative?
Edit: By the way, 8000 Mj is an integer number, 180 kW = 180 kJ/sec = 3 kJ/tick = 3 kJ is an integer number, production time 105 or 106 ticks also is an integer number. Everything here can be represented in the integer numbers, and if you are using float C++ type it doesn't give any rounding errors within integer numbers and 2^23 values, because these numbers can be stored using only significand fields.
Anyway, these errors should have сumulative effect less than 1 production unit within 38 hours for float or 2M years for double.
So I think the second bug has the lowest ever priority, but the first bug doesn't look like rounding errors.
Re: [0.13.3] Smelting progress and rounding errors
And again, I've wrote a small piece of code which simulates steel furnace behaviour (using float numbers) and it still gives exact results for 6 coal or 24 coal:
6 coal: http://codepad.org/L5BmSVz3 - 152 iron plates + 80/210 ~ 152.38 (as predicted by math)
24 coal: http://codepad.org/rIyBIrN4 - 609 iron plates + 110/210 ~ 609.52 (also predicted)
I am not asking to share your code, but it looks like you overrounded it.
6 coal: http://codepad.org/L5BmSVz3 - 152 iron plates + 80/210 ~ 152.38 (as predicted by math)
24 coal: http://codepad.org/rIyBIrN4 - 609 iron plates + 110/210 ~ 609.52 (also predicted)
I am not asking to share your code, but it looks like you overrounded it.
Re: [0.13.3] Smelting progress and rounding errors
After looking into it there's no rounding error but there is a flaw in how the crafting machine consumes and produces items in regards to the energy used.
Each tick energy is consumed and applied to the progress of the current recipe. When the progress is >= required it's reset to 0 and items are given. That means a *little* bit of energy is lost with each recipe cycle.
I'll see if I can figure out a way to make it not drop that little bit.
Each tick energy is consumed and applied to the progress of the current recipe. When the progress is >= required it's reset to 0 and items are given. That means a *little* bit of energy is lost with each recipe cycle.
I'll see if I can figure out a way to make it not drop that little bit.
If you want to get ahold of me I'm almost always on Discord.
Re: [0.13.3] [Rseding91] Smelting progress and rounding errors
Fixed for 0.13.5.
If you want to get ahold of me I'm almost always on Discord.
Re: [0.13.3] [Rseding91] Smelting progress and rounding errors
Now this got me interestedRseding91 wrote:Fixed for 0.13.5.
Do you keep the energy overshot in the furnace as a "bonus" for the next item produced? Then how do you respect the fact you probably don't know what the next item will be (iron/copper/...) ?
Or do you transfer the overshot energy in the furnance back to the energy stock?
It matters because it impacts the production time. The former gets a small bonus which (I think) accumulates and results in a one-tick-faster-producted-item after several iterations.
By the way nice find XKnight I'm so used to be drowned in bazillions of items I'd never accounted for these small number offsets. But it should be precise whereever possible, I agree, so thanks to the devs for being strict and fixing this one!
Re: [0.13.3] [Rseding91] Smelting progress and rounding errors
Thank you alot!Rseding91 wrote:Fixed for 0.13.5.
I have only one last question about new implementation:
What will happen if some item doesn't need a full tick to be finished? Will the rest of this tick be ignored or it will be used for the next item?
Also, can you clarify energy consumption in this case and production bonus.
Thank you in advance.
Re: [0.13.3] [Rseding91] Smelting progress and rounding errors
It ends up getting used for the next item. That was the bug that caused it to slowly use extra energy.XKnight wrote:Thank you alot!Rseding91 wrote:Fixed for 0.13.5.
I have only one last question about new implementation:
What will happen if some item doesn't need a full tick to be finished? Will the rest of this tick be ignored or it will be used for the next item?
Also, can you clarify energy consumption in this case and production bonus.
Thank you in advance.
If you want to get ahold of me I'm almost always on Discord.
Re: [0.13.3] [Rseding91] Smelting progress and rounding errors
So, hmmm, isn't this then creating the situation I described above with uneven timing between produced items because some get a headstart and falling into an earlier tick?Rseding91 wrote:It ends up getting used for the next item. That was the bug that caused it to slowly use extra energy.
Re: [0.13.3] [Rseding91] Smelting progress and rounding errors
No, the total time spent comes out to exactly what the math would say.dee- wrote:So, hmmm, isn't this then creating the situation I described above with uneven timing between produced items because some get a headstart and falling into an earlier tick?Rseding91 wrote:It ends up getting used for the next item. That was the bug that caused it to slowly use extra energy.
With 6 coal and 200 iron ore in a steel furnace in 0.13.5 it produces exactly 152 iron plates and the furnace is sitting at 38% progress towards the 153rd plate after the exact ticks you would expect it to take based off the crafting time and speed of the furnace.
If you want to get ahold of me I'm almost always on Discord.
Re: [0.13.3] [Rseding91] Smelting progress and rounding errors
Yes, it is.dee- wrote:So, hmmm, isn't this then creating the situation I described above with uneven timing between produced items because some get a headstart and falling into an earlier tick?Rseding91 wrote:It ends up getting used for the next item. That was the bug that caused it to slowly use extra energy.
If we need 1.5 ticks to produce one item, then first item will be produced at the second tick, while second item - at the third tick.
But overall time spent is equal to the value predicted by math.
But I think this is much more better than current behaviour. Because all calculations and all perfect ratios don't account for one extra tick in production time.
For example, according to math we need 105 ticks to produce one iron plate in steel furnace, but in fact - 106 ticks.
At the same time for one steel plate we need 525 ticks, but real value is 526 ticks.
So we think that correct ratio is 1:1 (1 furnace for iron production and 1 furnace for steel production), but real ratio is 526:530.
And this difference is even bigger for quickly made items and for speed modules.
(for green circuit production using assembler III the difference is about 4%, with 4 speed modules inside - 12.5%, with 4 speed beacons around - 20.8%)
Re: [0.13.3] [Rseding91] Smelting progress and rounding errors
Does this also apply to other machines that craft stuff over time, like assemblers?Rseding91 wrote:No, the total time spent comes out to exactly what the math would say.dee- wrote:So, hmmm, isn't this then creating the situation I described above with uneven timing between produced items because some get a headstart and falling into an earlier tick?Rseding91 wrote:It ends up getting used for the next item. That was the bug that caused it to slowly use extra energy.
With 6 coal and 200 iron ore in a steel furnace in 0.13.5 it produces exactly 152 iron plates and the furnace is sitting at 38% progress towards the 153rd plate after the exact ticks you would expect it to take based off the crafting time and speed of the furnace.
Re: [0.13.3] [Rseding91] Smelting progress and rounding errors
Yes, furnaces and assembling machines.
If you want to get ahold of me I'm almost always on Discord.
Re: [0.13.3] [Rseding91] Smelting progress and rounding errors
Alas, the perils of quantized time.XKnight wrote:Yes, it is.dee- wrote:So, hmmm, isn't this then creating the situation I described above with uneven timing between produced items because some get a headstart and falling into an earlier tick?Rseding91 wrote:It ends up getting used for the next item. That was the bug that caused it to slowly use extra energy.
If we need 1.5 ticks to produce one item, then first item will be produced at the second tick, while second item - at the third tick.
But overall time spent is equal to the value predicted by math.
But I think this is much more better than current behaviour. Because all calculations and all perfect ratios don't account for one extra tick in production time.
For example, according to math we need 105 ticks to produce one iron plate in steel furnace, but in fact - 106 ticks.
At the same time for one steel plate we need 525 ticks, but real value is 526 ticks.
So we think that correct ratio is 1:1 (1 furnace for iron production and 1 furnace for steel production), but real ratio is 526:530.
And this difference is even bigger for quickly made items and for speed modules.
(for green circuit production using assembler III the difference is about 4%, with 4 speed modules inside - 12.5%, with 4 speed beacons around - 20.8%)
Hm... considering our own world this goes deep. Maybe our forum representations as inserters are a tongue-in-cheek remark by Wube knowing about The Higher Ones, which are playing a round of their favorite Universorio with us...
That aside
How about switching the time system of factorio to an event-based sorted list of upcoming game events with a linear approximation between the event points? That way a factory says "in now+1.0 realtime seconds summon a new iron plate and have 10 Watt consumed." Then the game can interpolate between "now" having a state of 100 plates and 500 W and "now+1.0" with 101 plates and 490 Watt seamlessy and with (for plates) or without any quantization (for power) . Shouldn't be too hard.
Okay, forget it. Thanks for the insights everyone!
Re: [0.13.3] [Rseding91] Smelting progress and rounding errors
Hey mates ..
I came here from the 0.13.5 release changes link. I always wondered why the numbers in the productivity tab not matched the theoretical numbers. I wrote a mod that reads and extracts the "crafting_progress" from the assembler entity and you could see the "rounding" (not sure if the right word here) and I thought well it is how it is.
Anyway, I'm posting here because I think the productivity modules have a related problem - I might entirely wrong on this but maybe you can help me out.
I have an Assembling machine 3 - with 12 beacons around all have speed 3 modules
Crafting Speed: 11.25 with 4 speed modules in the assembler
Crafting Speed: 8 with 4 productivity modules in the assembler
If you look at the attachments you see the production tab for it. The Speed module image shows the right numbers (according to theory) but the productivity modules should have -40% consumption products - because its the same amount of items produced.
4000 * (1-0.4) = 2400
1300 * (1-0.4) = 780
As you can see in the image the numbers come not even close even if I give it a bit giggle room for rounding
Nothing else consumes any iron-plates or copper-cables, the numbers you see are only from the electronic circuit production
I'm sure I oversee something obvious here, thats because I thought I ask it here.
If you need more data or anything else I could help to make clear what I mean - feel free to ask
Thanks
Case
I came here from the 0.13.5 release changes link. I always wondered why the numbers in the productivity tab not matched the theoretical numbers. I wrote a mod that reads and extracts the "crafting_progress" from the assembler entity and you could see the "rounding" (not sure if the right word here) and I thought well it is how it is.
Anyway, I'm posting here because I think the productivity modules have a related problem - I might entirely wrong on this but maybe you can help me out.
I have an Assembling machine 3 - with 12 beacons around all have speed 3 modules
Crafting Speed: 11.25 with 4 speed modules in the assembler
Crafting Speed: 8 with 4 productivity modules in the assembler
If you look at the attachments you see the production tab for it. The Speed module image shows the right numbers (according to theory) but the productivity modules should have -40% consumption products - because its the same amount of items produced.
4000 * (1-0.4) = 2400
1300 * (1-0.4) = 780
As you can see in the image the numbers come not even close even if I give it a bit giggle room for rounding
Nothing else consumes any iron-plates or copper-cables, the numbers you see are only from the electronic circuit production
I'm sure I oversee something obvious here, thats because I thought I ask it here.
If you need more data or anything else I could help to make clear what I mean - feel free to ask
Thanks
Case
- Attachments
-
- Electronic Circuits with Speed Modules
- Speed_Modules.jpg (485.78 KiB) Viewed 10327 times
-
- Electronic Circuits with Productivity Modules
- Productivity_Modules.jpg (502.39 KiB) Viewed 10327 times
Check out the The Nano Factory - only one assembler gameplay
Check out the Bobs Nano Factory - bobs mod - one assembling machine gameplay
Check out the Bobs Nano Factory - bobs mod - one assembling machine gameplay
Re: [0.13.3] [Rseding91] Smelting progress and rounding errors
The stats window time views aren't 100% accurate. Especially so the smaller ones due to how "over time" stats are measured.
You need to measure exact counts using dedicated chests.
You need to measure exact counts using dedicated chests.
If you want to get ahold of me I'm almost always on Discord.
Re: [0.13.3] [Rseding91] Smelting progress and rounding errors
Hmm .. it shows the recent change just fine I can see that after the update to 0.13.5 I produce ~100 items more with my setup. But I will check this out and see what I get ..
thanks for the response
thanks for the response
Check out the The Nano Factory - only one assembler gameplay
Check out the Bobs Nano Factory - bobs mod - one assembling machine gameplay
Check out the Bobs Nano Factory - bobs mod - one assembling machine gameplay
Re: [0.13.3] [Rseding91] Smelting progress and rounding errors
Yes with chests the item count is ok.
thanks
thanks
Check out the The Nano Factory - only one assembler gameplay
Check out the Bobs Nano Factory - bobs mod - one assembling machine gameplay
Check out the Bobs Nano Factory - bobs mod - one assembling machine gameplay