Page 1 of 1

Infinite resource with probability

Posted: Fri Oct 02, 2015 4:58 pm
by Ranakastrasz
I've been trying to modify the "Deep Ores Mod" by Darloth. I wanted to increase the ratio of stone you get per copper or iron. However, alterations had really bizzare effects.




https://forums.factorio.com/forum/vie ... 97&t=14694
The original.

Code: Select all

{type="item", name="iron-ore", amount=1, probability = 0.35},
{type="item", name="stone", amount=1, probability = 0.25},
{type="item", name="iron-ore", amount=2, probability = 0.40}
First modification. Results in no stone until depleted. Didnt check ratio after that.

Code: Select all

{type="item", name="iron-ore", amount=1, probability = 0.35},
{type="item", name="stone", amount=1, probability = 0.50},
{type="item", name="iron-ore", amount=2, probability = 0.40}
Second attempt. Results in 6 iron per 1 stone, instead of the expected 4:1 ratio.

Code: Select all

{name="iron-ore", amount_min = 1, amount_max = 3, probability = 1.0},
{name="stone", amount_min=1,amount_max = 1, probability = 0.50}
I can only assume that there is a bug here, or I don't understand how this stuff works. Probably both.

Re: Infinite resource with probability

Posted: Sat Oct 03, 2015 11:45 am
by Adil
The original probabilities sum up to 1.

Re: Infinite resource with probability

Posted: Sat Oct 03, 2015 5:30 pm
by Ranakastrasz
I am aware of that. However, according to my research, that shouldn't matter, as they are supposed to all be independent random numbers.

Re: Infinite resource with probability

Posted: Tue Oct 06, 2015 11:10 am
by cartmen180
I played around with probabilities for mining ores some time ago. As I recall, the numbers worked out in the long term across multiple miners.
I am not sure about this but I believe i had the probabilities sum up to 1.

Re: Infinite resource with probability

Posted: Thu Oct 08, 2015 6:26 am
by UberWaffe
@bobingabout had a similar issue at some point with his gems ore (that produces multiple outputs with probabilities).

He fixed it by giving his miner more storage slots.

Code: Select all

storage_slots = 6,
Note: Miner storage slots are not visible in game, but do exist.
The reason being, that miners only have 1 storage slot by default, meaning that when the random numbers do generate more than 1 output in a single tick, there is no storage slots for the others to be put into, hence the engine doesn't create them.

The miner will output the storage slots over multiple ticks.

I believe this is the same issue here. Maybe?

Re: Infinite resource with probability

Posted: Thu Oct 08, 2015 1:37 pm
by Ranakastrasz
o_o
Well, that is almost certainly the problem. If I do the math.....

Well, It doesnt add up at all, since the infinite resource part almost certainly screws up the rest. Certainly explains why I got 100% iron until near depleted in the second case.

Re: Infinite resource with probability

Posted: Mon Oct 19, 2015 9:41 am
by bobingabout
Infinite rersources do tend to mess things up a bit, it works differently for an item result than it does for a fluid result.

Fluids cannot exist freely in the world, so a fluid miner will give a result in a fluid box. they can also exist as fractions, so a fluid miner will give a certain number of fluid per mining cycle. This means that it is quite easy to change how much is produced, so infinite will scale the amount you get based on the amount in the resource.

Mining items are not stored in the machine, but deposited directly into the world. Items in the world can only exist as a stack of one, therefore what you get from mining items becomes a probabillity.

The probabillity of a resource being given is the item probabillity, multiplied by the "mining probabillity", calculated as min(current,normal)/normal (min is a function that returns the lowest value of the 2). so if you have a structure like the oil where normal is 10 times the minimum, then when you start to fall below the normal level as you aproach minimum, your cycles start skipping ores as the probabillity drops.

this basically means that with infinite ores, if you have the normal level or more, you mine as normal, but if you have less than the normal value, you get mining cycles where no ores are returned. so if your minimum is 10% of the normal value, and your item mining probabillity is 10%, then the chance of getting that item per mining cycle is reduced to 1%.

The easy fix for this problem is to set ore infinite values so that they never enter this depleated phase, by setting the normal to the same value as minimum, then the results never change as the ore is depleated to the minimum point. To set it in such a way that you'll never find a field that has less than the minimum, you'll need to set both values to 1.

There are other issues however... for exmaple, the display of the mining drill on infinite ore will display ore/sec, this is not in any way a true representation of what you get for 2 reasons. The first being that it will always give you a number assuming it is giving fluids, so if you have higher than the normal probabillity, it will over-estimate. the second reason is that it will add all ore patchs in the miner's field, where the miner actually mines them one at a time in a random sequence.

Re: Infinite resource with probability

Posted: Tue Oct 20, 2015 8:17 am
by SirRichie
To add to the very nice analysis of bobingabout:

There is also a difference between a miner that has a single ore patch with probability 50% and a miner that has two ore patches with probability 25% (though I have not thoroughly tested this):
It seems that for each mining cycle, Factorio selects a single, non-empty ore patch in the miner's radius. It then evaluates the probability of that ore patch.

This also means that a miner with a single 100% ore patch, will work faster than a miner with a 100% ore patch and 5 10% patches.

Re: Infinite resource with probability

Posted: Tue Oct 20, 2015 9:33 am
by bobingabout
SirRichie wrote:To add to the very nice analysis of bobingabout:

There is also a difference between a miner that has a single ore patch with probability 50% and a miner that has two ore patches with probability 25% (though I have not thoroughly tested this):
It seems that for each mining cycle, Factorio selects a single, non-empty ore patch in the miner's radius. It then evaluates the probability of that ore patch.

This also means that a miner with a single 100% ore patch, will work faster than a miner with a 100% ore patch and 5 10% patches.
From my observations, I will agree with this analysis. This is how I think it works.