I'm trying to figure out a formula to use to get the TOTAL pollution produced at any given time.
We can get the current evolution factor, and we can get the total game time, and we can (let,s just say for now).... ignore how many enemies bases have been destroyed. (assume zero for my purposes). So this function would be:
pollution_produced = f(time_played, current_evolution_level)
The tricky part is that on each tick the formula used by the game to increment evolution uses (1-current_evolution) as a variable. So it's some kind of exponential decay formula I'd guess.....
Alternatively, if anyone knows of an api call that can just tell me total pollution produced, that'd work too.
Any math wizards out there?
-
- Filter Inserter
- Posts: 478
- Joined: Sat Aug 23, 2014 11:43 pm
- Contact:
Re: Any math wizards out there?
http://lua-api.factorio.com/latest/LuaS ... _pollution
Pollution is the same per chunk so the below code should give the total amount of pollution for the default surface(nauvis)
Pollution is the same per chunk so the below code should give the total amount of pollution for the default surface(nauvis)
Code: Select all
/c
local totalPollution = 0
for chunk in game.surfaces.nauvis.get_chunks() do
totalPollution = totalPollution + game.surfaces.nauvis.get_pollution({chunk.x * 32, chunk.y * 32})
end
Waste of bytes : P
Re: Any math wizards out there?
Thanks! I'll try that.
Doesn't get total pollution produced for the whole game since pollution dissipates but this could still work for what I'm trying to do.
Brilliant. Hopefully that will not eat too many UPI's.Pollution is the same per chunk so the below code should give the total amount of pollution for the default surface(nauvis)
Doesn't get total pollution produced for the whole game since pollution dissipates but this could still work for what I'm trying to do.
Re: Any math wizards out there?
So you are asking (assuming no spawners are/were destroyed), what is the function f(t) such that
where t is the current tick, A is the time evolution increase factor (default 0.000004 according to the wiki), p is the total pollution produced and B is the pollution evolution increase factor (0.000015 according to the wiki).
Assuming there is an smooth function satisfying this relation, we can use a first-order approximation to get a differential equation:
After some "massaging" you realize it is probably a decaying exponential, and since the second term has the argument t we can assume it has up to second order in the exponent, so "guess" a solution in the form:
and calculate the derivative:
So it comes down to finding L and Q, such that for every t:
and since this should hold true for every t you can separate this to two equations - one with t and one without:
And so the original function is:
Note that this assumes the pollution produced (p) does not change with time, but since you can calculate this every tick and you are interested in the current pollution production I think this should work.
Code: Select all
f(t+1) = f(t) + (1-f(t))*(tA + pB)
Assuming there is an smooth function satisfying this relation, we can use a first-order approximation to get a differential equation:
Code: Select all
f'(t) = (1-f(t)) * (tA + pB)
Code: Select all
f(t) = 1 - exp(Lt + Qt²)
Code: Select all
f'(t) = -(L + 2Qt)*exp(Lt + Qt^2)
Code: Select all
-(L + 2Qt) = (tA + pB)
Code: Select all
-L = pB ==> L=-pB
-2Q = A ==> Q = -A/2
Code: Select all
f(t) = 1 - exp(-pBt - At²/2)
Note that this assumes the pollution produced (p) does not change with time, but since you can calculate this every tick and you are interested in the current pollution production I think this should work.
Re: Any math wizards out there?
Wow! I knew there were smart people on this forum! So given....
How do I solve for the p? I think it has something to do with natural logs. But all my logs are fake and the cobwebs in my head just won't let me do math like in the old days.
Code: Select all
f(t) = 1 - exp(-pBt - At²/2)
Re: Any math wizards out there?
Assuming I made no silly mistakes, it should be:
Where E is the current evolution (i.e. f(t)), and by `log` I mean the natural logarithm, of course (not the base 10 engineers often use, or base 2 computer scientists like).
Code: Select all
p = - [log(1-E) + At²/2] / Bt